/* Atharvi Finance Tracker - shared design system (shell, forms, tables, cards). */
:root {
  color-scheme: light;
  --bg: #f6f7fb; --surface: #ffffff; --line: #e6e8f0; --line-strong: #d3d7e3;
  --text: #0f172a; --text-2: #334155; --muted: #64748b;
  --primary: #4f46e5; --primary-hover: #4338ca; --primary-soft: #eef2ff;
  --income: #047857; --income-soft: #ecfdf5;
  --expense: #be123c; --expense-soft: #fff1f2;
  --saving: #0369a1; --saving-soft: #f0f9ff;
  --warn: #b45309; --warn-soft: #fffbeb;
  --side: #0f172a; --side-2: #1e1b4b; --side-text: #cbd5e1; --side-active: rgba(255, 255, 255, .09);
  --radius: 14px; --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .05);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, .12);
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 Inter, "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif; }
h1, h2, h3, p { margin: 0; }
a { color: var(--primary); }
.hidden { display: none !important; }
.muted { color: var(--muted); font-weight: 400; font-size: 13px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- form controls ---------- */
input, select, button { font: inherit; color: inherit; }
input, select { width: 100%; min-width: 0; height: 38px; padding: 0 12px; background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 8px; outline: none; transition: border-color .12s, box-shadow .12s; }
input[type="checkbox"] { width: 16px; height: 16px; padding: 0; accent-color: var(--primary); flex: none; }
select { width: auto; padding-right: 28px; }
input::placeholder { color: #98a2b3; }
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 70, 229, .2); }
input:disabled { background: #f2f4f7; color: var(--muted); cursor: not-allowed; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; font-size: 12px; font-weight: 600; color: var(--text-2); }
.field.check, label.check { flex-direction: row; align-items: center; gap: 8px; display: flex; font-size: 14px; font-weight: 400; color: var(--text); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); gap: 12px; align-items: end; }
.form-grid .full { grid-column: 1 / -1; }

button { height: 38px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface);
  font-weight: 600; color: var(--text-2); cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s; }
button:hover:not(:disabled) { background: #f9fafb; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover:not(:disabled) { background: var(--primary-hover); }
button.link { height: auto; padding: 4px 8px; border: 0; background: none; font-weight: 500; color: var(--muted); }
button.link:hover:not(:disabled) { color: var(--primary); background: var(--primary-soft); }
button.link.danger:hover:not(:disabled) { color: var(--expense); background: var(--expense-soft); }

/* ---------- app shell ---------- */
body.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: var(--side); color: var(--side-text); display: flex; flex-direction: column; padding: 20px 12px;
  position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 20px; color: #fff; text-decoration: none; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--primary); display: grid; place-items: center;
  font-weight: 700; font-size: 17px; color: #fff; flex: none; }
.brand-name { font-weight: 700; font-size: 15px; line-height: 1.2; }
.brand-sub { font-size: 12px; color: var(--side-text); font-weight: 400; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a, .side-foot button { display: flex; align-items: center; gap: 10px; height: 40px; padding: 0 10px; border-radius: 8px;
  color: var(--side-text); text-decoration: none; font-weight: 500; border: 0; background: none; width: 100%; }
.nav a:hover, .side-foot button:hover:not(:disabled) { background: var(--side-active); color: #fff; }
.nav a.active { background: var(--side-active); color: #fff; box-shadow: inset 3px 0 0 var(--primary); }
.nav svg, .side-foot svg { width: 18px; height: 18px; flex: none; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 2px; border-top: 1px solid #22334f; padding-top: 12px; }
.side-foot form { margin: 0; }

.app { min-width: 0; display: flex; flex-direction: column; }
.appbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 28px;
  background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.appbar h1 { font-size: 19px; font-weight: 700; }
.appbar .sub { color: var(--muted); font-size: 13px; }
.clock { text-align: right; line-height: 1.3; white-space: nowrap; }
.clock-date { display: block; font-size: 12px; color: var(--muted); }
.clock-time { display: block; font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
main { padding: 24px 28px 48px; width: 100%; min-width: 0; max-width: 1280px; }

@media (max-width: 860px) {
  body.shell { display: block; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 10px 12px; }
  .brand { padding: 0 6px 0 0; }
  .brand-sub { display: none; }
  .nav { flex-direction: row; }
  .side-foot { margin: 0 0 0 auto; flex-direction: row; border: 0; padding: 0; }
  .nav a, .side-foot button { width: auto; height: 36px; }
  .nav a.active { box-shadow: none; }
  .appbar { position: static; padding: 12px 16px; }
  main { padding: 16px 16px 40px; }
}

/* ---------- shared components ---------- */
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 28px 0 12px; }
.section-head h2, main > h2 { font-size: 15px; font-weight: 700; }
main > h2 { margin: 28px 0 12px; }
main > h2 .muted, .section-head .muted { margin-left: 8px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.period { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.period label { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.badge { display: inline-flex; align-items: center; height: 24px; padding: 0 10px; border-radius: 99px; font-size: 12px; font-weight: 600;
  background: #f2f4f7; color: var(--text-2); white-space: nowrap; }
.badge.open { background: var(--income-soft); color: var(--income); }
.badge.frozen { background: var(--warn-soft); color: var(--warn); }
.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; text-transform: capitalize; background: #f2f4f7; color: var(--text-2); }
.pill.salary, .pill.income { background: var(--income-soft); color: var(--income); }
.pill.expense { background: var(--expense-soft); color: var(--expense); }
.pill.saving { background: var(--saving-soft); color: var(--saving); }

.banner { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-weight: 500;
  background: var(--warn-soft); color: var(--warn); border: 1px solid #fedf89; }
.banner.negative { background: var(--expense-soft); color: var(--expense); border-color: #fda29b; font-weight: 600; }

.card, .stat, .chart, .table-wrap, .panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: 14px; }
.stat { padding: 16px 18px; border-left: 4px solid var(--line-strong); min-width: 0; }
.stat .label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .value { margin-top: 6px; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; line-height: 1.25; }
.stat.income, .stat.good { border-left-color: var(--income); }
.stat.expense, .stat.bad { border-left-color: var(--expense); }
.stat.saving { border-left-color: var(--saving); }
.stat.good .value, .stat.income .value { color: var(--income); }
.stat.bad .value, .stat.expense .value { color: var(--expense); }
.stat.saving .value { color: var(--saving); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 16px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; background: #f9fafb; }
th.num, td.num { text-align: right; }
td.note { white-space: normal; min-width: 160px; color: var(--text-2); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafbfc; }
tr.selected td { background: var(--primary-soft); font-weight: 600; }
.t-income { color: var(--income); } .t-expense { color: var(--expense); } .t-saving { color: var(--saving); }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 50; max-width: calc(100vw - 32px);
  background: var(--text); color: #fff; padding: 11px 18px; border-radius: 8px; font-weight: 500; box-shadow: 0 8px 24px rgba(16, 24, 40, .25); }
.toast.err { background: var(--expense); }

dialog { border: 0; border-radius: 14px; padding: 0; width: min(500px, calc(100vw - 32px)); color: var(--text);
  box-shadow: 0 20px 48px rgba(16, 24, 40, .28); }
dialog::backdrop { background: rgba(12, 26, 48, .55); }
dialog form { display: flex; flex-direction: column; gap: 14px; padding: 24px; }
dialog h2 { font-size: 18px; }
dialog details { font-size: 13px; color: var(--muted); }
dialog details summary { cursor: pointer; }
dialog details .field { margin-top: 12px; }
.help { background: #f9fafb; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 13px; color: var(--text-2); }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.spacer { flex: 1; }
#settings-msg.ok { color: var(--income); font-weight: 600; } #settings-msg.err { color: var(--expense); font-weight: 600; }

/* ---------- home ---------- */
.home-intro { margin-bottom: 20px; }
.home-intro h2 { font-size: 22px; }
.home { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); gap: 20px; }
.home-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 28px;
  text-decoration: none; color: var(--text); display: flex; flex-direction: column; gap: 12px; min-height: 230px; transition: box-shadow .15s, border-color .15s, transform .15s; }
.home-card:hover { border-color: var(--primary); box-shadow: 0 8px 24px rgba(16, 24, 40, .1); transform: translateY(-2px); }
.home-icon { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.home-card.planning .home-icon { background: var(--saving-soft); color: var(--saving); }
.home-icon svg { width: 24px; height: 24px; }
.home-card h2 { font-size: 20px; }
.home-card p { color: var(--muted); flex: 1; }
.home-card .go { font-weight: 600; color: var(--primary); }

/* ---------- login ---------- */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; background: var(--side); }
.login-box { background: var(--surface); border-radius: 16px; padding: 32px; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 16px;
  box-shadow: 0 20px 48px rgba(0, 0, 0, .35); }
.login-box .brand { color: var(--text); padding: 0; }
.login-box .brand-sub { color: var(--muted); }
.login-box h1 { font-size: 20px; }
.error { color: var(--expense); font-weight: 600; background: var(--expense-soft); border-radius: 8px; padding: 9px 12px; }

/* ---------- refinement layer ---------- */
body { -webkit-font-smoothing: antialiased; letter-spacing: -.003em; }
input, select { height: 40px; border-radius: var(--radius-sm); }
select { appearance: none; padding-right: 34px; cursor: pointer; background-color: var(--surface);
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
button { height: 40px; border-radius: var(--radius-sm); }
button.primary { background: linear-gradient(180deg, #6366f1, var(--primary)); border-color: var(--primary); box-shadow: 0 1px 2px rgba(79, 70, 229, .35); }
button.primary:hover:not(:disabled) { background: linear-gradient(180deg, var(--primary), var(--primary-hover)); }
button:active:not(:disabled) { transform: translateY(1px); }

.sidebar { background: linear-gradient(180deg, var(--side) 0%, var(--side-2) 100%); padding: 22px 14px; }
.brand-mark { background: linear-gradient(135deg, #818cf8, #4f46e5); border-radius: 11px; box-shadow: 0 4px 12px rgba(79, 70, 229, .45); }
.nav { gap: 4px; }
.nav a, .side-foot button { height: 42px; padding: 0 12px; border-radius: var(--radius-sm); }
.nav a.active { background: rgba(129, 140, 248, .2); box-shadow: none; color: #fff; font-weight: 600; }
.nav a.active svg { color: #a5b4fc; }
.side-foot { border-top-color: rgba(255, 255, 255, .1); }
.appbar { background: rgba(255, 255, 255, .88); backdrop-filter: blur(10px); padding: 16px 32px; }
.appbar h1 { font-size: 20px; letter-spacing: -.015em; }
.clock { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 6px 14px; }
main { padding: 28px 32px 56px; }
main > h2, .section-head h2 { font-size: 16px; letter-spacing: -.01em; }
main > h2 { margin: 36px 0 14px; }

.toolbar { padding: 14px 18px; }
.summary { gap: 16px; }
.stat { border-left: 0; padding: 18px 20px; position: relative; overflow: hidden; }
.stat::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--line-strong); }
.stat.income::before, .stat.good::before { background: var(--income); }
.stat.expense::before, .stat.bad::before { background: var(--expense); }
.stat.saving::before { background: var(--saving); }
.stat.good { background: linear-gradient(180deg, var(--income-soft), var(--surface) 70%); }
.stat.bad { background: linear-gradient(180deg, var(--expense-soft), var(--surface) 70%); }
.stat .label { font-size: 11.5px; letter-spacing: .06em; }
.stat .value { font-size: 24px; letter-spacing: -.02em; }
.stat:not(.good):not(.bad):not(.income):not(.expense):not(.saving) .value { color: var(--text); }

th { background: #f8fafc; font-size: 11.5px; letter-spacing: .06em; }
th, td { padding: 12px 18px; }
tbody tr:hover td { background: #f8fafc; }
.badge { height: 26px; padding: 0 12px; }
.banner { border-radius: var(--radius-sm); }
.toast { border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); }
dialog { border-radius: 18px; box-shadow: var(--shadow-lg); }
dialog::backdrop { background: rgba(15, 23, 42, .55); backdrop-filter: blur(2px); }
.home-card { border-radius: 18px; padding: 32px; }
.home-card:hover { box-shadow: var(--shadow-lg); }
.home-icon { width: 52px; height: 52px; border-radius: 14px; }
.login-body { background: radial-gradient(1200px 600px at 20% 0%, #312e81 0%, var(--side) 60%); }
@media (max-width: 860px) { .appbar { padding: 12px 16px; } main { padding: 16px 16px 40px; } .clock { padding: 4px 10px; } }
