  :root {
    --bg: #0a0a0a;
    --panel: #131313;
    --panel-2: #1a1a1a;
    --border: #262626;
    --lime: #c8ff3d;
    --cyan: #3de8ff;
    --amber: #ffb020;
    --text: #f0f0f0;
    --text-dim: #8a8a8a;
    --text-faint: #555;
    --danger: #ff4d4d;
    --radius: 14px;
  }

  * { box-sizing: border-box; }

  /* Fix: inputs/selects/textareas default to min-width:auto, which lets them
     refuse to shrink inside flex/grid rows and push sibling elements (like the
     delete "✕" buttons in the Package Editor) outside their card. Applies globally
     so this class of bug can't recur in any new flex/grid row we add later. */
  input, select, textarea {
    min-width: 0;
  }

  /* Safety net: never allow horizontal scroll/bleed at the page level even if a
     future element miscalculates its width. */
  html, body {
    overflow-x: hidden;
  }

  body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
  }

  .app {
    max-width: 720px;
    margin: 0 auto;
    padding: 20px 16px 100px;
  }

  /* Header */
  .brand-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0 20px;
  }
  .brand-header .logo {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.5px;
  }
  .brand-header .logo span { color: var(--lime); }
  .brand-header .tag {
    font-size: 11px;
    color: var(--text-dim);
    letter-spacing: 1px;
    text-transform: uppercase;
  }
  .logout-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--panel);
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Section card */
  .section {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
    overflow: hidden;
  }
  .section-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
  }
  .section-num {
    width: 26px;
    height: 26px;
    border-radius: 8px;
    background: rgba(200,255,61,0.12);
    color: var(--lime);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    flex-shrink: 0;
  }
  .section-title {
    font-size: 15px;
    font-weight: 700;
    flex: 1;
  }
  .section-body { padding: 18px; }

  /* Toggle switch (Section 3/4 on-off) */
  .toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 26px;
    flex-shrink: 0;
  }
  .toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
  }
  .toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 26px;
    transition: 0.2s;
  }
  .toggle-slider::before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: var(--text-dim);
    border-radius: 50%;
    transition: 0.2s;
  }
  .toggle-switch input:checked + .toggle-slider {
    background: rgba(200,255,61,0.15);
    border-color: var(--lime);
  }
  .toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(18px);
    background: var(--lime);
  }

  /* Form fields */
  .field { margin-bottom: 14px; }
  .field:last-child { margin-bottom: 0; }
  .field label {
    display: block;
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 6px;
    font-weight: 600;
  }
  .field input[type="text"],
  .field input[type="date"],
  .field input[type="file"],
  .field select {
    width: 100%;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s;
  }
  .field input:focus, .field select:focus {
    border-color: var(--lime);
  }
  .field input[readonly] {
    color: var(--text-dim);
    background: #101010;
  }
  .field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }

  #f-payment-amount {
    height: 56px;
    font-size: 20px;
    font-weight: 700;
    padding: 12px 16px;
  }

  /* Category groups for price selection */
  .category {
    margin-bottom: 18px;
  }
  .category:last-child { margin-bottom: 0; }
  .category-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--cyan);
    letter-spacing: 1px;
    text-transform: uppercase;
    margin-bottom: 8px;
  }
  .price-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 8px;
    transition: border-color 0.15s, background 0.15s;
  }
  .price-item:last-child { margin-bottom: 0; }
  .price-item.checked {
    border-color: var(--lime);
    background: rgba(200,255,61,0.06);
  }
  .price-item .checkbox {
    width: 20px;
    height: 20px;
    border-radius: 6px;
    border: 2px solid var(--text-faint);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s;
  }
  .price-item.checked .checkbox {
    background: var(--lime);
    border-color: var(--lime);
  }
  .price-item.checked .checkbox::after {
    content: '✓';
    color: #000;
    font-size: 13px;
    font-weight: 900;
  }
  .price-item .info { flex: 1; min-width: 0; }
  .price-item .name { font-size: 14px; font-weight: 600; }
  .price-item .detail {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 2px;
    line-height: 1.4;
  }
  .price-item .rate {
    font-size: 13px;
    color: var(--amber);
    font-weight: 700;
    white-space: nowrap;
  }
  .price-item .qty-box {
    width: 54px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 6px;
    color: var(--text);
    text-align: center;
    font-size: 14px;
    outline: none;
    flex-shrink: 0;
  }
  .price-item .qty-box:focus { border-color: var(--lime); }

  .auto-badge {
    font-size: 10px;
    color: var(--cyan);
    background: rgba(61,232,255,0.1);
    padding: 3px 8px;
    border-radius: 6px;
    white-space: nowrap;
    font-weight: 700;
  }

  /* Running total bar */
  .total-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: var(--panel-2);
    border-top: 1px solid var(--border);
  }
  .total-bar .label { font-size: 13px; color: var(--text-dim); font-weight: 600; }
  .total-bar .value { font-size: 20px; font-weight: 800; color: var(--lime); }

  /* Buttons */
  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 13px 20px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 700;
    border: none;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s;
  }
  .btn:active { transform: scale(0.98); }
  .btn-primary { background: var(--lime); color: #000; }
  .btn-secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
  .btn-danger { background: rgba(255,77,77,0.12); color: var(--danger); border: 1px solid rgba(255,77,77,0.3); }
  .btn-full { width: 100%; }
  .btn:disabled { opacity: 0.4; cursor: not-allowed; }

  .action-bar {
    display: flex;
    gap: 10px;
    margin-top: 16px;
  }
  .action-bar .btn { flex: 1; }

  /* Screenshot upload */
  .upload-zone {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 24px 16px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s;
  }
  .upload-zone:hover { border-color: var(--lime); }
  .upload-zone .icon { font-size: 28px; margin-bottom: 8px; }
  .upload-zone .text { font-size: 13px; color: var(--text-dim); }

  .screenshot-list { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; }
  .screenshot-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px;
  }
  .screenshot-card img {
    width: 52px;
    height: 52px;
    object-fit: cover;
    border-radius: 8px;
    flex-shrink: 0;
  }
  .screenshot-card input[type="text"] {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    color: var(--text);
    font-size: 13px;
    outline: none;
  }
  .screenshot-card input:focus { border-color: var(--lime); }
  .screenshot-card .remove-btn {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: rgba(255,77,77,0.1);
    color: var(--danger);
    border: none;
    font-size: 16px;
    cursor: pointer;
    flex-shrink: 0;
  }

  /* CSV upload */
  .csv-summary {
    margin-top: 14px;
    padding: 12px 14px;
    background: rgba(200,255,61,0.06);
    border: 1px solid rgba(200,255,61,0.2);
    border-radius: 10px;
    font-size: 13px;
  }
  .csv-summary .row { display: flex; justify-content: space-between; margin-bottom: 4px; }
  .csv-summary .row:last-child { margin-bottom: 0; }
  .csv-summary .row .k { color: var(--text-dim); }
  .csv-summary .row .v { font-weight: 700; }
  .csv-summary .final { color: var(--lime); font-size: 15px; }

  .csv-table-wrap {
    margin-top: 12px;
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
  }
  table.csv-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
  }
  table.csv-table th {
    position: sticky;
    top: 0;
    background: var(--panel-2);
    text-align: left;
    padding: 8px 10px;
    color: var(--text-dim);
    font-weight: 700;
    border-bottom: 1px solid var(--border);
  }
  table.csv-table td {
    padding: 7px 10px;
    border-bottom: 1px solid var(--border);
  }
  table.csv-table tr:last-child td { border-bottom: none; }

  /* Format toggle (Section 4) */
  .format-toggle {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    background: var(--panel-2);
    padding: 4px;
    border-radius: 10px;
    border: 1px solid var(--border);
  }
  .format-btn {
    flex: 1;
    padding: 10px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
  }
  .format-btn.active {
    background: var(--lime);
    color: #000;
  }

  /* Editable CSV table cells */
  table.csv-table.editable td { padding: 4px 6px; }
  .cell-input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 8px;
    color: var(--text);
    font-size: 12px;
    outline: none;
  }
  .cell-input:focus { border-color: var(--lime); }
  .remove-btn.small {
    width: 26px;
    height: 26px;
    font-size: 13px;
    border-radius: 6px;
    background: rgba(255,77,77,0.1);
    color: var(--danger);
    border: none;
    cursor: pointer;
  }

  /* Serial format rows */
  .serial-header-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 50px 30px;
    gap: 8px;
    padding: 0 2px 6px;
    font-size: 10px;
    color: var(--text-faint);
    text-transform: uppercase;
    font-weight: 700;
  }
  .serial-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 50px 30px;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
  }
  .serial-input {
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 8px;
    color: var(--text);
    font-size: 13px;
    outline: none;
    width: 100%;
  }
  .serial-input:focus { border-color: var(--lime); }
  .serial-qty {
    text-align: center;
    font-size: 13px;
    font-weight: 700;
    color: var(--lime);
    background: rgba(200,255,61,0.08);
    border-radius: 8px;
    padding: 10px 0;
  }

  /* Empty state */
  .empty-hint {
    font-size: 12px;
    color: var(--text-faint);
    text-align: center;
    padding: 8px 0;
  }

  /* Toast */
  .toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--panel-2);
    border: 1px solid var(--lime);
    color: var(--text);
    padding: 12px 20px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    opacity: 0;
    pointer-events: none;
    transition: all 0.25s;
    z-index: 200;
    max-width: 90%;
    text-align: center;
  }
  .toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
  .toast.error { border-color: var(--danger); }

  /* Bill list view */
  .bill-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 10px;
    cursor: pointer;
  }
  .bill-card .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
  }
  .status-dot.draft { background: var(--amber); }
  .status-dot.final { background: var(--lime); }
  .bill-card .info { flex: 1; min-width: 0; }
  .bill-card .title { font-size: 14px; font-weight: 700; }
  .status-badge {
    font-size: 9px;
    font-weight: 800;
    padding: 2px 6px;
    border-radius: 5px;
    letter-spacing: 0.5px;
    margin-left: 4px;
    vertical-align: middle;
  }
  .status-badge.draft { background: rgba(255,176,32,0.15); color: var(--amber); }
  .status-badge.final { background: rgba(200,255,61,0.15); color: var(--lime); }
  .status-badge.opening { background: rgba(61,232,255,0.15); color: var(--cyan); }

  .bills-tab-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
    flex-wrap: wrap;
  }
  .bills-tab-actions .btn {
    flex: 1;
    min-width: 160px;
    font-size: 12px;
    padding: 10px 12px;
  }
  .opening-balance-card { border: 1px dashed rgba(61,232,255,0.3); }
  .bill-card .sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
  .bill-card .amount { font-size: 15px; font-weight: 800; color: var(--lime); white-space: nowrap; }
  .quick-download-btn {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: var(--cyan);
    font-size: 15px;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .spinner-dark {
    width: 14px; height: 14px;
    border: 2px solid rgba(0,0,0,0.15);
    border-top-color: var(--cyan);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    display: inline-block;
  }

  .top-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
  }

  /* Footer */
  .app-footer {
    text-align: center;
    padding: 24px 0 8px;
    font-size: 12px;
    color: var(--text-faint);
    line-height: 1.8;
  }
  .app-footer .accent { color: var(--cyan); }

  /* Loading spinner */
  .spinner {
    width: 16px; height: 16px;
    border: 2px solid rgba(255,255,255,0.2);
    border-top-color: #000;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    display: inline-block;
  }
  @keyframes spin { to { transform: rotate(360deg); } }

  .hidden { display: none !important; }

  ::-webkit-scrollbar { width: 6px; }
  ::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

  /* ============ BOTTOM NAV ============ */
  .bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-width: 720px;
    margin: 0 auto;
    background: var(--panel);
    border-top: 1px solid var(--border);
    display: flex;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px));
    z-index: 100;
  }
  .nav-btn {
    flex: 1;
    background: none;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 8px 4px;
    cursor: pointer;
    color: var(--text-dim);
    border-radius: 10px;
  }
  .nav-btn.active { color: var(--lime); }
  .nav-icon { font-size: 20px; line-height: 1; }
  .nav-label { font-size: 10px; font-weight: 700; letter-spacing: 0.3px; }

  /* Desktop-only "preview as mobile" toggle — never shown on an actual phone */
  .mobile-preview-btn { display: none; }

  /* ============ CLIENTS MASTER-DETAIL WRAPPER ============ */
  /* Mobile default: only the "active" pane is visible — full-screen navigation,
     identical to the old behavior where dashboard/client-detail were separate views.
     Desktop overrides this further down to show both panes side-by-side. */
  .master-detail[data-active="master"] .detail-pane { display: none; }
  .master-detail[data-active="detail"] .master-pane { display: none; }
  .empty-hint.centered {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 200px;
  }

  /* ============ DASHBOARD ============ */
  .dashboard-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
  }
  .dashboard-title {
    font-size: 20px;
    font-weight: 800;
  }
  .clear-data-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: rgba(255,77,77,0.1);
    border: 1px solid rgba(255,77,77,0.3);
    color: var(--danger);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  .filter-tabs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
    margin-bottom: 16px;
    -webkit-overflow-scrolling: touch;
  }
  .filter-tabs::-webkit-scrollbar { display: none; }
  .filter-tab {
    flex-shrink: 0;
    padding: 8px 16px;
    border-radius: 20px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
  }
  .filter-tab.active {
    background: var(--lime);
    color: #000;
    border-color: var(--lime);
  }

  .client-fin-row {
    display: flex;
    gap: 6px;
    margin-top: 6px;
    flex-wrap: wrap;
  }
  .fin-chip {
    font-size: 10px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 6px;
  }
  .fin-chip.amount { background: rgba(255,255,255,0.06); color: var(--text-dim); }
  .fin-chip.due { background: rgba(255,176,32,0.15); color: var(--amber); }
  .fin-chip.advance { background: rgba(61,232,255,0.15); color: var(--cyan); }
  .fin-chip.clear { background: rgba(200,255,61,0.15); color: var(--lime); }

  .client-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 10px;
    cursor: pointer;
  }
  .client-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(200,255,61,0.12);
    color: var(--lime);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    font-weight: 800;
    flex-shrink: 0;
  }
  .client-avatar.large { width: 56px; height: 56px; font-size: 22px; }
  .client-card .info { flex: 1; min-width: 0; }
  .client-card .title { font-size: 14px; font-weight: 700; }
  .client-card .sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
  .client-card .chevron { color: var(--text-faint); font-size: 20px; }

  /* ============ CLIENT DETAIL ============ */
  .client-detail-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 20px;
  }
  .client-detail-header .info .title { font-size: 19px; font-weight: 800; }
  .client-detail-header .info .sub { font-size: 13px; color: var(--text-dim); margin-top: 3px; }

  .summary-bar {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
    margin-bottom: 20px;
  }
  .summary-item {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 10px;
    text-align: center;
  }
  .summary-item .k { font-size: 10px; color: var(--text-dim); font-weight: 700; text-transform: uppercase; letter-spacing: 0.3px; margin-bottom: 6px; }
  .summary-item .v { font-size: 16px; font-weight: 800; }
  .summary-item .v.received { color: var(--cyan); }
  .summary-item .v.due { color: var(--amber); }
  .summary-item .v.clear { color: var(--lime); }

  .section-title-standalone {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-dim);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }

  /* ============ PAYMENTS ============ */
  .pay-badge {
    font-size: 9px;
    font-weight: 800;
    padding: 2px 6px;
    border-radius: 5px;
    letter-spacing: 0.5px;
    margin-left: 4px;
    vertical-align: middle;
  }
  .pay-badge.paid { background: rgba(200,255,61,0.15); color: var(--lime); }
  .pay-badge.partial { background: rgba(255,176,32,0.15); color: var(--amber); }
  .pay-badge.due { background: rgba(255,77,77,0.12); color: var(--danger); }

  .advance-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(61,232,255,0.08);
    border: 1px solid rgba(61,232,255,0.25);
    border-radius: 12px;
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--cyan);
  }
  .advance-amount { font-size: 16px; font-weight: 800; }

  /* Bills / Payments segmented toggle on the client detail page */
  .detail-tabs {
    display: flex;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 4px;
    gap: 4px;
    margin-bottom: 16px;
  }
  .detail-tab {
    flex: 1;
    padding: 10px 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-dim);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
  }
  .detail-tab.active {
    background: var(--lime);
    color: #000;
  }

  .payment-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 10px;
    cursor: pointer;
  }
  .payment-card .info { flex: 1; min-width: 0; }
  .payment-card .title { font-size: 14px; font-weight: 700; }
  .payment-card .payment-amount { color: var(--lime); font-weight: 800; margin-left: 6px; }
  .payment-card .sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
  .payment-card .chevron { color: var(--text-faint); font-size: 20px; }

  .dist-preview {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px 18px;
    margin-bottom: 16px;
  }
  .dist-preview-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
  }
  .dist-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
  }
  .dist-row:last-child { border-bottom: none; }
  .dist-row.advance-row { color: var(--cyan); font-weight: 700; }
  .dist-bill { font-size: 13px; font-weight: 700; }
  .dist-project { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
  .dist-right { text-align: right; }
  .dist-amount { font-size: 14px; font-weight: 800; }
  .dist-status { font-size: 10px; font-weight: 700; margin-top: 2px; text-transform: uppercase; }
  .dist-status.paid { color: var(--lime); }
  .dist-status.partial { color: var(--amber); }

  .advance-checkbox-row { margin-top: 14px; }
  .checkbox-row-inline {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    background: rgba(61,232,255,0.06);
    border: 1px solid rgba(61,232,255,0.2);
    border-radius: 10px;
    cursor: pointer;
    font-size: 13px;
    color: var(--cyan);
  }
  .checkbox-row-inline input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--cyan);
    cursor: pointer;
    flex-shrink: 0;
  }
  .checkbox-row-inline.small { padding: 8px 10px; font-size: 12px; margin-top: 8px; }
  .checkbox-row-inline-wrap { flex: 1; }

  /* ============ SETTINGS / PACKAGE EDITOR ============ */
  .settings-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 8px;
    cursor: pointer;
  }
  .settings-list-item .title { font-size: 14px; font-weight: 700; }
  .settings-list-item .chevron { color: var(--text-faint); font-size: 18px; }

  .delete-icon-btn {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: rgba(255,77,77,0.1);
    border: 1px solid rgba(255,77,77,0.3);
    color: var(--danger);
    font-size: 13px;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .group-block {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px;
    margin-bottom: 14px;
  }
  .group-block-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
  }
  .group-name-input {
    flex: 1;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--text);
    font-size: 14px;
    font-weight: 700;
    outline: none;
  }
  .group-name-input:focus { border-color: var(--lime); }

  .item-editor-row {
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 10px;
  }
  .item-name-input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 9px 10px;
    color: var(--text);
    font-size: 13px;
    font-weight: 700;
    outline: none;
    margin-bottom: 8px;
  }
  .item-name-input:focus { border-color: var(--lime); }
  .item-editor-grid {
    display: grid;
    grid-template-columns: 1fr 1.4fr 32px;
    gap: 8px;
    margin-bottom: 8px;
  }
  .item-price-input, .item-qtytype-input {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    color: var(--text);
    font-size: 12px;
    outline: none;
  }
  .item-price-input:focus, .item-qtytype-input:focus { border-color: var(--lime); }
  .item-desc-input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    color: var(--text-dim);
    font-size: 11px;
    outline: none;
    resize: vertical;
    font-family: inherit;
    box-sizing: border-box;
  }
  .item-desc-input:focus { border-color: var(--lime); }

  .small-btn { padding: 9px; font-size: 12px; margin-top: 4px; }

  .override-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
  }
  .override-row:last-child { border-bottom: none; }
  .override-row .info { flex: 1; min-width: 0; }
  .override-row .name { font-size: 13px; font-weight: 700; }
  .override-row .detail { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
  .override-input {
    width: 100px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 9px 10px;
    color: var(--text);
    font-size: 13px;
    outline: none;
    text-align: right;
  }
  .override-input:focus { border-color: var(--lime); }

  .pdf-detail-row-app {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
  }
  .pdf-detail-row-app:last-child { border-bottom: none; }
  .pdf-detail-row-app .k { color: var(--text-dim); font-weight: 600; }
  .pdf-detail-row-app .v { color: var(--text); font-weight: 700; }
  .pdf-detail-row-app .v.amount-highlight { color: var(--lime); font-size: 16px; }

  /* ============ PDF PRINT TEMPLATE ============ */
  /* Rendered off-screen, captured by html2canvas, then placed into jsPDF pages */
  #pdf-render-root {
    position: fixed;
    left: -9999px;
    top: 0;
    width: 794px; /* A4 width at 96dpi */
  }
  .pdf-page {
    width: 794px;
    min-height: 1123px; /* A4 height at 96dpi */
    background: #ffffff;
    color: #1a1a1a;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    padding: 48px 44px;
    box-sizing: border-box;
    position: relative;
  }
  .pdf-header {
    border-bottom: 3px solid #c8ff3d;
    padding-bottom: 16px;
    margin-bottom: 24px;
  }
  .pdf-logo { font-size: 26px; font-weight: 800; color: #111; letter-spacing: -0.5px; }
  .pdf-logo span { color: #7fae00; }
  .pdf-tag { font-size: 11px; color: #888; letter-spacing: 1px; text-transform: uppercase; margin-top: 2px; }

  .pdf-details { margin-bottom: 28px; }
  .pdf-detail-row {
    display: flex;
    justify-content: space-between;
    padding: 7px 0;
    border-bottom: 1px solid #eee;
    font-size: 13px;
  }
  .pdf-detail-row .k { color: #888; font-weight: 600; }
  .pdf-detail-row .v { color: #111; font-weight: 700; }

  .pdf-section-title {
    font-size: 15px;
    font-weight: 800;
    color: #111;
    margin-bottom: 12px;
    padding-bottom: 6px;
    border-bottom: 2px solid #111;
  }

  table.pdf-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin-bottom: 20px;
  }
  table.pdf-table th {
    text-align: left;
    padding: 8px 6px;
    background: #f4f4f4;
    color: #444;
    font-weight: 700;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
  }
  table.pdf-table td {
    padding: 8px 6px;
    border-bottom: 1px solid #eee;
    color: #222;
  }
  .pdf-item-name { font-weight: 600; }
  .pdf-item-detail {
    font-size: 10px;
    color: #999;
    margin-top: 2px;
    line-height: 1.4;
  }
  table.pdf-table th.center, table.pdf-table td.center { text-align: center; }
  table.pdf-table th.right, table.pdf-table td.right { text-align: right; }
  table.pdf-table tfoot td {
    border-bottom: none;
    border-top: 2px solid #111;
    padding-top: 12px;
  }
  .total-label { font-weight: 700; font-size: 13px; color: #111; }
  .total-value { font-weight: 800; font-size: 16px; color: #7fae00; }

  .pdf-shot-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
  }
  .pdf-shot-card {
    border: 1px solid #eee;
    border-radius: 8px;
    overflow: hidden;
  }
  .pdf-shot-card img { width: 100%; display: block; }
  .pdf-shot-label {
    padding: 8px 10px;
    font-size: 11px;
    font-weight: 700;
    color: #444;
    background: #f8f8f8;
  }

  .pdf-player-table tbody tr:nth-child(even) { background: #fafafa; }

  .pdf-footer {
    position: absolute;
    bottom: 32px;
    left: 44px;
    right: 44px;
    text-align: center;
    font-size: 10px;
    color: #999;
    border-top: 1px solid #eee;
    padding-top: 10px;
  }

  /* ============================================================
     DESKTOP LAYOUT — side nav bar + column-wise content
     Mobile styles above are untouched; everything below only
     applies at >=900px, so phones/small tablets render exactly
     as before.
     ============================================================ */
  @media (min-width: 900px) {
    :root {
      --sidebar-w: 240px;
    }

    /* ---- App container: give room for the fixed sidebar, widen content ---- */
    .app {
      max-width: 1100px;
      margin: 0;
      margin-left: var(--sidebar-w);
      padding: 32px 40px 48px;
    }

    /* ---- Brand header becomes the top of the sidebar ---- */
    .brand-header {
      position: fixed;
      top: 0;
      left: 0;
      width: var(--sidebar-w);
      height: 84px;
      margin: 0;
      padding: 0 20px;
      background: var(--panel);
      border-right: 1px solid var(--border);
      border-bottom: 1px solid var(--border);
      box-sizing: border-box;
      z-index: 30;
    }

    /* ---- Bottom nav becomes a vertical sidebar nav ---- */
    .bottom-nav {
      position: fixed;
      top: 84px;
      left: 0;
      bottom: 0;
      right: auto;
      width: var(--sidebar-w);
      max-width: var(--sidebar-w);
      margin: 0;
      flex-direction: column;
      align-items: stretch;
      gap: 4px;
      padding: 16px 12px;
      border-top: none;
      border-right: 1px solid var(--border);
      overflow-y: auto;
      z-index: 20;
    }
    .nav-btn {
      flex: 0 0 auto;
      flex-direction: row;
      justify-content: flex-start;
      gap: 12px;
      padding: 11px 14px;
      border-radius: 10px;
    }
    .nav-btn:hover { background: var(--panel-2); }
    .nav-btn.active { background: rgba(200,255,61,0.12); }
    .nav-icon { font-size: 17px; width: 20px; text-align: center; flex-shrink: 0; }
    .nav-label { font-size: 13px; }

    .mobile-preview-btn {
      display: flex;
      margin-top: auto;
      color: var(--cyan);
      border: 1px dashed rgba(61,232,255,0.35);
    }
    .mobile-preview-btn:hover { background: rgba(61,232,255,0.08); }

    /* ---- Clients master-detail: list + selected client side-by-side ---- */
    .master-detail {
      display: grid;
      grid-template-columns: 340px 1fr;
      gap: 24px;
      align-items: start;
    }
    .master-detail[data-active="master"] .detail-pane,
    .master-detail[data-active="detail"] .master-pane {
      display: block; /* undo the mobile hide-inactive-pane rule — desktop always shows both */
    }
    .master-pane {
      position: sticky;
      top: 32px;
      max-height: calc(100vh - 64px);
      overflow-y: auto;
      padding-right: 4px;
    }
    .detail-pane .empty-hint.centered {
      min-height: 320px;
      color: var(--text-faint);
    }

    /* ---- Column-wise content: dashboard clients / bills / payments ---- */
    .card-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
      gap: 12px;
    }
    .card-grid .empty-hint { grid-column: 1 / -1; }

    /* Forms read better as two columns on wide screens */
    .field-row {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 12px;
    }

    /* Toast stays bottom-right instead of full-width on desktop */
    .toast {
      left: auto;
      right: 32px;
      transform: translateY(20px);
    }
    .toast.show {
      transform: translateY(0);
    }
  }
