:root {
    --bg: #0e141b;
    --bg2: #121b24;
    --card: #18222e;
    --line: #2a3949;
    --text: #eef3f8;
    --muted: #8b9aab;
    --accent: #3ecf8e;
    --accent2: #5b8def;
    --warn: #f0b429;
    --bad: #ef6b6b;
    --radius: 16px;
    --topbar: 56px;
    --sidenav: 260px;
    font-family: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); min-height: 100%; }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; }

.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(1200px 600px at 20% -10%, #1b3a4a 0%, var(--bg) 55%);
    padding: 24px;
}
.auth-wrap { width: 100%; max-width: 420px; }
.auth-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 28px 24px;
}
.brand { text-align: center; margin-bottom: 20px; }
.brand h1, .brand-mark + div strong { margin: 8px 0 4px; }
.brand p { color: var(--muted); margin: 0; }
.brand-mark {
    width: 48px; height: 48px; border-radius: 14px;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 800; color: #062015; letter-spacing: 0.02em;
}
.auth-form label, .stack-form label { display: block; margin: 12px 0 6px; color: var(--muted); font-size: 13px; }
.field-hint { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
.freq-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: stretch; }
.auth-form input, .stack-form input, .stack-form select, .stack-form textarea,
.record-form input, .record-form textarea, .search-bar input, .search-bar select {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--line);
    color: var(--text);
    border-radius: 12px;
    padding: 12px 12px;
}
.stack-form .freq-row input {
    width: 6.5rem;
    max-width: 6.5rem;
    flex: 0 0 6.5rem;
}
.stack-form .freq-row select {
    flex: 1 1 12rem;
    width: auto;
    min-width: 12rem;
}
.auth-error { color: var(--bad); text-align: center; }

.btn {
    display: inline-flex; align-items: center; justify-content: center;
    border: 0; border-radius: 12px; padding: 11px 16px; cursor: pointer;
    font-weight: 650;
}
.btn-primary { background: var(--accent); color: #062015; }
.btn-secondary { background: #243243; color: var(--text); }
.btn-ghost { background: transparent; color: var(--bad); }
.btn-block { width: 100%; margin-top: 16px; }

.app-shell { min-height: 100vh; }
.sidenav {
    position: fixed; inset: 0 auto 0 0; width: min(86vw, var(--sidenav));
    background: var(--bg2); border-right: 1px solid var(--line);
    transform: translateX(-105%); transition: transform 0.22s ease;
    z-index: 30; padding: 18px 14px; display: flex; flex-direction: column; gap: 18px;
}
.sidenav.is-open { transform: translateX(0); }
.sidenav-brand { display: flex; gap: 10px; align-items: center; }
.sidenav-brand span, .sidenav-user small { display: block; color: var(--muted); font-size: 12px; }
.sidenav nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.sidenav nav a {
    color: var(--text); padding: 12px 12px; border-radius: 12px;
}
.sidenav nav a.is-active, .sidenav nav a:hover { background: #223142; }
.nav-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 20;
}
.topbar {
    position: sticky; top: 0; height: var(--topbar);
    display: flex; align-items: center; gap: 10px;
    padding: 0 12px; background: rgba(14,20,27,0.92);
    border-bottom: 1px solid var(--line); backdrop-filter: blur(8px); z-index: 10;
}
.topbar h1 { font-size: 16px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-btn, .topbar-user {
    width: 40px; height: 40px; border: 0; border-radius: 12px;
    background: #223142; color: var(--text); display: inline-flex;
    align-items: center; justify-content: center; font-weight: 700;
}
.menu-btn {
    flex-direction: column;
    gap: 4px;
    padding: 0;
}
.menu-btn span {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--text);
    border-radius: 1px;
}
.app-content { padding: 16px 14px 40px; max-width: 1100px; margin: 0 auto; }

.search-bar { display: flex; gap: 8px; margin-bottom: 18px; }
.search-bar input { flex: 1; }
.search-bar select { width: auto; }
.section { margin-bottom: 28px; }
.section h2, .panel h2 { margin: 0 0 8px; font-size: 18px; }
.section-sub, .muted, .meta-line, .chart-hint { color: var(--muted); }
.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }

.card-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.move-card, .panel, .empty-card, .metric-box {
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
}
.move-card { color: var(--text); padding: 14px; display: block; }
.card-grid-next .move-card {
    background: #173028;
    border-color: #2f6a4e;
}
.move-card-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.move-card h3 { margin: 0 0 8px; font-size: 16px; }
.pill { font-size: 11px; padding: 3px 8px; border-radius: 999px; background: #1f3d34; color: var(--accent); }
.move-card-stat .stat-label { color: var(--muted); font-size: 12px; font-weight: 400; }
.move-card-stat .last-date { font-weight: 400; font-size: 11px; }
.move-card-stat strong { display: block; font-size: 22px; line-height: 1.1; margin-top: 2px; }
.move-card-due { color: var(--muted); }
.move-card-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.move-card-metrics span { display: block; color: var(--muted); font-size: 12px; }
.delta.up { color: var(--accent); }
.delta.down { color: var(--bad); }
.delta.flat { color: var(--text); }
.delta.muted { color: var(--muted); }
.move-card-due { margin-top: 10px; font-size: 13px; }
.empty-card, .panel { padding: 16px; margin-bottom: 16px; }

.metric-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.metric-box { padding: 12px; }
.metric-box span, .metric-box small { color: var(--muted); display: block; }
.metric-box strong { font-size: 22px; }

.detail-actions { display: flex; gap: 8px; margin-bottom: 14px; }
.time-entry {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}
.record-form .time-entry input {
    width: 5.5rem;
    text-align: center;
    font-size: 1.45rem;
    font-variant-numeric: tabular-nums;
    padding: 14px 8px;
}
.time-colon {
    font-size: 1.7rem;
    font-weight: 700;
    line-height: 2.6rem;
    color: var(--muted);
}
.time-field { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.time-field span { color: var(--muted); font-size: 12px; }
.data-table tr.is-editing { background: #1a2e24; }
.note-recall { background: #13202c; border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; }
.note-recall span { color: var(--muted); font-size: 12px; }
.note-recall p { margin: 6px 0 0; }
.flash { background: #1f3d34; color: var(--accent); padding: 10px 12px; border-radius: 12px; }
.flash-error { background: #3a2020; color: #ffb4b4; }
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.data-table th { color: var(--muted); font-size: 12px; font-weight: 600; }
.check { display: flex; gap: 8px; align-items: center; }
.check input { width: auto; }
.row-actions { display: flex; gap: 12px; align-items: center; white-space: nowrap; }
.row-actions form { margin: 0; }
.link-danger {
    background: none; border: 0; padding: 0; cursor: pointer;
    color: var(--bad); font: inherit;
}
.danger-actions { display: flex; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
.danger-actions .danger-form { margin-top: 0; }
.metric-mini-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.metric-mini, .metric-due-card {
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 12px; color: var(--text); display: block;
}
.metric-due-card .move-card-stat-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
}
.metric-mini small { color: var(--muted); font-size: 11px; }
.metric-mini h3, .metric-due-card h3 { margin: 0 0 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
.metric-mini strong { font-size: 18px; display: block; }
.metric-mini .delta { font-size: 13px; }
.metric-due-card .metric-log-row {
    display: flex; gap: 8px; align-items: center; margin-top: 10px;
}
.metric-due-card .metric-log-row input {
    flex: 1; width: auto; background: var(--bg); border: 1px solid var(--line);
    color: var(--text); border-radius: 12px; padding: 10px 12px;
}
.metric-due-card .metric-log-row .btn { margin-top: 0; width: auto; }
.swipe-item { position: relative; overflow: hidden; border-radius: var(--radius); }
.swipe-bg {
    position: absolute; inset: 0;
    background: #7a2a2a; color: #fff;
    display: flex; align-items: center; justify-content: flex-end;
    padding-right: 18px; font-weight: 700;
}
.swipe-front { position: relative; z-index: 1; }
.swipe-front .move-card { margin: 0; }
.result-list { display: flex; flex-direction: column; gap: 8px; }
.result-row {
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 12px; color: var(--text);
}
.result-row.is-editing { background: #1a2e24; }
.result-row-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.result-row strong { font-size: 18px; }
.result-row small, .result-row .muted { color: var(--muted); }
.swipe-hint { font-size: 12px; margin-top: 8px; }
.heat-row { display: flex; gap: 4px; flex-wrap: wrap; }
.heat { width: 14px; height: 14px; border-radius: 3px; background: #223142; }
.heat-1 { background: #1c5c45; }
.heat-2 { background: #2a9d6a; }
.heat-3 { background: var(--accent); }
.rank-list { list-style: none; padding: 0; margin: 0; }
.rank-list li { margin-bottom: 10px; }
.rank-list a { display: flex; justify-content: space-between; color: var(--text); }
.rank-list small { color: var(--muted); }

canvas { width: 100%; max-width: 100%; background: #121c27; border-radius: 12px; }

@media (min-width: 900px) {
    .menu-btn { display: none; }
    .sidenav { transform: none; }
    .nav-backdrop { display: none !important; }
    .app-main { margin-left: var(--sidenav); }
    .card-grid { grid-template-columns: repeat(2, 1fr); }
    .metric-row { grid-template-columns: repeat(4, 1fr); }
    .search-bar { max-width: 720px; }
}

@media (min-width: 1200px) {
    .card-grid { grid-template-columns: repeat(3, 1fr); }
}
