@import url("/assets/fonts.css");

/* ============ tokens ============ */
:root {
  --bg: #fbf9f5;
  --surface: #ffffff;
  --surface-2: #f6f2ea;
  --ink: #211e1a;
  --ink-soft: #6a645b;
  --ink-faint: #9a9184;
  --line: #ebe5db;
  --accent: #cc4127;         /* persimmon — interactive fills (4.82:1 on white) */
  --accent-strong: #ab3319;
  --accent-tint: #fbeae4;
  --accent-ink: #ffffff;
  --leaf: #2f9e58;
  --danger: #c0392b;
  --danger-tint: #fbe9e7;
  --shadow: 0 1px 2px rgba(33, 30, 26, .04), 0 12px 32px -12px rgba(33, 30, 26, .18);
  --radius: 18px;
  --radius-sm: 11px;
  --ease: cubic-bezier(.22, 1, .36, 1);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16130f;
    --surface: #201b15;
    --surface-2: #2a241d;
    --ink: #f4eee4;
    --ink-soft: #b0a897;
    --ink-faint: #7d7568;
    --line: #322b22;
    --accent: #f0714a;
    --accent-strong: #f5865f;
    --accent-tint: #2e2019;
    --accent-ink: #1a120d;
    --leaf: #59c07d;
    --danger: #f0857b;
    --danger-tint: #2c1a17;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 18px 42px -14px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: "Sarabun", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ============ login layout ============ */
.auth {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 1.05fr 1fr;
}
@media (max-width: 860px) {
  .auth { grid-template-columns: 1fr; }
}

/* ---- brand panel ---- */
.brand {
  position: relative;
  overflow: hidden;
  background: var(--accent);
  color: #fff;
  padding: clamp(2rem, 5vw, 4rem);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
@media (max-width: 860px) {
  .brand { padding: 2rem 1.5rem 2.5rem; min-height: 34vh; }
}
.brand__mark {
  display: inline-flex;
  align-items: center;
  gap: .6rem;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: .01em;
}
.brand__mark svg { width: 30px; height: 30px; }
.brand__hero { margin: auto 0; max-width: 22ch; }
.brand__hero h1 {
  font-weight: 700;
  font-size: clamp(2.2rem, 4.4vw, 3.35rem);
  line-height: 1.08;
  letter-spacing: -.01em;
}
.brand__hero p {
  margin-top: 1rem;
  font-size: clamp(1rem, 1.6vw, 1.2rem);
  color: rgba(255, 255, 255, .82);
  max-width: 26ch;
}
.brand__foot { font-size: .85rem; color: rgba(255, 255, 255, .72); }
/* decorative fruit wash — pure CSS, no images */
.brand::after {
  content: "";
  position: absolute;
  right: -14%;
  bottom: -22%;
  width: 62%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 30%, rgba(255, 255, 255, .22), rgba(255, 255, 255, 0) 62%);
  pointer-events: none;
}
.brand__fruit {
  position: absolute;
  right: clamp(1rem, 4vw, 3rem);
  top: clamp(1.2rem, 5vw, 3.4rem);
  font-size: clamp(2.2rem, 6vw, 3.4rem);
  opacity: .9;
  filter: drop-shadow(0 8px 18px rgba(0, 0, 0, .18));
  user-select: none;
}

/* ---- form panel ---- */
.form-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(1.75rem, 4vw, 3rem);
  background: var(--surface);
}
.card {
  width: 100%;
  max-width: 380px;
}
.card__head { margin-bottom: 1.75rem; }
.card__head h2 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -.01em;
}
.card__head p {
  margin-top: .35rem;
  color: var(--ink-soft);
  font-size: .96rem;
}

.field { margin-bottom: 1.05rem; }
.field label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: .4rem;
}
.field input {
  width: 100%;
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: var(--surface-2);
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  padding: .72rem .9rem;
  transition: border-color .18s var(--ease), background .18s var(--ease);
}
.field input::placeholder { color: var(--ink-faint); }
.field input:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-tint);
}

.pw { position: relative; }
.pw input { padding-right: 3rem; }
.pw__toggle {
  position: absolute;
  right: .35rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ink-faint);
  font-size: .8rem;
  font-weight: 600;
  padding: .45rem .6rem;
  border-radius: 8px;
}
.pw__toggle:hover { color: var(--ink-soft); }
.pw__toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn {
  width: 100%;
  font: inherit;
  font-weight: 700;
  font-size: 1rem;
  color: var(--accent-ink);
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  padding: .82rem 1rem;
  cursor: pointer;
  margin-top: .3rem;
  transition: background .18s var(--ease), transform .08s var(--ease);
}
.btn:hover { background: var(--accent-strong); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.btn[disabled] { opacity: .6; cursor: progress; }

.alert {
  display: none;
  align-items: center;
  gap: .5rem;
  background: var(--danger-tint);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: .65rem .85rem;
  font-size: .9rem;
  margin-bottom: 1rem;
}
.alert.show { display: flex; }

.card__foot {
  margin-top: 1.6rem;
  font-size: .82rem;
  color: var(--ink-faint);
  text-align: center;
}

/* ============ app (post-login) ============ */
.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem clamp(1.25rem, 4vw, 2.75rem);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.topbar .brand__mark { color: var(--ink); }
.topbar .brand__mark .leaf { color: var(--leaf); }
.logout {
  font: inherit;
  font-size: .9rem;
  font-weight: 600;
  color: var(--ink-soft);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .45rem 1rem;
  cursor: pointer;
  text-decoration: none;
}
.logout:hover { color: var(--ink); border-color: var(--ink-faint); }

.main {
  flex: 1;
  width: 100%;
  max-width: 940px;
  margin: 0 auto;
  padding: clamp(2rem, 6vw, 4.5rem) clamp(1.25rem, 4vw, 2rem);
}
.welcome__eyebrow {
  display: inline-block;
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent-strong);
  background: var(--accent-tint);
  padding: .3rem .7rem;
  border-radius: 999px;
}
.welcome h1 {
  margin-top: 1rem;
  font-size: clamp(2rem, 5vw, 3.1rem);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -.02em;
  max-width: 18ch;
}
.welcome p {
  margin-top: 1rem;
  color: var(--ink-soft);
  font-size: 1.08rem;
  max-width: 52ch;
}

.stats {
  margin-top: 2.75rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.35rem 1.4rem;
  box-shadow: var(--shadow);
}
.stat .k {
  font-size: .82rem;
  font-weight: 600;
  color: var(--ink-soft);
}
.stat .v {
  margin-top: .5rem;
  font-size: clamp(1.6rem, 3vw, 2.1rem);
  font-weight: 700;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.stat .sub { margin-top: .2rem; font-size: .84rem; color: var(--ink-faint); }
.stat .v .unit { font-size: .62em; color: var(--ink-soft); font-weight: 600; }

.note {
  margin-top: 2rem;
  display: flex;
  gap: .7rem;
  align-items: flex-start;
  background: var(--surface-2);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  color: var(--ink-soft);
  font-size: .95rem;
}
.note b { color: var(--ink); font-weight: 700; }

.foot {
  padding: 1.5rem;
  text-align: center;
  color: var(--ink-faint);
  font-size: .82rem;
}

/* ============ ledger app ============ */
.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin: 2.5rem 0 1rem;
}
.section-title h2 { font-size: 1.25rem; font-weight: 700; letter-spacing: -.01em; }
.section-title .hint { font-size: .85rem; color: var(--ink-faint); }

/* summary stat accents */
.stat--in { border-left: 4px solid var(--leaf); }
.stat--out { border-left: 4px solid var(--accent); }
.stat--net { border-left: 4px solid var(--ink-faint); }
.stat .v.pos { color: var(--leaf); }
.stat .v.neg { color: var(--accent); }

/* segmented tabs */
.tabs {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px;
  gap: 2px;
}
.tab {
  font: inherit;
  font-weight: 600;
  font-size: .95rem;
  color: var(--ink-soft);
  background: none;
  border: none;
  border-radius: 999px;
  padding: .5rem 1.15rem;
  cursor: pointer;
  transition: color .15s var(--ease), background .15s var(--ease);
}
.tab[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* entry form */
.entry {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem;
  box-shadow: var(--shadow);
}
.entry h3 { font-size: 1rem; font-weight: 700; margin-bottom: .9rem; }
.entry-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: .75rem .8rem;
  align-items: end;
}
.entry-grid .field { margin: 0; }
.col-2 { grid-column: span 2; }
.col-3 { grid-column: span 3; }
.col-4 { grid-column: span 4; }
.col-5 { grid-column: span 5; }
.col-6 { grid-column: span 6; }
@media (max-width: 720px) { .entry-grid > * { grid-column: 1 / -1 !important; } }
.entry .field input { padding: .6rem .75rem; font-size: .95rem; }
.entry .btn { padding: .62rem 1.1rem; font-size: .95rem; }
.entry-actions { grid-column: span 2; }
@media (max-width: 720px) { .entry-actions { grid-column: 1 / -1 !important; } }

/* table */
.table-wrap {
  margin-top: 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.table-scroll { overflow-x: auto; }
table.ledger { width: 100%; border-collapse: collapse; min-width: 640px; }
table.ledger th {
  text-align: left;
  font-size: .78rem;
  font-weight: 700;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: .03em;
  padding: .75rem 1rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.ledger td {
  padding: .7rem 1rem;
  font-size: .93rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
table.ledger tr:last-child td { border-bottom: none; }
table.ledger tbody tr:hover { background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.money-out { color: var(--accent); font-weight: 600; }
.money-in { color: var(--leaf); font-weight: 600; }
.pill {
  display: inline-block;
  font-size: .78rem;
  color: var(--ink-soft);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .12rem .6rem;
}
.muted { color: var(--ink-faint); }
.del-btn {
  font: inherit;
  font-size: .82rem;
  color: var(--ink-faint);
  background: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .28rem .6rem;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.del-btn:hover { color: var(--danger); border-color: var(--danger); }
.del-btn:focus-visible { outline: 2px solid var(--danger); outline-offset: 1px; }
tfoot td { padding: .8rem 1rem; font-weight: 700; border-top: 2px solid var(--line); background: var(--surface-2); }

.empty {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--ink-faint);
}
.empty .big { font-size: 2rem; margin-bottom: .5rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%) translateY(1rem);
  background: var(--ink);
  color: var(--bg);
  padding: .7rem 1.15rem;
  border-radius: 999px;
  font-size: .9rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s var(--ease), transform .2s var(--ease);
  z-index: 50;
  box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.err { background: var(--danger); color: #fff; }

/* ============ motion ============ */
.rise { opacity: 0; transform: translateY(12px); }
.rise.in { opacity: 1; transform: none; transition: opacity .5s var(--ease), transform .5s var(--ease); }
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
  .rise { opacity: 1; transform: none; }
}
