:root {
    color-scheme: light;
    --ink: #18231f;
    --muted: #66736e;
    --paper: #f3f1ea;
    --surface: #ffffff;
    --surface-soft: #e9eee9;
    --line: #d9dfda;
    --green: #12372a;
    --green-2: #1f5a44;
    --lime: #d8ef9f;
    --orange: #e98b45;
    --red: #b42318;
    --shadow: 0 16px 40px rgba(29, 52, 42, 0.09);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); }
body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--paper); }
button, input { font: inherit; }
a { color: inherit; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 28px;
    min-height: 72px;
    padding: 10px max(22px, calc((100vw - 1160px) / 2));
    color: #fff;
    background: rgba(18, 55, 42, 0.97);
    backdrop-filter: blur(12px);
}

.brand { display: flex; align-items: center; gap: 11px; font-weight: 800; text-decoration: none; }
.brand-mark {
    display: inline-grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border-radius: 12px;
    color: var(--green);
    background: var(--lime);
    font-size: 13px;
    letter-spacing: -0.04em;
}
.brand-mark.large { width: 58px; height: 58px; border-radius: 18px; font-size: 18px; }
.main-nav { display: flex; gap: 6px; }
.main-nav a { padding: 9px 13px; border-radius: 10px; color: #d7e1dc; text-decoration: none; }
.main-nav a:hover, .main-nav a.active { color: #fff; background: rgba(255,255,255,.12); }
.logout-form { margin: 0; }

.page { width: min(1160px, calc(100% - 32px)); margin: 0 auto; padding: 44px 0 72px; }
.auth-page { display: grid; min-height: 100vh; place-items: center; padding: 28px 0; }
.auth-card { width: min(440px, 100%); padding: 34px; border-radius: 24px; background: var(--surface); box-shadow: var(--shadow); }
.auth-heading { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.auth-heading h1 { margin: 2px 0 0; font-size: 28px; }

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 10px; font-size: clamp(30px, 5vw, 50px); line-height: 1.04; letter-spacing: -.04em; }
h2 { margin-bottom: 10px; font-size: 22px; line-height: 1.2; letter-spacing: -.02em; }
.eyebrow { margin-bottom: 8px; color: var(--green-2); font-size: 12px; font-weight: 850; letter-spacing: .12em; text-transform: uppercase; }
.muted { color: var(--muted); }

.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 28px; margin-bottom: 30px; }
.page-heading > div { max-width: 750px; }
.page-heading.compact { align-items: start; }

.button {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    padding: 10px 17px;
    border: 0;
    border-radius: 12px;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
    transition: transform .15s ease, background .15s ease, opacity .15s ease;
}
.button:hover { transform: translateY(-1px); }
.button:disabled { cursor: wait; opacity: .55; transform: none; }
.button.primary { color: #fff; background: var(--green); }
.button.primary:hover { background: var(--green-2); }
.button.ghost { color: inherit; background: rgba(255,255,255,.1); border: 1px solid currentColor; }
.page .button.ghost { color: var(--green); background: transparent; border-color: var(--line); }
.button.small { min-height: 36px; padding: 7px 12px; font-size: 13px; }
.button.wide { width: 100%; }

.stack-form { display: grid; gap: 18px; margin-top: 25px; }
.stack-form label { display: grid; gap: 7px; font-weight: 750; }
.stack-form input {
    width: 100%;
    min-height: 48px;
    padding: 10px 13px;
    border: 1px solid var(--line);
    border-radius: 12px;
    color: var(--ink);
    background: #fff;
}
.stack-form input:focus { outline: 3px solid rgba(31, 90, 68, .18); border-color: var(--green-2); }

.notice { margin-bottom: 22px; padding: 13px 16px; border-radius: 12px; background: #e7eef8; }
.notice.success { color: #135c38; background: #e4f4e9; }
.notice.error { color: #842018; background: #fce8e6; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 22px; }
.metric { display: flex; min-height: 164px; flex-direction: column; padding: 22px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); }
.metric.featured { color: #fff; background: var(--green); border-color: var(--green); }
.metric span { color: var(--muted); font-size: 14px; }
.metric.featured span { color: #c9d8d0; }
.metric strong { margin: 12px 0 auto; font-size: 42px; line-height: 1; letter-spacing: -.05em; }
.metric small, .metric a { margin-top: 12px; color: var(--muted); font-size: 13px; }
.metric.featured a { color: var(--lime); }

.panel { padding: 28px; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); box-shadow: 0 6px 22px rgba(29,52,42,.04); }
.next-step { display: grid; grid-template-columns: 1.5fr 1fr; gap: 40px; align-items: center; }
.next-step p:not(.eyebrow) { max-width: 670px; color: var(--muted); }
.step-list { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; counter-reset: steps; }
.step-list li { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.step-list li::before { counter-increment: steps; content: counter(steps); display: grid; width: 28px; height: 28px; place-items: center; border-radius: 50%; background: var(--surface-soft); font-weight: 800; font-size: 12px; }
.step-list li.done { color: var(--ink); }
.step-list li.done::before { content: "✓"; color: #fff; background: var(--green-2); }

.upload-panel { max-width: 850px; }
.drop-zone { display: grid; min-height: 300px; place-items: center; align-content: center; gap: 9px; padding: 35px; border: 2px dashed #a8b7af; border-radius: 18px; text-align: center; background: #f8faf7; cursor: pointer; }
.drop-zone:hover { border-color: var(--green-2); background: #f1f7ef; }
.drop-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop-icon { display: grid; width: 56px; height: 56px; place-items: center; border-radius: 18px; color: #fff; background: var(--green); font-size: 28px; }
.drop-zone strong { margin-top: 8px; font-size: 21px; }
.drop-zone span:last-of-type { color: var(--muted); }
.upload-actions { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-top: 18px; }
.upload-progress { margin-top: 26px; padding-top: 24px; border-top: 1px solid var(--line); }
.progress-track { height: 10px; overflow: hidden; border-radius: 999px; background: var(--surface-soft); }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--green-2); transition: width .2s ease; }
.upload-progress p { margin: 10px 0; color: var(--muted); }
.result-list { display: grid; gap: 7px; padding: 0; list-style: none; }
.result-list li { padding: 10px 12px; border-radius: 10px; background: var(--surface-soft); overflow-wrap: anywhere; }
.result-list li.success { color: #135c38; background: #e4f4e9; }
.result-list li.warning { color: #795400; background: #fff2cf; }
.result-list li.error { color: #842018; background: #fce8e6; }
.hint-card { display: flex; max-width: 850px; gap: 16px; margin-top: 16px; padding: 18px 20px; border-radius: 16px; color: #3d4b45; background: #e5eadf; }
.hint-card strong { flex: 0 0 auto; }

.import-list { display: grid; gap: 12px; }
.import-card { display: grid; grid-template-columns: auto 1fr auto; gap: 17px; align-items: center; padding: 18px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.file-icon { display: grid; width: 48px; height: 56px; place-items: center; border-radius: 9px; color: #fff; background: #b8493f; font-size: 11px; font-weight: 900; }
.import-main { min-width: 0; }
.import-title-row { display: flex; align-items: center; gap: 12px; }
.import-title-row h2 { min-width: 0; margin: 0; overflow: hidden; font-size: 17px; text-overflow: ellipsis; white-space: nowrap; }
.import-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 6px; color: var(--muted); font-size: 13px; }
.status { display: inline-flex; flex: 0 0 auto; padding: 4px 8px; border-radius: 999px; font-size: 11px; font-weight: 850; }
.status.pending { color: #765300; background: #fff0c1; }
.status.success { color: #135c38; background: #daf0e1; }
.status.warning { color: #844c00; background: #ffe1b8; }
.status.error { color: #842018; background: #fbdad6; }
.status.neutral { color: #45534d; background: var(--surface-soft); }
.inline-error { margin: 8px 0 0; color: var(--red); font-size: 13px; }
.empty-state { max-width: 620px; padding: 50px 28px; text-align: center; margin-inline: auto; }
.empty-state .button { margin-top: 10px; }

.filter-tabs { display: flex; gap: 7px; margin-bottom: 18px; overflow-x: auto; }
.filter-tabs a { flex: 0 0 auto; padding: 9px 13px; border-radius: 999px; color: var(--muted); background: var(--surface-soft); font-size: 13px; font-weight: 750; text-decoration: none; }
.filter-tabs a.active { color: #fff; background: var(--green); }
.transaction-list { display: grid; gap: 10px; }
.transaction-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 24px; align-items: center; padding: 18px 20px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.transaction-main { min-width: 0; }
.transaction-main h2 { margin: 8px 0 0; font-size: 16px; line-height: 1.4; overflow-wrap: anywhere; }
.transaction-meta { display: flex; flex-wrap: wrap; gap: 5px 13px; color: var(--muted); font-size: 12px; }
.transaction-side { display: grid; min-width: 230px; gap: 12px; justify-items: end; }
.amount { font-size: 20px; white-space: nowrap; }
.amount.expense { color: var(--red); }
.amount.income { color: var(--green-2); }
.transaction-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }

@media (max-width: 850px) {
    .topbar { grid-template-columns: 1fr auto; gap: 12px; }
    .brand > span:last-child { display: none; }
    .main-nav { grid-row: 2; grid-column: 1 / -1; order: 3; overflow-x: auto; }
    .main-nav a { flex: 1 0 auto; text-align: center; }
    .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .next-step { grid-template-columns: 1fr; gap: 22px; }
}

@media (max-width: 600px) {
    .page { width: min(100% - 22px, 1160px); padding-top: 28px; }
    .topbar { padding-inline: 12px; }
    .page-heading { align-items: stretch; flex-direction: column; }
    .page-heading .button { width: 100%; }
    .metrics { grid-template-columns: 1fr 1fr; gap: 9px; }
    .metric { min-height: 138px; padding: 16px; }
    .metric strong { font-size: 34px; }
    .panel, .auth-card { padding: 21px; border-radius: 18px; }
    .drop-zone { min-height: 245px; padding: 24px 15px; }
    .upload-actions { align-items: stretch; flex-direction: column; }
    .upload-actions .button { width: 100%; }
    .hint-card { flex-direction: column; }
    .import-card { grid-template-columns: auto 1fr; align-items: start; }
    .import-card > .button { grid-column: 1 / -1; width: 100%; }
    .import-title-row { align-items: flex-start; flex-direction: column; gap: 7px; }
    .import-title-row h2 { width: 100%; white-space: normal; overflow-wrap: anywhere; }
    .transaction-card { grid-template-columns: 1fr; gap: 14px; padding: 16px; }
    .transaction-side { min-width: 0; justify-items: stretch; }
    .transaction-actions { justify-content: stretch; }
    .transaction-actions .button { flex: 1 1 auto; }
}
.settings-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; margin-bottom: 18px; }
.settings-panel h2, .rules-panel h2 { margin-top: 4px; }
.inline-create-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: end; margin: 22px 0; }
.inline-create-form label { display: grid; gap: 7px; font-weight: 750; }
.inline-create-form input, .compact-form select { width: 100%; min-height: 48px; padding: 10px 13px; border: 1px solid var(--line); border-radius: 12px; color: var(--ink); background: #fff; }
.setting-list, .rule-list { display: grid; gap: 8px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 12px 14px; border-radius: 12px; background: var(--surface-soft); }
.text-button { padding: 5px; border: 0; color: var(--green-2); background: transparent; font: inherit; font-size: 13px; font-weight: 750; cursor: pointer; }
.text-button.danger { color: var(--red); }
.compact-form { gap: 13px; }
.compact-form select:focus, .inline-create-form input:focus { outline: 3px solid rgba(31, 90, 68, .18); border-color: var(--green-2); }
.checkbox-row { grid-template-columns: auto 1fr; align-items: start; padding: 13px; border-radius: 12px; background: #fff4d4; }
.checkbox-row input { width: 18px; height: 18px; margin-top: 2px; }
.checkbox-row span { display: grid; gap: 4px; }
.checkbox-row small { color: var(--muted); font-weight: 500; line-height: 1.4; }
.section-title-row { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.rule-row { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 15px; border: 1px solid var(--line); border-radius: 13px; }
.rule-row.disabled { opacity: .55; }
.rule-row h3 { margin: 0; font-size: 16px; }
.rule-row p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.rule-row code { padding: 2px 5px; border-radius: 5px; color: var(--ink); background: var(--surface-soft); }
.rule-actions { display: flex; align-items: center; gap: 12px; }

@media (max-width: 850px) {
    .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
    .inline-create-form { grid-template-columns: 1fr; }
    .rule-row { align-items: flex-start; flex-direction: column; gap: 12px; }
    .rule-actions { width: 100%; justify-content: space-between; }
}
.transaction-actions select { min-height: 35px; max-width: 190px; padding: 6px 9px; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); background: #fff; }
.category-chip { padding: 2px 7px; border-radius: 999px; color: #185d3f; background: #dff1e5; font-weight: 750; }
