:root {
  --navy: #0f172a;
  --navy-2: #1e293b;
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #0f172a;
  --text-dim: #64748b;
  --border: #e2e8f0;

  --green: #16a34a;
  --green-bg: #dcfce7;
  --orange: #ea8a00;
  --orange-bg: #fff1d6;
  --yellow: #ca8a04;
  --yellow-bg: #fef9c3;
  --red: #dc2626;
  --red-bg: #fee2e2;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ---------- LOGIN ---------- */
.login-screen {
  min-height: 100vh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: linear-gradient(160deg, var(--navy), #1e3a5f);
  padding: 24px;
}
.login-card {
  background: var(--card);
  border-radius: 16px;
  padding: 32px 24px;
  width: 100%; max-width: 360px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}
.login-brand-logo {
  display: block;
  width: 220px; max-width: 70vw; height: auto;
  margin: 0 auto 28px;
}
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-sub { color: var(--text-dim); font-size: 13px; margin: 0 0 24px; }
.login-card form { text-align: left; }
.login-card label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 6px; }
.login-card input {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--border); border-radius: 10px; font-size: 16px;
}
.login-error {
  margin-top: 12px; background: var(--red-bg); color: var(--red);
  padding: 10px 12px; border-radius: 8px; font-size: 13px; font-weight: 600;
}

/* ---------- BUTTONS ---------- */
.btn {
  border: none; border-radius: 10px; padding: 13px 18px;
  font-size: 15px; font-weight: 700; transition: transform .05s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:disabled { opacity: .5; }
.btn-ghost { background: transparent; color: var(--text-dim); }
.btn-danger { background: var(--red); color: #fff; }
.btn-block { width: 100%; margin-top: 18px; }
.btn-icon {
  background: rgba(255,255,255,0.08); color: #fff; border: none;
  width: 36px; height: 36px; border-radius: 50%; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
}
.view .btn-icon { background: var(--navy-2); }

/* ---------- APP SHELL ---------- */
.app { min-height: 100vh; display: flex; flex-direction: column; padding-bottom: 74px; }
.app-header {
  background: var(--navy); color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; position: sticky; top: 0; z-index: 20;
  padding-top: max(14px, env(safe-area-inset-top));
}
.header-title { display: flex; align-items: center; gap: 10px; }
.header-logo-img { height: 26px; width: auto; display: block; }
.header-user { font-size: 11px; color: #94a3b8; margin-top: 2px; }
.header-actions { display: flex; gap: 8px; }

.app-main { flex: 1; padding: 14px 14px 24px; max-width: 640px; margin: 0 auto; width: 100%; }

/* ---------- BOTTOM NAV ---------- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  background: var(--navy); display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 12px rgba(0,0,0,0.15);
}
.nav-btn {
  flex: 1; background: none; border: none; color: #94a3b8;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 10px 4px 8px; font-size: 11px; font-weight: 600;
}
.nav-btn .nav-icon { font-size: 18px; }
.nav-btn.active { color: var(--green); }

/* ---------- PERIOD BAR ---------- */
.period-bar { display: flex; align-items: center; justify-content: center; gap: 16px; margin-bottom: 12px; }
.period-label { font-weight: 700; font-size: 16px; min-width: 160px; text-align: center; }

/* ---------- SUMMARY STRIP ---------- */
.summary-strip { display: grid; grid-template-columns: repeat(4,1fr); gap: 8px; margin-bottom: 14px; }
.summary-box { background: var(--card); border-radius: 10px; padding: 10px 6px; text-align: center; border: 1px solid var(--border); }
.summary-box .num { font-size: 18px; font-weight: 800; }
.summary-box .lbl { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .03em; }
.summary-box.red .num { color: var(--red); }
.summary-box.orange .num { color: var(--orange); }
.summary-box.yellow .num { color: var(--yellow); }
.summary-box.green .num { color: var(--green); }

/* ---------- FILTER CHIPS ---------- */
.filter-chips { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 14px; padding-bottom: 2px; }
.chip {
  border: 1.5px solid var(--border); background: var(--card); border-radius: 999px;
  padding: 7px 14px; font-size: 12.5px; font-weight: 700; color: var(--text-dim); white-space: nowrap;
}
.chip.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.chip-red.active { background: var(--red); border-color: var(--red); }
.chip-orange.active { background: var(--orange); border-color: var(--orange); }
.chip-yellow.active { background: var(--yellow); border-color: var(--yellow); }
.chip-green.active { background: var(--green); border-color: var(--green); }

/* ---------- TASK LIST ---------- */
.task-list { display: flex; flex-direction: column; gap: 10px; }
.task-card {
  background: var(--card); border-radius: 12px; padding: 12px 12px 12px 14px;
  display: flex; align-items: flex-start; gap: 12px;
  border-left: 5px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.task-card.status-yellow { border-left-color: var(--yellow); }
.task-card.status-orange { border-left-color: var(--orange); }
.task-card.status-red { border-left-color: var(--red); }
.task-card.status-green { border-left-color: var(--green); background: #fbfffc; }
.task-card.critical {
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220,38,38,0.35); }
  50% { box-shadow: 0 0 0 6px rgba(220,38,38,0); }
}
.task-card.status-orange.critical { animation-name: pulse-orange; }
@keyframes pulse-orange {
  0%, 100% { box-shadow: 0 0 0 0 rgba(234,138,0,0.35); }
  50% { box-shadow: 0 0 0 6px rgba(234,138,0,0); }
}

.task-check {
  width: 26px; height: 26px; border-radius: 50%; border: 2.5px solid var(--border);
  flex-shrink: 0; margin-top: 2px; display: flex; align-items: center; justify-content: center;
  background: #fff; font-size: 14px; color: transparent;
}
.task-card.status-red .task-check, .task-card.status-orange .task-check { border-color: currentColor; }
.task-card.status-red .task-check { color: var(--red); }
.task-card.status-orange .task-check { color: var(--orange); }
.task-card.status-yellow .task-check { border-color: var(--yellow); }
.task-card.status-green .task-check { background: var(--green); border-color: var(--green); color: #fff; }

.task-body { flex: 1; min-width: 0; }
.task-title { font-weight: 700; font-size: 14.5px; line-height: 1.3; }
.task-card.status-green .task-title { text-decoration: line-through; color: var(--text-dim); }
.task-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 5px; align-items: center; }
.tag {
  font-size: 10.5px; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  background: #eef2f7; color: var(--text-dim);
}
.tag.critical-tag { background: var(--red-bg); color: var(--red); font-weight: 800; }
.tag.due-today { background: var(--orange-bg); color: var(--orange); }
.task-sub { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.task-amount { font-weight: 800; font-size: 13px; }
.task-done-note { font-size: 11.5px; color: var(--text-dim); margin-top: 4px; }
.undo-link { font-size: 11px; color: var(--text-dim); text-decoration: underline; background: none; border: none; padding: 0; margin-top: 4px; }

/* ---------- FINANCIALS ---------- */
.view-title { font-size: 18px; margin: 4px 0 14px; }
.fin-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; }
.fin-card { background: var(--card); border-radius: 12px; padding: 14px; border: 1px solid var(--border); }
.fin-card .fin-lbl { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .03em; font-weight: 700; }
.fin-card .fin-val { font-size: 20px; font-weight: 800; margin-top: 4px; }
.fin-card.income .fin-val { color: var(--green); }
.fin-card.expense .fin-val { color: var(--red); }
.fin-card.net .fin-val { color: var(--navy); }
.fin-card.outstanding .fin-val { color: var(--orange); }
.section-heading { font-size: 13px; text-transform: uppercase; letter-spacing: .03em; color: var(--text-dim); margin: 20px 0 8px; }

.fin-categories { display: flex; flex-direction: column; gap: 8px; }
.bp-row { background: var(--card); border-radius: 10px; padding: 10px 12px; border: 1px solid var(--border); }
.bp-row-top { display: flex; justify-content: space-between; font-size: 13.5px; font-weight: 700; margin-bottom: 6px; }
.bp-personal { background: var(--orange); }
.tag-personal { background: #ede9fe; color: #6d28d9; }
.cat-row { background: var(--card); border-radius: 10px; padding: 10px 12px; border: 1px solid var(--border); }
.cat-row-top { display: flex; justify-content: space-between; font-size: 13px; font-weight: 700; margin-bottom: 6px; }
.cat-bar-track { height: 6px; background: #eef2f7; border-radius: 4px; overflow: hidden; }
.cat-bar-fill { height: 100%; background: var(--navy); border-radius: 4px; }
.cat-row-sub { font-size: 11px; color: var(--text-dim); margin-top: 4px; }

.fin-history { display: flex; flex-direction: column; gap: 8px; }
.hist-row { background: var(--card); border-radius: 10px; padding: 12px; border: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.hist-month { font-weight: 700; font-size: 13px; }
.hist-nums { text-align: right; font-size: 12px; }
.hist-nums .net-pos { color: var(--green); font-weight: 700; }
.hist-nums .net-neg { color: var(--red); font-weight: 700; }
.hist-change { font-size: 11px; margin-top: 2px; }
.hist-change.up { color: var(--red); }
.hist-change.down { color: var(--green); }

/* ---------- MANAGE ---------- */
.subtabs { display: flex; gap: 8px; margin-bottom: 14px; }
.subtab { flex: 1; background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 10px; font-weight: 700; font-size: 13px; color: var(--text-dim); }
.subtab.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.template-list { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.template-row { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.template-row-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.template-title { font-weight: 700; font-size: 13.5px; }
.template-meta { font-size: 11.5px; color: var(--text-dim); margin-top: 3px; }
.template-actions { display: flex; gap: 6px; flex-shrink: 0; }
.icon-btn { background: #eef2f7; border: none; border-radius: 7px; width: 30px; height: 30px; font-size: 13px; }
.icon-btn.danger { background: var(--red-bg); color: var(--red); }

/* ---------- ACTIVITY ---------- */
.activity-list { display: flex; flex-direction: column; gap: 6px; }
.activity-row { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 12.5px; }
.activity-row .a-top { display: flex; justify-content: space-between; font-weight: 700; }
.activity-row .a-detail { color: var(--text-dim); margin-top: 2px; }

/* ---------- MODAL ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,0.55); z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: #fff; border-radius: 16px 16px 0 0; padding: 22px; width: 100%; max-width: 480px;
  padding-bottom: max(22px, env(safe-area-inset-bottom));
}
.modal h3 { margin: 0 0 14px; font-size: 17px; }
.modal label { display: block; font-size: 13px; font-weight: 700; margin: 12px 0 6px; }
.modal input, .modal select, .modal textarea {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--border); border-radius: 10px; font-size: 16px;
}
.modal-hint { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions .btn { flex: 1; }
.modal-error { background: var(--red-bg); color: var(--red); padding: 8px 10px; border-radius: 8px; font-size: 12.5px; font-weight: 600; margin-top: 10px; }

/* ---------- TOAST ---------- */
.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 13px; font-weight: 600; z-index: 200; box-shadow: 0 6px 16px rgba(0,0,0,0.25);
}

@media (min-width: 640px) {
  .app-main { padding-top: 20px; }
}
