/* ===============================================================
   Tally — main stylesheet
   Dark mode by default; light mode under [data-theme="light"].
   =============================================================== */

:root, [data-theme="dark"] {
  --bg: #16130f;
  --bg-card: #1d1a15;
  --bg-deep: #0e0c09;
  --ink: #f0e9dc;
  --ink-soft: #a89e8c;
  --ink-meta: #6f675a;
  --ink-faint: #6b6356;
  --ink-very-faint: #4a4438;
  --rule: #2d2820;
  --rule-strong: #3d362a;
  --accent: #7ab8c4;
  --accent-soft: #1f3d44;
  --positive: #8aa872;
  --positive-soft: #2a3d22;
  --negative: #e07a52;
  --mum: #b89ad4;
  --mum-soft: #3d2f4f;
  --me: #94a3d4;
  --me-soft: #2a335a;
}

[data-theme="light"] {
  --bg: #f8f4ec;
  --bg-card: #ffffff;
  --bg-deep: #f0ebe1;
  --ink: #1d1812;
  --ink-soft: #5b554a;
  --ink-meta: #95897a;
  --ink-faint: #9a9286;
  --ink-very-faint: #c0b9a9;
  --rule: #e3dccd;
  --rule-strong: #d0c8b6;
  --accent: #2d6b7c;
  --accent-soft: #c8e0e6;
  --positive: #5a7d3f;
  --positive-soft: #d8e6c8;
  --negative: #b8472d;
  --mum: #7a5a9a;
  --mum-soft: #e6dcef;
  --me: #4a5a9b;
  --me-soft: #d4daed;
}

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

html, body {
  font-family: 'Manrope', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

/* ===== APP HEADER ===== */
.app-header {
  padding: 14px 22px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--rule);
}
.app-header .right {
  display: flex;
  align-items: center;
  gap: 6px;
}
.app-logo {
  font-family: 'Manrope', sans-serif;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.04em;
}
.app-logo::before {
  content: '◆';
  color: var(--accent);
  margin-right: 6px;
  font-size: 11px;
  vertical-align: middle;
}
.app-date {
  font-family: 'Manrope', sans-serif;
  font-size: 11px;
  color: var(--ink-soft);
}

.refresh-btn {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 50%;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 14px;
  padding: 0;
  transition: all 0.15s;
}
.refresh-btn:hover { color: var(--accent); border-color: var(--accent); }
.refresh-btn:active { transform: scale(0.95); }
.refresh-btn.spinning { animation: refresh-spin 0.6s ease-in-out; }
@keyframes refresh-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* ===== VIEWER HEADER (Jenny) ===== */
.mum-app-header {
  padding: 16px 22px 14px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: 1px solid var(--rule);
}
.mum-app-header .title {
  font-family: 'Caveat', cursive;
  font-size: 30px;
  font-weight: 600;
  line-height: 1;
  color: var(--ink);
}
.mum-app-header .title .accent { color: var(--accent); }
.mum-app-header .right { display: flex; align-items: center; gap: 6px; }
.mum-app-header .date { font-size: 11px; color: var(--ink-soft); }

/* ===== CONTENT ===== */
.content {
  flex: 1;
  padding: 16px 22px 80px;
  overflow-y: auto;
}

/* ===== BALANCE CARD ===== */
.balance-card {
  background: var(--bg-deep);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 18px 18px 16px;
  margin-bottom: 18px;
  position: relative;
  overflow: hidden;
}
.balance-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(122, 184, 196, 0.04) 0%, transparent 60%);
  pointer-events: none;
}
.balance-card .balance-label {
  font-family: 'Caveat', cursive;
  font-size: 20px;
  font-weight: 500;
  color: var(--ink-soft);
  margin-bottom: 2px;
  line-height: 1;
  position: relative;
  z-index: 1;
}
.balance-card .balance-amount {
  font-family: 'Manrope', sans-serif;
  font-weight: 600;
  font-size: 38px;
  font-feature-settings: "tnum";
  letter-spacing: -0.02em;
  line-height: 1;
  position: relative;
  z-index: 1;
}
.balance-card .balance-amount .currency {
  font-family: 'Geist Mono', monospace;
  font-size: 22px;
  font-weight: 500;
  color: var(--ink-soft);
  margin-right: 6px;
}
.balance-card .balance-sub {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 10px;
  position: relative;
  z-index: 1;
}
.balance-card.credit {
  border-color: var(--positive);
}
.balance-card.credit .balance-amount { color: var(--positive); }

/* ===== PERIOD/TAB SELECTOR ===== */
.period-selector {
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 10px 14px;
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}
.period-selector .label {
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-faint);
  margin-bottom: 1px;
}
.period-selector .value { font-size: 14px; color: var(--ink); }
.period-selector .chevron { color: var(--ink-faint); font-size: 14px; }

/* ===== TRANSACTION ROWS ===== */
.txn {
  padding: 11px 0;
  border-bottom: 1px solid var(--rule);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: baseline;
  margin: 0 -8px;
  padding-left: 8px;
  padding-right: 8px;
  transition: background 0.1s;
  cursor: pointer;
}
.txn:hover { background: var(--bg); border-radius: 4px; }
.txn:last-child { border-bottom: none; }

.txn .left { min-width: 0; }
.txn .item-line { font-size: 14px; color: var(--ink); margin-bottom: 3px; }
.txn .item-line .name { font-weight: 500; }
.txn .item-line .comment { color: var(--ink-soft); margin-left: 5px; }

.txn .meta { font-size: 11px; color: var(--ink-meta); }
.txn .meta .when, .txn .meta .cat { color: var(--ink-meta); }
.txn .meta .who-mum { color: var(--mum); opacity: 0.7; }
.txn .meta .who-me { color: var(--me); opacity: 0.7; }
.txn .meta .dot { margin: 0 5px; color: var(--ink-very-faint); }

.txn .amount {
  font-family: 'Manrope', sans-serif;
  font-weight: 600;
  font-feature-settings: "tnum";
  font-size: 15px;
  color: var(--ink);
}
.txn .amount.payment { color: var(--positive); }
.txn .amount .cur {
  font-family: 'Geist Mono', monospace;
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-faint);
  margin-right: 3px;
}

.txn.payment .item-line .name::before { content: '💵 '; margin-right: 2px; }

.txn.clearance {
  background: var(--positive-soft);
  border-radius: 4px;
  margin: 8px -8px;
  border-bottom: none;
  padding: 12px 8px;
}
.txn.clearance .item-line .name { color: var(--positive); font-weight: 500; }
.txn.clearance .item-line .name::before { content: '✓ '; }
.txn.clearance .amount { color: var(--positive); }

/* ===== GREETING / SECTION HEAD ===== */
.greeting { margin: 4px 0 18px; }
.greeting .hello {
  font-family: 'Caveat', cursive;
  font-size: 22px;
  font-weight: 500;
  color: var(--ink-soft);
  margin-bottom: 2px;
  line-height: 1;
}
.greeting h2 {
  font-family: 'Manrope', sans-serif;
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -0.03em;
  line-height: 1.2;
}
.greeting h2 em {
  font-style: normal;
  color: var(--accent);
  font-weight: 700;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 22px 0 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--rule);
}
.section-head h3 {
  font-family: 'Manrope', sans-serif;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.02em;
}
.section-head .more {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-soft);
  cursor: pointer;
  background: none;
  border: none;
}

/* ===== EMPTY STATE ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  text-align: center;
  min-height: 280px;
}
.empty-state .mark { font-size: 36px; color: var(--ink-very-faint); margin-bottom: 16px; line-height: 1; }
.empty-state .headline {
  font-family: 'Caveat', cursive;
  font-size: 32px;
  font-weight: 600;
  line-height: 1.1;
  color: var(--ink);
  margin-bottom: 8px;
}
.empty-state .sub {
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.6;
  max-width: 280px;
}

/* ===== LOGIN ===== */
.login-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 40px 28px 24px;
}
.login-brand { text-align: center; margin-bottom: 28px; }
.login-brand .mark { color: var(--accent); font-size: 18px; margin-bottom: 6px; line-height: 1; }
.login-brand .name {
  font-family: 'Caveat', cursive;
  font-size: 44px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1;
}
.login-brand .name .accent { color: var(--accent); }
.login-brand .tagline { font-size: 12px; color: var(--ink-soft); margin-top: 4px; }

.login-card { width: 100%; max-width: 320px; }
.login-card .greeting-line {
  font-family: 'Caveat', cursive;
  font-size: 22px;
  color: var(--ink-soft);
  text-align: center;
  margin-bottom: 14px;
  line-height: 1.1;
}
.login-username {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 4px;
  color: var(--ink);
  font-size: 14px;
  margin-bottom: 14px;
  text-align: center;
}
.login-username:focus { outline: none; border-color: var(--accent); }

.pin-label { font-size: 12px; color: var(--ink-soft); text-align: center; margin-bottom: 8px; }
.pin-display { display: flex; justify-content: center; gap: 12px; margin-bottom: 22px; padding: 14px 0; }
.pin-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1.5px solid var(--rule-strong);
  background: transparent;
  transition: all 0.15s;
}
.pin-dot.filled { background: var(--accent); border-color: var(--accent); }
.pin-display.shake { animation: pin-shake 0.4s ease-in-out; }
.pin-display.success .pin-dot { background: var(--positive); border-color: var(--positive); }
@keyframes pin-shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

.pin-message { font-size: 12px; text-align: center; margin-bottom: 14px; min-height: 18px; color: var(--ink-faint); }
.pin-message.error { color: var(--negative); }

.pin-keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; max-width: 280px; margin: 0 auto; }
.pin-key {
  aspect-ratio: 1.4 / 1;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 8px;
  font-weight: 500;
  font-size: 22px;
  font-feature-settings: "tnum";
  color: var(--ink);
  cursor: pointer;
  transition: all 0.1s;
}
.pin-key:hover { background: var(--rule); }
.pin-key:active { transform: scale(0.96); background: var(--accent-soft); }
.pin-key.action { background: transparent; border-color: transparent; color: var(--ink-soft); font-size: 14px; font-weight: 400; }

.login-footer { margin-top: 22px; text-align: center; font-size: 11px; color: var(--ink-faint); line-height: 1.5; padding: 0 8px; }

.lockout-notice {
  background: rgba(224, 122, 82, 0.08);
  border: 1px solid rgba(224, 122, 82, 0.3);
  border-radius: 4px;
  padding: 12px 14px;
  margin-bottom: 14px;
  text-align: center;
}
.lockout-notice .icon { color: var(--negative); font-size: 20px; margin-bottom: 4px; }
.lockout-notice .title { font-weight: 600; font-size: 13px; color: var(--ink); margin-bottom: 4px; }
.lockout-notice .sub { font-size: 11px; color: var(--ink-soft); }

/* ===== FORMS ===== */
.form-field { margin-bottom: 16px; }
.form-field label { display: block; font-size: 12px; color: var(--ink-soft); margin-bottom: 6px; }
.form-field input, .form-field select, .form-field textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 4px;
  color: var(--ink);
}
.form-field input:focus, .form-field select:focus, .form-field textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.btn {
  display: inline-block;
  padding: 12px 18px;
  background: var(--accent);
  color: var(--bg-deep);
  border: none;
  border-radius: 6px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
}
.btn.btn-secondary { background: transparent; border: 1px solid var(--rule); color: var(--ink-soft); }
.btn.btn-danger { background: var(--negative); color: var(--bg-deep); }

/* ===== ERROR PAGE ===== */
.error-page { padding: 60px 24px; text-align: center; }
.error-page .code { font-family: 'Manrope', sans-serif; font-size: 80px; font-weight: 700; color: var(--ink-very-faint); line-height: 1; }
.error-page .message { font-family: 'Caveat', cursive; font-size: 30px; color: var(--ink-soft); margin: 16px 0 24px; }
