/* Mobile business dashboard — drawer, bottom nav, previews */

.ip-mobile-menu-btn,
.ip-mobile-bottom-nav,
.ip-mobile-drawer,
.ip-mobile-fab {
  display: none;
}

@media (max-width: 820px) {
  .ip-mobile-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    margin-right: 10px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-3);
    color: var(--text-primary);
    font-size: 18px;
    cursor: pointer;
  }

  .topbar {
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
  }

  .topbar-left {
    flex: 1 1 calc(100% - 52px);
    min-width: 0;
  }

  .topbar-left h2 {
    font-size: 26px;
  }

  .topbar-left p {
    font-size: 12.5px;
  }

  .top-actions {
    flex: 1 1 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    width: 100%;
  }

  .top-actions .ip-btn-link {
    flex: 1 1 auto;
    min-width: 0;
    text-align: center;
    font-size: 12px;
    padding: 8px 12px;
  }

  .top-actions .theme-toggle #ipThemeLabel {
    display: none;
  }

  .top-actions .theme-toggle {
    margin-left: auto;
  }

  .ip-current-user {
    max-width: 140px;
  }

  /* Bottom navigation */
  .ip-mobile-bottom-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 900;
    height: 62px;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
    background: var(--bg-2);
    border-top: 1px solid var(--border);
    box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.25);
    justify-content: space-around;
    align-items: stretch;
    gap: 4px;
  }

  .invoicepulse-app.light .ip-mobile-bottom-nav {
    background: #fff;
    box-shadow: 0 -4px 20px rgba(15, 23, 36, 0.08);
  }

  .ip-mob-nav-item {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    padding: 4px 6px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--text-muted);
    text-decoration: none;
    font-family: inherit;
    font-size: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease;
  }

  .ip-mob-nav-item.is-active {
    color: var(--accent);
    background: var(--accent-dim);
  }

  .ip-mob-nav-icon {
    font-size: 16px;
    line-height: 1;
  }

  .ip-mob-nav-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
  }

  /* Drawer */
  .ip-mobile-drawer {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 10000;
    pointer-events: none;
    visibility: hidden;
    transition: visibility 0.25s ease;
  }

  .ip-mobile-drawer.is-open {
    pointer-events: auto;
    visibility: visible;
  }

  .ip-mobile-drawer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    opacity: 0;
    transition: opacity 0.25s ease;
  }

  .ip-mobile-drawer.is-open .ip-mobile-drawer-backdrop {
    opacity: 1;
  }

  .ip-mobile-drawer-panel {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(300px, 88vw);
    max-width: 100%;
    background: var(--bg-2);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform 0.28s ease;
    overflow: hidden;
  }

  .invoicepulse-app.light .ip-mobile-drawer-panel {
    background: #fff;
  }

  .ip-mobile-drawer.is-open .ip-mobile-drawer-panel {
    transform: translateX(0);
  }

  .ip-mobile-drawer-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    padding: 16px 14px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }

  .ip-mobile-drawer-head .brand {
    padding: 0;
    border: none;
    flex: 1;
    min-width: 0;
  }

  .ip-mobile-drawer-head .brand-text h1 {
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .ip-mobile-drawer-close {
    flex-shrink: 0;
    font-size: 22px;
    line-height: 1;
    padding: 4px 10px;
    min-width: 0;
  }

  .ip-mobile-drawer-nav {
    flex: 1;
    overflow-y: auto;
    padding: 12px 12px 20px;
    -webkit-overflow-scrolling: touch;
  }

  .ip-mobile-drawer-nav .nav-link,
  .ip-mobile-drawer-nav .nav-sublink {
    margin-bottom: 2px;
  }

  .ip-mobile-drawer-nav .nav-sublink {
    display: flex;
    margin-left: 8px;
  }

  .ip-mobile-drawer-foot {
    flex-shrink: 0;
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border);
  }

  /* FAB for new quote/invoice */
  .ip-mobile-fab {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    right: 16px;
    bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    z-index: 850;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0db868, #10d87a);
    color: #061a0e;
    font-size: 28px;
    font-weight: 400;
    line-height: 1;
    text-decoration: none;
    box-shadow: 0 6px 24px rgba(16, 216, 122, 0.45);
  }

  /* Panels & tables */
  .panel {
    border-radius: 12px;
  }

  .panel-header {
    flex-wrap: wrap;
    gap: 8px;
  }

  .ip-table-wrap {
    margin: 0 -4px;
    padding: 0 4px;
    -webkit-overflow-scrolling: touch;
  }

  .ip-data-table {
    font-size: 12.5px;
  }

  .ip-data-table th,
  .ip-data-table td {
    padding: 10px 8px;
    white-space: nowrap;
  }

  .ip-list-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .ip-list-toolbar-filters {
    width: 100%;
  }

  .bottom-grid,
  .content-grid {
    gap: 16px;
  }

  .ip-form-row-2 {
    grid-template-columns: 1fr;
  }

  .ip-business-view .plan-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .ip-plan-row-block .plan-row-value {
    max-width: 100%;
    text-align: left;
  }

  /* Doc builder */
  .ip-wizard-top {
    flex-direction: column;
    align-items: stretch;
  }

  .ip-wizard-title {
    font-size: 18px;
  }

  .ip-wizard-footer,
  .ip-wizard-form-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .ip-wizard-form-footer .btn-primary {
    margin-left: 0;
    width: 100%;
  }

  .ip-line-items-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .ip-a4-frame--wizard {
    min-height: 200px;
    padding: 8px 0;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
  }

  .ip-wizard-preview-panel--a4 {
    padding: 12px 8px 20px;
  }

  /* Invoice / quote preview modal — full-screen friendly */
  .ip-modal.ip-modal-a4.is-open {
    padding: 0;
    align-items: stretch;
  }

  .ip-modal-a4 .ip-modal-a4-box {
    max-width: 100%;
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    max-height: none;
    margin: 0;
    border-radius: 0;
    border-left: none;
    border-right: none;
    padding: 12px 10px calc(16px + env(safe-area-inset-bottom, 0px));
    display: flex;
    flex-direction: column;
  }

  .ip-modal-a4-toolbar {
    margin: 0 40px 10px 0;
    flex-shrink: 0;
  }

  .ip-modal-a4-toolbar .btn {
    font-size: 12px;
    padding: 8px 12px;
  }

  .ip-a4-frame--modal {
    flex: 1;
    min-height: 0;
    width: 100%;
    max-width: 100%;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    align-items: flex-start;
    justify-content: flex-start;
    padding: 4px 0 12px;
  }

  .ip-invoice-view-body {
    width: 100%;
    min-width: 0;
    overflow: visible;
    display: flex;
    justify-content: center;
  }

  .ip-invoice-view-body .ip-doc-preview.ip-a4-sheet {
    width: 210mm;
    max-width: none;
    max-height: none;
    min-height: auto;
    aspect-ratio: 210 / 297;
    flex-shrink: 0;
    overflow: visible;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  }

  /* Generic modals */
  .ip-modal {
    padding: 12px;
    align-items: flex-end;
  }

  .ip-modal-box {
    max-height: 92vh;
    max-height: 92dvh;
    border-radius: 14px 14px 0 0;
  }

  .ip-modal-view .ip-modal-view-box {
    max-width: 100%;
  }

  .ip-modal-actions {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .ip-modal-actions .btn {
    width: 100%;
  }

  /* Quick invoice on dashboard */
  .ip-quick-invoice-grid {
    grid-template-columns: 1fr;
  }

  .stat-card .stat-value {
    font-size: 22px;
  }

  /* Desktop-only / mobile-only dashboard blocks */
  .ip-dash-desktop-only {
    display: none !important;
  }

  .ip-dash-mobile-only {
    display: block;
  }

  .ip-dashboard-layout {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  .ip-dash-quick-section {
    order: 10;
  }

  .ip-mobile-dash-hero {
    padding: 18px 16px;
    border-radius: 14px;
    background: linear-gradient(145deg, color-mix(in srgb, var(--accent) 18%, var(--bg-2)), var(--bg-2));
    border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--border));
  }

  .invoicepulse-app.light .ip-mobile-dash-hero {
    background: linear-gradient(145deg, #ecfdf3, #fff);
    border-color: #bbf7d0;
  }

  .ip-mobile-dash-stat-label {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 4px;
  }

  .ip-mobile-dash-stat-value {
    display: block;
    font-family: 'Instrument Serif', serif;
    font-size: 32px;
    line-height: 1.1;
    color: var(--text-primary);
  }

  .ip-mobile-dash-stat-meta {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
  }

  .ip-mobile-dash-cta {
    width: 100%;
    justify-content: center;
    margin-top: 14px;
    padding: 14px 18px;
    font-size: 15px;
  }

  .ip-mobile-dash-recent {
    margin: 0;
  }

  .ip-mobile-doc-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .ip-mobile-doc-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg-3);
    text-decoration: none;
    color: inherit;
  }

  .invoicepulse-app.light .ip-mobile-doc-card {
    background: #f9fafb;
  }

  .ip-mobile-doc-main {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
  }

  .ip-mobile-doc-number {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
  }

  .ip-mobile-doc-client {
    font-size: 12px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .ip-mobile-doc-end {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    flex-shrink: 0;
  }

  .ip-mobile-doc-amount {
    font-weight: 600;
    font-size: 14px;
    color: var(--accent);
  }

  .ip-mobile-quick-invoice-panel .panel-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .ip-mob-collapsible {
    display: none;
  }

  .ip-quick-invoice-expanded .ip-mob-collapsible {
    display: block;
  }

  .ip-mob-toggle-extra {
    width: 100%;
    margin-bottom: 8px;
  }

  .ip-table-bulk-bar {
    display: none !important;
  }

  .ip-panel-header-actions {
    flex-wrap: wrap;
    gap: 6px;
  }

  .ip-panel-header-actions .btn {
    font-size: 11px;
    padding: 7px 10px;
  }

  /* Card-style data tables */
  .ip-data-table.ip-mobile-cards {
    border: 0;
    background: transparent;
  }

  .ip-data-table.ip-mobile-cards thead {
    display: none;
  }

  .ip-data-table.ip-mobile-cards tbody tr {
    display: block;
    margin-bottom: 10px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-3);
    cursor: pointer;
  }

  .invoicepulse-app.light .ip-data-table.ip-mobile-cards tbody tr {
    background: #fff;
  }

  .ip-data-table.ip-mobile-cards tbody tr.is-selected {
    border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  }

  .ip-data-table.ip-mobile-cards tbody td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 5px 0;
    border: none;
    white-space: normal;
    text-align: right;
  }

  .ip-data-table.ip-mobile-cards tbody td::before {
    content: attr(data-label);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    text-align: left;
    flex-shrink: 0;
  }

  .ip-data-table.ip-mobile-cards tbody td.ip-mob-hide {
    display: none !important;
  }

  .ip-data-table.ip-mobile-cards tbody td.ip-mob-primary {
    display: block;
    padding: 0 0 8px;
    margin-bottom: 6px;
    border-bottom: 1px solid var(--border);
    text-align: left;
  }

  .ip-data-table.ip-mobile-cards tbody td.ip-mob-primary::before {
    display: none;
  }

  .ip-data-table.ip-mobile-cards tbody td.ip-mob-primary .doc-number {
    font-size: 15px;
  }

  .ip-data-table.ip-mobile-cards tbody td.ip-mob-amount {
    font-weight: 600;
    color: var(--accent);
  }

  .ip-data-table.ip-mobile-cards tbody td.ip-table-actions {
    display: block;
    padding: 10px 0 0;
    margin-top: 4px;
    border-top: 1px dashed var(--border);
    cursor: default;
  }

  .ip-data-table.ip-mobile-cards tbody td.ip-table-actions::before {
    display: none;
  }

  .ip-data-table.ip-mobile-cards .ip-actions-menu-toggle {
    display: inline-flex;
    width: 100%;
    justify-content: center;
  }

  .ip-data-table.ip-mobile-cards .ip-row-actions {
    right: auto;
    left: 0;
    width: 100%;
    min-width: 0;
  }

  .ip-data-table.ip-mobile-cards--settings tbody tr {
    cursor: default;
  }

  .ip-mob-primary .ip-mob-primary-title {
    display: block;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.3;
  }

  .ip-mob-primary .ip-mob-sub {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: var(--muted, #8896b0);
    line-height: 1.35;
    word-break: break-word;
  }

  .ip-team-table .ip-team-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .ip-team-table .ip-team-actions .btn {
    flex: 1 1 calc(50% - 4px);
    justify-content: center;
  }

  .ip-email-notify-table.ip-mobile-cards tbody td:first-child {
    font-weight: inherit;
    color: inherit;
  }

  .ip-email-notify-table.ip-mobile-cards tbody td.ip-mob-primary .ip-mob-inline-badge {
    display: inline-flex;
    margin: 0 0 6px;
  }

  .ip-email-notify-table.ip-mobile-cards tbody td.ip-email-cell-actions {
    display: block;
    padding-top: 10px;
    margin-top: 8px;
    border-top: 1px solid var(--border, rgba(255, 255, 255, 0.1));
  }

  .ip-email-notify-table.ip-mobile-cards tbody td.ip-email-cell-actions .btn {
    width: 100%;
    justify-content: center;
  }

  .ip-quick-gateway-group {
    margin-bottom: 4px;
  }

  .ip-gateway-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .ip-gateway-picker-option {
    position: relative;
    flex: 1 1 calc(50% - 4px);
    min-width: 120px;
    margin: 0;
    cursor: pointer;
  }

  .ip-gateway-picker-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
  }

  .ip-gateway-picker-visual {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2px 4px;
    border: none;
    background: transparent;
    box-shadow: none;
    min-height: 0;
  }

  .ip-gateway-picker-option input:checked + .ip-gateway-picker-visual,
  .ip-gateway-picker-option.is-selected .ip-gateway-picker-visual {
    border: none;
    background: transparent;
    box-shadow: none;
  }

  .ip-gateway-picker-option:not(:has(input:checked)) .ip-pay-logo-img {
    opacity: 0.45;
  }

  .ip-gateway-picker-visual .ip-pay-logo-img {
    max-height: 28px;
    width: auto;
    max-width: 100%;
    object-fit: contain;
    background: none;
    border: none;
    box-shadow: none;
  }

  .ip-gateway-picker-visual .ip-pay-logo-badge {
    font-size: 9px;
    padding: 4px 8px;
    min-height: 24px;
  }
}

/* Desktop: hide mobile-only blocks */
@media (min-width: 821px) {
  .ip-dash-mobile-only {
    display: none !important;
  }

  .ip-dash-desktop-only {
    display: revert;
  }

  .stats-grid.ip-dash-desktop-only {
    display: grid;
  }

  .content-grid.ip-dash-desktop-only {
    display: grid;
  }

  .quick-grid.ip-dash-desktop-only {
    display: grid;
  }

  .bottom-grid.ip-dash-quick-section {
    display: grid;
  }
}

@media (max-width: 480px) {
  .main {
    padding: 12px 12px 84px;
  }

  .topbar-left h2 {
    font-size: 22px;
  }

  .top-actions .ip-btn-link:not(.btn-primary) {
    display: none;
  }

  .top-actions .btn-primary.ip-btn-link {
    flex: 1 1 100%;
  }

  .ip-mob-nav-label {
    font-size: 9px;
  }
}
