/* ADPROE — application styles
   Tokens · base · layout · components · pages · responsive */

:root {
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial,
        "Noto Sans Thai", "Leelawadee UI", "PingFang SC", "Microsoft YaHei", "Noto Sans SC",
        "Noto Sans Myanmar", "Myanmar Text", "Pyidaungsu", "Noto Sans Khmer", "Khmer UI", "Khmer OS",
        sans-serif;
    --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

    --r: 6px;
    --r-lg: 8px;
    --sidebar-w: 232px;
    --topbar-h: 56px;
    --bottomnav-h: 60px;

    --bg: #f7f7f5;
    --sidebar: #efeeea;
    --surface: #ffffff;
    --subtle: #f4f3f0;
    --hover: #ebeae6;
    --border: #e4e2dc;
    --border-strong: #d3d0c8;
    --text: #1d1c1a;
    --text-2: #45433e;
    --muted: #75726b;
    --ink: #1d1c1a;
    --on-ink: #ffffff;
    --accent: #0b7a55;
    --accent-soft: #e3f1ea;
    --focus: rgba(11, 122, 85, 0.28);
    --pos: #0b7a55;
    --neg: #b42318;
    --neg-soft: #fbe9e7;
    --warn: #a15c07;
    --warn-soft: #fbf0dc;
    --info-soft: #eef2f7;
    --avatar: #dedbd3;
    --avatar-text: #45433e;
    --gold: #c9a227;
    --silver: #a9aaa6;
    --bronze: #b07a4f;
    --shadow: 0 1px 2px rgba(29, 28, 26, 0.06);
    --shadow-pop: 0 12px 32px rgba(29, 28, 26, 0.16);
    --overlay: rgba(29, 28, 26, 0.4);
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #141413;
        --sidebar: #1a1a18;
        --surface: #1d1d1b;
        --subtle: #232321;
        --hover: #2a2a27;
        --border: #2e2e2b;
        --border-strong: #3d3d39;
        --text: #ecebe7;
        --text-2: #c9c7c1;
        --muted: #95928a;
        --ink: #ecebe7;
        --on-ink: #141413;
        --accent: #3fbf8c;
        --accent-soft: rgba(63, 191, 140, 0.12);
        --focus: rgba(63, 191, 140, 0.32);
        --pos: #3fbf8c;
        --neg: #f0776a;
        --neg-soft: rgba(240, 119, 106, 0.12);
        --warn: #e5a93b;
        --warn-soft: rgba(229, 169, 59, 0.13);
        --info-soft: #22262b;
        --avatar: #34332f;
        --avatar-text: #d9d7d0;
        --shadow: none;
        --shadow-pop: 0 12px 32px rgba(0, 0, 0, 0.55);
        --overlay: rgba(0, 0, 0, 0.55);
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #141413;
    --sidebar: #1a1a18;
    --surface: #1d1d1b;
    --subtle: #232321;
    --hover: #2a2a27;
    --border: #2e2e2b;
    --border-strong: #3d3d39;
    --text: #ecebe7;
    --text-2: #c9c7c1;
    --muted: #95928a;
    --ink: #ecebe7;
    --on-ink: #141413;
    --accent: #3fbf8c;
    --accent-soft: rgba(63, 191, 140, 0.12);
    --focus: rgba(63, 191, 140, 0.32);
    --pos: #3fbf8c;
    --neg: #f0776a;
    --neg-soft: rgba(240, 119, 106, 0.12);
    --warn: #e5a93b;
    --warn-soft: rgba(229, 169, 59, 0.13);
    --info-soft: #22262b;
    --avatar: #34332f;
    --avatar-text: #d9d7d0;
    --shadow: none;
    --shadow-pop: 0 12px 32px rgba(0, 0, 0, 0.55);
    --overlay: rgba(0, 0, 0, 0.55);
    color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}
:lang(my) body, :lang(km) body, :lang(th) body { line-height: 1.7; }
h1, h2, h3, h4 { font-weight: 600; line-height: 1.3; color: var(--text); }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.125rem; }
h3 { font-size: 0.95rem; }
h4 { font-size: 0.875rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); font-size: 0.85em; background: var(--subtle); border: 1px solid var(--border); padding: 0.05em 0.35em; border-radius: 4px; }
small { font-size: 0.8rem; }
ol, ul { padding-left: 1.2rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.icon { width: 16px; height: 16px; flex-shrink: 0; display: inline-block; vertical-align: middle; }
.text-muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    background: var(--sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 60;
    transition: transform 0.2s ease;
}
.sidebar-brand {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0 1rem;
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: 0.02em;
    color: var(--text);
}
.brand-mark {
    width: 22px;
    height: 22px;
    border-radius: 5px;
    background: var(--ink);
    color: var(--on-ink);
    display: grid;
    place-items: center;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0;
}
.sidebar .sidebar-close { margin-left: auto; display: none; }
.brand { display: inline-flex; align-items: center; gap: 0.55rem; min-width: 0; }
.brand-logo { display: block; height: 26px; width: auto; max-width: 120px; object-fit: contain; border-radius: 5px; }
.sidebar-scroll { flex: 1; overflow-y: auto; padding: 0.5rem 0.625rem 1rem; }
.nav-label { font-size: 0.75rem; color: var(--muted); padding: 0 0.625rem; margin: 1rem 0 0.25rem; }
.nav-label:first-child { margin-top: 0.25rem; }
.sidebar-nav { list-style: none; padding: 0; }
.sidebar-nav-link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    height: 32px;
    padding: 0 0.625rem;
    border-radius: var(--r);
    color: var(--text-2);
    font-size: 0.875rem;
    cursor: pointer;
    border: 1px solid transparent;
    user-select: none;
}
.sidebar-nav-link:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.sidebar-nav-link .icon { color: var(--muted); }
.sidebar-nav-link.active { background: var(--surface); border-color: var(--border); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.sidebar-nav-link.active .icon { color: var(--accent); }

.sidebar-footer { padding: 0.75rem 0.625rem; border-top: 1px solid var(--border); display: grid; gap: 0.625rem; }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0 0.375rem; font-size: 0.8125rem; color: var(--muted); }
.currency-control { display: inline-flex; align-items: center; gap: 0.4rem; }
.currency-control .fi { width: 18px; height: 13px; border-radius: 2px; background-size: cover; box-shadow: 0 0 0 1px var(--border); }
.bare-select {
    appearance: none;
    -webkit-appearance: none;
    border: 0;
    background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2375726b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right center / 14px;
    padding-right: 18px;
    color: var(--text);
    font: inherit;
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    outline: none;
}
.bare-select option { background: var(--surface); color: var(--text); }

.user-card { display: flex; align-items: center; gap: 0.6rem; padding: 0.25rem 0.375rem 0; }
.user-card-info { flex: 1; min-width: 0; line-height: 1.3; }
.user-card-name { display: block; font-weight: 600; font-size: 0.8125rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-card-role { font-size: 0.75rem; color: var(--muted); }
.avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--avatar);
    color: var(--avatar-text);
    font-weight: 600;
    font-size: 0.75rem;
    flex-shrink: 0;
    overflow: hidden;
}

.main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; min-width: 0; }
.topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0 1.5rem;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 { font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 0.375rem; }
.lang-picker {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    height: 32px;
    padding: 0 0.5rem;
    border-radius: var(--r);
    color: var(--muted);
}
.lang-picker:hover { background: var(--hover); }
.lang-picker .bare-select { background-image: none; padding-right: 0; }

.icon-btn {
    width: 32px;
    height: 32px;
    display: inline-grid;
    place-items: center;
    border-radius: var(--r);
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    flex-shrink: 0;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.menu-btn { display: none; }
.theme-toggle .i-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .i-sun { display: inline-block; }
:root[data-theme="dark"] .theme-toggle .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-toggle .i-sun { display: inline-block; }
    :root:not([data-theme="light"]) .theme-toggle .i-moon { display: none; }
}

.content { width: 100%; max-width: 1200px; margin: 0 auto; padding: 1.5rem; flex: 1; }
.content.narrow { max-width: 760px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h2 { font-size: 1.125rem; }
.page-head p { color: var(--muted); font-size: 0.8125rem; margin-top: 0.125rem; }
.page-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

.sidebar-overlay { position: fixed; inset: 0; background: var(--overlay); z-index: 55; opacity: 0; visibility: hidden; transition: opacity 0.2s, visibility 0.2s; }
.sidebar-overlay.open { opacity: 1; visibility: visible; }

.bottom-nav {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 45;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav ul { list-style: none; display: flex; padding: 0; height: var(--bottomnav-h); }
.bottom-nav li { flex: 1; }
.bottom-nav a { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 0.6875rem; }
.bottom-nav a:hover { text-decoration: none; }
.bottom-nav a .icon { width: 20px; height: 20px; }
.bottom-nav a.active { color: var(--text); font-weight: 600; }
.bottom-nav a.active .icon { color: var(--accent); }

/* ---------- Card ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow); min-width: 0; overflow: hidden; }
.card + .card { margin-top: 1rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); min-height: 52px; }
.card-title { font-size: 0.875rem; font-weight: 600; }
.card-sub { font-size: 0.8125rem; color: var(--muted); }
.card-body { padding: 1rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; align-items: start; }
.grid-aside { display: grid; grid-template-columns: minmax(0, 320px) minmax(0, 1fr); gap: 1rem; align-items: start; }
.grid-2 .card + .card, .grid-aside .card + .card, .stack .card + .card { margin-top: 0; }
.stack { display: grid; gap: 1rem; }
.mb { margin-bottom: 1rem; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); }
.kpis.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpi { padding: 0.875rem 1rem 1rem; box-shadow: 1px 0 0 var(--border), 0 1px 0 var(--border); min-width: 0; }
.kpi-label { font-size: 0.8125rem; color: var(--muted); }
.kpi-value { font-size: 1.375rem; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; margin-top: 0.125rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; }
.kpi-value.money { color: var(--pos); }
.kpi-hint { font-size: 0.75rem; color: var(--muted); margin-top: 0.25rem; }
.stat-comparison { display: block; margin-top: 0.25rem; font-size: 0.75rem; font-weight: 500; font-variant-numeric: tabular-nums; color: var(--muted); text-align: center; }
.stat-comparison.positive { color: var(--pos); }
.stat-comparison.negative { color: var(--neg); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    height: 34px;
    padding: 0 0.875rem;
    border-radius: var(--r);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
}
.btn:hover { background: var(--subtle); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn .icon { width: 15px; height: 15px; }
.btn-primary { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.btn-primary:hover:not(:disabled) { background: var(--ink); opacity: 0.88; }
.btn-danger { color: var(--neg); }
.btn-danger:hover:not(:disabled) { background: var(--neg-soft); border-color: var(--neg); }
.btn-success { color: var(--pos); }
.btn-success:hover:not(:disabled) { background: var(--accent-soft); border-color: var(--pos); }
.btn-block { width: 100%; }
.btn-sm, .data-table .actions .btn { height: 28px; padding: 0 0.625rem; font-size: 0.75rem; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 0.875rem; display: flex; flex-direction: column; gap: 0.3rem; }
.form-group:last-child { margin-bottom: 0; }
.form-group label, .form-label { font-size: 0.8125rem; font-weight: 500; color: var(--text-2); }
.form-group label .opt { color: var(--muted); font-weight: 400; }
.form-group input, .form-group select, .form-group textarea, .form-input, .select-inline, .date-input {
    width: 100%;
    height: 36px;
    padding: 0 0.7rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--r);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 0.875rem;
    outline: none;
}
.form-group textarea { height: auto; min-height: 72px; padding: 0.5rem 0.7rem; resize: vertical; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus, .form-input:focus, .select-inline:focus, .date-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--focus);
}
.form-group input[readonly] { background: var(--subtle); color: var(--muted); }
.form-group small, .form-hint { font-size: 0.75rem; color: var(--muted); }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 0.875rem; }
.form-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 0.875rem; }
.form-divider { font-size: 0.8125rem; font-weight: 600; margin: 1.25rem 0 0.75rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.form-group select, .select-inline {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2375726b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.55rem center;
    background-size: 14px;
    padding-right: 1.9rem;
    cursor: pointer;
}
.select-inline { width: auto; height: 34px; font-size: 0.8125rem; }
.date-input { width: auto; height: 34px; font-size: 0.8125rem; }
.filter-bar { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.filter-bar label { font-size: 0.8125rem; color: var(--muted); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.8125rem; font-variant-numeric: tabular-nums; }
.data-table th {
    text-align: left;
    font-weight: 500;
    color: var(--muted);
    padding: 0.55rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--subtle);
    white-space: nowrap;
}
.data-table th[onclick] { cursor: pointer; user-select: none; }
.data-table th[onclick]:hover { color: var(--text); }
.data-table th span:not(.th-label) { font-size: 0.85em; margin-left: 0.15rem; opacity: 0.6; }
.data-table td { padding: 0.6rem 1rem; border-bottom: 1px solid var(--border); color: var(--text); white-space: nowrap; vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover td { background: var(--subtle); }
.data-table td strong { font-weight: 600; }
.data-table td.actions .btn + .btn { margin-left: 0.3rem; }
.data-table .num, .data-table th.num { text-align: right; }
.data-table td.cell-revenue { color: var(--pos); font-weight: 600; }
.data-table .row-total td { font-weight: 600; background: var(--subtle); border-top: 1px solid var(--border-strong); }
.empty-cell, .data-table td.empty-cell { text-align: center; color: var(--muted); padding: 2.25rem 1rem; white-space: normal; }

/* Numbers right-aligned; first column (and the daily Domain column) stay left */
.revenue-table th:not(:first-child), .revenue-table td:not(:first-child),
.country-table th:not(:first-child), .country-table td:not(:first-child) { text-align: right; }
.revenue-table .cell-domain, .revenue-table th.hide-m:nth-child(3) { text-align: left; color: var(--text-2); }
.revenue-table td.cell-revenue, .country-table td.cell-revenue { color: var(--pos); font-weight: 600; }
/* Columns that only exist on phones (moved columns) */
.data-table .m-only { display: none; }
.country-cell { display: inline-flex; align-items: center; gap: 0.5rem; }
.country-cell .fi { width: 18px; height: 13px; border-radius: 2px; background-size: cover; box-shadow: 0 0 0 1px var(--border); flex-shrink: 0; }
.country-cell .fi-none { background: var(--subtle); }

/* ---------- Pagination ---------- */
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; padding: 0.625rem 1rem; border-top: 1px solid var(--border); }
.pagination:empty { display: none; }
.pagination-pages { display: inline-flex; gap: 0.25rem; flex-wrap: wrap; order: 2; }
.pagination-meta { font-size: 0.75rem; color: var(--muted); order: 1; }
.page-btn { min-width: 32px; height: 28px; padding: 0 0.5rem; border-radius: var(--r); border: 1px solid var(--border); background: var(--surface); color: var(--text-2); font: inherit; font-size: 0.75rem; font-variant-numeric: tabular-nums; cursor: pointer; }
.page-btn:hover { background: var(--subtle); }
.page-btn.active { background: var(--ink); border-color: var(--ink); color: var(--on-ink); cursor: default; }
.page-gap { color: var(--muted); padding: 0 0.25rem; align-self: center; }

/* ---------- Badges ---------- */
.status-badge, .badge {
    display: inline-block;
    padding: 0.05rem 0.45rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    background: var(--subtle);
    color: var(--text-2);
    border: 1px solid var(--border);
    white-space: nowrap;
}
.status-badge.paid, .status-badge.status-active { background: var(--accent-soft); color: var(--pos); border-color: transparent; }
.status-badge.pending, .status-badge.status-pending { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.status-badge.cancelled, .status-badge.unpaid { background: var(--neg-soft); color: var(--neg); border-color: transparent; }

/* ---------- Notices ---------- */
.notice { padding: 0.875rem 1rem; border-radius: var(--r-lg); border: 1px solid var(--border); background: var(--subtle); color: var(--text-2); font-size: 0.8125rem; }
.notice h4 { font-size: 0.8125rem; margin-bottom: 0.3rem; color: var(--text); }
.notice ol, .notice ul { margin-top: 0.25rem; line-height: 1.8; }
.notice p + p { margin-top: 0.35rem; }
.notice-warn { background: var(--warn-soft); border-color: transparent; }
.notice-error { background: var(--neg-soft); border-color: transparent; color: var(--neg); }
.notice-error h4 { color: var(--neg); }
.notice.center { text-align: center; padding: 2rem 1rem; }

.alert { display: none; padding: 0.625rem 0.875rem; border-radius: var(--r); font-size: 0.8125rem; }
.alert.show { display: block; }
.alert-success { background: var(--accent-soft); color: var(--pos); }
.alert-error { background: var(--neg-soft); color: var(--neg); }
.alerts:not(:has(.alert.show)) { display: none; }
.alerts .alert + .alert { margin-top: 0.5rem; }

.error-message { display: none; margin-top: 0.75rem; font-size: 0.8125rem; color: var(--neg); }
.error-message.show { display: block; }

.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--muted); width: 100%; font-size: 0.875rem; }
.empty-state .icon { width: 24px; height: 24px; margin-bottom: 0.5rem; }
.loading-spinner { display: flex; justify-content: center; padding: 2.25rem; width: 100%; }
.spinner { width: 20px; height: 20px; border: 2px solid var(--border); border-top-color: var(--text-2); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Modal ---------- */
.modal { display: none; position: fixed; inset: 0; z-index: 1000; background: var(--overlay); padding: 1rem; }
.modal.active { display: flex; align-items: center; justify-content: center; }
.modal-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-pop);
    width: 100%;
    max-width: 500px;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    padding: 0 1.25rem 1.25rem;
}
.modal-header {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0 -1.25rem 1rem;
    padding: 0.875rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 0.9375rem; }
.close { width: 28px; height: 28px; display: grid; place-items: center; border-radius: var(--r); font-size: 1.25rem; line-height: 1; color: var(--muted); cursor: pointer; }
.close:hover { background: var(--hover); color: var(--text); }
.modal-content form > .btn[type="submit"] { width: 100%; margin-top: 0.5rem; height: 38px; }

/* ---------- Login ---------- */
body.auth-page { min-height: 100vh; min-height: 100dvh; }
.auth { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 3rem 1rem 9rem; }
.auth-top { position: fixed; top: 0.75rem; right: 0.75rem; display: flex; gap: 0.25rem; align-items: center; }
.auth-brand { display: flex; align-items: center; gap: 0.55rem; font-weight: 700; letter-spacing: 0.02em; margin-bottom: 1.5rem; }
.auth-brand .brand-mark { width: 26px; height: 26px; font-size: 14px; border-radius: 6px; }
.auth-brand .brand { gap: 0.55rem; color: inherit; text-decoration: none; }
.auth-brand .brand-logo { height: 32px; max-width: 160px; }
.branding-preview .brand { font-weight: 700; font-size: 0.875rem; }
.branding-preview .brand-logo { height: 32px; }
.auth-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 1.75rem 1.5rem; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 1.25rem; }
.auth-card .lead { color: var(--muted); font-size: 0.875rem; margin: 0.25rem 0 1.25rem; }
.auth-card .form-group input { height: 40px; }
.password-input-wrapper { position: relative; }
.password-input-wrapper input { padding-right: 2.5rem; }
.password-toggle { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 32px; height: 32px; display: grid; place-items: center; border: 0; background: transparent; color: var(--muted); border-radius: var(--r); cursor: pointer; }
.password-toggle:hover { color: var(--text); background: var(--hover); }
.btn-login { width: 100%; height: 40px; margin-top: 0.375rem; font-size: 0.875rem; }
.auth-card .form-group[hidden], .auth-card [hidden] { display: none; }
.auth-card .label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; }
.auth-card .link-btn { border: 0; background: none; padding: 0; font: inherit; font-size: 0.8125rem; color: var(--accent, var(--text)); cursor: pointer; }
.auth-card .link-btn:hover { text-decoration: underline; }
.auth-card #passwordGroup:not([hidden]) { animation: auth-reveal 0.2s ease-out; }
@keyframes auth-reveal { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.auth-foot { margin-top: 1.5rem; font-size: 0.75rem; color: var(--muted); }

/* ---------- Ranking ---------- */
.custom-date-picker { margin-bottom: 1rem; }
.date-inputs { display: flex; gap: 0.75rem; align-items: flex-end; flex-wrap: wrap; }
.date-input-group { display: flex; flex-direction: column; gap: 0.25rem; }
.date-input-group label { font-size: 0.75rem; color: var(--muted); }
.podium-section { padding: 2rem 1rem 0; border-bottom: 1px solid var(--border); }
.podium-container { display: flex; justify-content: center; align-items: flex-start; max-width: 440px; margin: 0 auto; min-height: 140px; }
.podium-item { display: flex; flex-direction: column; align-items: center; flex: 1; min-width: 0; }
.podium-item.first { order: 2; }
.podium-item.second { order: 1; padding-top: 28px; }
.podium-item.third { order: 3; padding-top: 40px; }
.winner-avatar-wrapper { position: relative; margin-bottom: 0.5rem; }
.crown-icon { display: none; }
.podium-item.first .crown-icon { display: block; position: absolute; top: -22px; left: 50%; transform: translateX(-50%); width: 20px; height: 20px; color: var(--gold); }
.crown-icon .icon { width: 100%; height: 100%; }
.winner-avatar { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; font-size: 1.25rem; font-weight: 600; background: var(--avatar); color: var(--avatar-text); overflow: hidden; border: 2px solid var(--ring, var(--border)); }
.podium-item.first .winner-avatar { width: 72px; height: 72px; font-size: 1.5rem; --ring: var(--gold); }
.podium-item.second .winner-avatar { --ring: var(--silver); }
.podium-item.third .winner-avatar { --ring: var(--bronze); }
.winner-info { text-align: center; margin-bottom: 0.75rem; padding: 0 0.25rem; max-width: 100%; }
.winner-name { font-size: 0.8125rem; font-weight: 600; word-break: break-word; }
.winner-score { display: flex; justify-content: center; }
.podium-stage { display: flex; align-items: flex-end; max-width: 440px; margin: 0 auto; }
.podium-bar { flex: 1; display: grid; place-items: center; font-size: 0.875rem; font-weight: 600; color: var(--text-2); background: var(--subtle); border: 1px solid var(--border); border-bottom: 0; border-radius: 4px 4px 0 0; }
.podium-bar.bar-first { order: 2; height: 56px; border-top: 3px solid var(--gold); margin: 0 4px; }
.podium-bar.bar-second { order: 1; height: 40px; border-top: 3px solid var(--silver); }
.podium-bar.bar-third { order: 3; height: 28px; border-top: 3px solid var(--bronze); }
.rankings-list:empty { display: none; }
.ranking-item { display: flex; align-items: center; gap: 0.75rem; padding: 0.625rem 1rem; border-bottom: 1px solid var(--border); }
.ranking-item:last-child { border-bottom: 0; }
.rank-number { width: 20px; text-align: right; color: var(--muted); font-size: 0.8125rem; font-variant-numeric: tabular-nums; }
.user-avatar-small { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--avatar); color: var(--avatar-text); font-weight: 600; font-size: 0.8125rem; overflow: hidden; flex-shrink: 0; }
.user-name { flex: 1; min-width: 0; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-comparison { margin-left: auto; }
.revenue-comparison { font-size: 0.75rem; font-weight: 500; font-variant-numeric: tabular-nums; color: var(--muted); }
.revenue-comparison.positive { color: var(--pos); }
.revenue-comparison.negative { color: var(--neg); }
.confetti-container { position: fixed; inset: 0; pointer-events: none; z-index: 1000; overflow: hidden; }
.confetti { position: absolute; width: 7px; height: 7px; animation: confetti-fall 3s ease-in-out forwards; }
@keyframes confetti-fall { 0% { opacity: 1; transform: translateY(-100px) rotate(0); } 100% { opacity: 0; transform: translateY(100vh) rotate(720deg); } }

/* ---------- Billing ---------- */
.bank-info-empty { text-align: center; padding: 1rem 0.5rem; color: var(--muted); }
.bank-info-empty p { margin-bottom: 0.875rem; font-size: 0.875rem; }
.bank-info-item { display: flex; justify-content: space-between; gap: 1rem; padding: 0.55rem 0; font-size: 0.8125rem; }
.bank-info-item + .bank-info-item { border-top: 1px solid var(--border); }
.bank-info-item .label { color: var(--muted); }
.bank-info-item .value { font-weight: 500; text-align: right; word-break: break-word; }
.payment-item { display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); }
.payment-item:last-child { border-bottom: 0; }
.payment-icon { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0; color: var(--muted); background: var(--subtle); }
.payment-icon .icon { width: 15px; height: 15px; }
.payment-icon.paid { color: var(--pos); background: var(--accent-soft); }
.payment-icon.pending { color: var(--warn); background: var(--warn-soft); }
.payment-icon.unpaid, .payment-icon.cancelled { color: var(--neg); background: var(--neg-soft); }
.payment-info { flex: 1; min-width: 0; }
.payment-period { font-weight: 500; font-size: 0.875rem; }
.payment-date { font-size: 0.75rem; color: var(--muted); }
.payment-amount { display: flex; flex-direction: column; align-items: flex-end; gap: 0.15rem; text-align: right; }
.amount-value { font-weight: 600; font-variant-numeric: tabular-nums; }
.deduction-info { font-size: 0.75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.payment-status { font-size: 0.6875rem; font-weight: 500; padding: 0 0.4rem; border-radius: 4px; background: var(--subtle); color: var(--text-2); }
.payment-status.paid { background: var(--accent-soft); color: var(--pos); }
.payment-status.pending { background: var(--warn-soft); color: var(--warn); }
.payment-status.unpaid, .payment-status.cancelled { background: var(--neg-soft); color: var(--neg); }

/* ---------- Profile ---------- */
.profile-card .card-body { display: flex; flex-direction: column; gap: 1rem; }
.profile-id { display: flex; align-items: center; gap: 0.875rem; }
.profile-avatar-wrapper { position: relative; width: 64px; height: 64px; flex-shrink: 0; }
.profile-avatar { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: var(--avatar); color: var(--avatar-text); font-size: 1.5rem; font-weight: 600; overflow: hidden; cursor: pointer; }
.profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-edit-btn { position: absolute; right: -2px; bottom: -2px; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); color: var(--text-2); border: 1px solid var(--border-strong); cursor: pointer; }
.avatar-edit-btn .icon { width: 12px; height: 12px; }
.avatar-delete-btn { position: absolute; right: -2px; top: -2px; width: 20px; height: 20px; border-radius: 50%; display: none; place-items: center; background: var(--surface); color: var(--neg); border: 1px solid var(--border-strong); cursor: pointer; }
.avatar-delete-btn .icon { width: 10px; height: 10px; }
.avatar-delete-btn.show { display: grid; }
#imageInput { display: none; }
.profile-name { font-size: 1rem; font-weight: 600; }
.profile-meta { font-size: 0.8125rem; color: var(--muted); display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; margin-top: 0.125rem; }
.stats-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border: 1px solid var(--border); border-radius: var(--r); }
.stat-item { padding: 0.625rem 0.75rem; }
.stat-item + .stat-item { border-left: 1px solid var(--border); }
.stat-item .l { font-size: 0.75rem; color: var(--muted); }
.stat-item .v { font-size: 1.05rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.image-crop-modal { display: none; position: fixed; inset: 0; z-index: 9999; background: var(--overlay); align-items: center; justify-content: center; padding: 1rem; }
.image-crop-modal.show { display: flex; }
.crop-container { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--shadow-pop); }
.crop-header { display: flex; justify-content: space-between; align-items: center; padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); }
.crop-header h3 { font-size: 0.9375rem; }
.crop-close { width: 28px; height: 28px; display: grid; place-items: center; border: 0; background: transparent; color: var(--muted); border-radius: var(--r); cursor: pointer; }
.crop-close:hover { background: var(--hover); }
.crop-body { background: var(--subtle); display: flex; justify-content: center; align-items: center; min-height: 280px; }
.crop-body img { max-width: 100%; max-height: 320px; display: block; }
.crop-actions { display: flex; gap: 0.5rem; padding: 0.75rem 1rem; border-top: 1px solid var(--border); justify-content: flex-end; }
.cropper-view-box { outline: 2px solid var(--accent); outline-offset: -2px; }
.cropper-line, .cropper-point { background-color: var(--accent) !important; }
.cropper-center { display: none; }

/* ---------- Admin ---------- */
.tab-content { display: none; }
.tab-content.active { display: block; }
.payment-month-section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); margin-bottom: 0.625rem; overflow: hidden; }
.payment-month-header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 0.75rem 1rem; cursor: pointer; }
.payment-month-header:hover { background: var(--subtle); }
.payment-month-header h3 { font-size: 0.875rem; }
.month-summary { display: block; font-size: 0.75rem; color: var(--muted); margin-top: 0.1rem; font-variant-numeric: tabular-nums; }
.toggle-icon { color: var(--muted); font-size: 0.625rem; flex-shrink: 0; }
.payment-month-content { border-top: 1px solid var(--border); overflow-x: auto; }
.username-cell { cursor: pointer; color: var(--accent) !important; font-weight: 500; }
.username-cell:hover { text-decoration: underline; }
.bank-tooltip { display: none; position: absolute; z-index: 9999; min-width: 240px; padding: 0.75rem 0.875rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-pop); white-space: nowrap; cursor: default; color: var(--text); }
.bank-tooltip.active { display: block; }
.bank-tooltip-overlay { display: none; position: fixed; inset: 0; z-index: 9998; }
.bank-tooltip-overlay.active { display: block; }
.bank-tooltip .bt-title { font-weight: 600; font-size: 0.8125rem; padding-bottom: 0.4rem; margin-bottom: 0.4rem; border-bottom: 1px solid var(--border); }
.bank-tooltip .bt-row { display: flex; justify-content: space-between; gap: 1rem; font-size: 0.8125rem; padding: 0.1rem 0; }
.bank-tooltip .bt-label { color: var(--muted); }
.bank-tooltip .bt-value { font-weight: 500; }
.bank-tooltip .bt-empty { font-size: 0.8125rem; color: var(--muted); }
.sysinfo { display: grid; grid-template-columns: max-content 1fr; gap: 0.4rem 1.25rem; font-size: 0.8125rem; }
.sysinfo dt { color: var(--muted); }
.sysinfo dd { font-family: var(--mono); font-size: 0.8rem; }
.branding-row { display: flex; align-items: center; gap: 1rem; }
.branding-row + .branding-row { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.branding-preview { flex-shrink: 0; width: 150px; height: 64px; display: grid; place-items: center; border: 1px dashed var(--border-strong); border-radius: var(--r); background: var(--subtle); overflow: hidden; }
.branding-preview.square { width: 64px; }
.branding-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.branding-preview .brand-mark { width: 32px; height: 32px; font-size: 16px; border-radius: 7px; }
.branding-info { flex: 1; min-width: 0; }
.branding-info h4 { font-size: 0.875rem; font-weight: 600; }
.branding-info p { font-size: 0.75rem; color: var(--muted); margin: 0.15rem 0 0.5rem; }
.branding-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.branding-actions input[type="file"] { display: none; }
#dashCustomDateInputs { align-items: center; gap: 0.5rem; flex-wrap: wrap; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
    .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1023px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-pop); }
    .sidebar .sidebar-close { display: inline-grid; }
    .main { margin-left: 0; }
    .menu-btn { display: inline-grid; }
    .topbar { padding: 0 0.75rem; }
    .content { padding: 1rem; }
    .grid-aside, .grid-2 { grid-template-columns: minmax(0, 1fr); }
    .kpis.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 767px) {
    .has-bottom-nav .bottom-nav { display: block; }
    .has-bottom-nav .main { padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom)); }
    .topbar-title .title-long { display: none; }
    .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .kpi-value { font-size: 1.15rem; }
    .data-table th, .data-table td { padding: 0.55rem 0.625rem; }
    .revenue-table th span:not(.th-label) { display: none; }
    /* Phones: Date · Impressions · Page views · eCPM · Revenue (same idea for Country) */
    .data-table .m-only { display: table-cell; }
    .data-table .d-only, .data-table .hide-m { display: none; }
    .country-table th span:not(.th-label) { display: none; }
    .country-table td:first-child { white-space: normal; min-width: 0; }
    /* Five columns must fit a phone: tighter cells, headers may wrap */
    .revenue-table, .country-table { font-size: 0.75rem; }
    .revenue-table th, .revenue-table td,
    .country-table th, .country-table td { padding: 0.5rem 0.35rem; }
    .revenue-table th, .country-table th { white-space: normal; line-height: 1.25; vertical-align: bottom; }
    .revenue-table th:first-child, .revenue-table td:first-child,
    .country-table th:first-child, .country-table td:first-child { padding-left: 0.75rem; }
    .revenue-table th:last-child, .revenue-table td:last-child,
    .country-table th:last-child, .country-table td:last-child { padding-right: 0.75rem; }
    .country-cell { gap: 0.35rem; }
    /* Title and period picker share the first row; the custom date range wraps below */
    .stats-filter { display: contents; }
    #statsCustomRange { width: 100%; }
    #statsCustomRange { flex-wrap: nowrap; }
    #statsCustomRange .date-input { flex: 1 1 0; min-width: 0; padding: 0 0.4rem; }
    .form-row { grid-template-columns: minmax(0, 1fr); }
    .form-actions { flex-direction: column-reverse; }
    .form-actions .btn { width: 100%; }
    .modal { padding: 0; }
    .modal.active { align-items: flex-end; }
    .modal-content { max-width: none; border-radius: var(--r-lg) var(--r-lg) 0 0; max-height: 92vh; padding-bottom: calc(1.25rem + env(safe-area-inset-bottom)); }
}
@media (max-width: 380px) {
    .winner-avatar { width: 46px; height: 46px; }
    .podium-item.first .winner-avatar { width: 60px; height: 60px; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
