/* Expense Tracker styles - plain CSS, light and dark themes. */

:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-ink: #ffffff;
  --primary-soft: #e8eefb;
  --pos: #16a34a;
  --neg: #dc2626;
  --warn-bg: #fff7e6;
  --warn-ink: #92400e;
  --err-bg: #fdecec;
  --err-ink: #991b1b;
  --ok-bg: #e9f7ef;
  --ok-ink: #166534;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 2px 8px rgba(15, 23, 42, .04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #131c2e;
    --surface-2: #1a2438;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --border: #26324a;
    --primary: #3b82f6;
    --primary-soft: #1c2c4d;
    --pos: #22c55e;
    --neg: #f87171;
    --warn-bg: #3a2a0c;
    --warn-ink: #fcd34d;
    --err-bg: #3b1515;
    --err-ink: #fca5a5;
    --ok-bg: #12301f;
    --ok-ink: #86efac;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Sinhala", "Noto Sans Tamil", sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 1rem 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.center { text-align: center; }
.strong { font-weight: 600; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.optional { color: var(--muted); font-weight: 400; font-size: .8rem; }

/* ------------------------------------------------------------ Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 1rem;
  padding: .6rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.mainnav { display: flex; align-items: center; gap: .25rem; margin-left: auto; flex-wrap: wrap; }
.mainnav a, .mainnav .linklike {
  padding: .45rem .7rem; border-radius: 8px; color: var(--muted); font-weight: 500;
}
.mainnav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.mainnav a.active { background: var(--primary-soft); color: var(--primary); }
.logout-form { margin: 0; }
.nav-toggle { display: none; margin-left: auto; background: none; border: 0; font-size: 1.4rem; color: var(--text); cursor: pointer; }

@media (max-width: 760px) {
  .nav-toggle { display: block; }
  .mainnav { display: none; width: 100%; flex-direction: column; align-items: stretch; }
  .topbar { flex-wrap: wrap; }
  body.nav-open .mainnav { display: flex; }
}

/* ------------------------------------------------------------ Layout */
.container { max-width: 1120px; margin: 0 auto; padding: 1.25rem 1rem 6rem; }
.container-compact { max-width: 420px; padding: .75rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head p { margin: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.1rem; margin-bottom: 1rem; box-shadow: var(--shadow);
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.empty { text-align: center; padding: 2rem 1rem; }
details.card summary { cursor: pointer; }

/* ------------------------------------------------------------ Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; box-shadow: var(--shadow); }
.stat-label { color: var(--muted); font-size: .85rem; }
.stat-value { font-size: 1.35rem; font-weight: 700; margin-top: .15rem; font-variant-numeric: tabular-nums; }
.stat-note { color: var(--muted); font-size: .78rem; margin-top: .2rem; }

/* ------------------------------------------------------------ Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  padding: .55rem .95rem; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 500; cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary); filter: brightness(1.08); }
.btn-danger { background: var(--neg); border-color: var(--neg); color: #fff; }
.btn-danger-outline { color: var(--neg); border-color: var(--neg); background: transparent; }
.btn-block { width: 100%; }
.btn-icon { padding: .45rem .7rem; font-size: 1.1rem; line-height: 1; }
.btn:disabled { opacity: .6; cursor: default; }
.btn-group { display: flex; gap: .5rem; flex-wrap: wrap; }
.linklike { background: none; border: 0; padding: 0; color: var(--primary); font: inherit; cursor: pointer; }
.linklike.danger { color: var(--neg); }
.inline-form { display: inline; margin: 0 0 0 .75rem; }
.chip {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 999px; padding: .35rem .75rem; font: inherit; font-size: .85rem; cursor: pointer;
}
.fab {
  position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 30;
  width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center;
  background: var(--primary); color: #fff; font-size: 2rem; line-height: 1;
  box-shadow: 0 6px 18px rgba(37, 99, 235, .35);
}
.fab:hover { text-decoration: none; filter: brightness(1.08); }

/* ------------------------------------------------------------ Forms */
.form label { display: block; margin-bottom: .85rem; font-weight: 500; font-size: .9rem; }
.form input[type=text], .form input[type=email], .form input[type=password], .form input[type=number],
.form input[type=date], .form input[type=search], .form select,
.filter-bar input, .filter-bar select {
  display: block; width: 100%; margin-top: .3rem; padding: .55rem .7rem;
  border: 1px solid var(--border); border-radius: 9px; background: var(--surface); color: var(--text);
  font: inherit; font-weight: 400;
}
.form input:focus, .form select:focus, .filter-bar input:focus, .filter-bar select:focus {
  outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary);
}
.form input[type=color] { display: block; margin-top: .3rem; width: 64px; height: 38px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); padding: 2px; }
.form-narrow { max-width: 620px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 .75rem; }
@media (max-width: 560px) { .row-2, .row-3 { grid-template-columns: 1fr; } }
.hint { display: block; color: var(--muted); font-weight: 400; font-size: .78rem; margin-top: .25rem; }
.field-error { color: var(--neg); font-size: .82rem; font-weight: 500; margin-top: .25rem; }
.form-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .5rem; }
.date-row { display: flex; gap: .5rem; align-items: center; margin-top: .3rem; }
.date-row input { margin-top: 0 !important; flex: 1; }
.delete-form { margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.danger-zone { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--border); }

.type-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; margin-bottom: 1rem; background: var(--surface-2); padding: .3rem; border-radius: 11px; }
.type-tabs.single { grid-template-columns: 1fr; }
.type-tab { margin: 0 !important; text-align: center; cursor: pointer; }
.type-tab input { position: absolute; opacity: 0; pointer-events: none; }
.type-tab span, span.type-tab { display: block; padding: .5rem; border-radius: 8px; font-weight: 600; color: var(--muted); }
.type-tab.active span, span.type-tab.active { background: var(--surface); box-shadow: var(--shadow); }
.type-tab.expense.active span, span.type-tab.expense { color: var(--neg); }
.type-tab.income.active span, span.type-tab.income { color: var(--pos); }
.type-tab.transfer.active span, span.type-tab.transfer { color: var(--primary); }
.type-tab input:focus-visible + span { outline: 2px solid var(--primary); }
.amount-field input { font-size: 1.6rem !important; font-weight: 700 !important; padding: .6rem .8rem !important; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ Filters + tabs */
.filter-bar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; padding: .75rem; }
.filter-bar input, .filter-bar select { width: auto; margin-top: 0; flex: 1 1 150px; }
.filter-bar input[type=search] { flex: 2 1 220px; }
.filter-bar .btn { flex: 0 0 auto; }
.period-nav { display: flex; gap: .35rem; align-items: center; flex: 1 1 220px; }
.period-nav select { flex: 1; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: .6rem .9rem; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }
.tabs a:hover { text-decoration: none; color: var(--text); }
.pager { display: flex; justify-content: center; align-items: center; gap: 1rem; margin: 1rem 0; }

/* ------------------------------------------------------------ Tables */
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: .55rem .5rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .02em; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions form { display: inline; margin-left: .75rem; }
.table tfoot td { border-bottom: 0; border-top: 2px solid var(--border); }
.table tr.archived td { color: var(--muted); }
.table td.indent { padding-left: 1.75rem; }
.table-scroll { overflow-x: auto; }
.badge { display: inline-block; font-size: .7rem; padding: .05rem .4rem; border-radius: 6px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); margin-left: .35rem; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .45rem; vertical-align: 0; flex: 0 0 auto; }

/* ------------------------------------------------------------ Transactions */
.day-group { margin-bottom: 1rem; }
.day-head { display: flex; justify-content: space-between; padding: 0 .25rem .35rem; font-size: .85rem; font-weight: 600; color: var(--muted); }
.txn-list.card { padding: .25rem .5rem; }
.txn-row {
  display: flex; align-items: center; gap: .75rem; padding: .65rem .4rem;
  color: var(--text); border-bottom: 1px solid var(--border);
}
.txn-row:last-child { border-bottom: 0; }
.txn-row:hover { background: var(--surface-2); text-decoration: none; border-radius: 8px; }
.txn-dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.txn-dot.income { background: var(--pos); }
.txn-dot.expense { background: var(--neg); }
.txn-dot.transfer { background: var(--primary); }
.txn-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.txn-title { font-weight: 600; }
.txn-sub { color: var(--muted); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.txn-amount { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.txn-amount.income { color: var(--pos); }
.txn-amount.expense { color: var(--neg); }
.txn-amount.transfer { color: var(--muted); }

/* ------------------------------------------------------------ Accounts */
.account-list { list-style: none; margin: 0; padding: 0; }
.account-list a { display: flex; align-items: center; gap: .5rem; padding: .6rem .25rem; border-bottom: 1px solid var(--border); color: var(--text); }
.account-list li:last-child a { border-bottom: 0; }
.account-list a:hover { text-decoration: none; background: var(--surface-2); }
.acc-name { flex: 1; display: flex; flex-direction: column; }
.acc-name small { color: var(--muted); }
.acc-bal { font-weight: 600; font-variant-numeric: tabular-nums; }
.account-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.account-card {
  background: var(--surface); border: 1px solid var(--border); border-left: 5px solid var(--acc);
  border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow);
}
.account-card-top { display: flex; justify-content: space-between; gap: 1rem; }
.acc-type { color: var(--muted); font-size: .8rem; }
.acc-title { font-weight: 700; font-size: 1.05rem; }
.acc-balance { font-weight: 700; font-size: 1.1rem; text-align: right; font-variant-numeric: tabular-nums; }
.account-card-actions { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: .9rem; padding-top: .7rem; border-top: 1px solid var(--border); font-size: .88rem; }
.account-card-actions form { margin: 0; }

/* ------------------------------------------------------------ Bars + charts */
.bar-list { list-style: none; padding: 0; margin: 0; }
.bar-list li { display: flex; align-items: center; gap: .6rem; padding: .4rem 0; font-size: .9rem; }
.bar-label { flex: 0 0 40%; display: flex; align-items: center; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar-track span { display: block; height: 100%; border-radius: 4px; }
.bar-value { margin-left: auto; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chart-wrap { position: relative; height: 300px; }
.chart-wrap.small { height: 200px; margin-bottom: .75rem; }

/* ------------------------------------------------------------ Flash */
.flash { display: flex; align-items: center; gap: .5rem; padding: .7rem .9rem; border-radius: 10px; margin-bottom: 1rem; font-size: .92rem; }
.flash-success { background: var(--ok-bg); color: var(--ok-ink); }
.flash-error { background: var(--err-bg); color: var(--err-ink); }
.flash-warning { background: var(--warn-bg); color: var(--warn-ink); }
.flash a, .flash .linklike { color: inherit; text-decoration: underline; font-weight: 600; }

/* ------------------------------------------------------------ Auth */
.auth-card { max-width: 400px; margin: 3rem auto; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 1.75rem; box-shadow: var(--shadow); }
body.compact .auth-card { margin: .5rem auto; padding: 1rem; border: 0; box-shadow: none; }

/* ------------------------------------------------------------ Quick add (extension popup) */
body.compact { background: var(--surface); }
.quick-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .6rem; font-size: .9rem; }
.txn-form.compact label { margin-bottom: .6rem; }
.txn-form.compact .row-2 { grid-template-columns: 1fr; }
.txn-form.compact .amount-field input { font-size: 1.3rem !important; }
.txn-form.compact .hint { display: none; }
.txn-form.compact button[value="another"] { display: none; }

/* ------------------------------------------------------------ Home-screen app (iPhone notch / home bar) */
.topbar {
  padding-top: calc(.6rem + env(safe-area-inset-top));
  padding-left: calc(1.25rem + env(safe-area-inset-left));
  padding-right: calc(1.25rem + env(safe-area-inset-right));
}
body:not(.has-topbar) { padding-top: env(safe-area-inset-top); }
.container { padding-bottom: calc(6rem + env(safe-area-inset-bottom)); }
.fab { bottom: calc(1.25rem + env(safe-area-inset-bottom)); right: calc(1.25rem + env(safe-area-inset-right)); }
.form label.check { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
.form label.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--primary); }
/* Bigger tap targets and no zoom-on-focus on iPhone (inputs need 16px+) */
@media (max-width: 760px) {
  .form input, .form select, .filter-bar input, .filter-bar select { font-size: 16px; }
  .txn-row { padding: .8rem .4rem; }
}
.date-row { flex-wrap: wrap; }
.date-row input { flex: 1 1 150px; min-width: 0; }
@media (max-width: 560px) { .date-row input { flex-basis: 100%; } }
