:root {
    color-scheme: dark;
    --bg: #151922;
    --panel: #202632;
    --panel-soft: #2a3140;
    --text: #f5f7fb;
    --muted: #aeb8c6;
    --line: #3a4454;
    --accent: #68d391;
    --info: #7dd3fc;
    --warn: #fbbf24;
    --danger: #fb7185;
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
    font: inherit;
}

a {
    color: inherit;
    text-decoration: none;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px clamp(16px, 4vw, 40px);
    background: rgba(21, 25, 34, 0.86);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(18px);
}

.brand,
nav {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand {
    font-weight: 700;
}

.brand-mark {
    width: 18px;
    height: 18px;
    border: 2px solid var(--info);
    border-radius: 50%;
    box-shadow: inset 6px 0 0 transparent;
}

.nav-link {
    padding: 8px 10px;
    color: var(--muted);
    border-radius: var(--radius);
}

.nav-link.active,
.nav-link:hover {
    color: var(--text);
    background: var(--panel-soft);
}

.shell {
    width: min(1180px, calc(100% - 32px));
    margin: 28px auto 56px;
}

.shell.narrow {
    width: min(760px, calc(100% - 32px));
}

.hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 24px;
    align-items: end;
    padding: clamp(20px, 4vw, 36px);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: linear-gradient(135deg, #252b38, #1f2632 58%, #242b38);
}

.eyebrow,
.muted,
.panel-head p,
.metric span,
.metric small,
td {
    color: var(--muted);
}

.eyebrow {
    margin: 0 0 8px;
    font-size: 0.9rem;
}

h1,
h2 {
    margin: 0;
    line-height: 1.1;
    letter-spacing: 0;
}

.hero h1 {
    font-size: clamp(3rem, 9vw, 6.5rem);
    font-variant-numeric: tabular-nums;
}

.muted {
    margin: 10px 0 0;
}

.button-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 10px;
}

button {
    min-height: 42px;
    padding: 0 16px;
    color: var(--text);
    background: var(--panel-soft);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    cursor: pointer;
}

button:hover {
    border-color: #596678;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #07120d;
    font-weight: 700;
}

.danger {
    color: #fff;
    border-color: rgba(251, 113, 133, 0.55);
}

.ghost {
    background: transparent;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin: 14px 0;
}

.metric,
.panel {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
}

.metric {
    padding: 18px;
}

.metric strong {
    display: block;
    margin: 8px 0 4px;
    font-size: 1.7rem;
    font-variant-numeric: tabular-nums;
}

.metric.positive strong,
.positive {
    color: var(--accent);
}

.metric.negative strong,
.negative {
    color: var(--danger);
}

.panel {
    padding: clamp(16px, 3vw, 24px);
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.panel-head p {
    margin: 6px 0 0;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 860px;
}

th,
td {
    padding: 12px 10px;
    text-align: left;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

th {
    color: #cbd5e1;
    font-size: 0.82rem;
    font-weight: 700;
}

td {
    font-variant-numeric: tabular-nums;
}

tr.manual td:first-child {
    position: relative;
    color: var(--text);
    background: rgba(251, 191, 36, 0.07);
    box-shadow: inset 2px 0 0 rgba(251, 191, 36, 0.7);
}

.pill {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 0 8px;
    border-radius: 999px;
    background: var(--panel-soft);
    color: #dbeafe;
}

.row-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

.icon-button {
    display: inline-grid;
    place-items: center;
    width: 32px;
    min-width: 32px;
    height: 32px;
    min-height: 32px;
    padding: 0;
    color: var(--muted);
    background: transparent;
    border-color: transparent;
}

.icon-button:hover {
    color: var(--text);
    background: var(--panel-soft);
    border-color: var(--line);
}

.icon-button.danger {
    color: #fda4af;
}

.icon-button svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

dialog {
    width: min(520px, calc(100% - 32px));
    padding: 0;
    color: var(--text);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

dialog::backdrop {
    background: rgba(0, 0, 0, 0.65);
}

form {
    display: grid;
    gap: 14px;
}

#entryForm,
.settings-form {
    padding: 22px;
}

label {
    display: grid;
    gap: 7px;
    color: #cbd5e1;
}

label small {
    color: var(--muted);
    line-height: 1.4;
}

input,
select {
    width: 100%;
    min-height: 42px;
    padding: 0 12px;
    color: var(--text);
    background: #171c26;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.two-cols {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.schedule-row {
    grid-template-columns: minmax(110px, 1fr) 92px 92px 42px 42px;
    align-items: center;
}

.form-status {
    min-height: 22px;
    color: var(--accent);
}

.setup-error {
    padding: 12px 14px;
    color: #0d1117;
    background: var(--warn);
    border-radius: var(--radius);
}

@media (max-width: 760px) {
    .topbar,
    .hero,
    .panel-head {
        align-items: stretch;
        flex-direction: column;
    }

    .hero {
        grid-template-columns: 1fr;
    }

    .button-row {
        justify-content: stretch;
    }

    .button-row button {
        flex: 1 1 calc(50% - 6px);
    }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .two-cols,
    .schedule-row {
        grid-template-columns: 1fr;
    }
}
