/* =========================================================
   Dasvandh Tracker
   White canvas. Playfair Display + DM Sans. Navy + gold accents.
   Glassmorphism cards. Mel Milaap brand typography.
   ========================================================= */

/* ---------- Tokens ---------- */
:root {
  --bg:           #ffffff;
  --surface:      rgba(255, 255, 255, 0.85);
  --surface-line: rgba(255, 255, 255, 0.6);

  --ink:          #1f1a14;
  --ink-soft:     #6b6055;
  --ink-faint:    #8a7a6a;
  --line:         #e8e0d0;
  --line-soft:    #f0ece4;

  --navy:         #1a1e2e;
  --navy-2:       #0d1219;
  --gold:         #c8a957;
  --gold-light:   #e8c97a;
  --gold-deep:    #8b6914;

  --green:        #4ade80;
  --green-deep:   #166534;
  --red:          #f87171;
  --red-deep:     #991b1b;

  --serif:        "Playfair Display", "Iowan Old Style", "Apple Garamond", Georgia, serif;
  --sans:         "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;

  --radius-card:  16px;
  --radius-input: 10px;
  --radius-pill:  999px;

  --shadow-card:  0 4px 24px rgba(0, 0, 0, 0.06), 0 1px 4px rgba(0, 0, 0, 0.04);
  --shadow-lift:  0 12px 36px rgba(0, 0, 0, 0.10), 0 2px 8px rgba(0, 0, 0, 0.05);
  --shadow-panel: 0 8px 32px rgba(0, 0, 0, 0.30), inset 0 1px 0 rgba(255, 255, 255, 0.1);

  --ease:         cubic-bezier(0.4, 0, 0.2, 1);

  --safe-top:     env(safe-area-inset-top, 0px);
  --safe-bot:     env(safe-area-inset-bottom, 0px);
}

/* ---------- Reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}
body {
  margin: 0;
  font-family: var(--sans);
  font-weight: 400;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
h1, h2, h3 {
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.2;
  margin: 0;
  letter-spacing: -0.005em;
}
p { margin: 0; }
button { font-family: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }

.hidden { display: none !important; }

/* Reveal animation */
.reveal {
  opacity: 0;
  transform: translateY(8px);
  animation: revealIn 0.5s var(--ease) forwards;
}
.reveal:nth-child(1) { animation-delay: 0.04s; }
.reveal:nth-child(2) { animation-delay: 0.10s; }
.reveal:nth-child(3) { animation-delay: 0.16s; }
.reveal:nth-child(4) { animation-delay: 0.22s; }
.reveal:nth-child(5) { animation-delay: 0.28s; }
.reveal:nth-child(6) { animation-delay: 0.34s; }
@keyframes revealIn {
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .reveal { opacity: 1; transform: none; animation: none; }
  * { transition: none !important; }
}

/* ---------- Connection banner ---------- */
.banner {
  background: #fee2e2;
  color: var(--red-deep);
  padding: 10px 16px;
  padding-top: calc(10px + var(--safe-top));
  font-family: var(--sans);
  font-size: 0.9rem;
  font-weight: 500;
  text-align: center;
  border-bottom: 1px solid #fecaca;
}

/* ---------- Header ---------- */
.site-header {
  background: var(--navy);
  color: #ffffff;
  padding: calc(30px + var(--safe-top)) 20px 30px;
  text-align: center;
  position: relative;
}
.site-header::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(200, 169, 87, 0.6), transparent);
}
.header-inner {
  max-width: 680px;
  margin: 0 auto;
}
.site-header h1 {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
  color: #ffffff;
  letter-spacing: 0.1em;
  line-height: 1.15;
}
.site-header .sub {
  margin-top: 8px;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.15em;
  color: var(--gold);
  text-transform: none;
}

/* ---------- Container ---------- */
.container {
  max-width: 420px;
  margin: 0 auto;
  padding: 20px 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ---------- Generic card (glass) ---------- */
.card {
  background: rgba(255, 255, 255, 0.85);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.6);
  box-shadow: var(--shadow-card);
  border-radius: var(--radius-card);
  padding: 22px 20px;
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lift);
}
.card h2 {
  font-family: var(--serif);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 14px;
  letter-spacing: -0.005em;
}

/* ---------- Dark summary panel ---------- */
.summary-panel {
  background: var(--navy);
  background-image: linear-gradient(180deg, #1c2032 0%, #14182a 100%);
  color: #ffffff;
  border-radius: var(--radius-card);
  padding: 6px;
  box-shadow: var(--shadow-panel);
}
.summary-panel .panel-inner {
  background: rgba(255, 255, 255, 0.05);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.30), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 18px 6px;
  display: grid;
  grid-template-columns: 1fr 1px 1fr 1px 1fr;
  align-items: center;
}
.metric {
  padding: 4px 10px;
  text-align: center;
  min-width: 0;
}
.metric-label {
  font-family: var(--sans);
  font-size: 9.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.55);
  font-weight: 500;
  margin-bottom: 8px;
  white-space: nowrap;
}
.metric-value {
  font-family: var(--serif);
  font-size: clamp(1rem, 4.6vw, 1.4rem);
  font-weight: 600;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  word-break: break-all;
}
.v-accrued { color: var(--gold); }
.v-balance { color: var(--green); }
.v-deficit { color: var(--red); transition: color 400ms var(--ease); }
#deficit-card.is-clear .v-deficit { color: var(--green); }
.metric-divider {
  height: 38px;
  width: 1px;
  background: rgba(255, 255, 255, 0.12);
  justify-self: center;
}

/* ---------- Progress ---------- */
.progress-section {
  padding: 14px 4px 0;
}
.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
}
.progress-label {
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.progress-pct {
  font-family: var(--serif);
  font-size: 14px;
  color: var(--gold-deep);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.progress-track {
  height: 8px;
  background: var(--line-soft);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gold), var(--gold-light));
  border-radius: var(--radius-pill);
  box-shadow: 0 0 8px rgba(200, 169, 87, 0.4);
  transition: width 0.6s var(--ease);
}

/* ---------- Schedule info ---------- */
.schedule-box {
  background: rgba(255, 255, 255, 0.85);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-left: 3px solid var(--gold);
  border-radius: var(--radius-card);
  padding: 14px 16px;
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--ink-soft);
  line-height: 1.55;
  box-shadow: var(--shadow-card);
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.schedule-box:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lift);
}
.schedule-box p { display: flex; flex-direction: column; gap: 4px; }
.sched-line { display: block; }
.sched-key { font-weight: 600; color: var(--ink); }

/* ---------- Form ---------- */
.form-card { padding: 22px 20px; }
.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field > span {
  font-family: var(--sans);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.field input,
.field select {
  font-family: var(--sans);
  font-size: 16px;            /* avoid iOS auto-zoom */
  font-weight: 400;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  border-radius: var(--radius-input);
  padding: 13px 14px;
  min-height: 48px;
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 150ms var(--ease), box-shadow 150ms var(--ease), background 150ms var(--ease);
}
.field input:hover,
.field select:hover { border-color: #d6c8aa; }
.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(200, 169, 87, 0.15);
  background: #ffffff;
}
.field select {
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink-soft) 50%),
    linear-gradient(135deg, var(--ink-soft) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 50%,
    calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 36px;
}
.field-full { margin-top: 14px; }

.form-error {
  margin-top: 12px;
  font-family: var(--sans);
  color: var(--red-deep);
  background: #fee2e2;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 500;
}

.form-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 18px;
}
.quick-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* Buttons */
.btn {
  font-family: var(--sans);
  font-weight: 500;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  padding: 14px 20px;
  border-radius: var(--radius-input);
  min-height: 48px;
  width: 100%;
  border: 1.5px solid transparent;
  transition: transform 80ms var(--ease),
              background 200ms var(--ease),
              border-color 200ms var(--ease),
              box-shadow 200ms var(--ease),
              color 200ms var(--ease);
}
.btn:active { transform: scale(0.985); }
.btn-primary {
  background: var(--navy);
  color: var(--gold);
  border-color: var(--navy);
  box-shadow: 0 2px 8px rgba(26, 30, 46, 0.15);
}
.btn-primary:hover {
  background: var(--navy-2);
  box-shadow: 0 4px 16px rgba(26, 30, 46, 0.30);
}
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-outline {
  background: transparent;
  color: var(--gold-deep);
  border-color: var(--gold);
  padding: 12px 16px;
  font-size: 0.88rem;
}
.btn-outline:hover {
  background: rgba(200, 169, 87, 0.08);
  border-color: var(--gold-deep);
}
.btn-outline:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Repayment planner ---------- */
.planner-box {
  background: rgba(254, 226, 226, 0.5);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-left: 4px solid var(--red);
  border-radius: var(--radius-card);
  padding: 22px 20px;
  box-shadow: var(--shadow-card);
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.planner-box:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lift);
}
.planner-box h2 {
  font-family: var(--serif);
  font-size: 1.05rem;
  color: #9f1239;
  font-weight: 600;
  margin-bottom: 14px;
}
.planner-output { margin-top: 14px; }
.planner-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 0;
  border-top: 1px solid rgba(248, 113, 113, 0.20);
}
.planner-row:first-child { border-top: none; padding-top: 6px; }
.planner-label {
  font-family: var(--sans);
  color: #9f1239;
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.planner-value {
  font-family: var(--serif);
  color: var(--ink);
  font-weight: 600;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.planner-summary {
  margin-top: 10px;
  font-family: var(--sans);
  font-size: 0.85rem;
  color: #9f1239;
  line-height: 1.55;
}

/* ---------- Entry log ---------- */
.log-card { padding: 22px 20px; }
.entry-log { display: flex; flex-direction: column; gap: 10px; }
.log-empty {
  font-family: var(--sans);
  color: var(--ink-faint);
  text-align: center;
  padding: 24px 8px;
  font-size: 0.9rem;
}

/* Mobile: per-entry glass card */
.log-row {
  position: relative;
  background: rgba(255, 255, 255, 0.9);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-left: 4px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.log-row:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lift);
}
.log-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 8px;
}
.log-date {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
  margin-bottom: 4px;
}
.log-amount {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  line-height: 1.15;
}
.log-notes {
  margin-top: 6px;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--ink-faint);
  line-height: 1.45;
  word-break: break-word;
}
.log-delete {
  background: transparent;
  border: none;
  color: var(--ink-faint);
  font-size: 22px;
  line-height: 1;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
  transition: background 150ms var(--ease), color 150ms var(--ease);
}
.log-delete:hover { background: #fee2e2; color: var(--red-deep); }

.amount-positive { color: var(--green-deep); }
.amount-negative { color: var(--red-deep); }

/* Type badges (pills) */
.type-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.4;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Per-type colours (badges + log row left border) */
.type-dasvandh_leg_archform.type-badge { background: #dcfce7; color: #166534; }
.type-dasvandh_abnaasi.type-badge       { background: #ccfbf1; color: #0f766e; }
.type-deficit_repayment.type-badge      { background: #dbeafe; color: #1d4ed8; }
.type-gurdwara_disbursement.type-badge  { background: #ffedd5; color: #9a3412; }
.type-emergency_withdrawal.type-badge   { background: #fee2e2; color: #991b1b; }

.log-row.type-dasvandh_leg_archform { border-left-color: #166534; }
.log-row.type-dasvandh_abnaasi       { border-left-color: #0f766e; }
.log-row.type-deficit_repayment      { border-left-color: #1d4ed8; }
.log-row.type-gurdwara_disbursement  { border-left-color: #9a3412; }
.log-row.type-emergency_withdrawal   { border-left-color: #991b1b; }

/* Desktop table hidden on mobile */
.log-table { display: none; }

/* ---------- Footer ---------- */
.site-footer {
  background: var(--navy);
  color: var(--gold);
  text-align: center;
  padding: 18px 16px calc(18px + var(--safe-bot));
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.1em;
  margin-top: 12px;
}
.site-footer p { opacity: 0.9; font-weight: 400; }

/* =========================================================
   DESKTOP / TABLET (>= 641px)
   ========================================================= */
@media (min-width: 641px) {
  .site-header { padding: 36px 24px 36px; }
  .site-header h1 { font-size: 26px; }
  .site-header .sub { font-size: 13px; }

  .container {
    max-width: 680px;
    padding: 28px 24px 40px;
    gap: 22px;
  }

  .summary-panel { padding: 8px; }
  .summary-panel .panel-inner { padding: 26px 14px; }
  .metric { padding: 4px 14px; }
  .metric-label { font-size: 10.5px; margin-bottom: 10px; }
  .metric-value { font-size: 1.6rem; }
  .metric-divider { height: 48px; }

  .progress-section { padding: 8px 4px 0; }
  .progress-pct { font-size: 15px; }

  .schedule-box {
    padding: 14px 18px;
    font-size: 0.9rem;
  }
  .schedule-box p { flex-direction: row; gap: 18px; flex-wrap: wrap; }

  .form-grid {
    grid-template-columns: 1fr 1.4fr 1fr;
    gap: 14px;
  }

  /* Quick buttons stay side-by-side on desktop too */
  .planner-value { font-size: 22px; }

  /* Desktop log: switch to table */
  .entry-log.has-rows .log-row { display: none; }
  .entry-log.has-rows .log-table {
    display: table;
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
  }
  .log-table th, .log-table td {
    text-align: left;
    padding: 14px 12px;
    border-bottom: 1px solid var(--line);
    font-family: var(--sans);
    font-size: 0.9rem;
    vertical-align: middle;
  }
  .log-table th {
    color: var(--ink-faint);
    font-weight: 600;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding-bottom: 10px;
    border-bottom: 1px solid #d9cbb2;
  }
  .log-table tbody tr:nth-child(even) { background: rgba(248, 244, 235, 0.5); }
  .log-table tbody tr:hover { background: rgba(248, 244, 235, 0.85); }
  .log-table tbody tr:last-child td { border-bottom: none; }
  .log-table td.col-amount {
    font-family: var(--serif);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    text-align: right;
    white-space: nowrap;
    font-size: 1rem;
    letter-spacing: -0.01em;
  }
  .log-table td.col-date {
    font-variant-numeric: tabular-nums;
    color: var(--ink-soft);
    white-space: nowrap;
    font-size: 0.85rem;
  }
  .log-table td.col-notes {
    color: var(--ink-soft);
    font-size: 0.85rem;
  }
  .log-table td.col-delete { text-align: right; width: 1%; }
  .log-table .log-delete {
    width: 30px;
    height: 30px;
    font-size: 20px;
  }
}
