/* ================================================================
   Sales Reports Mobile Web App -- Mobile-first CSS
   ================================================================ */

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #dbeafe;
    --success: #16a34a;
    --success-light: #dcfce7;
    --error: #dc2626;
    --error-light: #fef2f2;
    --warning: #f59e0b;
    --warning-light: #fef9c3;
    --bg: #f8fafc;
    --bg-card: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    --border: #e2e8f0;
    --border-focus: #2563eb;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
    --radius: 12px;
    --radius-sm: 8px;
    --bottom-nav-height: 84px;
}

body.dark-theme {
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-light: #1e3a5f;
    --success: #22c55e;
    --success-light: #14532d;
    --error: #ef4444;
    --error-light: #450a0a;
    --warning: #f59e0b;
    --warning-light: #451a03;
    --bg: #0f172a;
    --bg-card: #1e293b;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --text-light: #64748b;
    --border: #334155;
    --border-focus: #3b82f6;
    --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.3), 0 2px 4px rgba(0,0,0,0.2);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.4), 0 4px 6px rgba(0,0,0,0.2);
}
body.dark-theme .form-input,
body.dark-theme .form-select {
    background: #0f172a;
    color: var(--text);
    border-color: var(--border);
}
body.dark-theme .data-table th {
    background: #0f172a;
}
body.dark-theme .data-table tr:nth-child(even) {
    background: rgba(255,255,255,0.03);
}
body.dark-theme .btn-outline {
    border-color: var(--border);
    color: var(--text-muted);
}
body.dark-theme .login-card {
    background: var(--bg-card);
}
body.dark-theme .badge-admin {
    background: #422006;
    color: #fbbf24;
}
body.dark-theme .badge-salesman {
    background: var(--primary-light);
    color: #60a5fa;
}
body.dark-theme .status-dash-active,
body.dark-theme .status-dash-completed {
    background: var(--success-light);
    color: #4ade80;
}
body.dark-theme .status-dash-overdue,
body.dark-theme .status-dash-failed {
    background: var(--error-light);
    color: #f87171;
}
body.dark-theme .status-dash-running {
    background: var(--warning-light);
    color: #fbbf24;
}
body.dark-theme .status-dash-new {
    background: var(--primary-light);
    color: #60a5fa;
}
body.dark-theme .status-dash-inactive,
body.dark-theme .status-dash-no_data {
    background: #1e293b;
    color: var(--text-muted);
}
body.dark-theme .status-badge {
    border: 1px solid rgba(255,255,255,0.1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    padding-bottom: var(--bottom-nav-height);
}

/* -- Header -------------------------------------------------------------- */

.app-header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header-logo {
    font-weight: 700;
    font-size: 18px;
    color: var(--primary);
    text-decoration: none;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    flex-shrink: 0;
}
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    min-height: 32px;
    padding: 4px;
}

.user-name {
    display: none;
}

@media (min-width: 480px) {
    .user-name { display: inline; color: var(--text-muted); }
}

.badge {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 99px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-admin {
    background: #fef3c7;
    color: #92400e;
}

.badge-salesman {
    background: var(--primary-light);
    color: var(--primary);
}

/* -- Bottom Navigation --------------------------------------------------- */

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: flex-start;
    justify-content: space-around;
    z-index: 200;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--text-light);
    font-size: 11px;
    font-weight: 500;
    transition: color 0.15s;
    -webkit-tap-highlight-color: transparent;
    gap: 4px;
    padding: 12px 0 8px;
}

.bottom-nav-item.active {
    color: var(--primary);
}

.bottom-nav-item:hover {
    color: var(--primary);
}

.bottom-nav-icon {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bottom-nav-icon svg {
    width: 22px;
    height: 22px;
}

.bottom-nav-label {
    font-size: 11px;
    line-height: 1;
}

.nav-badge {
    position: absolute;
    top: -6px;
    right: -10px;
    background: var(--error);
    color: white;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 99px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    line-height: 1;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* -- Container ----------------------------------------------------------- */

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 16px;
}

@media (min-width: 768px) {
    .container { padding: 24px 32px; }
}

/* -- Buttons ------------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    text-decoration: none;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.btn svg { width: 18px; height: 18px; }

.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:active { transform: scale(0.98); }

.btn-outline {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}
.btn-outline:hover { background: var(--bg); }

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 14px 24px; font-size: 17px; }
.btn-block { width: 100%; }

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* -- Login Page ---------------------------------------------------------- */

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 100px);
    padding: 24px;
}

.login-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 40px 32px;
    max-width: 420px;
    width: 100%;
    text-align: center;
}

.login-icon {
    color: var(--primary);
    margin-bottom: 16px;
}

.login-icon.error-icon { color: var(--error); }

.login-card h1 {
    font-size: 24px;
    margin-bottom: 8px;
}

.login-subtitle {
    color: var(--text-muted);
    font-size: 15px;
    margin-bottom: 24px;
}

/* -- Page Header --------------------------------------------------------- */

.page-header {
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 24px;
    font-weight: 700;
}

.page-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.page-subtitle {
    color: var(--text-muted);
    font-size: 15px;
    margin-top: 4px;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--primary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 12px;
}

.back-link svg { width: 18px; height: 18px; }

/* -- Report Grid --------------------------------------------------------- */

.report-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Presets */
.presets-section { margin-bottom: 20px; }
.presets-header h2 { font-size: 16px; font-weight: 600; margin-bottom: 8px; color: var(--text); }
.presets-grid { display: grid; gap: 8px; }
.preset-card {
    display: flex; align-items: center; justify-content: space-between;
    background: var(--bg-card); border-radius: 10px; box-shadow: 0 1px 3px rgba(0,0,0,.06);
    border: 1px solid var(--border);
}
.preset-card-body {
    flex: 1; padding: 12px 14px;
}
.preset-card-name { font-size: 15px; font-weight: 600; color: var(--text); }
.preset-card-report { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.preset-card-actions {
    display: flex; align-items: center; gap: 4px; padding-right: 8px; flex-shrink: 0;
}
.preset-run-btn {
    display: inline-flex; align-items: center; gap: 4px; font-size: 13px;
    padding: 6px 12px; white-space: nowrap;
}
.preset-delete-btn {
    background: none; border: none; color: var(--text-muted); padding: 8px;
    cursor: pointer; flex-shrink: 0;
}
.preset-delete-btn:hover { color: var(--error); }
.preset-delete-btn svg { width: 16px; height: 16px; }

.report-card {
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    text-decoration: none;
    color: var(--text);
    transition: all 0.15s ease;
    box-shadow: var(--shadow);
    -webkit-tap-highlight-color: transparent;
}

.report-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
}

.report-card:active {
    transform: scale(0.99);
}

.report-card-icon {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.report-card-icon svg { width: 24px; height: 24px; }

.report-card-body {
    flex: 1;
    min-width: 0;
}

.report-card-body h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 2px;
}

.report-card-body p {
    font-size: 13px;
    color: var(--text-muted);
}

.report-card-arrow {
    flex-shrink: 0;
    color: var(--text-light);
}

.report-card-arrow svg { width: 20px; height: 20px; }

/* -- Form ---------------------------------------------------------------- */

.report-form {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

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

.form-label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
}

.form-input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 16px;
    background: var(--bg);
    color: var(--text);
    -webkit-appearance: none;
    appearance: none;
    transition: border-color 0.15s;
}

.form-input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 40px;
}

/* -- Period Buttons ------------------------------------------------------ */

.period-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.period-btn,
.status-btn {
    flex: 1 1 auto;
    min-width: 100px;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    text-align: center;
    -webkit-tap-highlight-color: transparent;
}

.period-btn:hover,
.status-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.period-btn.active,
.status-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* -- Date Row ------------------------------------------------------------ */

.date-row {
    display: flex;
    gap: 12px;
}

.date-field {
    flex: 1;
}

/* -- Loading ------------------------------------------------------------- */

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    backdrop-filter: blur(2px);
}

.loading-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 40px 32px;
    text-align: center;
    box-shadow: var(--shadow-lg);
    max-width: 320px;
    width: 90%;
}

.loading-card h3 { margin-top: 16px; font-size: 18px; }
.loading-card p { color: var(--text-muted); font-size: 14px; margin-top: 8px; }

.spinner {
    width: 44px;
    height: 44px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    margin: 0 auto;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* -- Progress bar -------------------------------------------------------- */

.progress-bar-track {
    width: 100%;
    height: 8px;
    background: var(--border);
    border-radius: 99px;
    margin-top: 16px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 99px;
    transition: width 0.4s ease;
}

.progress-steps {
    display: flex;
    justify-content: space-between;
    margin-top: 10px;
    font-size: 11px;
    color: var(--text-light);
}

.progress-step {
    transition: color 0.3s;
}

.progress-step.active {
    color: var(--primary);
    font-weight: 600;
}

.progress-step.done {
    color: var(--success);
}

/* -- Status badges (history) --------------------------------------------- */

.status-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 99px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.status-completed {
    background: var(--success-light);
    color: #166534;
}

.status-running {
    background: var(--primary-light);
    color: #1e40af;
}

.status-failed {
    background: var(--error-light);
    color: var(--error);
}

.status-no_data {
    background: var(--warning-light);
    color: #854d0e;
}

body.dark-theme .status-completed {
    background: var(--success-light);
    color: #4ade80;
}
body.dark-theme .status-running {
    background: var(--primary-light);
    color: #60a5fa;
}
body.dark-theme .status-failed {
    background: var(--error-light);
    color: #f87171;
}
body.dark-theme .status-no_data {
    background: var(--warning-light);
    color: #fbbf24;
}

/* -- Dashboard status badges --------------------------------------------- */

.status-dash-active {
    background: var(--success-light);
    color: #166534;
}

.status-dash-overdue {
    background: var(--error-light);
    color: var(--error);
}

.status-dash-inactive {
    background: var(--bg);
    color: var(--text-muted);
}

.status-dash-new {
    background: var(--primary-light);
    color: var(--primary);
}

.status-dash-running {
    background: var(--warning-light);
    color: #92400e;
}

.status-dash-completed {
    background: var(--success-light);
    color: #166534;
}

.status-dash-failed {
    background: var(--error-light);
    color: var(--error);
}

.status-dash-no_data {
    background: var(--bg);
    color: var(--text-muted);
}

/* -- Results ------------------------------------------------------------- */

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

.results-header h2 { font-size: 20px; }

/* -- Tabs ---------------------------------------------------------------- */

.tabs {
    display: flex;
    border-bottom: 2px solid var(--border);
    margin-bottom: 16px;
    gap: 0;
}

.tab-btn {
    flex: 1;
    padding: 12px 16px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: -2px;
}

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

.tab-content { display: none; }
.tab-content.active { display: block; }

.sheet-tabs {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    padding-bottom: 8px;
    margin-bottom: 12px;
    -webkit-overflow-scrolling: touch;
}

.sheet-tab-btn {
    flex-shrink: 0;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 99px;
    background: var(--bg);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.sheet-tab-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* -- Summary Cards ------------------------------------------------------- */

.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.summary-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    text-align: center;
    box-shadow: var(--shadow);
}

.summary-card .card-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.summary-card .card-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
}

/* -- Data Table ---------------------------------------------------------- */

.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    box-shadow: var(--shadow);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    white-space: nowrap;
}

.dash-activity-table {
    white-space: normal;
    min-width: 600px;
}

.dash-activity-table .cell-nowrap {
    white-space: nowrap;
}

.data-table th {
    background: var(--bg);
    font-weight: 600;
    text-align: left;
    padding: 10px 12px;
    border-bottom: 2px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 1;
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    cursor: pointer;
    user-select: none;
}

.data-table th:hover {
    color: var(--primary);
}

.data-table th .sort-arrow {
    margin-left: 4px;
    font-size: 10px;
    opacity: 0.4;
}

.data-table th.sorted .sort-arrow {
    opacity: 1;
    color: var(--primary);
}

.data-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
}

.data-table tr:last-child td { border-bottom: none; }

.data-table tr:hover td { background: var(--bg); }

.data-table .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.btn-params-toggle {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px 8px;
    cursor: pointer;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    transition: background 0.15s, color 0.15s;
}
.btn-params-toggle:hover,
.btn-params-toggle.active {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
}
.log-params-detail {
    margin-top: 6px;
    font-size: 12px;
    line-height: 1.5;
}
.log-param-item {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 260px;
}
.log-param-key {
    font-weight: 600;
    color: var(--text-muted);
}
.log-params-cell {
    min-width: 80px;
}

/* -- Chart --------------------------------------------------------------- */

.chart-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
    max-height: 300px;
}

/* -- Flash Messages ------------------------------------------------------ */

.flash-messages {
    margin-bottom: 16px;
}

.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    margin-bottom: 8px;
}

.alert-error {
    background: var(--error-light);
    color: var(--error);
    border: 1px solid var(--error-light);
}

.alert-success {
    background: #f0fdf4;
    color: var(--success);
    border: 1px solid #bbf7d0;
}
body.dark-theme .alert-success {
    background: var(--success-light);
    color: #4ade80;
    border-color: #166534;
}
body.dark-theme .alert-error {
    background: var(--error-light);
    color: #f87171;
    border-color: #7f1d1d;
}

/* -- Error display ------------------------------------------------------- */

.error-box {
    background: var(--error-light);
    border: 1px solid var(--error-light);
    border-radius: var(--radius-sm);
    padding: 20px;
    margin: 16px 0;
    text-align: center;
}

.error-box h3 {
    color: var(--error);
    font-size: 16px;
    margin-bottom: 8px;
}

.error-box p {
    color: var(--error);
    font-size: 14px;
}

/* -- Run button emphasis ------------------------------------------------- */

#runBtn {
    margin-top: 8px;
    font-size: 18px;
    padding: 16px 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    min-height: 56px;
}

#runBtn:active {
    transform: scale(0.97);
    box-shadow: var(--shadow);
}

/* -- Touch-friendly minimums --------------------------------------------- */

.period-btn,
.status-btn,
.sheet-tab-btn,
.tab-btn,
.form-input,
.form-select {
    min-height: 44px;
}

/* -- Customer Multi-Select Picker ---------------------------------------- */

.selected-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
    min-height: 0;
}

.selected-chips:empty {
    display: none;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 99px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.chip:hover {
    background: var(--primary);
    color: white;
}

.chip .chip-remove {
    font-size: 15px;
    font-weight: 700;
    line-height: 1;
    opacity: 0.6;
}

.chip:hover .chip-remove { opacity: 1; }

.customer-picker {
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    -webkit-overflow-scrolling: touch;
}

.customer-picker-loading {
    padding: 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

.customer-picker-empty {
    padding: 16px;
    text-align: center;
    color: var(--text-light);
    font-size: 14px;
}

.customer-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.1s;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
}

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

.customer-item:hover { background: var(--bg); }

.customer-item.selected {
    background: var(--primary-light);
}

.customer-item .cust-check {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    border: 2px solid var(--border);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    font-size: 14px;
    color: transparent;
}

.customer-item.selected .cust-check {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.customer-item .cust-label {
    flex: 1;
    min-width: 0;
    font-size: 14px;
}

.customer-item .cust-label .cust-account {
    font-weight: 600;
    margin-right: 6px;
}

.customer-item .cust-label .cust-name {
    color: var(--text-muted);
}

/* -- History ------------------------------------------------------------- */

.history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.history-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    box-shadow: var(--shadow);
}

.history-item-main {
    flex: 1;
    min-width: 0;
}

.history-item-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 6px;
    flex-wrap: wrap;
}

.history-report-name {
    font-weight: 600;
    font-size: 15px;
}

.history-timestamp {
    font-size: 12px;
    color: var(--text-light);
    white-space: nowrap;
}

.history-params {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 4px;
}

.history-param-tag {
    display: inline-block;
    font-size: 12px;
    padding: 2px 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 99px;
    color: var(--text-muted);
}

.history-summary-line {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.history-stat strong {
    color: var(--text);
}

.history-item-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
}

/* -- Empty state --------------------------------------------------------- */

.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}

.empty-state i, .empty-state svg {
    margin-bottom: 16px;
    opacity: 0.4;
}

.empty-state h3 {
    font-size: 18px;
    color: var(--text);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 14px;
    max-width: 300px;
    margin: 0 auto;
}

/* -- History button ------------------------------------------------------ */

.history-label {
    display: none;
}

@media (min-width: 400px) {
    .history-label { display: inline; }
}

/* -- Dashboard Summary Cards --------------------------------------------- */

.dash-summary-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

@media (min-width: 600px) {
    .dash-summary-cards {
        grid-template-columns: repeat(4, 1fr);
    }
}

.dash-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
    box-shadow: var(--shadow);
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
}

.dash-card-filter {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.dash-card-filter:active {
    transform: scale(0.97);
}

.dash-card-filter-active {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-light), var(--shadow);
}

.dash-card-active .dash-card-value {
    color: var(--success);
}

.dash-card-overdue .dash-card-value {
    color: var(--error);
}

.dash-card-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.dash-card-value {
    font-size: 28px;
    font-weight: 800;
    color: var(--text);
    line-height: 1.2;
}

.dash-card-unit {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    margin-left: 4px;
}

/* -- Dashboard Alerts ---------------------------------------------------- */

.dash-alerts {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 20px;
}

.dash-alerts-header {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
}

.dash-alerts-header .dash-section-title {
    margin-bottom: 0;
    flex: 1;
}

.dash-alerts-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dash-alerts-toggle::after {
    content: '\25B2';
    font-size: 11px;
    color: var(--text-muted);
    transition: transform 0.2s;
}

.dash-alerts-toggle.collapsed::after {
    transform: rotate(180deg);
}

.dash-alerts-body {
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.2s ease;
    max-height: 2000px;
    opacity: 1;
    margin-top: 12px;
}

.dash-alerts-body.collapsed {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
    box-shadow: var(--shadow);
}

.dash-section-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.dash-alert-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px;
    background: var(--error-light);
    border: 1px solid var(--error-light);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    transition: all 0.3s;
}

.dash-alert-item:last-child {
    margin-bottom: 0;
}

.dash-alert-content {
    flex: 1;
    min-width: 0;
}

.dash-alert-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--error);
    margin-bottom: 2px;
}

.dash-alert-msg {
    font-size: 13px;
    color: var(--error);
}

.dash-alert-dismiss {
    flex-shrink: 0;
    background: none;
    border: none;
    color: var(--error);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    opacity: 0.6;
    transition: opacity 0.15s;
}

.dash-alert-dismiss:hover {
    opacity: 1;
}

/* -- Dashboard Refresh Panel --------------------------------------------- */

.dash-refresh-panel {
    margin-bottom: 16px;
    padding: 10px 0;
}

.dash-refresh-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.dash-refresh-times {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.dash-refresh-time {
    font-size: 12px;
    color: var(--text-light);
    line-height: 1.4;
}

.dash-refresh-requested {
    color: var(--text-muted);
}

.dash-refresh-progress {
    margin-top: 10px;
}

.dash-refresh-progress-track {
    width: 100%;
    height: 6px;
    background: var(--border);
    border-radius: 99px;
    overflow: hidden;
}

.dash-refresh-progress-bar {
    height: 100%;
    width: 30%;
    background: var(--primary);
    border-radius: 99px;
    animation: dash-refresh-slide 1.4s ease-in-out infinite;
}

@keyframes dash-refresh-slide {
    0%   { transform: translateX(-100%); }
    50%  { transform: translateX(250%); }
    100% { transform: translateX(-100%); }
}

.dash-refresh-progress-label {
    display: block;
    margin-top: 4px;
    font-size: 11px;
    color: var(--text-muted);
}

/* -- Dashboard Table Header ---------------------------------------------- */

.dash-table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

/* -- Settings ------------------------------------------------------------ */

.settings-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.settings-section-title {
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.settings-section-title.collapsible {
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
}

.settings-section-title.collapsible::after {
    content: '\25B2';
    margin-left: auto;
    font-size: 11px;
    color: var(--text-muted);
    transition: transform 0.2s;
}

.settings-section-title.collapsible.collapsed::after {
    transform: rotate(180deg);
}

.collapsible-body {
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.2s ease;
    max-height: 2000px;
    opacity: 1;
}

.collapsible-body.collapsed {
    max-height: 0;
    opacity: 0;
}

.settings-section-desc {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 16px;
    line-height: 1.5;
}

.settings-save-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--warning-light);
    border: 1px solid #fde68a;
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    margin-bottom: 12px;
    font-size: 13px;
    font-weight: 500;
    color: #92400e;
}
body.dark-theme .settings-save-bar {
    color: #fbbf24;
    border-color: #78350f;
}

.settings-customer-list {
    max-height: 500px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    -webkit-overflow-scrolling: touch;
}

.settings-customer-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s, opacity 0.15s;
    min-height: 52px;
}

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

.people-group + .people-group {
    border-top: 2px solid var(--border);
}

.settings-customer-item.excluded {
    opacity: 0.5;
    background: var(--bg);
}

.settings-cust-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.settings-cust-account {
    font-size: 14px;
    font-weight: 600;
}

.settings-cust-name {
    font-size: 13px;
    color: var(--text-muted);
}

.settings-cust-meta {
    font-size: 11px;
    color: var(--text-light);
}

/* -- Toggle Switch ------------------------------------------------------- */

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 28px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--border);
    border-radius: 99px;
    transition: background 0.2s;
}

.toggle-slider::before {
    content: "";
    position: absolute;
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--success);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

/* -- Responsive ---------------------------------------------------------- */

@media (max-width: 480px) {
    .period-btn,
    .status-btn {
        min-width: 80px;
        padding: 10px 12px;
        font-size: 13px;
    }

    .summary-cards {
        grid-template-columns: repeat(2, 1fr);
    }

    .container { padding: 12px; }

    .report-form { padding: 16px; }

    .results-header {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }

    .app-header {
        padding: 10px 12px;
    }

    .header-logo { font-size: 16px; }

    .history-item {
        flex-direction: column;
    }

    .history-item-actions {
        flex-direction: row;
        width: 100%;
    }

    .history-item-actions .btn {
        flex: 1;
    }

    .dash-table-header {
        flex-direction: column;
        align-items: stretch;
    }
}


/* ===================================================================== */
/* -- Clickable table rows ----------------------------------------------- */
/* ===================================================================== */

.clickable-row {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.clickable-row:active td {
    background: var(--primary-light);
}

/* ===================================================================== */
/* -- Detail pages (customer / order) ---------------------------------- */
/* ===================================================================== */

.detail-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px 20px;
}

@media (max-width: 480px) {
    .detail-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.detail-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.detail-value {
    font-size: 15px;
    font-weight: 500;
    color: var(--text);
}

.detail-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.detail-count {
    font-size: 13px;
    color: var(--text-muted);
}

.detail-toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 0 0;
    margin-top: 14px;
    border-top: 1px solid var(--border);
}
.detail-toggle-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.detail-toggle-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}
.detail-toggle-desc {
    font-size: 12px;
    color: var(--text-muted);
}

.detail-table {
    white-space: normal;
    min-width: 500px;
}

.detail-table .cell-nowrap {
    white-space: nowrap;
}

.detail-row {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.detail-row:active td {
    background: var(--primary-light);
}

/* ===================================================================== */
/* -- Filter bar (period buttons) -------------------------------------- */
/* ===================================================================== */

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
    align-items: center;
}

.filter-bar-secondary {
    margin-bottom: 16px;
}

.filter-bar-label {
    font-size: 13px;
    color: var(--text-muted);
    margin-right: 2px;
}

.filter-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 99px;
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.15s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.filter-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.filter-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.filter-btn-sm {
    padding: 4px 10px;
    font-size: 12px;
    min-width: 32px;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(-50%) translateY(20px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* -- Permission grid table ---------------------------------------------- */

.perm-grid-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    max-height: 600px;
    overflow-y: auto;
}

.perm-grid {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    white-space: nowrap;
}

.perm-grid th,
.perm-grid td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    text-align: center;
    vertical-align: middle;
}

.perm-grid th {
    background: var(--bg);
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 2;
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.perm-grid-sticky {
    text-align: left !important;
    min-width: 160px;
    max-width: 220px;
    position: sticky;
    left: 0;
    z-index: 3;
    background: var(--bg-card);
}

.perm-grid th.perm-grid-sticky {
    z-index: 4;
    background: var(--bg);
}

.perm-grid tbody tr:hover {
    background: var(--bg);
}

.perm-grid tbody tr:hover td.perm-grid-sticky {
    background: var(--bg);
}

.perm-user-info {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.perm-user-name {
    font-weight: 600;
    font-size: 12px;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
}

.perm-user-email {
    font-size: 10px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
}

.perm-user-key {
    font-size: 10px;
    color: var(--primary);
    font-weight: 500;
}

.perm-cb {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--primary);
}

.collapse-arrow {
    margin-left: auto;
    font-size: 11px;
    color: var(--text-muted);
    transition: transform 0.2s;
}

.collapsible:not(.collapsed) .collapse-arrow {
    transform: rotate(180deg);
}

.perm-user-row {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.1s;
    -webkit-tap-highlight-color: transparent;
}

.perm-user-row:last-child { border-bottom: none; }
.perm-user-row:hover { background: var(--bg); }
.perm-user-row:active { background: var(--border); }

.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 40px 16px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal-content {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 24px;
    width: 90%;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
