/* Ledger & Shield: a passbook on a pine desk. Pine for structure, paper for content, seal red only for things that need action. */
:root {
  --pine: #173f35;
  --pine-2: #22574a;
  --pine-ink: #e7efea;
  --pine-dim: #9fbcb2;
  --paper: #f3f5f2;
  --sheet: #ffffff;
  --ink: #1a2b27;
  --muted: #61716c;
  --rule: #d9e1dc;
  --rule-soft: #eaefec;
  --seal: #b8392c;
  --seal-wash: #fbece9;
  --brass: #8a6a22;
  --brass-wash: #f6f0df;
  --good: #2c7a5b;
  --good-wash: #e5f2ec;
  --rise: #d23a2a;
  --fall: #1f5fbf;
  --focus: #d39a2c;
  --radius-sheet: 14px;
  --radius-control: 9px;
  --shadow: 0 1px 0 rgba(23, 63, 53, .06), 0 8px 24px -12px rgba(23, 63, 53, .18);
  --font: 'IBM Plex Sans KR', 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --pine: #0f2a24; --pine-2: #1d4a3f; --pine-ink: #dfeae5; --pine-dim: #8eaaa0;
    --paper: #121a18; --sheet: #18221f; --ink: #e3ebe7; --muted: #94a6a0;
    --rule: #2b3935; --rule-soft: #22302c;
    --seal: #e0675a; --seal-wash: #3a1f1b; --brass: #d3ae5c; --brass-wash: #312a19;
    --good: #5cc097; --good-wash: #183229;
    --rise: #ff7a6b; --fall: #6ea8ff;
    --shadow: 0 1px 0 rgba(0, 0, 0, .3), 0 10px 30px -14px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.6 var(--font);
  font-feature-settings: 'tnum' 1;
  word-break: keep-all;
  overflow-wrap: break-word;
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: 26px; line-height: 1.25; font-weight: 700; letter-spacing: -.02em; }
h2 { font-size: 18px; line-height: 1.35; font-weight: 600; letter-spacing: -.01em; }
h3 { font-size: 15px; line-height: 1.4; font-weight: 600; }
small, .muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
svg:not(.line-chart) { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.booting { padding: 40vh 0; text-align: center; color: var(--muted); }

/* Controls */
button, input, select, textarea { font: inherit; color: inherit; }
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 16px;
  border: 1px solid var(--rule); border-radius: var(--radius-control);
  background: var(--sheet); color: var(--ink); cursor: pointer; font-weight: 500;
}
.button:hover { border-color: var(--pine-2); }
.button.primary { background: var(--pine); border-color: var(--pine); color: var(--pine-ink); }
.button.primary:hover { background: var(--pine-2); }
.button.danger { color: var(--seal); }
.button:disabled { opacity: .55; cursor: progress; }
.icon-button { display: inline-grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: var(--radius-control); background: transparent; cursor: pointer; color: var(--muted); }
.icon-button:hover { background: var(--rule-soft); color: var(--ink); }
label.field { display: grid; gap: 6px; font-size: 13px; font-weight: 500; color: var(--muted); }
input, select, textarea {
  width: 100%; min-width: 0; min-height: 42px; padding: 9px 11px;
  border: 1px solid var(--rule); border-radius: var(--radius-control);
  background: var(--sheet); color: var(--ink); font-size: 15px;
}
textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--pine-2); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--pine-2) 22%, transparent); }
.form-error { color: var(--seal); font-size: 14px; min-height: 1px; }
.form-error:empty { display: none; }

/* Login: a closed passbook */
.login {
  min-height: 100vh; min-height: 100dvh;
  display: grid; place-items: center; padding: 24px 16px;
  background: var(--pine);
  background-image: repeating-linear-gradient(0deg, transparent 0 31px, rgba(255, 255, 255, .025) 31px 32px);
}
.passbook {
  width: min(420px, 100%);
  background: var(--sheet); color: var(--ink);
  border-radius: 6px 16px 16px 6px;
  box-shadow: 0 30px 60px -30px rgba(0, 0, 0, .55);
  border-left: 14px solid var(--pine-2);
  position: relative;
  padding: 36px 32px 30px 30px;
}
.passbook::before { /* stitched binding */
  content: ''; position: absolute; left: -9px; top: 18px; bottom: 18px;
  border-left: 2px dashed rgba(255, 255, 255, .35);
}
.passbook .mark { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.passbook .mark h1 { font-size: 28px; }
.passbook .mark p { font-size: 13px; color: var(--muted); }
.seal-mark {
  width: 46px; height: 46px; border-radius: 50%;
  border: 2px solid var(--seal); color: var(--seal);
  display: grid; place-items: center; font-weight: 700; font-size: 14px; letter-spacing: -.04em;
  transform: rotate(-8deg);
}
.passbook form { display: grid; gap: 16px; }
.passbook .button.primary { min-height: 46px; margin-top: 6px; }
.passbook .note { margin-top: 18px; font-size: 12.5px; color: var(--muted); line-height: 1.55; }

/* App shell */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; }
.rail {
  position: sticky; top: 0; height: 100vh; height: 100dvh;
  background: var(--pine); color: var(--pine-ink);
  display: flex; flex-direction: column; padding: 26px 16px 20px;
}
.rail .brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 26px; }
.rail .brand strong { font-size: 19px; letter-spacing: -.02em; }
.rail .brand .seal-mark { width: 32px; height: 32px; font-size: 10.5px; border-color: #e0786b; color: #e0786b; }
.tabs { display: grid; gap: 2px; }
.tab {
  display: flex; align-items: center; gap: 12px;
  min-height: 44px; padding: 10px 12px; border: 0; border-radius: 10px;
  background: transparent; color: var(--pine-dim); cursor: pointer; text-align: left; font-weight: 500;
}
.tab:hover { color: var(--pine-ink); background: rgba(255, 255, 255, .06); }
.tab[aria-current="page"] { background: var(--pine-2); color: #fff; }
.tab .short { display: none; }
.rail .foot { margin-top: auto; padding: 0 8px; font-size: 12.5px; color: var(--pine-dim); display: grid; gap: 10px; }
.rail .foot button { justify-self: start; background: none; border: 0; padding: 0; color: var(--pine-ink); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

.main { min-width: 0; padding: 30px 40px 60px; max-width: 1180px; width: 100%; }
.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.topbar .lead { color: var(--muted); font-size: 14px; margin-top: 4px; }
.save-state { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); }
.save-state::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
.save-state[data-state="saving"]::before { background: var(--brass); }
.save-state[data-state="error"] { color: var(--seal); }
.save-state[data-state="error"]::before { background: var(--seal); }

.banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 16px; border-radius: 10px; margin-bottom: 18px; font-size: 14px; }
.banner.alert { background: var(--seal-wash); color: var(--seal); }
.banner.info { background: var(--good-wash); color: var(--good); }

/* Content surfaces */
.sheet { background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius-sheet); padding: 22px 24px; box-shadow: var(--shadow); }
.sheet + .sheet { margin-top: 18px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.empty { padding: 34px 12px; text-align: center; display: grid; gap: 6px; justify-items: center; }
.empty strong { font-size: 16px; }
.empty p { color: var(--muted); max-width: 42ch; font-size: 14px; }
.empty .button { margin-top: 10px; }

/* Phone: rail becomes a bottom tab bar */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .rail {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; z-index: 20;
    flex-direction: row; padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  }
  .rail .brand, .rail .foot { display: none; }
  .tabs { grid-template-columns: repeat(6, 1fr); width: 100%; gap: 0; }
  .tab { flex-direction: column; gap: 2px; padding: 6px 2px; min-height: 52px; font-size: 11px; justify-content: center; text-align: center; }
  .tab .long { display: none; }
  .tab .short { display: inline; }
  .main { padding: 18px 16px calc(96px + env(safe-area-inset-bottom)); }
  h1 { font-size: 22px; }
  .sheet { padding: 18px 16px; }
  .mobile-only { display: inline-flex !important; }
}
.mobile-only { display: none !important; }

/* Dialog */
dialog {
  width: min(640px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  border: 0; border-radius: 16px; padding: 0; background: var(--sheet); color: var(--ink);
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .45);
}
dialog::backdrop { background: rgba(15, 35, 30, .45); }
dialog form { display: grid; gap: 18px; padding: 22px 24px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.fields .wide { grid-column: 1 / -1; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }
@media (max-width: 560px) { .fields { grid-template-columns: 1fr; } }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

.password-box { position: relative; display: block; }
.password-box input { padding-right: 64px; }
.password-box .link { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font-size: 13px; }
.ime-warn { color: var(--seal); font-weight: 500; }
