/* Subscriptions Killer — design system */

:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #fafbfc;
    --surface-hover: #f1f5f9;
    --border: #e3e6eb;
    --border-strong: #cbd5e1;
    --text: #1f2937;
    --text-muted: #6b7280;
    --text-subtle: #9ca3af;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --good: #16a34a;
    --good-bg: #dcfce7;
    --warn: #d97706;
    --warn-bg: #fed7aa;
    --warn-surface: #fff7ed;
    --warn-border: #fed7aa;
    --danger: #dc2626;
    --danger-bg: #fee2e2;
    --accent: #7c3aed;
    --accent-bg: #ede9fe;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-strong: 0 10px 25px rgba(15, 23, 42, 0.1), 0 4px 10px rgba(15, 23, 42, 0.04);
    --radius: 10px;
    --radius-sm: 6px;
}

[data-theme="dark"] {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-2: #182338;
    --surface-hover: #243049;
    --border: #2d3a52;
    --border-strong: #3f4d68;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --text-subtle: #64748b;
    --primary: #60a5fa;
    --primary-hover: #93c5fd;
    --good: #4ade80;
    --good-bg: #14532d;
    --warn: #fbbf24;
    --warn-bg: #78350f;
    --warn-surface: #1e1810;
    --warn-border: #92400e;
    --danger: #f87171;
    --danger-bg: #7f1d1d;
    --accent: #a78bfa;
    --accent-bg: #4c1d95;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-strong: 0 10px 25px rgba(0, 0, 0, 0.5), 0 4px 10px rgba(0, 0, 0, 0.3);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0f172a;
        --surface: #1e293b;
        --surface-2: #182338;
        --surface-hover: #243049;
        --border: #2d3a52;
        --border-strong: #3f4d68;
        --text: #f1f5f9;
        --text-muted: #94a3b8;
        --text-subtle: #64748b;
        --primary: #60a5fa;
        --primary-hover: #93c5fd;
        --good: #4ade80;
        --good-bg: #14532d;
        --warn: #fbbf24;
        --warn-bg: #78350f;
        --warn-surface: #1e1810;
        --warn-border: #92400e;
        --danger: #f87171;
        --danger-bg: #7f1d1d;
        --accent: #a78bfa;
        --accent-bg: #4c1d95;
        --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
        --shadow-strong: 0 10px 25px rgba(0, 0, 0, 0.5), 0 4px 10px rgba(0, 0, 0, 0.3);
    }
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.2s, color 0.2s;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Topbar === */
.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 17px; }
.brand .logo { font-size: 22px; }
nav { display: flex; gap: 6px; align-items: center; }
nav a, nav button {
    color: var(--text);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: transparent;
    border: none;
    cursor: pointer;
    font-family: inherit;
}
nav a:hover, nav button:hover { background: var(--surface-hover); text-decoration: none; }

.theme-toggle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    background: var(--surface-hover);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: transform 0.2s;
}
.theme-toggle:hover { transform: rotate(15deg); }
[data-theme="dark"] .theme-toggle .sun-icon,
:root:not([data-theme="light"]) .theme-toggle .sun-icon { display: inline; }
[data-theme="dark"] .theme-toggle .moon-icon,
:root:not([data-theme="light"]) .theme-toggle .moon-icon { display: none; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-toggle .sun-icon { display: inline; }
    :root:not([data-theme="light"]) .theme-toggle .moon-icon { display: none; }
}
.theme-toggle .sun-icon { display: none; }
.theme-toggle .moon-icon { display: inline; }
[data-theme="light"] .theme-toggle .sun-icon { display: none !important; }
[data-theme="light"] .theme-toggle .moon-icon { display: inline !important; }

main { max-width: 1320px; margin: 24px auto; padding: 0 24px; }

footer {
    max-width: 1320px;
    margin: 32px auto 16px;
    padding: 16px 24px;
    color: var(--text-muted);
    font-size: 13px;
    display: flex;
    justify-content: space-between;
    border-top: 1px solid var(--border);
}

/* === KPIs === */
.kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 28px;
}
.kpi {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 18px 16px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: relative;
    overflow: hidden;
    transition: transform 0.15s, box-shadow 0.15s;
}
.kpi:hover { transform: translateY(-1px); box-shadow: var(--shadow-strong); }
.kpi.muted { opacity: 0.6; }
.kpi.accent::before {
    content: '';
    position: absolute; top: 0; left: 0; right: 0; height: 3px;
    background: var(--primary);
}
.kpi-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
    display: flex; align-items: center; gap: 6px;
}
.kpi-icon { font-size: 14px; }
.kpi-value {
    font-size: 26px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}
.kpi-sub {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* === Sections === */
section { margin-bottom: 28px; }

.section-title {
    font-size: 13px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
    margin: 0 0 12px;
    display: flex; align-items: center; gap: 8px;
}
.section-title-icon { font-size: 16px; }

/* === Two-column layout === */
.grid-2col {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 20px;
    margin-bottom: 28px;
}
@media (max-width: 900px) {
    .grid-2col { grid-template-columns: 1fr; }
}

/* === Card === */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}
.card h2 { margin-top: 0; font-size: 14px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }

/* === Top costs chart === */
.bar-chart { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; font-size: 13px; }
.bar-row .bar-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row .bar-amount { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); }
.bar-row .bar-track { grid-column: 1 / -1; height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; }
.bar-row .bar-fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); border-radius: 3px; }

/* === Upcoming === */
.upcoming-list { list-style: none; margin: 0; padding: 0; }
.upcoming-list li {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    display: grid;
    grid-template-columns: 70px 1fr auto;
    gap: 12px;
    align-items: center;
    font-size: 13px;
}
.upcoming-list li:last-child { border-bottom: none; }
.upcoming-date {
    text-align: center;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px 0;
    font-variant-numeric: tabular-nums;
}
.upcoming-date strong { display: block; font-size: 16px; line-height: 1.1; }
.upcoming-date small { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.upcoming-amount { font-variant-numeric: tabular-nums; font-weight: 600; }
.upcoming-soon { border-left: 3px solid var(--warn); }

/* === Alerts === */
.alerts {
    background: var(--warn-surface);
    border: 1px solid var(--warn-border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 24px;
}
.alerts h2 { margin: 0 0 10px; font-size: 14px; color: var(--warn); display: flex; gap: 8px; }
.alerts ul { list-style: none; padding: 0; margin: 0; }
.alerts li { padding: 8px 0; border-bottom: 1px dashed var(--warn-border); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.alerts li:last-child { border-bottom: none; }

/* === Filters / Search === */
.toolbar {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 14px;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.toolbar-group { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.toolbar-group .label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.toolbar-search {
    flex: 1;
    min-width: 220px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 7px 12px;
    font-size: 14px;
    color: var(--text);
    font-family: inherit;
}
.toolbar-search:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15); }

.chip {
    padding: 5px 11px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 12.5px;
    font-weight: 500;
    transition: all 0.12s;
}
.chip:hover { text-decoration: none; background: var(--surface-hover); border-color: var(--border-strong); }
.chip-on { background: var(--primary); color: white; border-color: var(--primary); }
.chip-on:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

/* === Table === */
.subs-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}
.subs-table th, .subs-table td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 13.5px;
    vertical-align: middle;
}
.subs-table th {
    background: var(--surface-2);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    position: sticky;
    top: 60px;
    z-index: 1;
}
.subs-table tr:last-child td { border-bottom: none; }
.subs-table tr:hover { background: var(--surface-hover); }
.subs-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.subs-table .empty { text-align: center; padding: 48px; color: var(--text-muted); }
.row-stopped td { opacity: 0.55; }
.row-cancelled td { opacity: 0.4; }
.row-cancelled td:first-child strong { text-decoration: line-through; }
.row-hidden { display: none !important; }

.label-with-meta strong { display: block; }
.label-with-meta small { color: var(--text-muted); font-size: 11.5px; }

/* === Badges === */
.badge {
    display: inline-block;
    padding: 2.5px 9px;
    border-radius: 999px;
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    line-height: 1.4;
}
.badge-ok { background: var(--good-bg); color: var(--good); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-good { background: var(--good-bg); color: var(--good); }
.badge-cancel { background: var(--danger-bg); color: var(--danger); }
.badge-mute { background: var(--surface-hover); color: var(--text-muted); }
.badge-accent { background: var(--accent-bg); color: var(--accent); }

.account-chip {
    display: inline-block;
    padding: 1px 7px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    margin: 1px 2px;
    font-size: 11px;
    color: var(--text-muted);
}

/* === Buttons === */
.btn-primary, .btn-ghost, .btn-icon {
    border: none;
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-size: 13px;
    padding: 7px 14px;
    font-weight: 500;
    font-family: inherit;
    transition: all 0.12s;
}
.btn-primary {
    background: var(--primary);
    color: white;
    border: 1px solid var(--primary);
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost {
    background: var(--surface-2);
    color: var(--text-muted);
    border: 1px solid var(--border);
    padding: 5px 10px;
}
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); border-color: var(--border-strong); }
.btn-icon {
    background: transparent;
    color: var(--text-muted);
    padding: 4px 8px;
    font-size: 14px;
    border: 1px solid transparent;
}
.btn-icon:hover { background: var(--surface-hover); border-color: var(--border); }

.actions-cell { white-space: nowrap; }
.actions-cell button { margin: 0 1px; }

.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
small { font-size: 12px; }
code {
    background: var(--surface-2);
    border: 1px solid var(--border);
    padding: 1.5px 6px;
    border-radius: 4px;
    font-size: 12px;
    font-family: ui-monospace, 'SF Mono', Monaco, Consolas, monospace;
}

/* === Flash messages === */
.flash-zone { max-width: 1320px; margin: 12px auto -12px; padding: 0 24px; }
.flash {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    font-size: 14px;
    border: 1px solid transparent;
}
.flash-success { background: var(--good-bg); color: var(--good); border-color: var(--good); }
.flash-error { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }

/* === Detail page === */
.back { display: inline-block; margin-bottom: 14px; color: var(--text-muted); font-size: 13px; }
.back:hover { color: var(--text); }

.state-row { display: flex; gap: 16px; margin-bottom: 12px; flex-wrap: wrap; }
.state-row label { display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: 14px; }
textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    font-family: inherit;
    font-size: 13.5px;
    background: var(--bg);
    color: var(--text);
    resize: vertical;
}
textarea:focus { outline: none; border-color: var(--primary); }

.tx-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.tx-table th, .tx-table td { padding: 7px 10px; border-bottom: 1px solid var(--border); }
.tx-table th { color: var(--text-muted); font-weight: 600; text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }

.kv { list-style: none; padding: 0; margin: 0; }
.kv li { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.kv li:last-child { border-bottom: none; }
.kv span { color: var(--text-muted); }

/* === Sparkline === */
.sparkline { background: var(--surface-2); border-radius: var(--radius-sm); padding: 16px; }
.sparkline svg { width: 100%; height: 120px; }
.sparkline path.line { fill: none; stroke: var(--primary); stroke-width: 2; }
.sparkline path.area { fill: var(--primary); opacity: 0.1; }
.sparkline circle { fill: var(--primary); }
.sparkline circle.last { fill: var(--accent); r: 4; }

/* === Detail header === */
.detail-header h1 { margin: 0 0 6px; font-size: 24px; }

/* === Misc === */
hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }
