/* Recurra: Ember palette on a black ground. Crimson/ruby accent, warm off-white
   text, clay-rose secondary. Surfaces are lifted off the black with soft shadows;
   subscription cards take a per-service brand colour on the raised surface.
   Type: Cinzel (display) + Cormorant (body), self-hosted as variable woff2. */
@font-face {
    font-family: 'Cinzel';
    font-style: normal;
    font-weight: 400 900;
    font-display: swap;
    src: url('/assets/fonts/cinzel.woff2') format('woff2');
}
@font-face {
    font-family: 'Cormorant';
    font-style: normal;
    font-weight: 300 700;
    font-display: swap;
    src: url('/assets/fonts/cormorant.woff2') format('woff2');
}
@font-face {
    font-family: 'Space Grotesk';
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url('/assets/fonts/space-grotesk.woff2') format('woff2');
}
:root {
    --bg: #000000;
    --bg-soft: #120a0a;
    --bg-raise: #1b0f10;
    --heading: #f6efed;
    --text: #e3d2cf;
    --muted: #a89090;
    --line: rgba(196, 61, 77, 0.20);
    --line-strong: rgba(196, 61, 77, 0.42);
    --accent: #c43d4d;
    --accent-dim: #7e2531;
    --accent-bright: #e2596a;
    --accent-2: #cf8d84;
    --accent-2-dim: #9c5f56;
    --danger: #e0715c;
    --danger-soft: rgba(224, 113, 92, 0.16);
    --success: #cf8d84;
    --success-soft: rgba(207, 141, 132, 0.16);
    --font-display: 'Cinzel', Georgia, 'Times New Roman', serif;
    --font-body: 'Cormorant', Georgia, 'Times New Roman', serif;
    --font-num: 'Space Grotesk', ui-monospace, 'SF Mono', system-ui, sans-serif;
    --radius: 12px;
    --radius-sm: 9px;
    --tap: 44px;
    --shadow: 0 16px 38px -18px rgba(0, 0, 0, 0.9);
    --shadow-sm: 0 8px 20px -14px rgba(0, 0, 0, 0.85);
    --highlight: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

* { box-sizing: border-box; }

/* Honour the hidden attribute even on flex/grid items (used by the picker filter). */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font-body);
    font-weight: 500;
    background-color: var(--bg);
    background-image: radial-gradient(130% 80% at 50% -8%, rgba(196, 61, 77, 0.12), rgba(196, 61, 77, 0) 46%);
    background-attachment: fixed;
    color: var(--text);
    line-height: 1.5;
    font-size: 16px;
    min-height: 100vh;
}

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

h1 { font-family: var(--font-display); font-size: 1.5rem; margin: 0 0 0.25rem; color: var(--heading); letter-spacing: 0.02em; }
h2 { font-family: var(--font-display); font-size: 1.1rem; margin: 0 0 0.75rem; color: var(--heading); letter-spacing: 0.02em; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.center { text-align: center; }
.dot { color: var(--line-strong); }
.mt { margin-top: 1rem; }
.grow { flex: 1; }

/* ---------- Top bar ---------- */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 1rem; padding: 0.75rem 1rem;
    background: rgba(8, 4, 4, 0.82); border-bottom: 1px solid var(--line);
    -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
    box-shadow: 0 12px 30px -20px rgba(0, 0, 0, 0.9);
    position: sticky; top: 0; z-index: 10;
}
.brand { display: inline-flex; align-items: center; gap: 0.5rem; color: var(--heading); font-family: var(--font-display); font-weight: 700; letter-spacing: 0.04em; }
.brand:hover { text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; width: 28px; height: 28px; }
.brand-mark img { width: 100%; height: 100%; display: block; }
.nav { display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; }
.nav a, .linklike {
    color: var(--text); padding: 0.4rem 0.6rem; border-radius: var(--radius-sm);
    background: transparent; border: 0; cursor: pointer; font: inherit;
}
.nav a:hover, .linklike:hover { background: rgba(196, 61, 77, 0.08); color: var(--accent); text-decoration: none; }
.linklike.danger { color: var(--danger); }
.inline-form { display: inline; margin: 0; }

/* ---------- Layout ---------- */
.container { max-width: 1040px; margin: 0 auto; padding: 1rem; }
.footer { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 1.5rem 1rem; }
.footer-auth { position: fixed; bottom: 0; left: 0; right: 0; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }

.panel {
    background: transparent; border: 1px solid var(--line);
    border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem;
}
.panel.narrow { max-width: 32rem; margin: 1rem auto; }
.panel.pad-lg { padding: 2rem; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }

/* ---------- Flash ---------- */
.flash-stack { max-width: 1040px; margin: 0.75rem auto 0; padding: 0 1rem; }
.flash { padding: 0.65rem 0.85rem; border-radius: var(--radius-sm); margin-bottom: 0.5rem; border: 1px solid transparent; }
.flash-success { background: var(--success-soft); color: var(--accent-2); border-color: var(--accent-2-dim); }
.flash-error { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: var(--tap); padding: 0.5rem 1rem;
    background: transparent; color: var(--accent);
    border: 1px solid var(--accent-dim); border-radius: var(--radius-sm);
    font: inherit; font-weight: 600; letter-spacing: 0.02em; cursor: pointer;
}
.btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-bright); border-color: var(--accent-bright); color: #fff; }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }

/* ---------- Forms ---------- */
.field { display: block; margin-bottom: 0.85rem; }
.field > span { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.3rem; }
input, select, textarea {
    width: 100%; min-height: var(--tap); padding: 0.55rem 0.7rem;
    background: var(--bg-soft); color: var(--text);
    border: 1px solid var(--line); border-radius: var(--radius-sm);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.45);
    font: inherit;
}
/* Numbers and dates in form fields use the number face, matching money figures. */
input[type="number"], input[type="date"] {
    font-family: var(--font-num);
    font-variant-numeric: tabular-nums;
}
textarea { min-height: 3rem; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible, button:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 2px; border-color: var(--accent);
}
.stack > * { margin-bottom: 0.85rem; }
.row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.row.gap { gap: 0.75rem; }
.row.end { align-items: flex-end; }
.hint { display: block; color: var(--muted); font-size: 0.8rem; margin-top: 0.3rem; }
.err { display: block; color: var(--danger); font-size: 0.8rem; margin-top: 0.25rem; }
.check { display: flex; align-items: center; gap: 0.5rem; }
.check input { width: auto; min-height: auto; }
.fineprint { color: var(--muted); font-size: 0.8rem; text-align: center; margin-top: 1.5rem; }
.divider { display: flex; align-items: center; gap: 0.75rem; color: var(--muted); margin: 1rem 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.form-error { background: var(--danger-soft); color: var(--danger); border: 1px solid var(--danger); padding: 0.65rem 0.85rem; border-radius: var(--radius-sm); margin-bottom: 1rem; }
.form-warning { background: rgba(196, 61, 77, 0.08); color: var(--accent-bright); border: 1px solid var(--line-strong); padding: 0.65rem 0.85rem; border-radius: var(--radius-sm); margin-bottom: 1rem; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 0.75rem; margin-top: 0.5rem; }
.delete-form { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: 1rem; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* ---------- Add flow: picker first, manual form behind it ---------- */
/* JS adds .picker-active in add mode; without JS the full form shows as normal. */
.picker { display: none; }
.form-panel.picker-active .picker { display: block; }
.form-panel.picker-active .entry-form { display: none; }

.picker-search input { margin-bottom: 0.85rem; }
.picker-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(116px, 1fr));
    gap: 0.6rem; max-height: 62vh; overflow-y: auto; padding: 0.15rem;
}
.tile {
    display: flex; flex-direction: column; align-items: center; gap: 0.35rem; text-align: center;
    background: transparent; border: 1px solid var(--line); border-radius: var(--radius);
    padding: 0.8rem 0.5rem; color: var(--text); font: inherit; cursor: pointer;
}
.tile:hover { border-color: var(--accent); background: rgba(196, 61, 77, 0.06); }
.tile-logo {
    display: inline-grid; place-items: center; width: 42px; height: 42px; border-radius: 50%;
    background: var(--bg-soft); border: 1px solid var(--brand, var(--line));
    color: var(--brand, var(--accent)); font-weight: 700;
}
.tile-logo img { width: 24px; height: 24px; object-fit: contain; }
.tile-logo-custom { font-size: 1.5rem; line-height: 1; color: var(--accent); }
.tile-name { font-weight: 600; color: var(--heading); font-size: 0.9rem; line-height: 1.15; }
.tile-sub { color: var(--muted); font-size: 0.75rem; line-height: 1.1; }
.picker-empty { margin-top: 0.85rem; }

.entry-head {
    display: flex; align-items: center; gap: 0.6rem;
    padding-bottom: 0.85rem; margin-bottom: 0.85rem; border-bottom: 1px solid var(--line);
}
.entry-id { display: flex; flex-direction: column; flex: 1; min-width: 0; }

.more { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0 0.75rem; margin-bottom: 0.85rem; }
.more > summary { cursor: pointer; padding: 0.65rem 0; color: var(--accent); font-weight: 600; }
.more[open] > summary { border-bottom: 1px solid var(--line); margin-bottom: 0.85rem; }

/* ---------- Auth ---------- */
.auth { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 1rem; }
.auth-card { width: 100%; max-width: 24rem; background: transparent; border: 1px solid var(--line); border-radius: var(--radius); padding: 1.5rem; }
.auth-brand { display: flex; align-items: center; gap: 0.5rem; font-family: var(--font-display); font-weight: 700; margin-bottom: 1rem; color: var(--heading); }
.auth-title { margin-bottom: 0.2rem; }
.auth-sub { margin: 0 0 1.25rem; font-size: 0.95rem; }

/* ---------- Totals ---------- */
.totals { display: grid; grid-template-columns: 1fr; gap: 0.75rem; margin-bottom: 1rem; }
.total-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; background: transparent; border-left: 4px solid var(--line); }
.total-subscription { border-left-color: var(--accent); }
.total-bill { border-left-color: var(--accent-2); }
.total-combined { border-left-color: var(--accent-bright); }
.total-card h2 { margin-bottom: 0.5rem; }
.total-row { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; padding: 0.2rem 0; }
.total-tag { color: var(--muted); font-size: 0.85rem; }
.total-amt { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-weight: 600; color: var(--heading); }

/* ---------- Charts ---------- */
.charts { display: grid; grid-template-columns: 1fr; gap: 1rem; }
.chart-panel { margin: 0; }

/* ---------- Upcoming ---------- */
.upcoming { list-style: none; margin: 0; padding: 0; }
.upcoming li { display: flex; align-items: center; gap: 0.75rem; padding: 0.55rem 0; border-bottom: 1px solid var(--line); }
.upcoming li:last-child { border-bottom: 0; }
.up-main { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.up-name { font-weight: 600; }
.up-right { display: flex; align-items: center; gap: 0.6rem; }
.up-price { font-family: var(--font-num); font-variant-numeric: tabular-nums; }

.avatar {
    flex: none; display: inline-grid; place-items: center;
    width: 38px; height: 38px; border-radius: 50%; color: #fff; font-weight: 700;
    background: hsl(var(--hue, 350) 42% 38%);
}
/* Logo avatars: real brand mark on a neutral chip so colour comes from the logo. */
.avatar-logo { background: var(--bg-soft); border: 1px solid var(--line); }
.avatar-logo img { width: 22px; height: 22px; object-fit: contain; display: block; }

/* ---------- Badges ---------- */
.badge { font-size: 0.72rem; padding: 0.2rem 0.5rem; border-radius: 6px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge-active { color: var(--accent-2); border-color: var(--accent-2-dim); }
.badge-trial { color: var(--accent-bright); border-color: var(--accent-dim); }
.badge-paused { color: var(--muted); }
.badge-cancelled { color: var(--danger); border-color: var(--danger); }
.badge-soon { color: #fff; background: var(--accent); border-color: var(--accent); }

/* ---------- Cards (outline only) ---------- */
.card-section { margin-top: 0.5rem; }
.cards { display: grid; grid-template-columns: 1fr; gap: 0.75rem; }
.card { background: transparent; border: 1px solid var(--line); border-radius: var(--radius); padding: 0.85rem; display: flex; flex-direction: column; gap: 0.55rem; }
/* Subscriptions cards take a border in the service's real brand colour, falling
   back to a deterministic hue when no logo/colour is known. */
.card--service { border-color: var(--brand, hsl(var(--hue, 350) 48% 52%)); }
.card.status-cancelled, .card.status-paused { opacity: 0.6; }
.card-top { display: flex; align-items: center; gap: 0.6rem; }
.card-id { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.card-name { font-weight: 700; color: var(--heading); }
.card-price { display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap; font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.price-main { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--heading); }
.price-main .small { font-weight: 400; margin-left: 0.15rem; }
.card-meta { display: flex; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; color: var(--muted); font-size: 0.85rem; }
.card-foot { display: flex; gap: 1rem; border-top: 1px solid var(--line); padding-top: 0.55rem; }

/* Depth: lift surfaces off the black ground with a soft shadow and a hairline top edge. */
.panel, .total-card, .card, .auth-card { background: var(--bg-soft); box-shadow: var(--shadow), var(--highlight); }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 0.5rem 0.5rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
.ok { color: var(--accent-2); } .bad { color: var(--danger); }

/* ---------- Recovery codes ---------- */
.codes-grid { list-style: none; margin: 1rem 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.rc-code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; background: var(--bg-soft); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0.5rem; text-align: center; letter-spacing: 0.05em; }
.copytext { font-family: ui-monospace, monospace; background: var(--bg-soft); padding: 0.15rem 0.4rem; border-radius: 6px; }

/* ---------- Responsive ---------- */
@media (min-width: 640px) {
    .totals { grid-template-columns: repeat(3, 1fr); }
    .cards { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 900px) {
    .charts { grid-template-columns: 1fr 1fr; }
    .cards { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 520px) {
    .form-grid { grid-template-columns: 1fr; }
    .codes-grid { grid-template-columns: 1fr; }
}

/* Respect reduced motion: only animate when the user allows it. */
@media (prefers-reduced-motion: no-preference) {
    .btn, .nav a, .linklike, input, select, textarea { transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease; }
}
