@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@500;600&display=swap');

:root {
    --bg:            #0b0e18;
    --surface:       #111827;
    --surface-2:     #1a2235;
    --surface-3:     #232d42;
    --border:        rgba(255,255,255,0.07);
    --border-2:      rgba(255,255,255,0.13);
    --text:          #e2e8f4;
    --text-dim:      #94a3b8;
    --text-muted:    #4b5775;
    --accent:        #3b82f6;
    --accent-dim:    rgba(59,130,246,0.14);
    --accent-glow:   rgba(59,130,246,0.28);
    --green:         #10b981;
    --green-dim:     rgba(16,185,129,0.12);
    --red:           #ef4444;
    --red-dim:       rgba(239,68,68,0.12);
    --topbar-h:      52px;
    --controls-h:    auto;
    --font:          'Inter', system-ui, sans-serif;
    --font-mono:     'JetBrains Mono', 'Consolas', monospace;
    --radius:        8px;
    --radius-lg:     12px;
    --radius-xl:     16px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ─── App shell ─────────────────────────────────────────────────────────── */

.app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    height: 100vh;
    overflow: hidden;
}

/* ─── Topbar ─────────────────────────────────────────────────────────────── */

.topbar {
    flex-shrink: 0;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    gap: 16px;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.topbar-home {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: inherit;
    text-decoration: none;
}

.topbar-logo { display: flex; align-items: center; }

.topbar-brand {
    font-weight: 700;
    font-size: 15px;
    letter-spacing: -0.01em;
    color: var(--text);
}

.topbar-home:hover .topbar-brand {
    color: #ffffff;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-chip {
    display: inline-flex;
    align-items: center;
    height: 26px;
    padding: 0 10px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 12px;
    font-weight: 500;
    font-family: var(--font-mono);
    white-space: nowrap;
}

.status-chip-warn {
    background: rgba(245,158,11,0.12);
    border-color: rgba(245,158,11,0.28);
    color: #fbbf24;
}

.status-chip-button {
    appearance: none;
    font: inherit;
    cursor: pointer;
    transition: opacity 150ms, background 150ms, border-color 150ms, color 150ms;
}

.status-chip-button:hover:not(:disabled) {
    background: rgba(245,158,11,0.18);
    border-color: rgba(245,158,11,0.42);
    color: #fde68a;
}

.status-chip-button:disabled,
.status-chip-button.is-loading {
    opacity: 0.72;
    cursor: wait;
}

.topbar-loader {
    display: none;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
}

.topbar-loader.is-visible {
    display: flex;
}

.loader-ring {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(59,130,246,0.2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

.topbar-logout {
    display: inline-flex;
    align-items: center;
    height: 30px;
    padding: 0 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border-2);
    background: transparent;
    color: var(--text-dim);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: color 150ms, border-color 150ms, background 150ms;
}

.btn-ads-sync {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 30px;
    padding: 0 12px;
    border-radius: var(--radius);
    border: 1px solid rgba(245,158,11,0.35);
    background: rgba(245,158,11,0.12);
    color: #fbbf24;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: color 150ms, border-color 150ms, background 150ms, opacity 150ms;
    white-space: nowrap;
}

.btn-ads-sync:hover:not(:disabled) {
    color: #fde68a;
    border-color: rgba(245,158,11,0.55);
    background: rgba(245,158,11,0.18);
}

.btn-ads-sync:disabled {
    opacity: 0.7;
    cursor: wait;
}

.topbar-logout:hover {
    color: var(--text);
    border-color: var(--accent);
    background: var(--accent-dim);
}

/* ─── Controls ───────────────────────────────────────────────────────────── */

.controls-wrap {
    flex-shrink: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.controls-inner {
    padding: 14px 20px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ctrl-row {
    display: flex;
    align-items: flex-start;
    gap: 20px;
    flex-wrap: wrap;
}

.ctrl-row-filters {
    align-items: flex-end;
}

.ctrl-block {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ctrl-block-range {
    flex: 1;
    min-width: 0;
}

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

/* VAT toggle */

.vat-toggle {
    display: inline-flex;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2px;
    gap: 2px;
}

.vat-btn {
    border: none;
    border-radius: calc(var(--radius) - 3px);
    background: transparent;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 500;
    font-family: inherit;
    padding: 3px 9px;
    cursor: pointer;
    transition: background 130ms, color 130ms;
    white-space: nowrap;
}

.vat-btn:hover:not(.is-active) {
    background: rgba(255,255,255,0.05);
    color: var(--text);
}

.vat-btn.is-active {
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}

/* Segmented control (view selector) */

.seg-control {
    display: inline-flex;
    padding: 3px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    gap: 2px;
}

.seg-btn {
    border: none;
    border-radius: calc(var(--radius) - 2px);
    background: transparent;
    color: var(--text-dim);
    font: inherit;
    font-size: 13px;
    font-weight: 500;
    padding: 6px 14px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 130ms, color 130ms;
}

.seg-btn:hover:not(.is-active) {
    background: rgba(255,255,255,0.05);
    color: var(--text);
}

.seg-btn.is-active {
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}

/* Range chips */

.range-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.range-chip {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    color: var(--text-dim);
    font: inherit;
    font-size: 12px;
    font-weight: 500;
    padding: 5px 11px;
    cursor: pointer;
    transition: background 130ms, color 130ms, border-color 130ms;
    white-space: nowrap;
}

.range-chip:hover:not(.is-active) {
    background: var(--surface-3);
    color: var(--text);
    border-color: var(--border-2);
}

.range-chip.is-active {
    background: var(--accent-dim);
    border-color: rgba(59,130,246,0.4);
    color: #93c5fd;
    font-weight: 600;
}

/* Custom date range */

.custom-dates {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.date-input {
    height: 30px;
    padding: 0 10px;
    border: 1px solid var(--border-2);
    border-radius: var(--radius);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    font-family: var(--font-mono);
    cursor: pointer;
    transition: border-color 150ms;
    color-scheme: dark;
}

.date-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

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

/* Filters row */

.filter-field {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 160px;
    flex: 1;
    max-width: 260px;
}

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

.filter-input {
    height: 32px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    transition: border-color 150ms, box-shadow 150ms;
}

.filter-input::placeholder { color: var(--text-muted); }

.filter-input:focus {
    outline: none;
    border-color: rgba(59,130,246,0.45);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.filter-input.has-value {
    border-color: rgba(59,130,246,0.35);
    background: var(--accent-dim);
}

/* ─── Multi-select dropdown ───────────────────────────────────────────────── */

.ms-wrap {
    position: relative;
}

.ms-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    height: 32px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    color: var(--text-dim);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
    text-align: left;
    transition: border-color 150ms, color 150ms, background 150ms;
    white-space: nowrap;
    overflow: hidden;
}

.ms-trigger:hover {
    border-color: var(--border-2);
    color: var(--text);
}

.ms-trigger.has-selection {
    border-color: rgba(59,130,246,0.4);
    background: var(--accent-dim);
    color: #93c5fd;
}

.ms-trigger-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ms-arrow {
    flex-shrink: 0;
    color: var(--text-muted);
    transition: transform 150ms;
}

.ms-wrap.is-open .ms-arrow {
    transform: rotate(180deg);
}

.ms-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 100%;
    width: max-content;
    max-width: 320px;
    z-index: 200;
    border: 1px solid var(--border-2);
    border-radius: var(--radius-lg);
    background: var(--surface-2);
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    overflow: hidden;
    animation: ms-open 120ms ease;
}

@keyframes ms-open {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.ms-search-wrap {
    padding: 8px;
    border-bottom: 1px solid var(--border);
}

.ms-search {
    width: 100%;
    height: 28px;
    padding: 0 9px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-3);
    color: var(--text);
    font: inherit;
    font-size: 12px;
    transition: border-color 150ms;
}

.ms-search::placeholder { color: var(--text-muted); }

.ms-search:focus {
    outline: none;
    border-color: rgba(59,130,246,0.45);
}

.ms-list {
    max-height: 220px;
    overflow-y: auto;
    padding: 4px;
}

.ms-list::-webkit-scrollbar { width: 4px; }
.ms-list::-webkit-scrollbar-track { background: transparent; }
.ms-list::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 2px; }

.ms-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 7px 9px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    color: var(--text-dim);
    transition: background 100ms, color 100ms;
    user-select: none;
}

.ms-item:hover {
    background: rgba(255,255,255,0.05);
    color: var(--text);
}

.ms-item.is-selected {
    color: var(--text);
}

.ms-checkbox {
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    border: 1.5px solid var(--border-2);
    border-radius: 3px;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 130ms, border-color 130ms;
}

.ms-item.is-selected .ms-checkbox {
    background: var(--accent);
    border-color: var(--accent);
}

.ms-checkbox-tick {
    display: none;
    width: 8px;
    height: 8px;
}

.ms-item.is-selected .ms-checkbox-tick { display: block; }

.ms-item-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ms-empty {
    padding: 12px;
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
}

.ms-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    flex-shrink: 0;
}

/* ─────────────────────────────────────────────────────────────────────────── */

.clear-btn {
    height: 32px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-dim);
    font: inherit;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: color 150ms, border-color 150ms, background 150ms;
    align-self: flex-end;
}

.clear-btn:hover {
    color: var(--red);
    border-color: rgba(239,68,68,0.4);
    background: var(--red-dim);
}

/* ─── KPI strip ──────────────────────────────────────────────────────────── */

.kpi-strip {
    flex-shrink: 0;
    display: flex;
    gap: 1px;
    background: var(--border);
    border-bottom: 1px solid var(--border);
}

.kpi-card {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 14px 20px;
    background: var(--surface);
}

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

.kpi-val {
    font-family: var(--font-mono);
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--text);
    line-height: 1.2;
}

.kpi-val-money { color: var(--green); }
.kpi-val-ads { color: #fbbf24; }

/* ─── Data area / table ──────────────────────────────────────────────────── */

.data-area {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.error-banner {
    flex-shrink: 0;
    margin: 12px 20px 0;
    padding: 10px 14px;
    border-radius: var(--radius);
    border: 1px solid rgba(239,68,68,0.3);
    background: var(--red-dim);
    color: #fca5a5;
    font-size: 13px;
}

.table-wrap {
    flex: 1;
    min-height: 0;
    overflow: auto;
}

/* placeholder / loading state */
.table-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    height: 200px;
    color: var(--text-muted);
    font-size: 13px;
}

.placeholder-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(59,130,246,0.18);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* results table */
.results-table {
    width: 100%;
    min-width: 500px;
    border-collapse: collapse;
}

.results-table thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 11px 16px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border-2);
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--text-dim);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    transition: color 150ms;
}

.results-table thead th:hover { color: var(--text); }

.results-table thead th.sort-asc::after  { content: ' ↑'; color: var(--accent); }
.results-table thead th.sort-desc::after { content: ' ↓'; color: var(--accent); }

.results-table thead th.col-num,
.results-table tbody td.col-num {
    text-align: right;
}

.results-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 100ms;
}

.results-table tbody tr:hover { background: rgba(255,255,255,0.025); }
.results-table tbody tr:last-child { border-bottom: none; }

.results-table tbody td {
    padding: 10px 16px;
    font-size: 13px;
    color: var(--text);
    white-space: nowrap;
}

.results-table tbody td.col-dim {
    font-weight: 500;
    color: var(--text);
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.results-table tbody td.col-name {
    max-width: 340px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-dim);
}

.results-table tbody td.col-num {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-dim);
}

.results-table tbody td.col-ingresos {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--text);
}

.results-table thead th.col-ads {
    color: #f59e0b;
}

.results-table tbody td.col-ads {
    font-family: var(--font-mono);
    font-size: 13px;
    color: #f59e0b;
}

.results-table thead th.col-cac {
    color: #cbd5e1;
}

.results-table tbody td.col-cac {
    font-family: var(--font-mono);
    font-size: 13px;
    color: #cbd5e1;
}

.col-ads-na {
    color: var(--text-muted);
    font-weight: 400;
}

.results-table thead th.col-pct {
    color: #64748b;
}

.results-table tbody td.col-pct {
    font-family: var(--font-mono);
    font-size: 13px;
    color: #64748b;
}

.results-table thead th[title] {
    cursor: help;
    text-decoration-line: underline;
    text-decoration-style: dotted;
    text-underline-offset: 3px;
}

.results-table tbody td.col-date {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

.results-table tbody td.col-order {
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 13px;
}

.table-link {
    appearance: none;
    border: none;
    padding: 0;
    background: transparent;
    color: #93c5fd;
    font: inherit;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.table-link:hover {
    color: #dbeafe;
}

.no-rows {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 160px;
    color: var(--text-muted);
    font-size: 13px;
}

/* ─── Auth page ──────────────────────────────────────────────────────────── */

.auth-body {
    display: grid;
    place-items: center;
    min-height: 100vh;
    overflow: auto;
    background: var(--bg);
}

.auth-shell {
    width: min(420px, calc(100vw - 32px));
}

.auth-card {
    border: 1px solid var(--border-2);
    border-radius: var(--radius-xl);
    background: var(--surface);
    padding: 32px;
}

.auth-eyebrow {
    margin: 0 0 12px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--accent);
}

.auth-card h1 {
    margin: 0;
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--text);
}

.auth-copy {
    margin: 10px 0 0;
    color: var(--text-dim);
    font-size: 14px;
    line-height: 1.6;
}

.auth-form {
    display: grid;
    gap: 14px;
    margin-top: 24px;
}

.field-group {
    display: grid;
    gap: 6px;
}

.field-group span {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.field-group input {
    height: 40px;
    padding: 0 14px;
    border: 1px solid var(--border-2);
    border-radius: var(--radius);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-size: 14px;
    transition: border-color 150ms, box-shadow 150ms;
    color-scheme: dark;
}

.field-group input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.primary-button,
.auth-button {
    height: 40px;
    padding: 0 20px;
    border: none;
    border-radius: var(--radius);
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 150ms, transform 150ms;
}

.primary-button:hover,
.auth-button:hover { opacity: 0.88; }

.primary-button:active,
.auth-button:active { transform: scale(0.98); }

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

.danger-button {
    height: 40px;
    padding: 0 20px;
    border: 1px solid rgba(239,68,68,0.42);
    border-radius: var(--radius);
    background: rgba(239,68,68,0.14);
    color: #fca5a5;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 150ms, transform 150ms, background 150ms, border-color 150ms;
}

.danger-button:hover {
    opacity: 0.92;
    background: rgba(239,68,68,0.2);
    border-color: rgba(239,68,68,0.56);
}

.danger-button:active {
    transform: scale(0.98);
}

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

.auth-button { width: 100%; margin-top: 4px; }

.message {
    margin-top: 14px;
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
}

.message-error {
    border: 1px solid rgba(239,68,68,0.3);
    background: var(--red-dim);
    color: #fca5a5;
}

/* ─── Settings button ────────────────────────────────────────────────────── */

.btn-settings {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: var(--radius);
    border: 1px solid var(--border-2);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 150ms, border-color 150ms, background 150ms;
    padding: 0;
}

.btn-settings:hover {
    color: var(--text);
    border-color: var(--accent);
    background: var(--accent-dim);
}

/* ─── Settings modal ─────────────────────────────────────────────────────── */

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 500;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
}

.modal-overlay.is-open {
    display: flex;
    animation: fade-in 120ms ease;
}

.modal-box {
    width: min(440px, calc(100vw - 32px));
    background: var(--surface);
    border: 1px solid var(--border-2);
    border-radius: var(--radius-xl);
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border);
}

.modal-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text);
}

.modal-heading {
    min-width: 0;
}

.modal-title-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.order-open-link {
    display: inline-flex;
    align-items: center;
    height: 24px;
    padding: 0 8px;
    border-radius: var(--radius);
    border: 1px solid var(--border-2);
    background: var(--surface-2);
    color: #93c5fd;
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    transition: border-color 120ms, color 120ms, background 120ms;
}

.order-open-link:hover {
    color: #bfdbfe;
    border-color: rgba(147,197,253,0.5);
    background: rgba(59,130,246,0.14);
}

.modal-meta {
    margin: 6px 0 0;
    color: var(--text-dim);
    font-size: 12px;
    font-family: var(--font-mono);
}

.modal-link-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.modal-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 120ms, background 120ms;
    padding: 0;
}

.modal-close:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.07);
}

.modal-body {
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.settings-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.settings-label {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.settings-input {
    height: 36px;
    padding: 0 12px;
    border: 1px solid var(--border-2);
    border-radius: var(--radius);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-size: 14px;
    font-family: var(--font-mono);
    transition: border-color 150ms, box-shadow 150ms;
    color-scheme: dark;
}

.settings-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.settings-hint {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
}

.date-modal-error {
    margin-top: -4px;
    font-size: 12px;
    color: #fca5a5;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px 24px 20px;
    border-top: 1px solid var(--border);
}

.modal-btn {
    height: 34px;
    padding: 0 16px;
    border-radius: var(--radius);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 150ms, background 150ms;
}

.modal-btn-secondary {
    border: 1px solid var(--border-2);
    background: transparent;
    color: var(--text-dim);
}

.modal-btn-secondary:hover { background: rgba(255, 255, 255, 0.05); color: var(--text); }

.modal-btn-primary {
    border: none;
    background: var(--accent);
    color: #fff;
}

.modal-btn-primary:hover { opacity: 0.88; }
.modal-btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }

.modal-btn-danger {
    border: none;
    background: var(--red);
    color: #fff;
}

.modal-btn-danger:hover {
    opacity: 0.9;
}

.modal-btn-danger:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.modal-box-detail {
    width: min(1120px, calc(100vw - 32px));
}

.quality-modal-box {
    width: min(720px, calc(100vw - 32px));
}

.modal-body-detail {
    min-height: 320px;
    max-height: min(70vh, 720px);
    padding-top: 16px;
    overflow: hidden;
}

.quality-modal-body {
    max-height: min(70vh, 720px);
    overflow-y: auto;
}

.quality-modal-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.detail-modal-content {
    min-height: 280px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.detail-chart-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0));
    padding: 12px 12px 10px;
}

.detail-chart-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.detail-chart-title {
    font-size: 12px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.detail-chart-legend {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    font-size: 11px;
    color: var(--text-dim);
}

.detail-chart-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.detail-chart-legend-line {
    display: inline-block;
    width: 14px;
    height: 0;
    border-top: 2px solid #60a5fa;
}

.detail-chart-legend-bar {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 3px;
    background: rgba(245,158,11,0.3);
    border: 1px solid rgba(245,158,11,0.45);
}

.detail-chart-svg-wrap {
    position: relative;
    width: 100%;
    overflow: auto;
}

.detail-chart-svg {
    display: block;
    width: 100%;
    min-width: 620px;
    height: auto;
}

.detail-chart-grid {
    stroke: rgba(148,163,184,0.22);
    stroke-width: 1;
    shape-rendering: crispEdges;
}

.detail-chart-bar {
    fill: rgba(245,158,11,0.24);
    stroke: rgba(245,158,11,0.38);
    stroke-width: 1;
    transition: fill 120ms, stroke 120ms, opacity 120ms;
}

.detail-chart-line {
    fill: none;
    stroke: #60a5fa;
    stroke-width: 2.4;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.detail-chart-point {
    fill: #93c5fd;
    stroke: #1e3a8a;
    stroke-width: 1;
    transition: r 120ms, fill 120ms;
}

.detail-chart-guide {
    stroke: rgba(148,163,184,0.5);
    stroke-width: 1;
    stroke-dasharray: 3 3;
    pointer-events: none;
}

.detail-chart-hit {
    fill: rgba(0,0,0,0);
    cursor: pointer;
}

.detail-chart-hit:focus {
    outline: none;
}

.detail-chart-point.is-active {
    fill: #bfdbfe;
}

.detail-chart-bar.is-active {
    fill: rgba(245,158,11,0.38);
    stroke: rgba(245,158,11,0.62);
}

.detail-chart-tooltip {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 2;
    min-width: 132px;
    padding: 8px 10px;
    border: 1px solid var(--border-2);
    border-radius: var(--radius);
    background: rgba(11,14,24,0.95);
    box-shadow: 0 8px 18px rgba(0,0,0,0.32);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.35;
    pointer-events: none;
}

.detail-chart-tooltip strong,
.detail-chart-tooltip span {
    display: block;
}

.detail-chart-tooltip strong {
    margin-bottom: 4px;
    color: #bfdbfe;
}

.detail-chart-axis-text {
    fill: var(--text-dim);
    font-size: 10px;
    font-family: var(--font-mono);
}

.detail-chart-axis-text-pvp {
    fill: #fbbf24;
}

.detail-modal-table-wrap {
    flex: 1;
    min-height: 0;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.detail-results-table {
    min-width: 980px;
}

.detail-results-table thead th {
    cursor: default;
}

.detail-results-table thead th:hover {
    color: var(--text-dim);
}

.detail-modal-message {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 220px;
    padding: 24px;
    border: 1px dashed var(--border-2);
    border-radius: var(--radius-lg);
    color: var(--text-dim);
    text-align: center;
}

.detail-modal-message.is-error {
    border-color: rgba(239,68,68,0.35);
    background: rgba(239,68,68,0.08);
    color: #fca5a5;
}

.detail-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 10px;
}

.detail-summary-card {
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
}

.detail-summary-label {
    display: block;
    margin-bottom: 4px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.detail-summary-value {
    display: block;
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 1.35;
}

/* ─── MC column ──────────────────────────────────────────────────────────── */

.results-table thead th.col-mc {
    color: #a78bfa;
}

.results-table tbody td.col-mc {
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 600;
    color: #a78bfa;
}

.results-table tbody td.col-mc.is-negative {
    color: var(--red);
}

/* ─── MC KPI ─────────────────────────────────────────────────────────────── */

.kpi-val-mc { color: #a78bfa; }
.kpi-val-mc.is-negative { color: var(--red); }

/* ─── Animations ─────────────────────────────────────────────────────────── */

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

@keyframes fade-in {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.results-table { animation: fade-in 180ms ease; }

/* ─── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 760px) {
    html, body {
        height: auto;
        min-height: 100%;
        overflow: auto;
    }

    .app {
        height: auto;
        min-height: 100dvh;
        overflow: visible;
    }

    .topbar {
        height: auto;
        padding: 12px 14px;
        align-items: flex-start;
        flex-wrap: wrap;
        gap: 12px;
    }

    .topbar-left,
    .topbar-right {
        width: 100%;
        min-width: 0;
        flex-wrap: wrap;
    }

    .topbar-right {
        justify-content: flex-start;
    }

    .topbar-home {
        min-width: 0;
    }

    .topbar-brand,
    .topbar-page {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .topbar-sep {
        display: none;
    }

    .status-chip {
        font-size: 11px;
        padding: 0 8px;
    }

    .btn-ads-sync,
    .btn-back,
    .topbar-logout {
        min-height: 34px;
    }

    .controls-inner {
        padding: 12px 14px;
    }

    .ctrl-row { flex-direction: column; gap: 12px; }
    .ctrl-block,
    .ctrl-block-range,
    .filter-field {
        width: 100%;
        max-width: none;
        min-width: 0;
    }

    .seg-control {
        display: flex;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .seg-control::-webkit-scrollbar {
        display: none;
    }

    .seg-btn {
        flex: 0 0 auto;
    }

    .kpi-strip { flex-wrap: wrap; }
    .kpi-card { flex: 1 1 calc(50% - 1px); min-width: 150px; }
    .kpi-card { padding: 12px 14px; }
    .kpi-val { font-size: 18px; }

    .data-area {
        flex: 0 0 auto;
        min-height: 320px;
        overflow: visible;
    }

    .error-banner {
        margin: 12px 14px 0;
    }

    .quality-wrap {
        padding: 10px 14px 14px;
    }

    .table-wrap {
        flex: 0 0 auto;
        min-height: 320px;
        overflow: auto;
        -webkit-overflow-scrolling: touch;
    }

    .results-table {
        min-width: 640px;
    }

    .results-table thead th,
    .results-table tbody td { padding: 8px 12px; }

    .modal-overlay {
        align-items: flex-end;
        padding: 12px;
        overflow-y: auto;
    }

    .modal-box {
        width: 100%;
        max-height: calc(100dvh - 24px);
    }

    .modal-body {
        overflow-y: auto;
    }

    .modal-footer {
        flex-wrap: wrap;
    }

    .modal-btn {
        flex: 1 1 140px;
    }

    .cfg-body {
        padding: 16px 14px 28px;
    }

    .cfg-section-header,
    .cfg-section-body {
        padding-left: 16px;
        padding-right: 16px;
    }

    .cfg-input-sm,
    .cfg-select,
    .cfg-table .cfg-input {
        width: 100%;
        min-width: 0;
    }

    .cfg-actions {
        justify-content: stretch;
    }

    .cfg-actions .primary-button,
    .cfg-actions .danger-button {
        width: 100%;
    }

    .auth-body {
        display: block;
        min-height: 100dvh;
        padding: 16px;
    }

    .auth-shell {
        width: 100%;
        max-width: 420px;
        margin: 0 auto;
    }

    .auth-card {
        padding: 24px 18px;
    }
}

@media (max-width: 520px) {
    .topbar-right .status-chip {
        display: none;
    }

    .btn-back,
    .btn-ads-sync {
        width: 100%;
        justify-content: center;
    }
}

/* ─── Config page ─────────────────────────────────────────────────────────── */

.cfg-app {
    overflow: auto;
}

.topbar-sep {
    color: var(--text-muted);
    font-size: 15px;
    margin: 0 2px;
}

.topbar-page {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-dim);
}

.btn-back {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 30px;
    padding: 0 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border-2);
    background: transparent;
    color: var(--text-dim);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: color 150ms, border-color 150ms, background 150ms;
}

.btn-back:hover {
    color: var(--text);
    border-color: var(--accent);
    background: var(--accent-dim);
}

.cfg-body {
    flex: 1;
    overflow: visible;
    padding: 28px 28px 48px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    max-width: 860px;
    width: 100%;
    margin: 0 auto;
}

.cfg-notice {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
}

.cfg-notice-ok {
    border: 1px solid rgba(16,185,129,0.35);
    background: var(--green-dim);
    color: #6ee7b7;
}

.cfg-notice-error {
    border: 1px solid rgba(239,68,68,0.35);
    background: var(--red-dim);
    color: #fca5a5;
}

.cfg-section {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    overflow: hidden;
}

.cfg-section-danger {
    border-color: rgba(239,68,68,0.24);
}

.cfg-section-header {
    padding: 18px 24px 16px;
    border-bottom: 1px solid var(--border);
}

.cfg-section-title {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text);
}

.cfg-section-desc {
    margin: 6px 0 0;
    font-size: 13px;
    color: var(--text-dim);
    line-height: 1.55;
}

.cfg-section-body {
    padding: 20px 24px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.cfg-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.cfg-label {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.cfg-input {
    height: 36px;
    padding: 0 12px;
    border: 1px solid var(--border-2);
    border-radius: var(--radius);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-size: 14px;
    transition: border-color 150ms, box-shadow 150ms;
    color-scheme: dark;
}

.cfg-input-sm { width: 160px; }

.cfg-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.cfg-hint {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
}

.cfg-danger-text {
    margin: 0;
    padding: 12px 14px;
    border: 1px solid rgba(239,68,68,0.24);
    border-radius: var(--radius);
    background: rgba(239,68,68,0.08);
    color: #fca5a5;
    font-size: 13px;
    line-height: 1.55;
}

.cfg-actions {
    display: flex;
    justify-content: flex-end;
    padding-top: 4px;
}

.cfg-empty {
    font-size: 13px;
    color: var(--text-muted);
    padding: 8px 0;
    margin: 0;
}

#feeds-wrap {
    max-height: min(58vh, 560px);
    overflow-y: auto;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

/* Feed mapping table */

.cfg-table {
    width: 100%;
    border-collapse: collapse;
}

.cfg-table thead th {
    padding: 9px 12px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border-2);
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--text-dim);
    white-space: nowrap;
}

.cfg-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 100ms;
}

.cfg-table tbody tr:hover { background: rgba(255,255,255,0.02); }
.cfg-table tbody tr:last-child { border-bottom: none; }

.cfg-table tbody td {
    padding: 10px 12px;
    font-size: 13px;
    vertical-align: middle;
}

.cfg-table-feed {
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 13px;
    color: var(--text);
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 8px;
}

.cfg-badge-unmapped {
    display: inline-flex;
    align-items: center;
    height: 18px;
    padding: 0 7px;
    border-radius: 999px;
    background: rgba(245,158,11,0.14);
    border: 1px solid rgba(245,158,11,0.3);
    color: #fbbf24;
    font-size: 11px;
    font-weight: 600;
    font-family: var(--font);
    white-space: nowrap;
}

.cfg-select {
    height: 32px;
    padding: 0 10px;
    border: 1px solid var(--border-2);
    border-radius: var(--radius);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
    transition: border-color 150ms;
    min-width: 160px;
    color-scheme: dark;
}

.cfg-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.cfg-table .cfg-input {
    height: 32px;
    font-size: 13px;
    width: 100%;
    min-width: 120px;
}

@media (max-width: 760px) {
    .cfg-body {
        padding: 16px 14px 28px;
    }

    .cfg-section-header,
    .cfg-section-body {
        padding-left: 16px;
        padding-right: 16px;
    }

    .cfg-input-sm,
    .cfg-select,
    .cfg-table .cfg-input {
        width: 100%;
        min-width: 0;
    }

    .cfg-actions {
        justify-content: stretch;
    }

    .cfg-actions .primary-button,
    .cfg-actions .danger-button {
        width: 100%;
    }
}

@media (max-width: 520px) {
    .btn-back {
        width: 100%;
        justify-content: center;
    }
}

.panel-warning {
    margin: 12px 24px 0;
    padding: 12px 14px;
    border: 1px solid #e7c75b;
    border-radius: 12px;
    background: #f5d96b;
    color: #171717;
    font-size: 14px;
    font-weight: 600;
}

.quality-wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: flex-end;
    align-items: center;
    padding: 10px 20px 16px;
}

.quality-trigger {
    appearance: none;
    border: none;
    background: transparent;
    padding: 0;
    font: inherit;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.03em;
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
    transition: color 140ms ease, opacity 140ms ease;
}

.quality-trigger.is-muted {
    color: rgba(148, 163, 184, 0.45);
}

.quality-trigger.has-issues {
    color: #fbbf24;
}

.quality-trigger.is-download {
    color: rgba(148, 163, 184, 0.9);
}

.quality-trigger:hover {
    opacity: 0.9;
}

.quality-trigger:focus-visible {
    outline: 2px solid rgba(251, 191, 36, 0.45);
    outline-offset: 4px;
    border-radius: 4px;
}

.quality-card {
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 14px;
    background: rgba(255,255,255,0.015);
    padding: 12px 14px;
}

.quality-header {
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.quality-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 10px;
    margin-top: 10px;
}

.quality-item {
    border: 1px solid rgba(255,255,255,0.04);
    border-radius: 12px;
    background: rgba(255,255,255,0.018);
    padding: 11px 12px;
}

.quality-label {
    display: block;
    color: var(--text-muted);
    font-size: 12px;
}

.quality-value {
    display: block;
    margin-top: 4px;
    color: var(--text-dim);
    font-size: 17px;
    font-weight: 600;
}

.quality-meta {
    display: block;
    margin-top: 4px;
    color: var(--text-muted);
    font-size: 12px;
}

.detail-mode-note {
    margin: 14px 0 10px;
    color: #475569;
    font-size: 13px;
    font-weight: 600;
}
