:root {
    --bg: #0f1117;
    --surface: #161923;
    --surface-2: #1d212e;
    --border: #262b3a;
    --text: #e6e9f0;
    --muted: #8b93a7;
    --primary: #6d5efc;
    --primary-2: #8a7bff;
    --green: #2ec17a;
    --red: #f2557a;
    --accent: #29c7d6;
    --radius: 16px;
    --shadow: 0 8px 30px rgba(0,0,0,.25);
    font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    background: radial-gradient(1200px 600px at 80% -10%, #1a1d2b 0%, var(--bg) 55%);
    color: var(--text);
    font-family: 'Inter', system-ui, sans-serif;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 256px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 22px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 22px; }
.brand-mark {
    width: 40px; height: 40px; border-radius: 12px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    display: grid; place-items: center; font-weight: 800; font-size: 20px; color: #fff;
}
.brand-text strong { display: block; letter-spacing: .5px; }
.brand-text small { color: var(--muted); font-size: 12px; }

.nav { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.nav-link {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 12px; border-radius: 12px; color: var(--muted);
    font-weight: 500; font-size: 14.5px; transition: .15s;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: linear-gradient(135deg, rgba(109,94,252,.18), rgba(41,199,214,.12)); color: #fff; }
.nav-link.active svg { color: var(--primary-2); }

.sidebar-foot { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.avatar { width: 36px; height: 36px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; font-weight: 700; }
.user-meta strong { display: block; font-size: 14px; }
.user-meta small { color: var(--muted); font-size: 12px; }
.logout { display: block; text-align: center; padding: 9px; border-radius: 10px; background: var(--surface-2); color: var(--muted); font-size: 13.5px; }
.logout:hover { color: var(--red); }

.main { flex: 1; padding: 28px 34px 60px; min-width: 0; }

/* ---------- Topbar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 26px; gap: 16px; flex-wrap: wrap; }
.topbar h1 { font-size: 24px; margin: 0; font-weight: 700; }
.topbar .sub { color: var(--muted); font-size: 14px; margin-top: 3px; }

/* ---------- Buttons ---------- */
.btn { border: 0; cursor: pointer; font-family: inherit; font-weight: 600; font-size: 14px; padding: 11px 18px; border-radius: 12px; transition: .15s; display: inline-flex; align-items: center; gap: 8px; }
.btn.primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; box-shadow: 0 6px 18px rgba(109,94,252,.35); }
.btn.primary:hover { transform: translateY(-1px); }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.ghost:hover { background: var(--border); }
.btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.btn.danger { background: rgba(242,85,122,.15); color: var(--red); }
.btn.danger:hover { background: rgba(242,85,122,.28); }

/* ---------- KPI Cards ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 16px; margin-bottom: 24px; }
.kpi {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 18px 18px 16px; position: relative; overflow: hidden;
}
.kpi::after { content: ''; position: absolute; inset: 0 0 auto 0; height: 3px; background: linear-gradient(90deg, var(--primary), var(--accent)); opacity: .8; }
.kpi .label { color: var(--muted); font-size: 12.5px; font-weight: 500; margin-bottom: 10px; }
.kpi .value { font-size: 21px; font-weight: 700; letter-spacing: .3px; }
.kpi .value.big { font-size: 23px; }

/* ---------- Panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 22px; margin-bottom: 22px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }
.panel-head h2 { font-size: 17px; margin: 0; font-weight: 650; }
.chart-wrap { position: relative; height: 320px; }

.filters { display: flex; gap: 8px; }
.chip { padding: 7px 14px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 13px; cursor: pointer; border: 1px solid transparent; font-weight: 500; }
.chip.active { background: rgba(109,94,252,.18); color: #fff; border-color: rgba(109,94,252,.4); }
.custom-range { display: none; gap: 8px; align-items: center; }
.custom-range.show { display: flex; }
.custom-range input { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); border-radius: 10px; padding: 7px 10px; font-family: inherit; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: right; padding: 12px 14px; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th { color: var(--muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .4px; border-bottom: 1px solid var(--border); }
tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child { border-bottom: 0; }
.roas-pill { background: rgba(46,193,122,.15); color: var(--green); padding: 3px 10px; border-radius: 999px; font-weight: 600; font-size: 13px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ---------- Delta indicators ---------- */
.delta { font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; gap: 3px; }
.delta.up { color: var(--green); }
.delta.down { color: var(--red); }
.delta.flat { color: var(--muted); }

/* ---------- Weekly note ---------- */
.note-box textarea { width: 100%; min-height: 110px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); border-radius: 12px; padding: 12px 14px; font-family: inherit; font-size: 14px; resize: vertical; }
.note-read { background: var(--surface-2); border-radius: 12px; padding: 14px 16px; color: var(--text); line-height: 1.55; white-space: pre-wrap; }
.muted { color: var(--muted); }

/* ---------- Week list ---------- */
.week-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.week-card { display: block; background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px; transition: .15s; }
.week-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.week-card .wk-range { font-weight: 650; font-size: 15px; }
.week-card .wk-meta { color: var(--muted); font-size: 13px; margin-top: 6px; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(6,8,14,.6); backdrop-filter: blur(3px); display: none; align-items: flex-start; justify-content: center; padding: 60px 16px; z-index: 50; }
.modal.open { display: flex; }
.modal-card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; width: 100%; max-width: 440px; box-shadow: var(--shadow); animation: pop .18s ease; }
@keyframes pop { from { transform: translateY(10px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-close { background: none; border: 0; color: var(--muted); font-size: 26px; line-height: 1; cursor: pointer; }
.modal-close:hover { color: var(--text); }

/* ---------- Forms ---------- */
.form { padding: 20px 22px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13.5px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
.field input, .field select { width: 100%; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); border-radius: 11px; padding: 11px 13px; font-family: inherit; font-size: 15px; }
.field input:focus, .field select:focus { outline: none; border-color: var(--primary); }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---------- Alerts ---------- */
.alert { padding: 12px 16px; border-radius: 12px; margin-bottom: 18px; font-size: 14px; }
.alert.error { background: rgba(242,85,122,.14); color: #ffb4c6; border: 1px solid rgba(242,85,122,.3); }
.alert.success { background: rgba(46,193,122,.14); color: #9fe9c2; border: 1px solid rgba(46,193,122,.3); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 38px 34px; width: 100%; max-width: 400px; box-shadow: var(--shadow); }
.login-card .brand { justify-content: center; padding-bottom: 26px; }
.login-card h1 { font-size: 20px; text-align: center; margin: 0 0 4px; }
.login-card .sub { text-align: center; color: var(--muted); font-size: 14px; margin-bottom: 26px; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 6px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
    .kpi-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 860px) {
    .layout { flex-direction: column; }
    .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; flex-wrap: wrap; gap: 8px; }
    .brand { padding: 4px 8px; }
    .nav { flex-direction: row; flex-wrap: wrap; margin-top: 0; }
    .nav-link span { display: none; }
    .sidebar-foot { margin-top: 0; padding-top: 0; border-top: 0; display: flex; align-items: center; gap: 12px; margin-left: auto; }
    .main { padding: 20px 16px 50px; }
}
@media (max-width: 560px) {
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}
