:root {
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-light: #ccfbf1;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --danger: #dc2626;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --radius: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }
a { color: var(--primary); text-decoration: none; }

/* ---------- AUTH ---------- */
.auth-screen {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, var(--primary) 0%, var(--primary-dark) 100%);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border-radius: 24px;
  padding: 32px 28px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.brand { text-align: center; margin-bottom: 24px; }
.brand-logo {
  width: 64px; height: 64px; margin: 0 auto 12px;
  background: var(--primary); color: #fff;
  border-radius: 18px;
  display: flex; align-items: center; justify-content: center;
  font-size: 34px; font-weight: 700;
}
.brand h1 { font-size: 26px; letter-spacing: -.5px; }
.brand-tag { color: var(--muted); font-size: 14px; margin-top: 4px; }

.auth-form h2 { font-size: 20px; margin-bottom: 18px; }
.auth-form label {
  display: block; font-size: 13px; font-weight: 600; color: var(--muted);
  margin-bottom: 14px;
}
.auth-form input {
  width: 100%; margin-top: 6px;
  padding: 12px 14px; font-size: 16px;
  border: 1px solid var(--border); border-radius: 12px;
  background: #f8fafc; color: var(--text);
}
.auth-form input:focus { outline: none; border-color: var(--primary); background: #fff; }
.auth-error { color: var(--danger); font-size: 13px; min-height: 18px; margin-bottom: 6px; }
.auth-switch { text-align: center; font-size: 14px; color: var(--muted); margin-top: 16px; }
.auth-note { text-align: center; font-size: 12px; color: var(--muted); margin-top: 22px; }

/* ---------- BUTTONS ---------- */
.btn-primary {
  background: var(--primary); color: #fff; border: none;
  padding: 12px 20px; border-radius: 12px; font-size: 15px; font-weight: 600;
}
.btn-primary:active { background: var(--primary-dark); }
.btn-block { width: 100%; }
.btn-outline {
  background: transparent; color: var(--primary);
  border: 1.5px dashed var(--primary); padding: 14px;
  border-radius: 12px; font-weight: 600; font-size: 15px;
}
.btn-ghost {
  background: transparent; border: none; color: var(--muted);
  font-size: 13px; font-weight: 600; padding: 6px 10px; border-radius: 8px;
}
.btn-ghost:active { background: var(--border); }
.btn-danger {
  background: #fee2e2; color: var(--danger); border: none;
  padding: 12px 18px; border-radius: 12px; font-weight: 600;
}

/* ---------- APP SHELL ---------- */
.app { min-height: 100%; padding-bottom: 150px; max-width: 760px; margin: 0 auto; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--card);
  padding: 14px 18px; padding-top: max(14px, env(safe-area-inset-top));
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.topbar-title span { font-size: 19px; font-weight: 700; }
.topbar-user { display: flex; align-items: center; gap: 6px; }
#user-greeting { font-size: 13px; color: var(--muted); }

.content { padding: 16px; }
.view { display: flex; flex-direction: column; gap: 8px; }

.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 18px 4px 8px;
}
.section-head h3 { font-size: 15px; font-weight: 700; }
.section-head small { color: var(--muted); font-weight: 400; }
.link-more { font-size: 13px; font-weight: 600; }
.view-hint { color: var(--muted); font-size: 13px; margin: 4px 4px 14px; }

/* ---------- BALANCE CARD ---------- */
.balance-card {
  background: linear-gradient(150deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff; border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 6px;
}
.balance-label { font-size: 13px; opacity: .85; }
.balance-value { font-size: 34px; font-weight: 800; letter-spacing: -1px; }
.balance-split { display: flex; gap: 24px; margin-top: 12px; }
.balance-split div { display: flex; flex-direction: column; gap: 2px; }
.balance-split span { font-size: 12px; opacity: .85; }
.balance-split b { font-size: 16px; }
.balance-period { font-size: 11px; opacity: .7; margin-top: 8px; }

/* ---------- CATEGORY LIST ---------- */
.cat-list { display: flex; flex-direction: column; gap: 10px; }
.cat-row { background: var(--card); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); }
.cat-row .cat-top { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 8px; }
.cat-row .cat-name { font-weight: 600; }
.cat-row .cat-amt { color: var(--muted); }
.cat-bar { height: 8px; background: var(--border); border-radius: 99px; overflow: hidden; }
.cat-bar > span { display: block; height: 100%; background: var(--primary); border-radius: 99px; }

/* ---------- TRANSACTIONS ---------- */
.txn-list { display: flex; flex-direction: column; gap: 8px; }
.txn-item {
  background: var(--card); border-radius: 12px; padding: 12px 14px;
  box-shadow: var(--shadow); display: flex; align-items: center; gap: 12px;
  cursor: pointer;
}
.txn-icon {
  width: 40px; height: 40px; border-radius: 11px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 18px;
  background: var(--primary-light);
}
.txn-mid { flex: 1; min-width: 0; }
.txn-title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.txn-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.txn-amt { font-weight: 700; font-size: 15px; white-space: nowrap; }
.txn-amt.neg { color: var(--red); }
.txn-amt.pos { color: var(--green); }

.filter-row { display: flex; gap: 10px; margin-bottom: 6px; }
.filter-row select, .filter-row input {
  flex: 1; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--card); font-size: 14px;
}

/* ---------- BUDGETS ---------- */
.budget-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }
.budget-card { background: var(--card); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); cursor: pointer; }
.budget-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.budget-name { font-weight: 700; font-size: 15px; }
.budget-nums { font-size: 13px; color: var(--muted); }
.budget-bar { height: 10px; background: var(--border); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.budget-bar > span { display: block; height: 100%; border-radius: 99px; transition: width .3s; }
.budget-msg { font-size: 12px; margin-top: 8px; font-weight: 600; }

/* ---------- TASKS ---------- */
.voice-bar { margin-bottom: 12px; }
.voice-btn {
  width: 100%; background: var(--primary-light); color: var(--primary-dark);
  border: none; border-radius: 14px; padding: 16px;
  font-size: 15px; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 8px;
}
.voice-btn.recording { background: #fee2e2; color: var(--danger); animation: pulse 1.2s infinite; }
.voice-btn .mic { font-size: 20px; }
@keyframes pulse { 0%,100%{opacity:1;} 50%{opacity:.55;} }
.voice-status { font-size: 12px; color: var(--muted); text-align: center; min-height: 16px; margin-top: 8px; }

.task-add-row { margin-bottom: 14px; }
.task-add-row input {
  width: 100%; padding: 12px 14px; font-size: 15px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--card);
}
.task-tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.task-tab {
  flex: 1; padding: 9px; border: 1px solid var(--border); background: var(--card);
  border-radius: 10px; font-weight: 600; font-size: 14px; color: var(--muted);
}
.task-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.task-list { display: flex; flex-direction: column; gap: 8px; }
.task-item {
  background: var(--card); border-radius: 12px; padding: 12px 14px;
  box-shadow: var(--shadow); display: flex; align-items: flex-start; gap: 12px;
}
.task-check {
  width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--primary);
  flex-shrink: 0; margin-top: 1px; display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 13px; background: transparent;
}
.task-item.done .task-check { background: var(--primary); }
.task-mid { flex: 1; min-width: 0; }
.task-text { font-size: 14px; font-weight: 500; word-break: break-word; }
.task-item.done .task-text { text-decoration: line-through; color: var(--muted); }
.task-meta { font-size: 11px; color: var(--muted); margin-top: 3px; }
.task-del { background: none; border: none; color: var(--muted); font-size: 16px; padding: 2px 4px; }

/* ---------- EMPTY STATE ---------- */
.empty { text-align: center; color: var(--muted); font-size: 14px; padding: 28px 16px; }
.empty .emoji { font-size: 32px; display: block; margin-bottom: 8px; }

/* ---------- FAB ---------- */
.fab {
  position: fixed; right: 18px; bottom: 84px; z-index: 30;
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--primary); color: #fff; border: none;
  font-size: 30px; line-height: 1; box-shadow: 0 6px 16px rgba(15,118,110,.45);
}
@media (min-width: 760px) { .fab { right: calc(50% - 380px + 18px); } }

/* ---------- BOTTOM NAV ---------- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 25;
  background: var(--card); border-top: 1px solid var(--border);
  display: flex; padding: 8px 4px; padding-bottom: max(8px, env(safe-area-inset-bottom));
  max-width: 760px; margin: 0 auto;
}
.nav-btn {
  flex: 1; background: none; border: none; color: var(--muted);
  font-size: 11px; font-weight: 600; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 4px;
}
.nav-btn span { font-size: 20px; }
.nav-btn.active { color: var(--primary); }

/* ---------- MODAL ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(15,23,42,.5);
  display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 600px) { .modal { align-items: center; } }
.modal-card {
  background: var(--card); width: 100%; max-width: 480px;
  border-radius: 24px 24px 0 0; padding: 22px;
  max-height: 92vh; overflow-y: auto;
  animation: slideup .25s ease;
}
@media (min-width: 600px) { .modal-card { border-radius: 24px; } }
@keyframes slideup { from { transform: translateY(40px); opacity:.6; } to { transform: translateY(0); opacity:1; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.modal-head h3 { font-size: 18px; }
.modal-close { background: var(--bg); border: none; width: 32px; height: 32px; border-radius: 50%; font-size: 14px; color: var(--muted); }

#txn-form label, #budget-form label, #loan-form label, #kameti-form label {
  display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 14px;
}
#txn-form label small, #budget-form label small, #loan-form label small, #kameti-form label small { font-weight: 400; }
#txn-form input, #budget-form input, #loan-form input, #kameti-form input {
  width: 100%; margin-top: 6px; padding: 12px 14px; font-size: 16px;
  border: 1px solid var(--border); border-radius: 12px; background: #f8fafc; color: var(--text);
}
#txn-form input:focus, #budget-form input:focus, #loan-form input:focus, #kameti-form input:focus {
  outline: none; border-color: var(--primary); background: #fff;
}

.type-toggle { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 16px; }
.type-toggle label { margin: 0; }
.type-toggle input { display: none; }
.type-toggle span {
  display: block; text-align: center; padding: 10px 4px; font-size: 13px; font-weight: 600;
  border: 1px solid var(--border); border-radius: 10px; color: var(--muted); background: #f8fafc;
}
.type-toggle input:checked + span { background: var(--primary); color: #fff; border-color: var(--primary); }

.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.modal-actions .btn-primary { flex: 1; }

.type-toggle.two { grid-template-columns: repeat(2, 1fr); }

/* ---------- MINI STATS (loans summary) ---------- */
.mini-stats { display: flex; gap: 12px; margin: 4px 0 6px; }
.mini-stat {
  flex: 1; background: var(--card); border-radius: 14px; padding: 14px 16px;
  box-shadow: var(--shadow); cursor: pointer; display: flex; flex-direction: column; gap: 4px;
  border-left: 4px solid var(--border);
}
.mini-stat span { font-size: 12px; color: var(--muted); }
.mini-stat b { font-size: 18px; }
.mini-stat.pos { border-left-color: var(--green); }
.mini-stat.pos b { color: var(--green); }
.mini-stat.neg { border-left-color: var(--red); }
.mini-stat.neg b { color: var(--red); }

/* ---------- KAMETI ALERT (dashboard) ---------- */
.kameti-alert {
  background: #fef3c7; color: #92400e; border-radius: 12px; padding: 12px 14px;
  font-size: 13px; font-weight: 600; margin-bottom: 4px; cursor: pointer;
  box-shadow: var(--shadow);
}

/* ---------- LOANS ---------- */
.loan-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.loan-card { background: var(--card); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); cursor: pointer; }
.loan-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.loan-person { font-weight: 700; font-size: 15px; }
.loan-remaining { font-weight: 700; font-size: 15px; white-space: nowrap; }
.loan-remaining.pos { color: var(--green); }
.loan-remaining.neg { color: var(--red); }
.loan-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.loan-bar { height: 7px; background: var(--border); border-radius: 99px; overflow: hidden; margin-top: 9px; }
.loan-bar > span { display: block; height: 100%; border-radius: 99px; background: var(--primary); }
.loan-badge { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; }
.loan-badge.settled { background: #dcfce7; color: var(--green); }
.loan-badge.due { background: #fee2e2; color: var(--red); }

.loan-tab { flex: 1; padding: 9px; border: 1px solid var(--border); background: var(--card);
  border-radius: 10px; font-weight: 600; font-size: 13px; color: var(--muted); }
.loan-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* repayment / months section inside modals */
.repay-section { background: #f8fafc; border: 1px solid var(--border); border-radius: 12px; padding: 12px; margin-bottom: 16px; }
.repay-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 8px; }
.repay-head b { color: var(--text); }
.repay-row { display: flex; justify-content: space-between; align-items: center; font-size: 13px; padding: 6px 0; border-bottom: 1px dashed var(--border); }
.repay-row:last-child { border-bottom: none; }
.repay-row .repay-del { background: none; border: none; color: var(--muted); font-size: 14px; }
.repay-add { display: flex; gap: 6px; margin-top: 10px; align-items: stretch; }
.repay-add input { margin-top: 0 !important; flex: 1; min-width: 0; }
.repay-add .btn-primary { padding: 10px 14px; white-space: nowrap; }
.repay-empty { font-size: 12px; color: var(--muted); padding: 4px 0; }

/* ---------- KAMETI ---------- */
.kameti-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }
.kameti-card { background: var(--card); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); cursor: pointer; }
.kameti-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.kameti-name { font-weight: 700; font-size: 16px; }
.kameti-meta { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.kameti-bar { height: 9px; background: var(--border); border-radius: 99px; overflow: hidden; }
.kameti-bar > span { display: block; height: 100%; border-radius: 99px; background: var(--primary); }
.kameti-nums { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 7px; }
.kameti-payout { font-size: 13px; font-weight: 600; margin-top: 8px; }
.kameti-badge { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; }
.kameti-badge.turn { background: #fef3c7; color: #92400e; }
.kameti-badge.received { background: #dcfce7; color: var(--green); }
.kameti-badge.due { background: #fee2e2; color: var(--red); }

.months-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.month-cell {
  position: relative; aspect-ratio: 1; border: 1px solid var(--border); background: #fff;
  border-radius: 8px; font-size: 12px; font-weight: 700; color: var(--text);
  display: flex; align-items: center; justify-content: center;
}
.month-cell.paid { background: var(--primary); color: #fff; border-color: var(--primary); }
.month-cell.turn { box-shadow: 0 0 0 2px #f59e0b inset; }
.month-cell.current::after { content: "⏳"; position: absolute; top: -6px; right: -6px; font-size: 11px; }
.month-cell .crown { position: absolute; top: -7px; left: -4px; font-size: 12px; }
.months-legend { font-size: 11px; color: var(--muted); margin-top: 10px; text-align: center; }

/* ---------- TASKS: client ---------- */
.task-add-row { display: flex; flex-direction: column; gap: 8px; }
.task-group-head { font-size: 12px; font-weight: 700; color: var(--primary); margin: 14px 4px 6px; text-transform: uppercase; letter-spacing: .04em; }
.task-group-head:first-child { margin-top: 0; }
