@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --bg: #f3faf7;
  --surface: #ffffff;
  --surface-2: #ecf9f3;
  --text: #0f2419;
  --muted: #5c7a6d;
  --border: #d7ede2;
  --accent: #10b981;
  --accent-2: #0d9488;
  --accent-text: #ffffff;
  --credit: #059669;
  --expense: #e11d48;
  --grid: #d7ede2;
  --series-1: #0d9488;
  --series-2: #f59e0b;
  --series-3: #2563eb;
  --series-4: #7c3aed;   /* இரசீது நன்கொடை (ledger donation) in the by-year chart */
  --series-5: #64748b;   /* முந்தைய இருப்பு  (series 5.. follow INCOME_KINDS order) */
  --series-6: #f97316;   /* உண்டியல் */
  --series-7: #db2777;   /* திருப்பணி நன்கொடை */
  --series-8: #65a30d;   /* நன்கொடை */
  --series-9: #0891b2;   /* பௌர்ணமி / முடி காணிக்கை */
  --status-good: #059669;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(6,78,59,0.05), 0 12px 26px -12px rgba(16,185,129,0.22);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; color-scheme: light; }

input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow-x: hidden;
}

header {
  padding: 22px 16px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

header h1 { margin: 0 0 4px; font-size: 1.5rem; font-weight: 800; color: #047857; letter-spacing: -0.01em; display: flex; align-items: center; justify-content: center; gap: 8px; }
/* Bottom banner: fixed to the bottom of the screen, like the Accounts page's (but green, to match this site).
   Its buttons sit in the middle. #app gets bottom padding so the last card is never hidden behind it. */
#app { padding-bottom: 62px; }
.bottom-banner {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; height: 46px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: linear-gradient(120deg, #34d399, #10b981 55%, #0d9488);
  box-shadow: 0 -6px 20px -8px rgba(13, 148, 136, 0.55);
}
.banner-btn { padding: 6px 16px; border-radius: 999px; background: rgba(255,255,255,0.22); border: 1px solid rgba(255,255,255,0.55); color: #fff; font-size: 0.88rem; font-weight: 700; text-decoration: none; }
.banner-btn:hover { background: rgba(255,255,255,0.34); }
button.banner-btn { font-family: inherit; cursor: pointer; }   /* the Logout button: same look as the <a> next to it */
@media (max-width: 600px) { .banner-btn { font-size: 0.75rem; padding: 6px 12px; } }
.header-logo { height: 2.2em; width: auto; flex-shrink: 0; margin: -0.45em 0; }
/* The logo sits at the left edge, out of the row, so the title is centred on the page and keeps the full width. */
header h1 { position: relative; }
header h1 .header-logo { position: absolute; left: 0; top: 50%; transform: translateY(-50%); margin: 0; }
header p { margin: 0; color: var(--muted); font-size: 0.9rem; }

.page { max-width: 1180px; margin: 0 auto; padding: 18px 16px 60px; display: flex; flex-direction: column; gap: 20px; }
.section { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card h2 { margin: 0 0 14px; font-size: 1.02rem; font-weight: 700; }

form { display: flex; flex-direction: column; gap: 10px; }
label { font-size: 0.85rem; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }

input, select, textarea {
  font: inherit; font-size: 16px; padding: 11px 12px; min-height: 44px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); width: 100%;
}

button {
  font: inherit; font-weight: 700; padding: 12px 16px; min-height: 44px; border-radius: 8px; border: none;
  background: var(--accent); color: var(--accent-text); cursor: pointer;
  box-shadow: 0 6px 14px -6px rgba(16,185,129,0.5);
}
button:hover { opacity: 0.92; }
button.secondary { background: transparent; border: 1px solid var(--border); color: var(--text); box-shadow: none; }

.status { font-size: 0.85rem; min-height: 1.2em; }
.status.error { color: var(--expense); }
.status.ok { color: var(--credit); }

/* position:relative so the absolutely-positioned .sr-only filter labels stay inside the scroller instead of landing past the page edge */
.table-wrap {
  position: relative; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch;
  /* Scroll shadows: the two white "local" gradients cover the shadows once you reach that edge, so a soft shadow
     shows only on a side that still has more to scroll to. */
  background:
    linear-gradient(to right, var(--surface) 30%, rgba(255,255,255,0)) left center / 40px 100% no-repeat local,
    linear-gradient(to left, var(--surface) 30%, rgba(255,255,255,0)) right center / 40px 100% no-repeat local,
    radial-gradient(farthest-side at 0 50%, rgba(6,78,59,0.25), rgba(6,78,59,0)) left center / 12px 100% no-repeat scroll,
    radial-gradient(farthest-side at 100% 50%, rgba(6,78,59,0.25), rgba(6,78,59,0)) right center / 12px 100% no-repeat scroll;
}
table { width: 100%; min-width: 480px; border-collapse: collapse; font-size: 0.88rem; margin-top: 4px; }
table.people-ledger { min-width: 530px; }
table.people-ledger th:nth-child(2), table.people-ledger td:nth-child(2) { min-width: 190px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; }
.amt-credit { color: var(--credit); font-weight: 600; }
.amt-expense { color: var(--expense); font-weight: 600; }

#gate { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(180deg, #eafbf3, var(--bg)); }
#gate .card { width: 100%; max-width: 360px; text-align: center; }
.gate-subtitle { color: var(--muted); margin-top: -6px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hidden { display: none !important; }

.santha-amount-cell { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.santha-amount-input { width: 80px; min-height: 34px; padding: 6px 8px; }
.santha-amount-save { padding: 6px 10px; min-height: 34px; font-size: 0.82rem; transition: transform 0.08s ease, opacity 0.15s ease; }
.santha-amount-save:active:not(:disabled) { transform: scale(0.93); }   /* visible "pressed" reaction */
.santha-amount-save:disabled { opacity: 0.6; cursor: progress; }
.saved-label { color: var(--accent-2); font-weight: 700; font-size: 0.85rem; animation: saved-pop 0.25s ease; }
@keyframes saved-pop { from { opacity: 0; transform: translateX(-4px); } to { opacity: 1; transform: none; } }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; text-align: center; }
#ov-extra-tiles { display: contents; }   /* its tiles sit in the .tiles grid as if the wrapper were not there */
.tile .value { font-size: 1.4rem; font-weight: 800; margin-top: 4px; }
.tile .label { color: var(--muted); font-size: 0.8rem; }
.tile.credit .value { color: var(--credit); }
.tile.expense .value { color: var(--expense); }

.chart-wrap { position: relative; height: 280px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

@media (max-width: 640px) { .two-col { grid-template-columns: 1fr; } .chart-wrap { height: 240px; } }

@media (max-width: 480px) {
  header h1 { font-size: 1.25rem; }
  .page { padding: 14px 12px 48px; gap: 16px; }
  .section { gap: 16px; }
  .card { padding: 14px; }
  .tile .value { font-size: 1.2rem; }
}

/* ---------- Table filter rows ---------- */

thead tr.filter-row th,
thead tr.filter-row td {
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  padding: 3px 6px;
}

.filter-input {
  width: 100%;
  min-height: 21px;
  padding: 2px 8px;
  font-size: 0.8rem;
  font-weight: 400;
}

/* ---------- Tabs (the three sections) ---------- */

.tabs { position: sticky; top: 0; z-index: 20; padding: 10px 16px; background: rgba(243,250,247,0.94); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.tabs-inner { max-width: 1180px; margin: 0 auto; display: flex; gap: 8px; padding: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; }
.tab { flex: 1; background: transparent; color: var(--muted); box-shadow: none; border-radius: 999px; }
.tab:hover { opacity: 1; color: var(--text); }
.tab[aria-selected="true"] { background: var(--accent); color: var(--accent-text); box-shadow: 0 6px 14px -6px rgba(16,185,129,0.5); }
.tab:focus-visible, .pill:focus-visible, tr.clickable:focus-visible { outline: 3px solid var(--series-3); outline-offset: 2px; }

.banner { max-width: 1180px; margin: 14px auto 0; padding: 12px 16px; border-radius: var(--radius); background: #fff1f2; border: 1px solid #fecdd3; color: #9f1239; font-size: 0.9rem; }

/* ---------- Hero tiles: வரவு / செலவு / மீதி ---------- */

.hero-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.hero-tile { background: var(--surface); border: 1px solid var(--border); border-top: 4px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.hero-tile .label { color: var(--muted); font-size: 0.85rem; font-weight: 600; }
.hero-tile .value { font-size: 1.9rem; font-weight: 800; margin-top: 2px; font-variant-numeric: tabular-nums; }
.hero-tile.income { border-top-color: var(--credit); }
.hero-tile.income .value { color: var(--credit); }
.hero-tile.expense { border-top-color: var(--expense); }
.hero-tile.expense .value { color: var(--expense); }
.hero-tile.balance { border-top-color: var(--series-3); }
.hero-tile.balance .value { color: var(--series-3); }
.hero-tile.balance.negative { border-top-color: var(--expense); }
.hero-tile.balance.negative .value { color: var(--expense); }
@media (max-width: 640px) {
  .hero-tiles { grid-template-columns: 1fr; gap: 10px; }
  .hero-tile { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 12px 16px; }
  .hero-tile .value { font-size: 1.5rem; margin-top: 0; }
}
.tile small, .card h2 small { font-weight: 500; color: var(--muted); font-size: 0.78rem; }
.card h2 .hint { margin-left: 8px; }

/* ---------- Explore: filter pills ---------- */

.filter-card { display: flex; flex-direction: column; gap: 12px; }
.pill-row { display: flex; align-items: flex-start; gap: 12px; }
.pill-label { flex: 0 0 70px; padding-top: 10px; font-size: 0.85rem; font-weight: 700; color: var(--muted); }
.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { min-height: 40px; padding: 8px 16px; border-radius: 999px; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); box-shadow: none; font-size: 0.88rem; }
.pill:hover { opacity: 1; border-color: var(--accent); }
.pill.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.selection { margin: 0; font-size: 0.85rem; color: var(--muted); }
@media (max-width: 480px) { .pill-row { flex-direction: column; gap: 4px; } .pill-label { flex: none; padding-top: 0; } }

/* ---------- Bar lists (share of total) ---------- */

.bar-row { margin-bottom: 12px; }
.bar-top { display: flex; justify-content: space-between; gap: 12px; font-size: 0.9rem; margin-bottom: 4px; }
.bar-amount { font-weight: 700; font-variant-numeric: tabular-nums; }
.bar-amount small { color: var(--muted); font-weight: 500; margin-left: 4px; }
.bar-track { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; }
.bar-fill.credit { background: var(--credit); }
.bar-fill.expense { background: var(--expense); }
.empty { color: var(--muted); font-size: 0.9rem; margin: 4px 0; }
.note { color: var(--muted); font-size: 0.82rem; margin: 10px 0 0; }

/* ---------- Scoreboard (one row per function) ---------- */

table.scoreboard { min-width: 520px; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
table.scoreboard tfoot td { font-weight: 800; border-top: 2px solid var(--border); border-bottom: 0; }
.year-inline { display: none; color: var(--muted); font-size: 0.85em; white-space: nowrap; }
/* Phones: the year moves next to the function name so all three amounts (not just the first) fit without sideways scrolling. */
@media (max-width: 640px) {
  table.scoreboard { min-width: 0; font-size: 0.8rem; }
  table.scoreboard th, table.scoreboard td { padding: 6px 4px; }
  .col-year { display: none; }
  .year-inline { display: inline; }
  .tiles .tile:last-child:nth-child(odd) { grid-column: 1 / -1; }   /* no half-width orphan tile on the last row */
}

/* ---------- Admin ---------- */

.admin-grid { align-items: start; }
#signout-btn { margin-top: 12px; width: 100%; }
@media (max-width: 640px) { .admin-grid { grid-template-columns: 1fr; } }

/* ---------- Extras: print button, compare years, unpaid list, swipe hint, phone dropdown ---------- */

.toolbar { display: flex; justify-content: flex-end; }
.toolbar button, .print-btn { min-height: 38px; padding: 6px 14px; font-size: 0.85rem; }
.filter-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.swipe-hint { margin: 0 0 6px; font-size: 0.78rem; color: var(--muted); }

table.compare, table.unpaid-table { min-width: 0; }
.compare td.num { line-height: 1.25; }
.delta { display: block; font-weight: 600; color: var(--muted); font-size: 0.74rem; }
.delta.good { color: var(--credit); }
.delta.bad { color: var(--expense); }
.delta .abs { font-weight: 500; }
@media (max-width: 640px) { .delta .abs { display: none; } }   /* phones: just the percentage */
#cmp-pills { margin-bottom: 12px; }

details.unpaid-fn { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; background: var(--surface); }
details.unpaid-fn summary { cursor: pointer; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; font-weight: 700; font-size: 0.92rem; }
.unpaid-count { font-weight: 500; color: var(--muted); font-size: 0.82rem; }
.unpaid-bar { margin: 10px 0; }
.unpaid-total { margin: 0 0 10px; }
a[href^="tel:"] { color: var(--accent-2); font-weight: 600; text-decoration: none; }
@media (max-width: 640px) { a[href^="tel:"] { display: inline-block; padding: 6px 0; } }   /* a 17px-tall link is hard to tap */

/* Phones: one dropdown instead of a long wrap of function pills. Wider screens keep the pills. */
.fn-select { display: none; flex: 1; }
@media (max-width: 640px) {
  .fn-select { display: block; }
  #ex-fn-pills { display: none; }
}

/* ---------- Print: only the summary block ---------- */

#print-summary { display: none; }
@media print {
  #gate, #app > *:not(#print-summary) { display: none !important; }
  body { background: #fff; color: #000; }
  #print-summary { display: block; font-size: 11pt; line-height: 1.35; }
  #print-summary h1 { font-size: 18pt; margin: 0; }
  #print-summary h2 { font-size: 13pt; margin: 2pt 0 4pt; font-weight: 600; }
  #print-summary h3 { font-size: 11.5pt; margin: 14pt 0 4pt; border-bottom: 1px solid #000; padding-bottom: 2pt; }
  #print-summary .print-meta { margin: 0 0 10pt; color: #333; }
  #print-summary table { width: 100%; min-width: 0; border-collapse: collapse; margin: 0; }
  #print-summary th, #print-summary td { padding: 3pt 6pt; border-bottom: 1px solid #bbb; text-align: left; }
  #print-summary .num, #print-summary table.print-totals td { text-align: right; font-variant-numeric: tabular-nums; }
  #print-summary table.print-totals th { text-align: right; }
  #print-summary table.print-totals td { font-size: 14pt; font-weight: 700; }
  @page { margin: 14mm; }
}

/* Password cards: a little air between the "which page is this for" line and the first field */
.pw-about { margin: -4px 0 14px; }
