/* FundTrack Comp66 — Minimalist Fintech UI (Mercury/Stripe + Open Collective)
 * 100% Responsive + Safari Auto-Zoom Prevention (inputs >= 16px) + Print-ready Thai PDF Statement
 */
:root {
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --surface-subtle: #F1F5F9;
  --border: #E2E8F0;
  --text: #0F172A;
  --text-muted: #64748B;
  --primary: #4F46E5;
  --primary-hover: #4338CA;
  --emerald: #059669;
  --emerald-bg: #ECFDF5;
  --amber: #D97706;
  --amber-bg: #FFFBEB;
  --rose: #E11D48;
  --rose-bg: #FFF1F2;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 20px 50px rgba(15, 23, 42, 0.18);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans Thai', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* Safari Auto-Zoom Prevention: ALL form controls MUST be >= 16px */
input, select, textarea, button {
  font-family: inherit;
  font-size: 16px;
}

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

.tabular { font-variant-numeric: tabular-nums; }

/* Top Navbar */
.navbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.navbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
  color: var(--text);
  text-decoration: none !important;
}
.brand-badge {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 15px;
}
.nav-links {
  display: flex;
  align-items: center;
  gap: 6px;
}
.nav-link {
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none !important;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: var(--surface-subtle); color: var(--text); }
.nav-link.active { background: #EEF2FF; color: var(--primary); font-weight: 600; }

.nav-actions { display: flex; align-items: center; gap: 8px; }

/* Mobile Bottom Nav */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 45;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  justify-content: space-around;
}
.mobile-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 8px;
  text-decoration: none !important;
}
.mobile-nav a.active { color: var(--primary); font-weight: 600; }

/* Container */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 16px 80px;
}

/* Page Header */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.page-title { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.page-subtitle { margin: 4px 0 0; color: var(--text-muted); font-size: 14px; }

/* Cards & Grids */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}
.kpi-label { font-size: 13px; color: var(--text-muted); font-weight: 500; }
.kpi-value { font-size: 26px; font-weight: 700; margin-top: 6px; letter-spacing: -0.02em; }
.kpi-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.kpi-emerald .kpi-value { color: var(--emerald); }
.kpi-rose .kpi-value { color: var(--rose); }
.kpi-primary .kpi-value { color: var(--primary); }

.two-col {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

/* Progress Bars */
.cat-row { margin-bottom: 14px; }
.cat-row:last-child { margin-bottom: 0; }
.cat-head { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 6px; }
.progress-track { height: 8px; background: var(--surface-subtle); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 999px; transition: width 0.35s ease; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 9px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-emerald { background: var(--emerald); color: #fff; }
.btn-emerald:hover { background: #047857; }
.btn-rose { background: var(--rose); color: #fff; }
.btn-rose:hover { background: #BE123C; }
.btn-outline { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--surface-subtle); }
.btn-sm { padding: 6px 10px; font-size: 13px; border-radius: 7px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge-emerald { background: var(--emerald-bg); color: var(--emerald); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-rose { background: var(--rose-bg); color: var(--rose); }
.badge-slate { background: var(--surface-subtle); color: var(--text-muted); }
.badge-indigo { background: #EEF2FF; color: var(--primary); }

/* Forms */
.form-grid { display: grid; gap: 16px; }
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.input, .select, .textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px; /* Prevents Safari auto-zoom */
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.14);
}
.input-error { border-color: var(--rose) !important; background: #FFF5F6; }
.field-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* Table */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); background: #F8FAFC; font-weight: 600; }
tr:hover td { background: #FAFBFF; }
.tx-void td { opacity: 0.55; text-decoration: line-through; }

/* Filter Bar */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}
.filter-bar .input, .filter-bar .select { width: auto; flex: 1; min-width: 160px; }

/* Custom Modal (Replaces ALL browser alert/confirm/prompt) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-backdrop.open { display: flex; }
.modal-box {
  background: var(--surface);
  border-radius: 16px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  animation: modalIn 0.18s ease-out;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-title { margin: 0; font-size: 17px; font-weight: 700; }
.modal-close {
  background: var(--surface-subtle);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  color: var(--text-muted);
}
.modal-body { padding: 20px; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.slip-img {
  width: 100%;
  max-height: 60vh;
  object-fit: contain;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #F8FAFC;
}

/* Toast */
.toast-container {
  position: fixed;
  top: 72px;
  right: 16px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
}
.toast {
  background: var(--text);
  color: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: var(--shadow-md);
}
.toast-error { background: var(--rose); }
.toast-success { background: var(--emerald); }
.toast-warning { background: var(--amber); }

/* Responsive */
@media (max-width: 960px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 680px) {
  .nav-links { display: none; }
  .mobile-nav { display: flex; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-value { font-size: 20px; }
  .form-row-2 { grid-template-columns: 1fr; }
  .container { padding: 16px 12px 92px; }
  .page-title { font-size: 20px; }
}

/* Print / PDF Statement (Thai 100%) */
@media print {
  .navbar, .mobile-nav, .no-print, .filter-bar, .modal-backdrop, .toast-container { display: none !important; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; border: 1px solid #cbd5e1; break-inside: avoid; }
  .container { max-width: 100%; padding: 0; }
  .print-only { display: block !important; }
}
.print-only { display: none; }
