:root {
    --bg: #0b0f1a;
    --panel: #121829;
    --panel-2: #182036;
    --line: #232c45;
    --text: #e7ebf5;
    --muted: #8a94ad;
    --accent: #14b8a6;
    --accent-2: #8b5cf6;
    --grad: linear-gradient(135deg, var(--accent), var(--accent-2));
    --ok: #22c55e;
    --warn: #f59e0b;
    --bad: #ef4444;
    --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}
a { color: inherit; text-decoration: none; }
svg { width: 18px; height: 18px; fill: currentColor; flex: none; }

/* --- Shell ------------------------------------------------------------------------- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
    position: sticky; top: 0; height: 100vh;
    display: flex; flex-direction: column; gap: 24px;
    padding: 24px 16px;
    background: linear-gradient(180deg, #10172a, #0d1222);
    border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; padding: 0 8px; }
.brand small { color: var(--muted); font-weight: 500; font-size: 12px; margin-left: 2px; }
.logo {
    display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px;
    background: var(--grad); color: #fff; font-weight: 800; box-shadow: 0 6px 20px rgba(20, 184, 166, .35);
}
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar nav a {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
    color: var(--muted); font-weight: 500; transition: background .15s, color .15s;
}
.sidebar nav a:hover { background: var(--panel-2); color: var(--text); }
.sidebar nav a.active { background: rgba(20, 184, 166, .12); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.logout { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 0 8px; }
.who { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }

.content { padding: 32px 40px; min-width: 0; }
.page-head { margin-bottom: 24px; }
.page-head h1 { margin: 0; font-size: 26px; letter-spacing: -.02em; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

/* --- Cards & stats ----------------------------------------------------------------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat, .card {
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
.stat { padding: 18px 20px; position: relative; overflow: hidden; }
.stat::after {
    content: ""; position: absolute; inset: auto -40px -60px auto; width: 140px; height: 140px;
    background: var(--grad); opacity: .12; border-radius: 50%;
}
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; }
.stat .hint { color: var(--muted); font-size: 12px; }
.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.card { padding: 20px; }
.card h2 { margin: 0 0 14px; font-size: 16px; }

.bar { height: 6px; border-radius: 4px; background: var(--panel-2); overflow: hidden; margin-top: 6px; }
.bar > span { display: block; height: 100%; background: var(--grad); border-radius: 4px; }
.rank { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.rank li .row { display: flex; justify-content: space-between; }
.rank li .row b { font-weight: 600; }

/* --- Toolbar, chips, search -------------------------------------------------------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip {
    display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px;
    background: var(--panel); border: 1px solid var(--line); color: var(--muted); font-weight: 500; font-size: 13px;
    transition: border-color .15s, color .15s;
}
.chip:hover { color: var(--text); border-color: #3a4566; }
.chip.active { background: rgba(20, 184, 166, .14); border-color: var(--accent); color: var(--text); }
.chip .n { background: var(--panel-2); padding: 0 7px; border-radius: 999px; font-size: 12px; }
.search { display: flex; gap: 8px; flex-wrap: wrap; }
input, select {
    background: var(--panel); border: 1px solid var(--line); color: var(--text);
    border-radius: 10px; padding: 9px 12px; font: inherit; outline: none;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(20, 184, 166, .18); }
.btn {
    border: 0; border-radius: 10px; padding: 9px 16px; font: inherit; font-weight: 600; cursor: pointer;
    background: var(--grad); color: #fff;
}
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.btn.ghost:hover { color: var(--text); border-color: #3a4566; }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg a { padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.seg a.active { background: var(--panel-2); color: var(--text); }
.filter-note { display: inline-flex; gap: 8px; align-items: center; color: var(--muted); }
.filter-note a { color: var(--accent); }

/* --- Tables ------------------------------------------------------------------------ */
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 16px; text-align: left; white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--line); }
td { border-bottom: 1px solid rgba(35, 44, 69, .6); }
tbody tr:not(.group):hover td { background: rgba(255, 255, 255, .02); }
tr.group td {
    background: var(--panel-2); font-weight: 600; font-size: 13px; color: var(--text);
    border-bottom: 1px solid var(--line); padding-top: 9px; padding-bottom: 9px;
}
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
/* Category tile like the app's (icon on a gradient); icons from Material Symbols. */
.ms { font-family: 'Material Symbols Rounded'; font-weight: normal; font-style: normal; line-height: 1; letter-spacing: normal;
    text-transform: none; white-space: nowrap; direction: ltr; font-feature-settings: 'liga'; }
.cat-tile { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: 8px;
    margin-right: 10px; vertical-align: middle; color: #fff; }
.cat-tile .ms { font-size: 15px; }
.cat-tile.lg { width: 40px; height: 40px; border-radius: 12px; }
.cat-tile.lg .ms { font-size: 22px; }
.ms.sm { font-size: 14px; vertical-align: -2px; margin-right: 4px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 8px; vertical-align: -1px; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.active { background: rgba(34, 197, 94, .14); color: var(--ok); }
.badge.paused { background: rgba(245, 158, 11, .14); color: var(--warn); }
.badge.cancelled { background: rgba(239, 68, 68, .14); color: var(--bad); }
.badge.neutral { background: var(--panel-2); color: var(--muted); }
.link { color: var(--accent); font-weight: 500; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 16px; color: var(--muted); }
.pager a, .pager span.cur { padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); }
.pager span.cur { border-color: var(--accent); color: var(--text); }

/* --- Login ------------------------------------------------------------------------- */
.login-page {
    min-height: 100vh; display: grid; place-items: center; padding: 16px;
    background:
        radial-gradient(600px circle at 15% 20%, rgba(20, 184, 166, .25), transparent 60%),
        radial-gradient(500px circle at 85% 80%, rgba(139, 92, 246, .25), transparent 60%),
        var(--bg);
}
.login-card {
    width: 100%; max-width: 400px; padding: 36px 32px; border-radius: 20px;
    background: rgba(18, 24, 41, .75); border: 1px solid rgba(255, 255, 255, .08);
    backdrop-filter: blur(16px); box-shadow: 0 30px 80px rgba(0, 0, 0, .45);
}
.login-card .logo { width: 48px; height: 48px; font-size: 22px; border-radius: 14px; margin-bottom: 20px; }
.login-card h1 { margin: 0; font-size: 24px; letter-spacing: -.02em; }
.login-card p { margin: 6px 0 24px; color: var(--muted); }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
.login-card input { width: 100%; padding: 12px 14px; }
.login-card .btn { width: 100%; margin-top: 24px; padding: 12px; font-size: 15px; box-shadow: 0 10px 30px rgba(20, 184, 166, .3); }
.alert { padding: 10px 14px; border-radius: 10px; background: rgba(239, 68, 68, .12); border: 1px solid rgba(239, 68, 68, .35); color: #fca5a5; font-size: 13px; }

/* --- Phone width ------------------------------------------------------------------- */
@media (max-width: 860px) {
    .shell { grid-template-columns: minmax(0, 1fr); }
    .sidebar { position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; padding: 12px 16px; gap: 12px; }
    .sidebar nav { flex-direction: row; overflow-x: auto; }
    .logout { margin: 0 0 0 auto; flex-direction: row; align-items: center; padding: 0; }
    .who { display: none; }
    .content { padding: 20px 16px; }
    .grid-2 { grid-template-columns: 1fr; }
}

/* --- Catalog editor ---------------------------------------------------------------- */
.notice { padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; background: rgba(34, 197, 94, .12); border: 1px solid rgba(34, 197, 94, .35); color: #86efac; }
tr.clickable { cursor: pointer; }
tr.hidden-row td { opacity: .5; }
tr.hidden-row td:last-child { opacity: 1; }
.btn { display: inline-block; }
.btn.danger { background: transparent; border: 1px solid rgba(239, 68, 68, .5); color: #fca5a5; }
.btn.danger:hover { background: rgba(239, 68, 68, .12); }
.edit-form { display: flex; flex-direction: column; gap: 16px; max-width: 920px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 500; }
.form-grid label small { font-weight: 400; opacity: .7; }
.form-grid label.wide, .form-grid .wide { grid-column: 1 / -1; }
.form-grid input, .form-grid select { width: 100%; }
.color-field { display: flex; gap: 8px; }
.color-field input[type=color] { width: 44px; flex: none; padding: 3px; height: 40px; cursor: pointer; }
table.prices { width: auto; }
table.prices th, table.prices td { padding: 6px 12px 6px 0; border: 0; }
input.xs { width: 80px; text-transform: uppercase; }
input.sm { width: 130px; }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 15px; padding: 6px; }
.icon-btn:hover { color: var(--bad); }
.form-actions { display: flex; gap: 12px; justify-content: flex-end; }
.danger-zone { max-width: 920px; margin-top: 32px; padding-top: 20px; border-top: 1px solid var(--line); }
.errors { margin: 0; padding-left: 18px; }

.sm-btn { padding: 6px 12px; font-size: 13px; }
label.inline { display: inline-flex; align-items: center; gap: 8px; }
.inline-form { display: inline; margin-left: 6px; }
.plan-form { display: flex; gap: 6px; align-items: center; flex-wrap: nowrap; }
.plan-form select, .plan-form input { padding: 5px 8px; font-size: 13px; }

/* Catalog logos */
.logo-thumb { width: 22px; height: 22px; border-radius: 6px; object-fit: cover; vertical-align: middle; margin-right: 8px; }
.logo-field { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.logo-field > label:not(.check) { flex: 1; min-width: 220px; }
.logo-preview { width: 56px; height: 56px; border-radius: 16px; object-fit: cover; flex: none; }
.logo-preview.empty { display: inline-flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 22px; }
.form-grid .logo-field .check { display: flex; align-items: center; gap: 6px; flex-direction: row; }
.logo-field .check input { width: auto; }
/* The app's bundled logo when none is uploaded (BrandLogos): Simple Icons font, Material Symbols or an SVG mask. */
@font-face { font-family: 'SimpleIcons'; src: url('/fonts/SimpleIcons.ttf') format('truetype'); font-display: block; }
.brand-tile { display: inline-flex; align-items: center; justify-content: center; flex: none; vertical-align: middle;
    color: #fff; font-weight: 700; line-height: 1; overflow: hidden; }
.brand-tile.on-white { box-shadow: inset 0 0 0 1px rgba(16, 24, 40, .12); }
.brand-tile.logo-thumb { font-size: 11px; }
.brand-tile.logo-preview { font-size: 22px; }
.brand-tile .si { font-family: 'SimpleIcons'; font-weight: normal; }
.brand-tile .si, .brand-tile .ms { font-size: 1.05em; }
.brand-tile.logo-thumb .si, .brand-tile.logo-thumb .ms { font-size: 12px; }
.brand-tile.logo-preview .si, .brand-tile.logo-preview .ms { font-size: 28px; }
.brand-tile .svg { width: 50%; height: 50%; -webkit-mask: var(--logo) center / contain no-repeat; mask: var(--logo) center / contain no-repeat; }

/* Multi-select dropdown (country picker) */
.form-grid .field { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 500; }
.form-grid .field small { font-weight: 400; opacity: .7; }
.multi { position: relative; }
.multi summary {
    list-style: none; cursor: pointer; background: var(--panel); border: 1px solid var(--line); color: var(--text);
    border-radius: 10px; padding: 9px 32px 9px 12px; font-size: 14px; font-weight: 400;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.multi summary::-webkit-details-marker { display: none; }
.multi summary::after { content: "▾"; position: absolute; right: 12px; top: 9px; color: var(--muted); }
.multi[open] summary { border-color: var(--accent); }
.multi-panel {
    position: absolute; z-index: 20; left: 0; right: 0; min-width: 260px; margin-top: 6px; padding: 10px;
    background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px rgba(0, 0, 0, .45);
}
.multi-tools { display: flex; gap: 8px; margin-bottom: 8px; }
.multi-tools input { flex: 1; min-width: 0; }
.multi-list { max-height: 260px; overflow-y: auto; display: flex; flex-direction: column; }
.form-grid .multi-item {
    flex-direction: row; align-items: center; gap: 8px; padding: 6px 4px; border-radius: 8px;
    color: var(--text); font-size: 14px; font-weight: 400; cursor: pointer;
}
.multi-item:hover { background: var(--panel-2); }
/* The rows are flex, which would override the hidden attribute the search sets. */
.form-grid .multi-item[hidden] { display: none; }
.form-grid .multi-item input { width: auto; }
.multi-item small { margin-left: auto; color: var(--muted); }

/* Country filter dropdown above lists */
.country-filter { margin-bottom: 16px; }
.country-filter select { min-width: 240px; max-width: 100%; }

/* Catalog category groups retain the existing country and search filters. */
.catalog-group { margin-bottom: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.catalog-group > summary { display: flex; align-items: center; gap: 12px; padding: 16px; cursor: pointer; list-style: none; border-radius: inherit; }
.catalog-group > summary::-webkit-details-marker { display: none; }
.catalog-group > summary:hover { background: var(--panel-2); }
.catalog-group > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.catalog-group-name { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: 15px; font-weight: 600; }
.catalog-group-chevron { color: var(--muted); }
.catalog-group[open] > summary .catalog-group-chevron { transform: rotate(180deg); }
.catalog-group[open] > summary { border-bottom: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0; }
.catalog-group > .table-wrap { border: 0; border-radius: 0 0 var(--radius) var(--radius); }
