/* Estex Systems UI Standard v1.1 — light navy/gold baseline */
@font-face {
  font-family: "Poppins"; font-weight: 500; font-style: normal; font-display: swap;
  src: url("/fonts/poppins-latin-500-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Poppins"; font-weight: 600; font-style: normal; font-display: swap;
  src: url("/fonts/poppins-latin-600-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Poppins"; font-weight: 700; font-style: normal; font-display: swap;
  src: url("/fonts/poppins-latin-700-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Inter"; font-weight: 400; font-style: normal; font-display: swap;
  src: url("/fonts/inter-latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Inter"; font-weight: 500; font-style: normal; font-display: swap;
  src: url("/fonts/inter-latin-500-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Inter"; font-weight: 600; font-style: normal; font-display: swap;
  src: url("/fonts/inter-latin-600-normal.woff2") format("woff2");
}

:root {
  --navy-900: #0B1F3A;
  --navy-700: #13325C;
  --gold-500: #C9A24B;
  --gold-700: #8A6A1F;
  --gold-200: #E8D3A0;
  --bg: #F8F5EE;
  --surface: #FFFFFF;
  --border: #E3DCCB;
  --text: #1D2733;
  --text-muted: #5B6673;
  --ok-bg: #E3F1E6; --ok-text: #1E6B3A;
  --warn-bg: #FBEFD2; --warn-text: #7A5A00;
  --err-bg: #FADBD8; --err-text: #9B2C22;
  --shadow: 0 2px 4px rgba(11, 31, 58, 0.05);
  --radius: 8px;
  --radius-card: 10px;
  --sidebar-w: 248px;
  --font-head: "Poppins", "Segoe UI", system-ui, sans-serif;
  --font-body: "Inter", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 14px/1.55 var(--font-body);
}
h1, h2, h3 { font-family: var(--font-head); margin: 0 0 8px; color: var(--navy-900); }
h1 { font-size: 20px; font-weight: 600; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
a { color: var(--gold-700); font-weight: 500; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, .menu-btn:focus-visible {
  outline: 2px solid var(--gold-500);
  outline-offset: 2px;
}
.muted { color: var(--text-muted); }
.amt { font-variant-numeric: tabular-nums; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- shell ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
  background: var(--navy-900); color: var(--gold-200);
  display: flex; flex-direction: column; padding: 20px 16px;
  z-index: 30;
}
.brand { display: flex; gap: 10px; align-items: center; margin-bottom: 24px; }
.mark { width: 28px; height: 28px; color: var(--gold-500); flex: none; }
.mark-sm { width: 16px; height: 16px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { font: 600 16px var(--font-head); color: #fff; }
.brand-motto { font: 500 12px var(--font-body); color: var(--gold-200); }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  color: var(--gold-200); text-decoration: none; font-weight: 500;
  padding: 11px 12px; border-radius: var(--radius); min-height: 44px;
  display: flex; align-items: center;
}
.nav a:hover { background: var(--navy-700); }
.nav a.is-active { background: var(--navy-700); color: #fff; box-shadow: inset 3px 0 0 var(--gold-500); }
.sidebar-foot {
  margin-top: auto; display: flex; gap: 8px; align-items: center;
  color: var(--gold-200); font-size: 12px; padding-top: 16px;
  border-top: 1px solid rgba(232, 211, 160, 0.25);
}
.shell { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 12px 24px;
}
.topbar h1 { margin: 0; }
.who { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.who-name { font-weight: 600; }
.menu-btn { display: none; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: var(--radius); border: 1px solid var(--border); color: var(--navy-900); cursor: pointer; background: var(--surface); }
.nav-toggle { display: none; }

.content { padding: 24px; display: flex; flex-direction: column; gap: 16px; flex: 1; }

/* ---------- cards and layout ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-card); box-shadow: var(--shadow);
  padding: 16px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid-2 > *, .grid-3 > * { min-width: 0; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-card); box-shadow: var(--shadow);
  padding: 14px 16px; display: flex; flex-direction: column; gap: 4px;
}
.kpi-label { font-size: 12px; color: var(--text-muted); }
.kpi-value { font: 600 22px var(--font-head); color: var(--navy-900); }
.kpi-value.small { font-size: 15px; }
.kpi-emphasis { border-color: var(--gold-500); }
.kpi-emphasis .kpi-value { color: var(--gold-700); }
.member-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.member-name { font-size: 22px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ---------- tables ---------- */
.table-scroll { overflow-x: auto; }
.table-scroll.tall { max-height: 420px; overflow-y: auto; }
.table { width: 100%; border-collapse: collapse; min-width: 560px; }
.table thead th {
  background: var(--navy-900); color: var(--gold-200);
  font: 600 12px var(--font-body); text-align: left;
  padding: 10px 12px; position: sticky; top: 0;
}
.table tbody td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.table tbody tr:hover { background: var(--bg); }
.opening-row td, .closing-row td { background: var(--bg); font-weight: 600; }
.empty { color: var(--text-muted); margin: 8px 0 0; }

/* ---------- chips ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  border-radius: 999px; padding: 3px 10px;
  font: 600 11px var(--font-body); white-space: nowrap;
}
.chip-plain { background: var(--bg); color: var(--text-muted); border: 1px solid var(--border); }
.chip-gold { background: var(--gold-200); color: var(--navy-900); }
.chip-ok { background: var(--ok-bg); color: var(--ok-text); }
.chip-warn { background: var(--warn-bg); color: var(--warn-text); }
.chip-err { background: var(--err-bg); color: var(--err-text); }

/* ---------- forms ---------- */
.row-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row-form.tight { margin-top: 12px; }
.stack-form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-grow { flex: 1; }
.field label { font: 500 12px var(--font-body); color: var(--text-muted); }
.req { color: var(--err-text); }
.input {
  min-height: 44px; padding: 10px 12px; font: 400 16px var(--font-body);
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); width: 100%;
}
.input:focus { border-color: var(--gold-500); }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; min-height: 44px; }
.check input { width: 20px; height: 20px; accent-color: var(--gold-700); }
.guarantor-row { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; }
.inline { display: inline; margin: 0; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 10px 16px; border-radius: var(--radius);
  font: 600 14px var(--font-body); cursor: pointer; text-decoration: none;
  border: 1px solid transparent; background: transparent; color: var(--navy-900);
}
.btn-primary { background: var(--gold-500); color: var(--navy-900); }
.btn-primary:hover { background: var(--gold-700); color: #fff; }
.btn-outline { border-color: var(--navy-700); color: var(--navy-700); background: var(--surface); }
.btn-outline:hover { background: var(--navy-700); color: #fff; }
.btn-quiet { color: var(--gold-700); padding: 10px 8px; }
.btn-quiet:hover { text-decoration: underline; }
.btn-block { width: 100%; }

/* ---------- flash messages ---------- */
.flash { border-radius: var(--radius); padding: 12px 14px; font-weight: 500; }
.flash.err { background: var(--err-bg); color: var(--err-text); border: 1px solid rgba(155, 44, 34, 0.25); }
.flash.ok { background: var(--ok-bg); color: var(--ok-text); border: 1px solid rgba(30, 107, 58, 0.25); }

/* ---------- auth screen ---------- */
.auth-body { display: flex; flex-direction: column; min-height: 100vh; }
.auth-card {
  width: min(420px, calc(100% - 32px)); margin: auto; margin-top: 8vh;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-card); box-shadow: var(--shadow);
  padding: 24px; display: flex; flex-direction: column; gap: 16px;
}
.auth-brand { display: flex; gap: 12px; align-items: center; }
.auth-name { font: 600 20px var(--font-head); color: var(--navy-900); }
.auth-motto { font: 500 12px var(--font-body); color: var(--gold-700); }
.auth-lead { margin: 0; color: var(--text-muted); font-weight: 500; }
.auth-hint { margin: 0; font-size: 12px; color: var(--text-muted); }
.auth-footer { margin-top: auto; }

/* ---------- footer ---------- */
.app-footer {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 16px 24px 24px; border-top: 1px solid var(--border);
  color: var(--text-muted); font-size: 12px; text-align: center;
}
.foot-sign { display: flex; align-items: center; gap: 6px; color: var(--gold-700); font-weight: 600; }
.foot-tag { font-size: 11px; }

/* ---------- pills ---------- */
.pill-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.pill-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 4px 10px; font-size: 13px;
}

/* ---------- responsive ---------- */
@media (max-width: 1023px) {
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 767px) {
  .sidebar {
    transform: translateX(-100%); transition: transform 0.2s ease;
    width: min(300px, 84vw);
  }
  .nav-toggle:checked ~ .sidebar { transform: translateX(0); box-shadow: 8px 0 24px rgba(11, 31, 58, 0.25); }
  .nav-toggle:checked ~ .shell::after {
    content: ""; position: fixed; inset: 0; background: rgba(11, 31, 58, 0.35); z-index: 25;
  }
  .shell { margin-left: 0; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 10px 16px; }
  .content { padding: 16px; }
  .who-name { display: none; }
  .table { min-width: 520px; }
  .guarantor-row { grid-template-columns: 1fr; }
  .row-form { flex-direction: column; align-items: stretch; }
  .row-form .btn { width: 100%; }
  .member-head { flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}
