:root {
    --ink: #17231d;
    --muted: #66736c;
    --line: #dfe6e1;
    --paper: #ffffff;
    --canvas: #f3f6f3;
    --green: #1f6b4f;
    --green-dark: #174d3b;
    --green-soft: #e8f3ed;
    --amber: #b7791f;
    --red: #b43a3a;
    --shadow: 0 12px 30px rgba(25, 46, 35, .08);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; color: var(--ink); background: var(--canvas); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", sans-serif; line-height: 1.55; }
a { color: var(--green); text-decoration: none; }
button, input, select, textarea { font: inherit; }
button, .button { cursor: pointer; }

.app-shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 28px 18px; background: #153d30; color: #fff; display: flex; flex-direction: column; }
.brand { color: #fff; font-weight: 750; font-size: 17px; display: flex; align-items: center; gap: 10px; margin: 0 8px 34px; }
.brand span, .login-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: #d8ad61; color: #153d30; font-weight: 900; }
.sidebar nav { display: grid; gap: 7px; }
.sidebar nav a { padding: 11px 13px; border-radius: 9px; color: #d4e2dc; }
.sidebar nav a:hover, .sidebar nav a.active { background: rgba(255,255,255,.12); color: #fff; }
.logout-form { margin-top: auto; }
.text-button { border: 0; background: transparent; color: #d4e2dc; padding: 10px; }
.main { min-width: 0; padding: 42px clamp(22px, 4vw, 64px) 70px; }

.page-header { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 5px; font-size: clamp(26px, 3vw, 38px); letter-spacing: -.03em; }
h2 { margin-bottom: 0; font-size: 19px; }
.eyebrow { margin-bottom: 4px; color: var(--green); font-size: 11px; font-weight: 800; letter-spacing: .13em; }
.muted, small { color: var(--muted); }

.year-select { display: flex; align-items: end; gap: 8px; }
.year-select label { font-size: 12px; color: var(--muted); }
.year-select input { width: 100px; display: block; margin-top: 4px; }
input, select, textarea { width: 100%; border: 1px solid #cbd6cf; border-radius: 8px; padding: 9px 10px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(31,107,79,.15); border-color: var(--green); }
label { font-size: 13px; font-weight: 650; }
label small { display: block; margin-top: 4px; font-weight: 400; }

button, .button { display: inline-flex; justify-content: center; align-items: center; border-radius: 8px; padding: 9px 15px; border: 1px solid transparent; font-weight: 700; }
.primary { background: var(--green); color: #fff; border-color: var(--green); }
.primary:hover { background: var(--green-dark); }
.secondary { background: #fff; color: var(--green); border-color: #bdccc3; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.metric, .panel { border: 1px solid var(--line); border-radius: 14px; background: var(--paper); box-shadow: var(--shadow); }
.metric { padding: 20px; }
.metric p { color: var(--muted); font-size: 12px; font-weight: 700; margin-bottom: 9px; }
.metric strong { display: block; font-size: clamp(22px, 2.2vw, 32px); letter-spacing: -.035em; }
.metric span { display: block; color: var(--muted); font-size: 12px; margin-top: 7px; }
.metric.featured { color: #fff; background: var(--green); border-color: var(--green); }
.metric.featured p, .metric.featured span { color: #d9e9e2; }
.metric.negative strong, .number-negative { color: var(--red); }
.metric.positive strong, .number-positive { color: var(--green); }

.two-column { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(340px, .75fr); gap: 14px; margin-top: 14px; }
.panel { padding: 22px; margin-bottom: 14px; }
.panel-heading { display: flex; justify-content: space-between; align-items: start; gap: 16px; margin-bottom: 18px; }
.panel-heading strong { font-size: 22px; }
progress { width: 100%; height: 12px; border: 0; border-radius: 999px; overflow: hidden; }
progress::-webkit-progress-bar { background: #e7ece8; }
progress::-webkit-progress-value { background: var(--green); border-radius: 999px; }
progress::-moz-progress-bar { background: var(--green); border-radius: 999px; }
.legend { display: flex; justify-content: space-between; gap: 14px; color: var(--muted); font-size: 12px; margin-top: 10px; }
.definition-grid { margin: 0; display: grid; gap: 11px; }
.definition-grid div { display: flex; justify-content: space-between; border-bottom: 1px solid var(--line); padding-bottom: 9px; }
.definition-grid dt { color: var(--muted); }
.definition-grid dd { margin: 0; font-weight: 800; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 680px; font-size: 13px; }
th { color: var(--muted); font-size: 11px; text-align: left; white-space: nowrap; }
th, td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
td small { display: block; }
.empty { text-align: center; color: var(--muted); padding: 24px; }
.bar-list { display: grid; gap: 12px; }
.bar-row > div { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; }
.bar-row progress { height: 7px; }

.expense-form { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 15px; }
.expense-form label { display: grid; align-content: start; gap: 5px; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; }
.form-actions button { min-width: 160px; }
.badge { display: inline-block; border-radius: 999px; padding: 3px 9px; background: #edf0ee; color: #526058; font-size: 11px; font-weight: 750; white-space: nowrap; }
.badge.estimated, .badge.tentative { background: #fff1d6; color: #8c5c11; }
.badge.confirmed { background: #e6f0ff; color: #265d9b; }
.badge.paid, .badge.completed { background: var(--green-soft); color: var(--green); }
.badge.cancelled { background: #f2f2f2; color: #777; }

.flash { max-width: 1100px; margin: 0 auto 18px; padding: 11px 14px; border-radius: 9px; background: var(--green-soft); color: var(--green-dark); border: 1px solid #cbe1d5; }
.flash.error { color: #8f2e2e; background: #fff0f0; border-color: #f0cccc; }
.login-shell { min-height: 100vh; background: radial-gradient(circle at 30% 20%, #edf5f0 0, #f5f7f5 45%, #e4ece7 100%); }
.login-main { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(430px, 100%); padding: 38px; background: #fff; border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 24px 70px rgba(22,61,48,.15); }
.login-card .login-mark { width: 46px; height: 46px; margin-bottom: 18px; }
.login-card h1 { font-size: 27px; }
.stack-form { display: grid; gap: 15px; margin-top: 24px; }
.stack-form label { display: grid; gap: 5px; }
.setup-card { width: min(560px, 100%); }
.setup-card fieldset { display: grid; gap: 13px; margin: 0; padding: 16px; border: 1px solid var(--line); border-radius: 10px; }
.setup-card legend { padding: 0 7px; color: var(--green); font-weight: 800; }
.full-button { width: 100%; }

@media (max-width: 1100px) {
    .metrics { grid-template-columns: repeat(2, 1fr); }
    .two-column { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
    .app-shell { display: block; }
    .sidebar { position: static; height: auto; padding: 14px; }
    .brand { margin: 0 0 12px; }
    .sidebar nav { display: flex; overflow-x: auto; }
    .sidebar nav a { white-space: nowrap; }
    .logout-form { position: absolute; top: 15px; right: 14px; }
    .main { padding: 26px 14px 50px; }
    .page-header { align-items: start; flex-direction: column; }
    .metrics { grid-template-columns: 1fr; }
    .expense-form { grid-template-columns: 1fr; }
    .span-2, .span-3 { grid-column: auto; }
    .panel { padding: 17px; }
}
