:root {
    --accent: #12b5a5;
    --accent-strong: #0e9d8f;
    --accent-soft: rgba(18, 181, 165, .12);
    --up: #16a34a;
    --up-soft: rgba(22, 163, 74, .12);
    --down: #ef4444;
    --down-soft: rgba(239, 68, 68, .1);
    --info: #6366f1;
    --info-soft: rgba(99, 102, 241, .12);
    --warn: #f59e0b;
    --warn-soft: rgba(245, 158, 11, .14);

    --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-mono: ui-monospace, "SF Mono", "Cascadia Code", "Roboto Mono", monospace;

    --r-sm: 10px;
    --r: 14px;
    --r-lg: 18px;
    --sb-w: 260px;

    --ink: #0d1117;
    --ink-2: #131a22;
    --ink-border: rgba(255, 255, 255, .07);
    --ink-text: #e8ecf2;
    --ink-muted: #8b95a5;
}

:root, :root[data-theme="light"] {
    --bg: #f1f3f7;
    --surface: #ffffff;
    --surface-2: #f4f6f9;
    --border: #e2e7ee;
    --text: #101828;
    --muted: #667085;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .06);
    --shadow: 0 2px 4px rgba(16, 24, 40, .05), 0 10px 28px rgba(16, 24, 40, .08);
    --shadow-lg: 0 12px 40px rgba(16, 24, 40, .14);
}

:root[data-theme="dark"] {
    --bg: #11161e;
    --surface: #182029;
    --surface-2: #1f2935;
    --border: #2b3644;
    --text: #e8ecf2;
    --muted: #8f99a9;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 10px 32px rgba(0, 0, 0, .35);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    font-size: 14px;
    line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4, h5 { margin: 0; font-weight: 700; letter-spacing: -.015em; }

.mono { font-family: var(--font-mono); }
.up { color: var(--up); }
.down { color: var(--down); }
.muted { color: var(--muted); }

.shell { display: flex; min-height: 100vh; }

/* ============ Sidebar ============ */
.rail {
    width: var(--sb-w); flex: none; position: sticky; top: 0; align-self: flex-start;
    height: 100vh; background: var(--ink); color: var(--ink-text);
    border-right: 1px solid var(--ink-border);
    display: flex; flex-direction: column;
    transition: margin .25s ease;
}
html.rail-hidden .rail { margin-left: calc(var(--sb-w) * -1); }

.rail-tab {
    position: fixed; left: var(--sb-w); top: 50%; transform: translateY(-50%); z-index: 70;
    width: 22px; height: 56px; border: 1px solid var(--border); border-left: 0;
    border-radius: 0 11px 11px 0; background: var(--surface); box-shadow: var(--shadow-sm);
    display: grid; place-items: center; cursor: pointer; color: var(--muted); padding: 0;
    transition: left .25s ease, color .15s, background .15s;
}
.rail-tab:hover { color: var(--accent); background: var(--surface-2); }
.rail-tab i { font-size: 13px; transition: transform .25s; }
html.rail-hidden .rail-tab { left: 0; }
html.rail-hidden .rail-tab i { transform: rotate(180deg); }
.rail-brand {
    display: flex; align-items: center; gap: 10px; padding: 22px 20px 16px;
    font-weight: 800; font-size: 15px; letter-spacing: .06em;
}
.rail-brand .mark {
    width: 12px; height: 12px; border-radius: 50%; flex: none;
    background: radial-gradient(circle at 35% 30%, #3ee8d4, var(--accent) 70%);
    box-shadow: 0 0 10px rgba(18, 181, 165, .55);
}
.rail-brand .co { color: var(--accent); }
.rail-nav { flex: 1; overflow-y: auto; padding: 4px 14px; }
.rail-nav::-webkit-scrollbar { width: 6px; }
.rail-nav::-webkit-scrollbar-thumb { background: var(--ink-border); border-radius: 4px; }
.rail-sect {
    font-size: 10.5px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
    color: var(--ink-muted); padding: 20px 12px 8px;
}
.rail-link {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px; margin-bottom: 2px;
    border-radius: var(--r-sm); color: #aeb7c4; font-weight: 500; font-size: 13.5px;
    transition: background .15s, color .15s;
}
.rail-link i { font-size: 17px; width: 20px; text-align: center; color: var(--ink-muted); transition: color .15s; }
.rail-link:hover { background: rgba(255, 255, 255, .05); color: #fff; }
.rail-link:hover i { color: #c6cedb; }
.rail-link.on { background: var(--accent-soft); color: #fff; font-weight: 600; }
.rail-link.on i { color: var(--accent); }

.rail-user {
    display: flex; align-items: center; gap: 11px; margin: 12px 14px 16px; padding: 12px;
    border-radius: var(--r); background: var(--ink-2); border: 1px solid var(--ink-border);
}
.rail-user .avatar { flex: none; }
.rail-user .info { flex: 1; min-width: 0; }
.rail-user .info .n { font-weight: 600; font-size: 13px; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rail-user .info .e { font-size: 11.5px; color: var(--ink-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rail-user form { display: flex; }
.rail-user button {
    border: 0; background: none; color: var(--ink-muted); cursor: pointer; font-size: 15px;
    padding: 6px; border-radius: 8px; transition: color .15s, background .15s;
}
.rail-user button:hover { color: var(--down); background: rgba(255, 255, 255, .06); }

/* ============ Main / topbar ============ */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
    height: 68px; padding: 0 28px;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: blur(12px); border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
}
.topbar .grow { flex: 1; }
#railToggle { display: none; }

[data-theme="dark"] .theme-when-light { display: none; }
:root:not([data-theme="dark"]) .theme-when-dark { display: none; }

.flag { width: 19px; height: 14px; border-radius: 3px; object-fit: cover; box-shadow: 0 0 0 1px var(--border); }

.search {
    display: flex; align-items: center; gap: 9px; width: min(320px, 34vw); height: 40px;
    padding: 0 14px; background: var(--bg); border: 1px solid var(--border);
    border-radius: 999px; transition: border-color .15s, box-shadow .15s, background .15s;
}
.search:focus-within { background: var(--surface); }
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search i { color: var(--muted); font-size: 15px; }
.search input { flex: 1; border: 0; background: none; font: inherit; color: var(--text); outline: none; }
.search input::placeholder { color: var(--muted); }

.ctrl {
    position: relative; display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px;
    border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
    color: var(--text); font-size: 13px; font-weight: 500; cursor: pointer;
    transition: border-color .15s, box-shadow .15s;
}
.ctrl:hover { border-color: var(--accent); }
.ctrl-icon { width: 40px; padding: 0; justify-content: center; font-size: 16px; }
.ctrl .flag-icon { border-radius: 3px; }
.ctrl .count {
    position: absolute; top: -4px; right: -4px; min-width: 17px; height: 17px; padding: 0 4px;
    border-radius: 999px; background: var(--down); color: #fff; font-size: 10px; font-weight: 700;
    display: grid; place-items: center;
}
.avatar {
    width: 30px; height: 30px; border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #3b82f6);
    color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px;
}

.menu { position: relative; }
.menu-pop {
    position: absolute; right: 0; top: calc(100% + 8px); min-width: 190px; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow-lg); padding: 6px;
    display: none; z-index: 40;
}
.menu.open .menu-pop { display: block; }
.menu-pop a, .menu-pop button {
    display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 11px; border: 0; background: none;
    color: var(--text); font: inherit; font-size: 13.5px; text-align: left; border-radius: var(--r-sm); cursor: pointer;
}
.menu-pop a:hover, .menu-pop button:hover { background: var(--surface-2); }
.menu-pop .on { color: var(--accent); font-weight: 600; }

.content { padding: 28px; flex: 1; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; font-weight: 800; }
.page-sub { color: var(--muted); font-size: 14px; margin-top: 4px; }

/* ============ Buttons ============ */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 18px;
    border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface); color: var(--text);
    font-family: var(--font); font-weight: 600; font-size: 13.5px; cursor: pointer; transition: all .15s;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 1px 2px rgba(18, 181, 165, .4); }
.btn-primary:hover { background: var(--accent-strong); }
.btn-ghost { background: none; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { color: var(--down); border-color: color-mix(in srgb, var(--down) 35%, var(--border)); background: none; }
.btn-danger:hover { background: var(--down-soft); }

/* ============ Cards / KPIs ============ */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); }
.card-pad { padding: 22px; }
.card-title { font-size: 16px; font-weight: 700; margin-bottom: 16px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); gap: 16px; }
.kpi {
    display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
    padding: 20px 22px; box-shadow: var(--shadow-sm); color: inherit;
    transition: box-shadow .18s, transform .18s;
}
a.kpi:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.kpi .k-label { font-size: 13px; font-weight: 500; color: var(--muted); }
.kpi .k-value { font-size: 28px; font-weight: 800; letter-spacing: -.02em; margin-top: 6px; }
.kpi .k-delta { display: flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; margin-top: 8px; }
.kpi .k-delta .vs { color: var(--muted); font-weight: 400; }
.chip {
    flex: none; width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center; font-size: 19px;
}
.chip.teal { background: var(--accent-soft); color: var(--accent); }
.chip.violet { background: var(--info-soft); color: var(--info); }
.chip.orange { background: var(--warn-soft); color: var(--warn); }
.chip.green { background: var(--up-soft); color: var(--up); }
.chip.blue { background: rgba(59, 130, 246, .12); color: #3b82f6; }
.chip.red { background: var(--down-soft); color: var(--down); }
.chip.sm { width: 36px; height: 36px; border-radius: 11px; font-size: 15px; }

/* ============ Tables ============ */
.tbl-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--shadow-sm); }
table.tbl { width: 100%; border-collapse: collapse; }
table.tbl th {
    text-align: left; font-size: 12px; font-weight: 600; color: var(--muted);
    padding: 12px 18px; border-bottom: 1px solid var(--border); background: var(--surface-2);
}
table.tbl td { padding: 14px 18px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
table.tbl tbody tr:last-child td { border-bottom: 0; }
table.tbl tbody tr:hover { background: var(--surface-2); }
.tbl-empty { text-align: center; color: var(--muted); padding: 40px 12px; }

/* ============ Badges ============ */
.badge {
    display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600;
    padding: 4px 10px; border-radius: 999px; background: var(--surface-2);
    border: 1px solid var(--border); color: var(--muted);
}
.badge.accent { background: var(--accent-soft); border-color: transparent; color: var(--accent-strong); }
.badge.up { background: var(--up-soft); border-color: transparent; color: var(--up); }
.badge.down { background: var(--down-soft); border-color: transparent; color: var(--down); }
.badge.info { background: var(--info-soft); border-color: transparent; color: var(--info); }
.badge.warn { background: var(--warn-soft); border-color: transparent; color: #b45309; }

/* ============ Forms ============ */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 7px; }
.input, .select, .textarea {
    width: 100%; padding: 10px 13px; font: inherit; font-size: 14px; color: var(--text);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm);
    transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.textarea { resize: vertical; min-height: 110px; }
.copy-row { display: flex; gap: 8px; }
.copy-row .input { font-family: var(--font-mono); font-size: 12.5px; }

input[type="color"] {
    width: 100%; height: 42px; padding: 4px; border: 1px solid var(--border);
    border-radius: var(--r-sm); background: var(--surface); cursor: pointer;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 7px; }

/* ============ Activity feed ============ */
.feed { display: flex; flex-direction: column; }
.feed-item { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.feed-item:last-child { border-bottom: 0; }
.feed-item .fi-main { flex: 1; min-width: 0; }
.feed-item .fi-title { font-weight: 600; font-size: 13.5px; }
.feed-item .fi-sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.feed-item .fi-time { font-size: 12px; color: var(--muted); flex: none; }

.link-more { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--accent-strong); margin-top: 14px; }
.link-more:hover { text-decoration: underline; }

.stack-sm > * + * { margin-top: 10px; }

@media (max-width: 900px) {
    .rail { position: fixed; z-index: 60; transform: translateX(-100%); transition: transform .25s; margin-left: 0 !important; }
    .rail.open { transform: none; }
    .rail-tab { display: none; }
    #railToggle { display: inline-flex; }
    .content { padding: 18px; }
    .search { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}
