/* css/styles1.css */
/* ── Faruma Abul currency font ── */
@font-face {
    font-family: 'FarumaAbul';
    src: url('fonts/faruma-abul.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

/* Calm palette: neutral surfaces, colour only where it means something
   (blue = action, green = paid, amber = unpaid, red = overdue / over limit). */
:root {
    --bg-primary: #f4f5f7;
    --bg-secondary: #ffffff;
    --bg-raised: #f8f9fb;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-dim: rgba(37,99,235,0.08);
    --success-color: #059669;
    --danger-color: #dc2626;
    --warning-color: #d97706;
    --orange-color: #ea580c;
    --shadow-sm: 0 1px 2px rgba(17,24,39,0.05);
    --shadow: 0 1px 3px rgba(17,24,39,0.07), 0 1px 2px rgba(17,24,39,0.04);
    --shadow-lg: 0 16px 40px rgba(17,24,39,0.14);
    --card-radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 14px;
    --accent-dim: rgba(37,99,235,0.08);
    --accent-bdr: rgba(37,99,235,0.35);
    --age-0: #94a3b8;
    --age-1: #f59e0b;
    --age-2: #ea580c;
    --age-3: #dc2626;
    --appbar-h: 64px;
    --bottomnav-h: 62px;
}

.dark-mode {
    --bg-primary: #0f1115;
    --bg-secondary: #16191f;
    --bg-raised: #1c2027;
    --text-primary: #e8eaed;
    --text-secondary: #9aa1ac;
    --border-color: #262b33;
    --primary-color: #5b8def;
    --primary-hover: #7aa3f3;
    --primary-dim: rgba(91,141,239,0.14);
    --success-color: #34d399;
    --danger-color: #f87171;
    --warning-color: #fbbf24;
    --orange-color: #fb923c;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.35);
    --shadow: 0 1px 3px rgba(0,0,0,0.4);
    --shadow-lg: 0 20px 50px rgba(0,0,0,0.55);
    --card-radius: 12px;
    --accent-dim: rgba(91,141,239,0.14);
    --accent-bdr: rgba(91,141,239,0.45);
    --age-0: #64748b;
    --age-1: #fbbf24;
    --age-2: #fb923c;
    --age-3: #f87171;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }

/* Scrollbar theming */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
.dark-mode ::-webkit-scrollbar-thumb { background: #334155; }
.dark-mode ::-webkit-scrollbar-thumb:hover { background: #475569; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    padding: 0;
    min-height: 100vh;
    transition: background-color 0.2s, color 0.2s;
    letter-spacing: -0.011em;
    -webkit-tap-highlight-color: transparent;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px 20px 40px;
}

.header {
    display: flex;
    align-items: center;
    margin-bottom: 22px;
    flex-wrap: nowrap;
    gap: 12px;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 13px;
    min-width: 0;
    flex: 1 1 auto;
}

.logo {
    width: 40px;
    height: 40px;
    border-radius: 11px;
    object-fit: contain;
    background: transparent !important;
    box-shadow: 0 0 0 1px var(--border-color), var(--shadow-sm);
    transition: box-shadow 0.25s;
}

h1 {
    color: var(--text-primary);
    font-size: 21px;
    font-weight: 800;
    letter-spacing: -0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

/* Add to styles1.css */
.customer-title {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Telegram test button */
.btn-telegram {
    background: linear-gradient(135deg, #0088cc, #34b7f1);
    color: white;
}

.btn-telegram:hover {
    background: linear-gradient(135deg, #0077b5, #2aa8e0);
}

.customer-title-name {
    font-weight: 600;
    color: var(--primary-color);
}

.customer-title-phone {
    font-size: 12px;
    opacity: 0.8;
}

.header-controls {
    display: flex;
    justify-content: flex-end;
    flex-direction: row;
    flex-shrink: 0;
    gap: 8px;
}

/* For modal header with customer info */
.modal-header-with-customer {
    align-items: flex-start !important;
}

.modal-header h3 {
    margin-bottom: 0;
}

.theme-toggle {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    padding: 9px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 13px;
    box-shadow: var(--shadow-sm);
    transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}
.theme-toggle:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow);
    border-color: var(--accent-bdr);
}
.theme-toggle:active { transform: translateY(0); }

/* Sorting styles */
th[onclick] {
    position: relative;
    user-select: none;
}

th[onclick]:hover {
    background-color: var(--bg-raised);
    color: var(--primary-color);
}

.sort-icon {
    margin-left: 5px;
    font-size: 12px;
    display: inline-block;
    width: 20px;
    text-align: center;
    opacity: 0.6;
}

.text-right {
    text-align: right;
}

/* Add hover effect for sortable headers */
th[onclick] {
    transition: background-color 0.2s, color 0.2s;
}

th[onclick]:active {
    background-color: var(--primary-color);
    color: white;
}

/* Sort indicator */
.sort-indicator {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
}

input[type="checkbox"]:indeterminate {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

/* Style for select all checkbox */
#select-all {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary-color);
}

.search-box {
    position: relative;
}

.search-box input {
    width: 100%;
    padding: 11px 40px 11px 40px; /* Added right padding for clear button */
    border: 1.5px solid var(--border-color);
    border-radius: var(--card-radius);
    font-size: 14px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: border-color 0.15s, box-shadow 0.15s;
    font-family: inherit;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px var(--primary-dim);
}

.search-icon {
    position: absolute;
    left: 13px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    pointer-events: none;
}

.clear-search {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    cursor: pointer;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 13px;
    transition: all 0.2s;
    background: var(--bg-raised);
}

.clear-search:hover {
    color: #fff;
    background: var(--danger-color);
}


.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: 20px;
    transition: background-color 0.3s, box-shadow 0.3s;
}

.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
    position: sticky;
    top: var(--appbar-h);
    z-index: 100;
    background: var(--bg-secondary);
    padding: 6px 6px 0;
    scrollbar-width: none;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.tabs::-webkit-scrollbar { display: none; }

/* Context controls that appear inside the sticky tabs bar - only one
   visible at a time, matching whichever tab is active (see switchTab). */
.tab-context-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    padding: 0 6px 8px;
    flex-shrink: 0;
    white-space: nowrap;
}
.tab-context-bar label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
}
.tab-context-bar input {
    padding: 7px 10px;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    min-height: 0;
}
.tab-context-bar input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px var(--primary-dim);
}
.tab-context-bar input[type="number"] { width: 90px; }

.tab {
    padding: 12px 20px;
    background: none;
    border: none;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 2.5px solid transparent;
    transition: color 0.2s, background-color 0.2s;
    white-space: nowrap;
    font-family: inherit;
}

.tab:hover {
    color: var(--text-primary);
    background: var(--bg-raised);
}

.tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    background: none;
}

.tab-content {
    padding: 22px;
}

.sales-summary-row {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 22px;
}
.sales-summary-row .summary-cards {
    margin-bottom: 0;
    flex: 1 1 auto;
    min-width: 0;
}

.selection-summary-panel {
    flex-shrink: 0;
    margin-left: auto;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--card-radius);
    padding: 14px 16px;
    box-shadow: var(--shadow-sm);
    min-width: 240px;
    max-width: 280px;
}
.sel-summary-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}
.sel-summary-amount {
    font-weight: 800;
    font-size: 16px;
    color: var(--primary-color);
    white-space: nowrap;
}
.sel-summary-plus {
    font-weight: 700;
    color: var(--text-secondary);
    flex-shrink: 0;
}
.sel-summary-input {
    flex: 1;
    min-width: 0;
    width: 0;
    padding: 7px 8px;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-raised);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    min-height: 0;
}
.sel-summary-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px var(--primary-dim);
}
.sel-summary-message-wrap {
    background: var(--bg-raised);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 10px;
}
.sel-summary-message {
    font-family: inherit;
    font-size: 12px;
    color: var(--text-primary);
    margin: 0 0 8px;
    line-height: 1.5;
    white-space: pre-line;
}
.sel-summary-copy-btn {
    width: 100%;
    justify-content: center;
    padding: 7px 10px;
    font-size: 12px;
}

.summary-cards {
    display: flex;
    gap: 14px;
    margin-bottom: 22px;
    overflow-x: auto;
    padding-bottom: 8px;
}

/* Neutral cards; the coloured dot next to the label carries the meaning */
.summary-card {
    padding: 14px 16px;
    border-radius: var(--card-radius);
    min-width: 150px;
    flex-shrink: 0;
    position: relative;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    --dot: var(--text-secondary);
}
.summary-card.blue   { --dot: var(--primary-color); }
.summary-card.green  { --dot: var(--success-color); }
.summary-card.red    { --dot: var(--warning-color); }
.summary-card.orange { --dot: var(--danger-color); }
.summary-card.orange .value { color: var(--danger-color); }

.summary-card .label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.summary-card .label::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--dot);
    flex-shrink: 0;
}

.summary-card .value {
    font-size: 20px;
    font-weight: 700;
    display: flex;
    align-items: center;
    letter-spacing: -0.01em;
}

.currency {
    font-family: 'FarumaAbul', monospace;
    font-size: 0.85em;
    font-weight: 600;
    vertical-align: baseline;
    letter-spacing: 0;
    font-size: 16px;
}

.toolbar {
    display: flex;
    gap: 10px;
    margin-bottom: 18px;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
}

.toolbar-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: nowrap;
    flex-shrink: 0;
}

/* ── Toolbar dropdown (Bulk Add / Bulk Audit) ── */
.dropdown-wrap {
    position: relative;
    flex-shrink: 0;
}
.dropdown-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    min-width: 170px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    padding: 6px;
    z-index: 50;
}
.dropdown-menu button {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 10px;
    border: none;
    background: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    font-family: inherit;
    text-align: left;
    transition: background-color 0.12s;
}
.dropdown-menu button:hover {
    background: var(--primary-dim);
    color: var(--primary-color);
}

.btn {
    padding: 10px 14px;
    border: none;
    border-radius: var(--card-radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 7px;
    transition: transform 0.15s, box-shadow 0.15s, background-color 0.15s, filter 0.15s;
    white-space: nowrap;
    flex-shrink: 0;
    min-width: 44px;
    justify-content: center;
    font-family: inherit;
}
.btn:active { transform: scale(0.98); }
a.btn { text-decoration: none; }
.btn:focus-visible, .icon-btn:focus-visible, .tab:focus-visible, a:focus-visible, button:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}
.dark-mode .btn-primary { color: #0b1220; }

.btn-primary:hover {
    background: var(--primary-hover);
}

/* Secondary actions stay neutral - only the main action is filled */
.btn-success {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-success:hover {
    background: var(--bg-raised);
}

.btn-secondary {
    background: var(--bg-raised);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    filter: brightness(0.92);
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-secondary);
    border-radius: var(--card-radius);
    overflow: hidden;
}

/* Shared horizontal-scroll wrapper for all three tables (sales, customers,
   summary) - keeps their overflow/touch-scroll behavior consistent instead
   of each table needing its own bespoke rules. */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Summary tab's daily breakdown - every column is a short number/date,
   unlike sales/customers tables there's no name-like column to exempt. */
#summary-table tbody tr td {
    text-align: center;
}

.chart-container {
    position: relative;
    height: 320px;
    margin-top: 20px;
    padding: 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--card-radius);
    box-shadow: var(--shadow-sm);
}

th, td {
    padding: 12px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    font-size: 14px;
    white-space: nowrap;
}

/* Long customer names/addresses shouldn't be able to stretch the table
   wider than reasonable at any screen size - truncates gracefully with
   an ellipsis rather than forcing horizontal scroll for one outlier cell.
   The mobile breakpoint further tightens these with its own max-width. */
#sales-table tbody tr td:nth-child(4) {
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
#customers-table tbody tr td:nth-child(3),
#customers-table tbody tr td:nth-child(5) {
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* #, Date, Phone, Bill No, Amount, Status, Due Date, Actions - every
   sales-table column except Customer (name stays left-aligned/readable) */
#sales-table tbody tr td:not(:nth-child(4)) {
    text-align: center;
}
#sales-table .action-btns {
    justify-content: center;
}

th {
    background: var(--bg-raised);
    font-weight: 700;
    color: var(--text-secondary);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    text-align: center;
}

tbody tr {
    transition: background-color 0.12s;
}

tr:hover {
    background: var(--bg-raised);
}

/* Customers at/over the pending limit: light tint + amber bar, text stays readable */
.highlight-pending td {
    background: rgba(217,119,6,0.07) !important;
}
.highlight-pending td:first-child {
    box-shadow: inset 3px 0 0 var(--warning-color);
}
.dark-mode .highlight-pending td {
    background: rgba(251,191,36,0.07) !important;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 11px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}

.status-badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

.status-paid {
    background: #dcfce7;
    color: #166534;
}

.status-unpaid {
    background: #fef3c7;
    color: #92400e;
}

.status-overdue {
    background: #fee2e2;
    color: #991b1b;
}

.dark-mode .status-paid {
    background: rgba(52,211,153,0.16);
    color: #6ee7b7;
}

.dark-mode .status-unpaid {
    background: rgba(251,191,36,0.14);
    color: #fcd34d;
}

.dark-mode .status-overdue {
    background: rgba(248,113,113,0.16);
    color: #fca5a5;
}

.action-btns {
    display: flex;
    gap: 6px;
}

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: var(--primary-dim);
    color: var(--primary-color);
}

.icon-btn.delete:hover {
    background: rgba(220,38,38,0.12);
    color: var(--danger-color);
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(8,12,22,0.55);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    z-index: 10001;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal.show {
    display: flex;
    animation: modalFadeIn 0.18s ease-out;
}

@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 22px;
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    z-index: 1001;
    animation: modalPopIn 0.2s cubic-bezier(.2,.9,.3,1.1);
}

@keyframes modalPopIn {
    from { opacity: 0; transform: translateY(10px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

.close-btn {
    background: var(--bg-raised);
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    flex-shrink: 0;
}
.close-btn:hover {
    background: var(--danger-color);
    color: #fff;
}

.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 16px !important;
    background: var(--bg-secondary);
    color: var(--text-primary);
    min-height: 44px !important;
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px var(--primary-dim);
}

.form-group textarea {
    resize: vertical;
}

.form-group input[type="tel"],
.form-group input[type="number"] {
    -webkit-appearance: none;
    -moz-appearance: textfield;
}

.form-group input[type="tel"]::-webkit-outer-spin-button,
.form-group input[type="tel"]::-webkit-inner-spin-button,
.form-group input[type="number"]::-webkit-outer-spin-button,
.form-group input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.suggestions {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    max-height: 200px;
    overflow-y: auto;
    margin-top: 6px;
    background: var(--bg-secondary);
    box-shadow: var(--shadow-sm);
}

.suggestion-item {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.15s;
}

.suggestion-item:hover {
    background: var(--primary-dim);
}

.suggestion-item:last-child {
    border-bottom: none;
}

.suggestion-name {
    font-weight: 600;
    color: var(--text-primary);
}

.suggestion-phone {
    font-size: 12px;
    color: var(--text-secondary);
}

.selected-customer {
    padding: 10px 12px;
    background: #dcfce7;
    border: 1px solid #86efac;
    border-radius: var(--radius-sm);
    margin-top: 6px;
}

.dark-mode .selected-customer {
    background: rgba(52,211,153,0.14);
    border-color: rgba(52,211,153,0.4);
    color: #a7f3d0;
}

.customer-not-found {
    padding: 10px 12px;
    background: #fef3c7;
    border: 1px solid #fde047;
    border-radius: var(--radius-sm);
    margin-top: 6px;
}

.dark-mode .customer-not-found {
    background: rgba(251,191,36,0.14);
    border-color: rgba(251,191,36,0.4);
    color: #fde68a;
}

.customer-not-found button {
    margin-top: 6px;
    color: var(--primary-color);
    background: none;
    border: none;
    cursor: pointer;
    text-decoration: underline;
    font-size: 14px;
    font-family: inherit;
}

.btn-group {
    display: flex;
    gap: 10px;
    margin-top: 18px;
}

.btn-group .btn {
    flex: 1;
    justify-content: center;
}

.hidden {
    display: none;
}

.month-selector {
    margin-bottom: 18px;
}

.month-selector label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 13px;
}

.month-selector input {
    padding: 10px 12px;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: inherit;
    max-width: 100%;
    box-sizing: border-box;
}
.month-selector input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px var(--primary-dim);
}

.text-success {
    color: var(--success-color);
}

.text-danger {
    color: var(--danger-color);
}

.text-warning {
    color: var(--warning-color);
}

.step-indicator {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
    position: relative;
}

.step-indicator::before {
    content: '';
    position: absolute;
    top: 15px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--border-color);
    z-index: 1;
}

.step {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    z-index: 2;
}

.step-number {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    margin-bottom: 6px;
    transition: background 0.2s, box-shadow 0.2s;
}

.step.active .step-number {
    background: linear-gradient(135deg, var(--primary-color), #6366f1);
    color: white;
    box-shadow: 0 4px 12px rgba(37,99,235,0.4);
}

.step-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
}

.step.active .step-label {
    color: var(--primary-color);
}

.empty-state {
    text-align: center;
    padding: 36px 16px;
    color: var(--text-secondary);
}

/* ── Live Sync Banner ── */
#sync-banner {
    position: fixed;
    top: -160px;
    margin-top: env(safe-area-inset-top); /* far enough up that a 2-line wrapped banner on phones stays fully hidden */
    max-width: calc(100% - 24px);
    text-align: center;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9000;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    background: var(--primary-color);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    border-radius: 999px;
    box-shadow: 0 8px 32px rgba(37,99,235,0.4);
    cursor: pointer;
    transition: top 0.28s cubic-bezier(.4,0,.2,1);
    pointer-events: none;
}
#sync-banner.visible { top: 16px; pointer-events: all; }
#sync-banner:hover { filter: brightness(1.1); }
#sync-banner svg { flex-shrink: 0; }

/* ── Sticky Selection Bar ── */
#selection-bar {
    position: fixed;
    bottom: -120px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 40px);
    max-width: 860px;
    z-index: 8000;
    transition: bottom 0.28s cubic-bezier(.4,0,.2,1);
    pointer-events: none;
}
#selection-bar.visible { bottom: 16px; pointer-events: all; }
.sel-inner {
    display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
    padding: 13px 18px;
    background: var(--bg-secondary);
    border: 1.5px solid var(--accent-bdr, rgba(59,130,246,0.4));
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}
.sel-info { flex: 1; display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 600; flex-wrap: wrap; }
.sel-info #selected-count { color: var(--primary-color); font-size: 16px; font-weight: 800; }
.sel-info #selected-total { color: var(--primary-color); font-weight: 800; font-variant-numeric: tabular-nums; }
.sel-sep { color: var(--text-secondary); }
.sel-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.sel-actions button {
    padding: 8px 14px; border-radius: var(--radius-sm); font-size: 12px; font-weight: 700;
    font-family: inherit; cursor: pointer;
    border: 1px solid var(--border-color);
    background: var(--bg-raised, var(--bg-primary));
    color: var(--text-secondary);
    transition: all 0.15s;
}
.sel-actions button:hover { color: var(--text-primary); transform: translateY(-1px); }
.sel-actions button.primary { background: var(--primary-color); color: #fff; border-color: var(--primary-color); }
.sel-actions button.primary:hover { filter: brightness(1.1); }
.sel-actions button.danger { background: var(--danger-color); color: #fff; border-color: var(--danger-color); }
.sel-actions button.danger:hover { filter: brightness(1.1); }

/* ── Row tap-to-select ── */
tr.selectable-row { cursor: pointer; user-select: none; -webkit-user-select: none; }
tr.selectable-row td { transition: background-color 0.12s; }
tr.row-selected td {
    background-color: var(--accent-dim, rgba(59,130,246,0.10)) !important;
    border-bottom-color: var(--accent-bdr, rgba(59,130,246,0.30)) !important;
}
tr.row-selected td:first-child { box-shadow: inset 3px 0 0 var(--primary-color); }

.alert {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 16px;
    border-radius: var(--card-radius);
    box-shadow: var(--shadow-lg);
    z-index: 1100;
    max-width: 350px;
    display: flex;
    align-items: center;
    gap: 12px;
    transform: translateX(400px);
    transition: transform 0.3s ease;
}

.alert.show {
    transform: translateX(0);
}

.alert-success {
    background: #dcfce7;
    color: #166534;
    border-left: 4px solid #16a34a;
}

.alert-error {
    background: #fee2e2;
    color: #991b1b;
    border-left: 4px solid #dc2626;
}

.alert-warning {
    background: #fef3c7;
    color: #92400e;
    border-left: 4px solid #d97706;
}

.alert-info {
    background: #dbeafe;
    color: #1e40af;
    border-left: 4px solid #3b82f6;
}

.dark-mode .alert-success {
    background: #14532d;
    color: #bbf7d0;
}

.dark-mode .alert-error {
    background: #7f1d1d;
    color: #fecaca;
}

.dark-mode .alert-warning {
    background: #78350f;
    color: #fde68a;
}

.dark-mode .alert-info {
    background: #1e3a8a;
    color: #bfdbfe;
}

.alert-icon {
    font-size: 20px;
}

.alert-content {
    flex: 1;
}

.alert-title {
    font-weight: 700;
    margin-bottom: 4px;
}

.alert-message {
    font-size: 14px;
}

.alert-close {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: inherit;
}

.filter-section {
    margin-bottom: 18px;
    padding: 14px;
    background: var(--bg-raised);
    border: 1px solid var(--border-color);
    border-radius: var(--card-radius);
}

.filter-input {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.filter-input input {
    padding: 8px 10px;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    width: 120px;
    font-family: inherit;
}
.filter-input input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px var(--primary-dim);
}

.filter-label {
    font-size: 14px;
    color: var(--text-secondary);
}

.loading {
    opacity: 0.6;
    pointer-events: none;
}

.logout-btn {
    text-decoration: none;
    padding: 10px 12px;
    font-size: 16px;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--card-radius);
    transition: transform 0.15s, box-shadow 0.15s;
}
.logout-btn:hover { transform: translateY(-1px); }

/* ══════════════════════════════════════════════════════
   MOBILE — Compact scrollable table
   ══════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  body { padding: 8px 8px 130px; font-size: 14px; }

  /* Header — single row */
  .header { flex-direction: row; align-items: center; justify-content: space-between; flex-wrap: nowrap; gap: 8px; margin-bottom: 12px; }
  .logo-container { display: flex; align-items: center; flex: 1; min-width: 0; gap: 8px; }
  .logo { width: 28px; height: 28px; flex-shrink: 0; }
  h1 { font-size: 13px; white-space: nowrap; min-width: 0; }
  .header-controls { display: flex; gap: 6px; flex-shrink: 0; align-items: center; }
  .theme-toggle { padding: 7px 9px; border-radius: 8px; gap: 0; }
  #theme-text { display: none; }
  .header-controls > a.btn { padding: 7px 9px; }
  .header-controls > a.btn .btn-label { display: none; }

  /* Summary — 2×2 */
  .sales-summary-row { flex-direction: column; margin-bottom: 12px; }
  .summary-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 0; overflow-x: visible; }
  .summary-card { padding: 10px 12px 9px; }
  .summary-card .label { font-size: 9px; margin-bottom: 3px; }
  .summary-card .value { font-size: 16px; }
  .currency { font-size: 11px; }
  .selection-summary-panel { margin-left: 0; width: 100%; max-width: 100%; min-width: 0; }

  /* Tabs */
  .tabs { padding: 4px 4px 0; flex-wrap: wrap; }
  .tab { padding: 9px 14px; font-size: 12px; }
  .tab-content { padding: 10px 0 0; }
  .tab-context-bar { width: 100%; margin-left: 0; padding: 8px 6px 8px; }
  .tab-context-bar input[type="number"] { flex: 1; width: auto; }

  /* Toolbar */
  .toolbar { flex-direction: column; gap: 8px; margin-bottom: 10px; align-items: stretch; }
  .search-box { min-width: 100%; max-width: 100%; }
  .search-box input { font-size: 16px; padding: 9px 32px 9px 36px; }
  .toolbar-buttons { display: flex; gap: 6px; width: 100%; }
  .toolbar-buttons .btn { flex: 1; justify-content: center; padding: 8px 4px; font-size: 11px; gap: 3px; }
  .toolbar-buttons .btn .btn-label { display: none; }
  .toolbar-buttons .dropdown-wrap { flex: 1; }
  .toolbar-buttons .dropdown-wrap .btn { width: 100%; }
  .dropdown-menu { left: 0; right: 0; min-width: 0; }

  /* ── Compact scrollable table ── */
  .card { overflow: visible; }

  /* Wrapper enables horizontal scroll */
  #sales-table,
  #customers-table,
  #summary-table { 
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 0;
  }

  /* Table itself stays as table but tighter */
  #sales-table table,
  #customers-table table,
  #summary-table table,
  #sales-table,
  #customers-table,
  #summary-table { min-width: 0; }

  /* Tighter cells */
  #sales-table th,
  #sales-table td { 
    padding: 9px 8px;
    font-size: 12px;
    white-space: nowrap;
  }
  #customers-table th,
  #customers-table td {
    padding: 9px 8px;
    font-size: 12px;
    white-space: nowrap;
  }
  #summary-table th,
  #summary-table td {
    padding: 9px 8px;
    font-size: 12px;
    white-space: nowrap;
  }

  /* Name column — constrained so one long name can't blow out the layout */
  #sales-table thead tr th:nth-child(4),
  #sales-table tbody tr td:nth-child(4) { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* Shrink status badge */
  .status-badge { font-size: 10px; padding: 3px 7px; gap: 3px; }
  .status-badge::before { width: 4px; height: 4px; }

  /* Action buttons — smaller */
  .icon-btn { width: 28px; height: 28px; }
  .action-btns { gap: 3px; }

  /* Constrain name column */
  #customers-table thead tr th:nth-child(3),
  #customers-table tbody tr td:nth-child(3) {
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .customer-thumb, .customer-thumb-placeholder { width: 26px; height: 26px; font-size: 11px; }

  /* Filter */
  .filter-section { padding: 8px 10px; }
  .filter-input { flex-direction: row; flex-wrap: wrap; gap: 6px; align-items: center; }
  .filter-input input { width: 85px; }

  /* Chart */
  .chart-container { height: 240px; padding: 10px; margin-top: 14px; }

  /* Modals — slide up */
  .modal { padding: 0; align-items: flex-end; }
  .modal-content { border-radius: 20px 20px 0 0; max-height: 92vh; padding: 20px 16px; width: 100%; max-width: 100%; }

  /* Selection bar */
  #selection-bar { width: calc(100% - 16px); }
  .sel-inner { padding: 10px 12px; gap: 8px; }
  .sel-info { font-size: 12px; gap: 6px; }
  /* Buttons wrap onto a second row so Transfer/Delete stay reachable on phones */
  .sel-actions { gap: 6px; flex-wrap: wrap; width: 100%; flex-shrink: 1; }
  .sel-actions button { padding: 8px 10px; font-size: 11px; flex: 1 1 auto; }

  /* Alerts */
  #alert-container { right: 8px; left: 8px; max-width: none; }
  .alert { font-size: 12px; }
}

/* Touch devices (phones + iPads): iOS Safari zooms the page when focusing
   any input under 16px - keep every text-entry field at 16px there. */
@media (pointer: coarse) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
  select,
  textarea { font-size: 16px !important; }
}

@media (max-width: 390px) {
  h1 { font-size: 11px; }
  .tab { padding: 8px 10px; font-size: 11px; }
  .summary-card .value { font-size: 14px; }
  #sales-table th, #sales-table td { font-size: 11px; padding: 8px 6px; }
}

/* Merge duplicate customers modal */
.field-hint {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 5px;
}

/* ── Customer photo ── */
.customer-photo-picker {
    display: flex;
    align-items: center;
    gap: 14px;
}
.customer-photo-preview {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--bg-raised);
    border: 1.5px dashed var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    cursor: pointer;
    overflow: hidden;
    flex-shrink: 0;
    transition: border-color 0.15s;
}
.customer-photo-preview:hover {
    border-color: var(--primary-color);
}
.customer-photo-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.customer-photo-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.customer-photo-actions .btn {
    padding: 7px 12px;
    font-size: 12px;
}

.customer-thumb {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
    background: var(--bg-raised);
}
.customer-thumb-placeholder {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--primary-dim);
    color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    text-transform: uppercase;
}

.merge-keep-info {
    padding: 10px 14px;
    background: var(--bg-raised);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-weight: 700;
}

.merge-candidates-list {
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    margin-top: 8px;
}

.merge-candidate-row {
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.12s;
}
.merge-candidate-row:last-child {
    border-bottom: none;
}
.merge-candidate-row:hover {
    background: var(--bg-raised);
}
.merge-candidate-row.selected {
    background: var(--primary-dim);
    font-weight: 600;
}

.merge-candidate-empty {
    padding: 14px;
    color: var(--text-secondary);
    text-align: center;
    font-size: 13px;
}

.merge-selected-wrap {
    margin-top: 16px;
}

.merge-selected-customer {
    padding: 10px 14px;
    background: rgba(246,109,109,0.1);
    border: 1px solid rgba(246,109,109,0.3);
    border-radius: var(--radius-sm);
    font-weight: 700;
}

.merge-warning {
    font-size: 12px;
    color: #f66d6d;
    margin-top: 8px;
}

/* ── Copy-number button next to phone numbers (turns green for a moment once copied) ── */
.phone-cell { white-space: nowrap; }
.copy-phone-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 20px; height: 20px; margin-left: 5px; padding: 0; vertical-align: middle;
    border-radius: 5px; border: 1px solid transparent; background: transparent;
    color: var(--text-secondary); cursor: pointer; flex-shrink: 0;
    transition: color .15s, background .15s, border-color .15s;
}
.copy-phone-btn:hover { color: var(--text-primary); background: var(--bg-raised, rgba(127,127,127,.12)); border-color: var(--border-color); }
.copy-phone-btn.copied, .copy-phone-btn.copied:hover { color: #fff; background: #16a34a; border-color: #16a34a; }

/* Customers tab: key button shows when the customer has a portal PIN */
.icon-btn.portal-on { background: rgba(5,150,105,.14); box-shadow: inset 0 0 0 1px rgba(5,150,105,.35); }

/* ══════════════════════════════════════════════════════
   NUMBERS — right-aligned, even-width digits so columns line up
   ══════════════════════════════════════════════════════ */
td, .summary-card .value, .sel-summary-amount { font-variant-numeric: tabular-nums; }

#sales-table tbody tr td.c-amt,
#sales-table thead th:nth-child(6) { text-align: right; padding-right: 18px; font-weight: 600; }

#customers-table td.num,
#summary-table td.num,
#customers-table thead th:nth-child(n+6):nth-child(-n+9),
#summary-table thead th:nth-child(n+2) { text-align: right; }

/* Phone / small tablet: summary cards fill the full width */
@media (max-width: 768px) {
  .sales-summary-row { align-items: stretch; }
  .summary-cards { width: 100%; }
}

/* ══════════════════════════════════════════════════════
   SMALL UTILITIES
   ══════════════════════════════════════════════════════ */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.muted { color: var(--text-secondary); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
td.over-limit { color: var(--danger-color); font-weight: 700; }
.limit-flag { display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 999px; font-size: 10px; font-weight: 700; background: rgba(220,38,38,0.1); color: var(--danger-color); vertical-align: 1px; }
.page-title { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; margin: 4px 0 6px; }
.page-lead { color: var(--text-secondary); font-size: 14px; margin-bottom: 18px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot-warn { background: var(--warning-color); }
.dot-danger { background: var(--danger-color); }

/* ══════════════════════════════════════════════════════
   APP SHELL - top bar (desktop menu) + bottom tab bar (phones)
   ══════════════════════════════════════════════════════ */
.appbar {
    position: sticky;
    top: 0;
    z-index: 900;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding-top: env(safe-area-inset-top);
}
.appbar-inner {
    max-width: 1200px;
    margin: 0 auto;
    height: var(--appbar-h);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 20px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text-primary); flex-shrink: 0; }
.brand-logo {
    width: 38px; height: 38px; border-radius: 10px;
    background: #111827;           /* the logo is white, so it always sits on a dark tile */
    display: grid; place-items: center; overflow: hidden; flex-shrink: 0;
}
.dark-mode .brand-logo { background: #262b33; }
.brand-logo img { width: 32px; height: 32px; object-fit: contain; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text b { font-size: 15px; font-weight: 700; }
.brand-text small { font-size: 12px; color: var(--text-secondary); font-weight: 500; }

.topnav { display: flex; gap: 2px; margin-left: 12px; flex: 1; min-width: 0; }
.topnav a {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 12px; border-radius: 10px;
    color: var(--text-secondary); text-decoration: none;
    font-size: 14px; font-weight: 600; white-space: nowrap;
    transition: background-color 0.15s, color 0.15s;
}
.topnav a svg { width: 18px; height: 18px; }
.topnav a:hover { background: var(--bg-raised); color: var(--text-primary); }
.topnav a.active { background: var(--primary-dim); color: var(--primary-color); }

.appbar-actions { margin-left: auto; display: flex; gap: 8px; flex-shrink: 0; }
.appbar-btn, .appbar-btn.theme-toggle {
    width: 40px; height: 40px; padding: 0; gap: 0;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    display: grid; place-items: center;
    cursor: pointer; text-decoration: none; box-shadow: none;
    transition: background-color 0.15s, color 0.15s;
}
.appbar-btn:hover, .appbar-btn.theme-toggle:hover { background: var(--bg-raised); color: var(--text-primary); transform: none; box-shadow: none; }
.appbar-btn svg, .appbar-btn #theme-icon svg { width: 18px; height: 18px; display: block; }
.appbar-btn.spinning svg { animation: cs-spin 0.8s linear infinite; }
@keyframes cs-spin { to { transform: rotate(360deg); } }

.bottomnav { display: none; }

@media (max-width: 1060px) {
    .topnav a span { display: none; }   /* icons only on small laptops/tablets */
    .topnav a { padding: 9px; }
}

@media (max-width: 860px) {
    :root { --appbar-h: 56px; }
    .appbar-inner { padding: 0 12px; gap: 10px; }
    .topnav { display: none; }
    .brand-logo { width: 34px; height: 34px; }
    .brand-logo img { width: 28px; height: 28px; }

    .bottomnav {
        display: grid;
        grid-template-columns: repeat(5, 1fr);
        position: fixed; left: 0; right: 0; bottom: 0;
        z-index: 950;
        background: var(--bg-secondary);
        border-top: 1px solid var(--border-color);
        padding-bottom: env(safe-area-inset-bottom);
    }
    .bottomnav a {
        height: var(--bottomnav-h);
        display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
        color: var(--text-secondary); text-decoration: none;
        font-size: 11px; font-weight: 600;
        position: relative;
    }
    .bottomnav a svg { width: 22px; height: 22px; }
    .bottomnav a.active { color: var(--primary-color); }
    .bottomnav a.active::before {
        content: ''; position: absolute; top: 0; left: 30%; right: 30%;
        height: 3px; border-radius: 0 0 3px 3px; background: var(--primary-color);
    }

    body { padding: 0 0 calc(var(--bottomnav-h) + env(safe-area-inset-bottom) + 12px); }
    #selection-bar.visible { bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom) + 8px); }
}

@media (max-width: 768px) {
    .container { padding: 12px 10px 24px; }
    /* the selection bar sits above the tab bar, so give the list room to scroll past it */
    body { padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom) + 130px); }
}

/* ══════════════════════════════════════════════════════
   DASHBOARD
   ══════════════════════════════════════════════════════ */
.dash-hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 4px 0 16px; }
.dash-date { font-size: 13px; color: var(--text-secondary); margin-bottom: 2px; }
.dash-title { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; white-space: normal; }

.quick-actions { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 16px; }
.qa {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px;
    background: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: var(--card-radius);
    color: var(--text-primary); text-decoration: none; font-weight: 600; font-size: 14px;
    transition: border-color 0.15s, background-color 0.15s;
}
.qa:hover { border-color: var(--accent-bdr); background: var(--bg-raised); }
.qa-icon {
    width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
    display: grid; place-items: center;
    background: var(--primary-dim); color: var(--primary-color);
}
.qa-primary .qa-icon { background: var(--primary-color); color: #fff; }
.dark-mode .qa-primary .qa-icon { color: #0b1220; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 14px; }
.kpi {
    display: flex; flex-direction: column; gap: 4px; min-width: 0;
    padding: 16px;
    background: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: var(--card-radius);
    color: var(--text-primary); text-decoration: none;
    transition: border-color 0.15s;
}
.kpi:hover { border-color: var(--accent-bdr); }
.kpi-label { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.kpi-value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; display: flex; align-items: baseline; gap: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-value .currency { font-size: 17px; color: var(--text-secondary); }
.kpi-sub { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-sub .currency { font-size: 11px; }
.kpi-danger .kpi-value { color: var(--danger-color); }
.kpi-success .kpi-value { color: var(--success-color); }

.limit-strip { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.limit-strip.hidden { display: none; }
.limit-pill {
    flex: 1 1 280px;
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px;
    background: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: var(--card-radius);
    color: var(--text-primary); text-decoration: none; font-size: 13px;
}
.limit-pill .currency { font-size: 12px; }
.limit-pill:hover { border-color: var(--accent-bdr); }
.limit-msg { flex: 1; min-width: 0; }
.limit-go { margin-left: auto; color: var(--primary-color); font-weight: 600; white-space: nowrap; }

/* Two independent columns (main 2/3, side 1/3): each panel stacks right under the
   one above it, so a short panel never leaves an empty gap beside a tall one. */
.dash-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 14px; align-items: start; }
.dash-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.panel {
    background: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: var(--radius-lg);
    padding: 16px 18px; min-width: 0;
}

.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.panel-head h2 { font-size: 15px; font-weight: 700; }
.panel-meta { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.panel-meta .currency { font-size: 12px; color: var(--text-secondary); }
.panel-link { display: inline-flex; align-items: center; gap: 2px; font-size: 13px; font-weight: 600; color: var(--primary-color); text-decoration: none; }
.panel-note { font-size: 12px; color: var(--text-secondary); margin-top: 10px; line-height: 1.5; }

.segmented { display: inline-flex; background: var(--bg-raised); border: 1px solid var(--border-color); border-radius: 10px; padding: 3px; gap: 2px; }
.segmented button {
    border: 0; background: none; cursor: pointer;
    padding: 6px 10px; border-radius: 7px;
    font: 600 12px/1.2 inherit; font-family: inherit; color: var(--text-secondary);
}
.segmented button.active { background: var(--bg-secondary); color: var(--text-primary); box-shadow: var(--shadow); }

.chart-totals { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12px; color: var(--text-secondary); margin-bottom: 10px; align-items: center; }
.chart-totals b { color: var(--text-primary); font-variant-numeric: tabular-nums; }
.chart-totals .currency { font-size: 11px; }
.ct-label { width: 100%; font-weight: 600; color: var(--text-secondary); }
.ct { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
.sw-given { background: linear-gradient(to top, var(--success-color) 50%, var(--warning-color) 50%); }
.sw-paid { background: var(--success-color); }
.sw-unpaid { background: var(--warning-color); }
.sw-collected { height: 3px; width: 14px; border-radius: 2px; background: var(--primary-color); }
.chart-box { position: relative; height: 280px; }

.mini-table { width: 100%; border-collapse: collapse; border-radius: 0; background: none; }
.mini-table th, .mini-table td { padding: 11px 4px; font-size: 14px; border-bottom: 1px solid var(--border-color); background: none; text-transform: none; letter-spacing: 0; }
.mini-table thead th { font-size: 12px; font-weight: 600; color: var(--text-secondary); padding-top: 0; }
.mini-table tbody th { text-align: left; font-weight: 600; color: var(--text-primary); }
.mini-table tbody tr:last-child th, .mini-table tbody tr:last-child td { border-bottom: 0; }
.mini-table tr:hover { background: none; }
.mini-table .num { text-align: right; font-weight: 600; }

.aging-bar { display: flex; gap: 2px; height: 12px; border-radius: 999px; overflow: hidden; background: var(--bg-raised); margin-bottom: 14px; }
.aging-bar span { display: block; height: 100%; }
.age-0 { background: var(--age-0); }
.age-1 { background: var(--age-1); }
.age-2 { background: var(--age-2); }
.age-3 { background: var(--age-3); }
.age-empty { background: var(--bg-raised); }
.aging-list { list-style: none; }
.aging-list li { display: grid; grid-template-columns: 10px 1fr auto auto 38px; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--border-color); font-size: 13px; }
.aging-list li:first-child { border-top: 0; }
.al-label { font-weight: 600; }
.al-bills { color: var(--text-secondary); font-size: 12px; }
.al-amt { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.al-amt .currency { font-size: 11px; color: var(--text-secondary); }
.al-pct { color: var(--text-secondary); text-align: right; font-size: 12px; font-variant-numeric: tabular-nums; }

.row-list { list-style: none; }
.row-list > li.muted { padding: 14px 0; font-size: 14px; }
.row-list > li + li .row { border-top: 1px solid var(--border-color); }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 0; color: var(--text-primary); text-decoration: none; }
.row:hover .row-main b { color: var(--primary-color); }
.avatar {
    width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
    display: grid; place-items: center; object-fit: cover;
    background: var(--primary-dim); color: var(--primary-color);
    font-weight: 700; font-size: 14px; text-transform: uppercase;
}
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-main b, .row-main small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-main b { font-size: 14px; font-weight: 600; transition: color 0.15s; }
.row-main small { font-size: 12px; color: var(--text-secondary); }
.row-end { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; flex-shrink: 0; text-align: right; }
.row-end b { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-end b .currency { font-size: 11px; color: var(--text-secondary); }
.row-end small { font-size: 12px; white-space: nowrap; }
.row-end .status-badge { font-size: 11px; padding: 2px 8px; }
.limit-bar { display: block; height: 4px; max-width: 160px; border-radius: 999px; background: var(--bg-raised); margin-top: 4px; overflow: hidden; }
.limit-bar span { display: block; height: 100%; background: var(--primary-color); border-radius: inherit; }
.limit-bar.over span { background: var(--danger-color); }

.shortcut-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.shortcut {
    display: flex; align-items: flex-start; gap: 12px;
    padding: 12px; border: 1px solid var(--border-color); border-radius: var(--card-radius);
    color: var(--text-primary); text-decoration: none;
    transition: background-color 0.15s, border-color 0.15s;
}
.shortcut svg { color: var(--primary-color); flex-shrink: 0; margin-top: 1px; }
.shortcut span { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.shortcut b { font-size: 14px; font-weight: 600; }
.shortcut small { font-size: 12px; color: var(--text-secondary); }
.shortcut:hover { background: var(--bg-raised); border-color: var(--accent-bdr); }

.dash-foot { text-align: center; font-size: 12px; color: var(--text-secondary); margin: 24px 0 8px; }

@media (max-width: 1100px) {
    .quick-actions { grid-template-columns: repeat(5, 1fr); }
    .qa { flex-direction: column; text-align: center; gap: 8px; padding: 12px 6px; font-size: 13px; }
}

/* Tablet portrait and phones: one column, most useful panels first */
@media (max-width: 900px) {
    .dash-grid { display: flex; flex-direction: column; align-items: stretch; }
    .dash-col { display: contents; }
    .dash-grid .panel { width: 100%; }
    .panel-chart { order: 1; }
    .panel-due { order: 2; }
    .panel-debtors { order: 3; }
    .panel-periods { order: 4; }
    .panel-aging { order: 5; }
    .panel-recent { order: 6; }
    .panel-shortcuts { order: 7; }
}

@media (max-width: 700px) {
    .dash-title { font-size: 21px; }
    .quick-actions { gap: 6px; }
    .qa { padding: 10px 2px; font-size: 11px; border-radius: 12px; line-height: 1.2; }
    .qa-icon { width: 40px; height: 40px; border-radius: 12px; }
    .kpi-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .kpi { padding: 12px; }
    .kpi-label { font-size: 12px; }
    .kpi-value { font-size: 19px; }
    .kpi-value .currency { font-size: 13px; }
    .kpi-sub { font-size: 11px; }
    .dash-grid { gap: 10px; }
    .panel { padding: 14px; border-radius: var(--card-radius); }
    .chart-box { height: 220px; }
    .segmented button { padding: 6px 8px; }
    .shortcut-grid { grid-template-columns: 1fr; }
}

/* ══════════════════════════════════════════════════════
   SETTINGS
   ══════════════════════════════════════════════════════ */
.container.narrow { max-width: 760px; }
.settings-section { margin-bottom: 14px; }
.settings-section .form-group:last-child { margin-bottom: 0; }
.optional { font-weight: 500; color: var(--text-secondary); font-size: 12px; margin-left: 4px; }
.field-error { color: var(--danger-color); font-size: 12px; font-weight: 600; margin-top: 4px; }
.field-error:empty { display: none; }
.input-prefix { position: relative; }
.input-prefix .currency { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-secondary); font-size: 15px; pointer-events: none; }
.form-group .input-prefix input { padding-left: 34px; }
.inline-fields { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.form-group .inline-fields select { width: auto; flex: 1 1 240px; }
.input-suffix { display: flex; align-items: center; gap: 8px; color: var(--text-secondary); font-size: 14px; }
.input-suffix.hidden { display: none; }
.form-group .input-suffix input { width: 110px; }
.message-preview { margin-top: 12px; background: var(--bg-raised); border: 1px solid var(--border-color); border-radius: 10px; padding: 12px; }
.preview-label { display: block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-secondary); margin-bottom: 6px; }
.message-preview pre { font-family: inherit; font-size: 13px; white-space: pre-wrap; margin: 0; }
.settings-actions { display: flex; align-items: center; justify-content: flex-end; gap: 14px; margin: 4px 0 18px; }
.save-status { font-size: 13px; font-weight: 600; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0; border-top: 1px solid var(--border-color); }
.settings-row:first-of-type { border-top: 0; padding-top: 0; }
.settings-row b { display: block; font-size: 14px; font-weight: 600; }
.settings-row small { display: block; font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.settings-value { font-weight: 600; white-space: nowrap; }
.form-group select { appearance: auto; }

/* Bills page: the section switcher moved to the main menu, so the Customers
   highlight box and Summary month picker now sit at the top of their section */
.tab-content > .tab-context-bar { margin: 0 0 16px; padding: 0; justify-content: flex-start; flex-wrap: nowrap; white-space: nowrap; }
.tab-content > .tab-context-bar input { min-width: 0; max-width: 200px; }
.tab-content > .tab-context-bar.hidden { display: flex; }
@media (max-width: 860px) {
    /* phone tab bar: as many equal columns as there are items */
    .bottomnav { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 1fr; }
}

/* ══════════════════════════════════════════════════════
   BILLS / CUSTOMERS / SUMMARY / PENDING WATCH - same look as the Dashboard:
   no big outer box; each block (number cards, toolbar, table, chart) is its
   own card sitting on the page background.
   ══════════════════════════════════════════════════════ */
.container > .card {
    background: none;
    border: 0;
    box-shadow: none;
    border-radius: 0;
    padding: 0 !important;
    margin-bottom: 0;
}
.container > .card > .tab-content { padding: 0; }

.table-scroll {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    overflow-x: auto;
}
.table-scroll table { border-radius: 0; background: transparent; }
.table-scroll thead th:first-child { border-top-left-radius: var(--radius-lg); }
.table-scroll thead th:last-child { border-top-right-radius: var(--radius-lg); }
.table-scroll tbody tr:last-child td { border-bottom: 0; }

#summary-tab .summary-cards,
#sales-tab .sales-summary-row { margin-bottom: 16px; }

@media (max-width: 768px) {
    .container > .card > .tab-content { padding: 0; }
    .table-scroll { border-radius: var(--card-radius); }
    .table-scroll thead th:first-child { border-top-left-radius: var(--card-radius); }
    .table-scroll thead th:last-child { border-top-right-radius: var(--card-radius); }
}

/* ── Floating selection bar: payment message lives here now (no layout jump) ── */
#selection-bar { max-width: 1100px; }
.sel-inner { flex-direction: column; align-items: stretch; gap: 10px; }
.sel-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.sel-top .sel-info { flex: 0 1 auto; }
.sel-pay { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-wrap: nowrap; }
.sel-pay.hidden { display: none; }
.sel-pay .sel-summary-input { width: 96px; flex: 0 0 96px; min-height: 34px; padding: 6px 8px; }
.sel-pay .sel-summary-amount { font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; }
.sel-pay .sel-summary-amount .currency { font-size: 12px; }
.sel-copy {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 12px; border-radius: var(--radius-sm);
    border: 1px solid var(--border-color); background: var(--bg-raised);
    color: var(--text-primary); font: 700 12px/1 inherit; font-family: inherit;
    cursor: pointer; white-space: nowrap;
}
.sel-copy:hover { border-color: var(--accent-bdr); color: var(--primary-color); }
.sel-actions { justify-content: flex-end; flex-wrap: wrap; }

@media (max-width: 768px) {
    .sel-pay { margin-left: 0; width: 100%; }
    .sel-pay .sel-summary-input { flex: 1 1 0; width: 0; min-width: 0; }
    .sel-pay .sel-summary-amount { white-space: nowrap; }
    .sel-copy { padding: 8px 10px; }
    body { padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom) + 190px); }
}

/* ══════════════════════════════════════════════════════
   BILLS PAGE LISTS: sticky search line, sticky table header,
   table sits directly on the page (no box), "⋯" menus, back-to-top
   ══════════════════════════════════════════════════════ */
:root { --toolbar-h: 0px; --list-bottom-gap: 16px; }

/* search fills the space up to the buttons */
.toolbar .search-box { flex: 1 1 auto; min-width: 0; max-width: none; }
.toolbar .search-box input { width: 100%; }

/* search + buttons line stays under the top bar while scrolling */
.tab-content > .toolbar {
    position: sticky;
    top: var(--appbar-h);
    z-index: 60;
    margin-bottom: 0;
    padding: 12px 0;
    background: var(--bg-primary);
}
/* page-coloured strip reaching into the side padding, so rows scrolling under it are hidden */
.tab-content > .toolbar::before {
    content: '';
    position: absolute;
    inset: 0 -20px;
    background: var(--bg-primary);
    z-index: -1;
}
@media (max-width: 768px) {
    .tab-content > .toolbar::before { inset: 0 -10px; }
}

/* the table: no box around it */
.table-scroll {
    background: none;
    border: 0;
    border-radius: 0;
}
.table-scroll > table,
.table-scroll > table#sales-table,
.table-scroll > table#customers-table,
.table-scroll > table#summary-table {
    display: table;
    overflow: visible;
    border-radius: 0;
    background: transparent;
}
.table-scroll thead th,
.table-scroll thead th:first-child,
.table-scroll thead th:last-child { border-radius: 0; }
.table-scroll tbody tr:last-child td { border-bottom: 1px solid var(--border-color); }

/* header row sticks under the search line */
.table-scroll thead th {
    position: sticky;
    top: calc(var(--appbar-h) + var(--toolbar-h));
    z-index: 30;
    background: var(--bg-raised);
    box-shadow: inset 0 -1px 0 var(--border-color);
}

/* Big screens: the table fits, so the page itself scrolls */
@media (min-width: 1101px) {
    .table-scroll { overflow: visible; }
}

/* Smaller screens: wide tables need sideways scrolling, so the table gets its own
   scroll area filling the rest of the screen - the header then sticks inside it */
@media (max-width: 1100px) {
    .table-scroll {
        overflow: auto;
        -webkit-overflow-scrolling: touch;
        max-height: calc(100dvh - var(--appbar-h) - var(--toolbar-h) - var(--list-bottom-gap) - env(safe-area-inset-top));
        overscroll-behavior: contain;
        /* the table area itself stays put under the search line once the cards above scroll away */
        position: sticky;
        top: calc(var(--appbar-h) + var(--toolbar-h));
    }
    .table-scroll thead th { top: 0; }
}
@media (max-width: 860px) {
    :root { --list-bottom-gap: calc(var(--bottomnav-h) + env(safe-area-inset-bottom) + 8px); }
    .tab-content > .toolbar { padding: 8px 0; }
}

/* "⋯" more-actions menu */
.btn-more { min-width: 44px; padding: 10px 12px; }
.dropdown-menu.dropdown-right { left: auto; right: 0; min-width: 200px; }
.toolbar-buttons .dropdown-wrap { flex: 0 0 auto; }
@media (max-width: 768px) {
    .toolbar-buttons .dropdown-wrap { flex: 0 0 auto; }
    .toolbar-buttons .dropdown-wrap .btn-more { width: auto; }
    .dropdown-menu.dropdown-right { left: auto; right: 0; min-width: 200px; }
}

/* back to top */
.to-top {
    position: fixed;
    right: 20px;
    bottom: calc(24px + env(safe-area-inset-bottom));
    z-index: 940;
    width: 46px; height: 46px; border-radius: 50%;
    display: grid; place-items: center;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    opacity: 0; transform: translateY(12px); pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
}
.to-top.show { opacity: 1; transform: none; pointer-events: auto; }
.to-top:hover { color: var(--primary-color); border-color: var(--accent-bdr); }
body:has(#selection-bar.visible) .to-top { opacity: 0; pointer-events: none; }
@media (max-width: 860px) {
    .to-top { right: 14px; bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom) + 14px); }
}

/* Bills page on smaller screens: the table area fills the screen exactly, so the page
   can't scroll past it (which would slide the sticky header away) */
@media (max-width: 1100px) {
    body:has(#sales-tab) { padding-bottom: 0; }
    body:has(#sales-tab) .container { padding-bottom: 8px; }
    :root { --list-bottom-gap: 8px; }
    /* room to scroll the last rows clear of the floating selection bar */
    body:has(#selection-bar.visible) .table-scroll { padding-bottom: 150px; }
}
@media (max-width: 860px) {
    body:has(#sales-tab) { padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom)); }
    :root { --list-bottom-gap: calc(var(--bottomnav-h) + env(safe-area-inset-bottom) + 8px); }
}
@media (max-width: 768px) {
    /* Customers: search, Add and ⋯ share one line on phones */
    #customers-tab > .toolbar { flex-direction: row; align-items: center; }
    #customers-tab > .toolbar .search-box { min-width: 0; }
    #customers-tab .toolbar-buttons { width: auto; flex: 0 0 auto; }
    #customers-tab .toolbar-buttons .btn { flex: 0 0 auto; width: 44px; height: 42px; padding: 0; }
}

/* Bills & Customers: search and buttons always on ONE line (labels become icons on small screens) */
.tab-content > .toolbar { flex-direction: row; flex-wrap: nowrap; align-items: center; }
.tab-content > .toolbar .toolbar-buttons { flex: 0 0 auto; width: auto; }
.tab-content > .toolbar .btn.hidden { display: none; }
@media (max-width: 900px) {
    .tab-content > .toolbar .search-box { min-width: 0; max-width: none; }
    .tab-content > .toolbar .toolbar-buttons { gap: 6px; }
    .tab-content > .toolbar .toolbar-buttons .btn { flex: 0 0 auto; width: 42px; height: 42px; min-width: 42px; padding: 0; gap: 0; }
    .tab-content > .toolbar .toolbar-buttons .btn .btn-label { display: none; }
    .tab-content > .toolbar .search-box input { font-size: 16px; padding-right: 30px; }
}

/* Dashboard header: Refresh + "Add" menu on the right */
.dash-hero { align-items: center; }
.dash-hero-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.dash-add-btn { height: 40px; padding: 0 14px; gap: 6px; border-radius: 10px; }
.dash-hero .dropdown-menu { top: calc(100% + 6px); z-index: 200; min-width: 190px; }
.dropdown-menu a {
    width: 100%;
    display: flex; align-items: center; gap: 10px;
    padding: 10px 10px;
    border-radius: var(--radius-sm);
    font-size: 14px; font-weight: 600;
    color: var(--text-primary); text-decoration: none;
    transition: background-color 0.12s;
}
.dropdown-menu a svg { color: var(--primary-color); flex-shrink: 0; }
.dropdown-menu a:hover { background: var(--primary-dim); color: var(--primary-color); }
.dropdown-menu button svg { flex-shrink: 0; }

/* "All time" label above the totals cards */
.section-label { font-size: 13px; font-weight: 600; color: var(--text-secondary); margin: 0 0 8px; text-transform: none; }
.kpi-warn .kpi-value { color: var(--warning-color); }

/* ══════════════════════════════════════════════════════
   SUMMARY section
   ══════════════════════════════════════════════════════ */
.summary-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.month-switch { display: flex; align-items: center; gap: 6px; }
.month-switch input[type="month"] {
    height: 40px; padding: 0 12px;
    border: 1px solid var(--border-color); border-radius: 10px;
    background: var(--bg-secondary); color: var(--text-primary);
    font: 600 15px/1 inherit; font-family: inherit;
    color-scheme: light dark;
}
.month-switch .appbar-btn:disabled { opacity: 0.35; cursor: default; }
.summary-compare { font-size: 13px; color: var(--text-secondary); }
.summary-compare .currency { font-size: 11px; }

.month-cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.summary-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 14px; align-items: start; margin-bottom: 18px; }
.summary-insights { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12px; color: var(--text-secondary); margin-bottom: 10px; }
.summary-insights b { color: var(--text-primary); }
.summary-insights .currency { font-size: 11px; }
.chart-legend { display: inline-flex; gap: 12px; font-size: 12px; color: var(--text-secondary); }
#summary-tab .chart-box { height: 260px; }
.summary-table-label { margin-top: 4px; }

@media (max-width: 900px) {
    .summary-grid { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
    .month-cards { grid-template-columns: 1fr 1fr; gap: 8px; }
    .month-cards .kpi { padding: 12px; }
    .month-cards .kpi-value { font-size: 19px; }
    .month-cards .kpi-sub { font-size: 11px; }
    #summary-tab .chart-box { height: 220px; }
    .month-switch { width: 100%; }
    .month-switch input[type="month"] { flex: 1; font-size: 16px; }
}

/* ══════════════════════════════════════════════════════
   BILLS: one customer found -> hide Phone/Customer columns, show their card
   ══════════════════════════════════════════════════════ */
#sales-table.single-customer th:nth-child(3),
#sales-table.single-customer td:nth-child(3),
#sales-table.single-customer th:nth-child(4),
#sales-table.single-customer td:nth-child(4) { display: none; }

.customer-card {
    display: flex; align-items: center; gap: 12px;
    padding: 8px 14px; margin-bottom: 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--card-radius);
}
.customer-card.hidden { display: none; }
.cc-who { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; }
.cc-who b { font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cc-who small { font-size: 12px; color: var(--text-secondary); display: flex; align-items: center; white-space: nowrap; overflow: hidden; }
.cc-stats { display: flex; gap: 18px; flex: 0 0 auto; }
.cc-stat { display: flex; flex-direction: column; text-align: right; line-height: 1.25; }
.cc-stat > span { font-size: 11px; font-weight: 600; color: var(--text-secondary); }
.cc-stat b { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cc-stat b .currency { font-size: 11px; color: var(--text-secondary); }
.cc-short { display: none; }
.cc-stat.cc-warn b { color: var(--warning-color); }
.cc-stat.cc-danger b { color: var(--danger-color); }
.cc-stat.cc-success b { color: var(--success-color); }

/* phones: still one line - whole numbers, tighter spacing */
@media (max-width: 700px) {
    .customer-card { padding: 7px 10px; gap: 8px; }
    .cc-who b { font-size: 13px; }
    .cc-who small { font-size: 11px; }
    .cc-who .copy-phone-btn, .cc-limit { display: none; }
    .cc-stats { gap: 9px; }
    .cc-stat > span { font-size: 10px; }
    .cc-stat b { font-size: 13px; }
    .cc-full { display: none; }
    .cc-short { display: inline; }
}

/* Settings: values to copy (widget address/key) */
.copy-value { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; word-break: break-all; user-select: all; }
