/* ═══════════════════════════════════════════════
   AJV Credits — Responsive Stylesheet
   Mobile-first, works on all screen sizes
═══════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:            #F8F7F4;
  --surface:       #FFFFFF;
  --surface2:      #F1EFE8;
  --border:        #D3D1C7;
  --border2:       #B4B2A9;
  --text:          #2C2C2A;
  --muted:         #5F5E5A;
  --hint:          #888780;
  --accent:        #185FA5;
  --accent-hover:  #0C447C;
  --accent-light:  #E6F1FB;
  --success:       #3B6D11;
  --success-light: #EAF3DE;
  --danger:        #A32D2D;
  --danger-light:  #FCEBEB;
  --warn:          #854F0B;
  --warn-light:    #FAEEDA;
  --purple:        #534AB7;
  --purple-light:  #EEEDFE;
  --sidebar-w:     220px;
  --topbar-h:      56px;
  --radius:        8px;
  --radius-lg:     10px;
  --touch-min:     44px;  /* minimum tap target */
}

/* ── Base ───────────────────────────────────── */
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
}

/* ═══════════════════════════════════════════
   LAYOUT — Sidebar + Main
═══════════════════════════════════════════ */
.app-shell  { display: flex; min-height: 100vh; }

/* Sidebar — desktop default */
.sidebar {
  width: var(--sidebar-w);
  background: #2C2C2A;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  transition: transform 0.25s ease;
}
.main-wrap {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
}

/* Overlay (mobile only) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 199;
}
.sidebar-overlay.open { display: block; }

/* ── Logo ───────────────────────────────── */
.logo {
  display: flex;
  align-items: center;
  padding: 18px 20px 16px;
  border-bottom: 1px solid #3a3a38;
  color: #fff;
  flex-shrink: 0;
}
.logo-name  { font-size: 18px; font-weight: 700; letter-spacing: -0.2px; white-space: nowrap; color: #fff; }
.logo-name::first-letter { color: #4FA3E8; } /* highlight the A for a subtle accent */
.logo-sub   { font-size: 10px; color: #888; letter-spacing: 1.2px; text-transform: uppercase; margin-top: 2px; }

/* ── Nav ───────────────────────────────── */
.nav        { flex: 1; padding: 10px 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.nav-footer { border-top: 1px solid #3a3a38; padding: 8px 0; flex-shrink: 0; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  min-height: var(--touch-min);
  color: #aaa;
  font-size: 13px;
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: all 0.12s;
  white-space: nowrap;
}
.nav-item:hover  { color: #fff; background: rgba(255,255,255,0.06); }
.nav-item.active { color: #fff; background: rgba(255,255,255,0.09); border-left-color: var(--accent); }
.nav-icon { width: 18px; text-align: center; flex-shrink: 0; }

/* ── Top bar ───────────────────────────── */
.top-bar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 0.5px solid var(--border);
  padding: 0 16px 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 10px;
}
.page-title    { font-size: 15px; font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-bar-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.top-date      { font-size: 11px; color: var(--muted); white-space: nowrap; }
.user-pill     { background: var(--accent-light); color: var(--accent); font-size: 12px; padding: 3px 10px; border-radius: 20px; font-weight: 500; white-space: nowrap; }

/* Hamburger button — hidden on desktop */
.hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  color: var(--muted);
  flex-shrink: 0;
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
}
.hamburger:hover { background: var(--surface2); }
.hamburger svg   { display: block; }

/* Content area */
.content { padding: 16px; flex: 1; }

/* ═══════════════════════════════════════════
   METRIC GRIDS
═══════════════════════════════════════════ */
.metrics   { display: grid; grid-template-columns: repeat(4,1fr); gap: 10px; margin-bottom: 16px; }
.metrics-3 { grid-template-columns: repeat(3,1fr); }
.metrics-2 { grid-template-columns: repeat(2,1fr); }
.metric    { background: var(--surface2); border-radius: var(--radius); padding: 12px 14px; }
.metric-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }
.metric-value { font-size: 22px; font-weight: 500; line-height: 1.2; }
.metric-sub   { font-size: 11px; color: var(--muted); margin-top: 2px; }
.metric.danger  { background: var(--danger-light); }
.metric.danger  .metric-label, .metric.danger  .metric-value { color: var(--danger); }
.metric.success { background: var(--success-light); }
.metric.success .metric-label, .metric.success .metric-value { color: var(--success); }
.metric.warn    { background: var(--warn-light); }
.metric.warn    .metric-label, .metric.warn    .metric-value { color: var(--warn); }

/* ═══════════════════════════════════════════
   CARD
═══════════════════════════════════════════ */
.card       { background: var(--surface); border: 0.5px solid var(--border); border-radius: var(--radius-lg); margin-bottom: 16px; }
.card-head  { padding: 12px 16px; border-bottom: 0.5px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.card-title { font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
.card-body  { padding: 16px; }
.card-table { padding: 0; overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ── Grid 2 ─────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }

/* ═══════════════════════════════════════════
   TABLE
═══════════════════════════════════════════ */
table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 480px; }
th {
  text-align: left;
  padding: 9px 12px;
  color: var(--muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 0.5px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--surface);
}
td { padding: 10px 12px; border-bottom: 0.5px solid var(--border); vertical-align: middle; }
tbody tr:last-child td  { border-bottom: none; }
tbody tr:hover td        { background: var(--surface2); }
.delinquent-row td       { background: #FFF8F8; }
.delinquent-row:hover td { background: #FFF0F0; }

/* ═══════════════════════════════════════════
   BADGE
═══════════════════════════════════════════ */
.badge        { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 500; white-space: nowrap; }
.badge-success{ background: var(--success-light); color: var(--success); }
.badge-danger { background: var(--danger-light);  color: var(--danger); }
.badge-warn   { background: var(--warn-light);    color: var(--warn); }
.badge-info   { background: var(--accent-light);  color: var(--accent); }
.badge-gray   { background: var(--surface2);      color: var(--muted); }
.badge-purple { background: var(--purple-light);  color: var(--purple); }

/* ═══════════════════════════════════════════
   BUTTONS
═══════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 8px 14px;
  min-height: 36px;
  border-radius: var(--radius);
  border: 0.5px solid var(--border2);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.12s;
  font-family: inherit;
  white-space: nowrap;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn:hover          { background: var(--surface2); }
.btn-primary        { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover  { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-sm             { padding: 5px 10px; font-size: 12px; min-height: 30px; }
.btn-danger         { background: var(--danger-light); color: var(--danger); border-color: #F7C1C1; }
.btn-danger:hover   { background: #F7C1C1; }
.btn-success        { background: var(--success-light); color: var(--success); border-color: #C0DD97; }
.btn-success:hover  { background: #C0DD97; }

/* ═══════════════════════════════════════════
   FORMS
═══════════════════════════════════════════ */
.form-group { margin-bottom: 14px; }
label { display: block; font-size: 12px; color: var(--muted); font-weight: 500; margin-bottom: 5px; }
input[type=text], input[type=number], input[type=email],
input[type=password], input[type=month], input[type=date],
select, textarea {
  width: 100%;
  padding: 10px 12px;
  min-height: var(--touch-min);
  border: 0.5px solid var(--border2);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border 0.12s;
  -webkit-appearance: none;
  appearance: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(24,95,165,0.1); }
.form-row   { display: grid; gap: 12px; }
.form-row-2 { grid-template-columns: 1fr 1fr; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-hint  { font-size: 11px; color: var(--hint); margin-top: 3px; }
.computed-box { background: var(--surface2); border-radius: var(--radius); padding: 12px 14px; font-size: 13px; color: var(--muted); border: 0.5px solid var(--border); }
.computed-box strong { color: var(--text); font-size: 18px; display: block; margin: 4px 0; }
.formula { font-size: 10px; font-family: 'Courier New', monospace; color: var(--hint); margin-top: 4px; }

/* ═══════════════════════════════════════════
   PROGRESS BAR
═══════════════════════════════════════════ */
.prog-wrap { width: 90px; }
.prog-bar  { height: 5px; background: var(--surface2); border-radius: 3px; overflow: hidden; margin-top: 4px; border: 0.5px solid var(--border); }
.prog-fill { height: 100%; border-radius: 3px; background: var(--accent); }
.prog-fill.warn    { background: var(--warn); }
.prog-fill.success { background: var(--success); }

/* ═══════════════════════════════════════════
   MODAL
═══════════════════════════════════════════ */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 300; align-items: center; justify-content: center; padding: 16px; }
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: fadeScaleIn 0.18s ease;
  box-shadow: 0 8px 40px rgba(0,0,0,0.18);
}
@keyframes fadeScaleIn { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }
.modal-title  { font-size: 16px; font-weight: 500; margin-bottom: 20px; display: flex; justify-content: space-between; align-items: center; }
.modal-close  { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--muted); line-height: 1; padding: 4px; min-width: 36px; min-height: 36px; display: flex; align-items: center; justify-content: center; border-radius: 50%; }
.modal-close:hover { background: var(--surface2); }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; padding-top: 16px; border-top: 0.5px solid var(--border); flex-wrap: wrap; }
.modal-lg { max-width: 700px; }
.modal-sm { max-width: 420px; }

/* ═══════════════════════════════════════════
   TABS
═══════════════════════════════════════════ */
.tabs       { display: flex; border-bottom: 0.5px solid var(--border); margin-bottom: 16px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tab-btn    { padding: 10px 16px; font-size: 13px; cursor: pointer; color: var(--muted); border: none; background: none; border-bottom: 2px solid transparent; transition: all 0.12s; font-family: inherit; white-space: nowrap; min-height: var(--touch-min); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-pane         { display: none; }
.tab-pane.active  { display: block; }

/* ═══════════════════════════════════════════
   FILTER BAR
═══════════════════════════════════════════ */
.filter-bar { display: flex; gap: 8px; margin-bottom: 14px; align-items: center; flex-wrap: wrap; }
.filter-bar input[type=text],
.filter-bar input[type=month] { width: auto; flex: 1; min-width: 140px; }
.pill-filter {
  padding: 6px 12px;
  border-radius: 20px;
  border: 0.5px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.1s;
  text-decoration: none;
  white-space: nowrap;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
}
.pill-filter.active { background: var(--text); color: #fff; border-color: var(--text); }

/* ═══════════════════════════════════════════
   ALERTS
═══════════════════════════════════════════ */
.alert        { padding: 12px 16px; border-radius: var(--radius); font-size: 13px; margin-bottom: 14px; }
.alert-info   { background: var(--accent-light); color: var(--accent);  border: 0.5px solid #B5D4F4; }
.alert-danger { background: var(--danger-light); color: var(--danger);  border: 0.5px solid #F7C1C1; }
.alert-success{ background: var(--success-light);color: var(--success); border: 0.5px solid #C0DD97; }
.alert-warn   { background: var(--warn-light);   color: var(--warn);    border: 0.5px solid #FAC775; }

/* ═══════════════════════════════════════════
   LOGIN PAGE
═══════════════════════════════════════════ */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 16px; }
.login-card { background: var(--surface); border: 0.5px solid var(--border); border-radius: 14px; padding: 32px 28px; width: 100%; max-width: 380px; }
.login-logo { text-align: center; margin-bottom: 24px; }
.login-logo h2 { font-size: 20px; font-weight: 600; color: var(--text); }
.login-logo p  { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ═══════════════════════════════════════════
   SECTION HEADER / MISC
═══════════════════════════════════════════ */
.section-head  { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 8px; flex-wrap: wrap; }
.section-title { font-size: 14px; font-weight: 500; }
.empty-state   { text-align: center; padding: 32px 20px; color: var(--muted); font-size: 13px; }
.text-danger   { color: var(--danger); font-weight: 500; }
.text-muted    { color: var(--muted); }
.text-right    { text-align: right; }
.fw-500        { font-weight: 500; }
.small         { font-size: 11px; color: var(--muted); }
.amort-tbl th, .amort-tbl td { padding: 7px 10px; }

/* ═══════════════════════════════════════════
   PAGINATION
═══════════════════════════════════════════ */
.pagination  { display: flex; align-items: center; gap: 4px; padding: 12px 14px; border-top: 0.5px solid var(--border); flex-wrap: wrap; }
.page-btn    { display: inline-flex; align-items: center; justify-content: center; min-width: 36px; height: 36px; padding: 0 8px; border-radius: 6px; border: 0.5px solid var(--border); background: var(--surface); color: var(--text); font-size: 13px; text-decoration: none; cursor: pointer; transition: all 0.12s; -webkit-tap-highlight-color: transparent; }
.page-btn:hover   { background: var(--surface2); border-color: var(--border2); }
.page-btn.active  { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 500; }
.page-btn.disabled{ color: var(--muted); cursor: default; pointer-events: none; }
.page-btn.dots    { border: none; background: none; cursor: default; }
.page-info        { margin-left: auto; font-size: 11px; color: var(--muted); white-space: nowrap; }

/* ═══════════════════════════════════════════
   FINANCIAL OVERVIEW PANEL
═══════════════════════════════════════════ */
.overview-panel { background: var(--surface); border: 0.5px solid var(--border); border-radius: var(--radius-lg); margin-bottom: 16px; overflow: hidden; }
.overview-header { display: flex; align-items: flex-start; justify-content: space-between; padding: 14px 16px; border-bottom: 0.5px solid var(--border); flex-wrap: wrap; gap: 10px; }
.overview-title  { font-size: 14px; font-weight: 600; color: var(--text); }
.overview-period { font-size: 12px; color: var(--muted); margin-top: 2px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.overview-preset-label { background: var(--accent-light); color: var(--accent); font-size: 10px; padding: 1px 7px; border-radius: 10px; font-weight: 500; }
.overview-presets { display: flex; gap: 4px; flex-wrap: wrap; }
.preset-btn { padding: 5px 11px; border-radius: 20px; border: 0.5px solid var(--border); background: var(--surface); color: var(--muted); font-size: 11px; cursor: pointer; text-decoration: none; transition: all 0.12s; white-space: nowrap; min-height: 30px; display: inline-flex; align-items: center; }
.preset-btn:hover  { background: var(--surface2); color: var(--text); }
.preset-btn.active { background: var(--text); color: #fff; border-color: var(--text); }
.overview-date-form { padding: 10px 16px; border-bottom: 0.5px solid var(--border); background: var(--surface2); }
.overview-grid { display: grid; grid-template-columns: repeat(6,1fr); }
.ov-card { padding: 16px 14px; border-right: 0.5px solid rgba(255,255,255,0.15); position: relative; }
.ov-card:last-child { border-right: none; }
.ov-icon  { font-size: 16px; opacity: 0.5; margin-bottom: 6px; }
.ov-label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px; opacity: 0.8; margin-bottom: 4px; }
.ov-value { font-size: 18px; font-weight: 600; margin-bottom: 4px; line-height: 1.1; letter-spacing: -0.3px; word-break: break-all; }
.ov-sub   { font-size: 10px; opacity: 0.75; line-height: 1.4; }
.ov-blue         { background: #1565A8; color: #fff; }
.ov-purple       { background: #533AB7; color: #fff; }
.ov-green        { background: #2D6A0F; color: #fff; }
.ov-teal         { background: #0F6B5C; color: #fff; }
.ov-amber        { background: #7A4500; color: #fff; }
.ov-net-positive { background: #185F44; color: #fff; }
.ov-net-negative { background: #8B1A1A; color: #fff; }

/* small inline tag for KPI labels (e.g. "live") */
.ov-tag { display: inline-block; margin-left: 6px; padding: 1px 6px; font-size: 9px; font-weight: 700; letter-spacing: 0.5px; border-radius: 8px; background: rgba(255,255,255,0.18); color: inherit; vertical-align: middle; cursor: help; }

/* ═══════════════════════════════════════════
   DATE FILTER POPOVER (.dfp = date filter popover)
   ═══════════════════════════════════════════ */
.dfp { display: inline-block; position: relative; }

/* Trigger button — single chip that shows current selection */
.dfp-trigger {
  display: inline-flex; align-items: center; gap: 12px;
  padding: 8px 14px;
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  min-width: 180px;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.dfp-trigger:hover { border-color: var(--text); }
.dfp-trigger[aria-expanded="true"] { border-color: var(--accent, #1565A8); box-shadow: 0 0 0 3px rgba(21, 101, 168, 0.12); }
.dfp-trigger-icon { font-size: 18px; opacity: 0.7; }
.dfp-trigger-text { display: flex; flex-direction: column; align-items: flex-start; flex: 1; line-height: 1.15; }
.dfp-trigger-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); font-weight: 600; }
.dfp-trigger-value { font-size: 14px; font-weight: 600; }
.dfp-trigger-caret { color: var(--muted); font-size: 10px; }

/* Popover panel — uses position:fixed so it escapes any ancestor's
   `overflow: hidden` or `border-radius` clipping. JavaScript positions
   it just below the trigger, aligned to its right edge. */
.dfp-popover {
  position: fixed;
  width: 380px; max-width: calc(100vw - 32px);
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.10);
  z-index: 10000;
  padding: 18px 18px 14px;
  display: none;
}
.dfp-popover.open { display: block; }

/* Sections */
.dfp-section { margin-bottom: 18px; }
.dfp-section:last-of-type { margin-bottom: 14px; }
.dfp-section-title {
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.7px;
  color: var(--muted);
  margin-bottom: 10px;
}

/* Quick preset pills */
.dfp-presets { display: flex; flex-wrap: wrap; gap: 6px; }
.dfp-pill {
  padding: 6px 14px;
  font-size: 12px; font-weight: 500;
  background: transparent;
  border: 0.5px solid var(--border);
  border-radius: 20px;
  color: var(--text);
  cursor: pointer;
  transition: all 0.12s;
}
.dfp-pill:hover { border-color: var(--text); }
.dfp-pill.active {
  background: #1A3A6B;
  color: #fff;
  border-color: #1A3A6B;
}

/* Year / Month row */
.dfp-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dfp-field { display: flex; flex-direction: column; gap: 5px; }
.dfp-field-label { font-size: 11px; font-weight: 600; color: var(--text); text-transform: uppercase; letter-spacing: 0.4px; }
.dfp-field select, .dfp-field input[type="date"] {
  padding: 7px 10px;
  font-size: 13px;
  border: 0.5px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  min-height: 34px;
}
.dfp-field select:disabled { opacity: 0.55; cursor: not-allowed; }
.dfp-field select:focus, .dfp-field input:focus { outline: none; border-color: var(--accent, #1565A8); box-shadow: 0 0 0 2px rgba(21, 101, 168, 0.15); }

/* Quarter buttons */
.dfp-quarters { display: flex; align-items: center; gap: 6px; margin-top: 10px; }
.dfp-quarters-label { font-size: 11px; color: var(--muted); margin-right: 4px; }
.dfp-quarter-btn {
  width: 36px; height: 28px;
  font-size: 11px; font-weight: 600;
  background: transparent;
  border: 0.5px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  cursor: pointer;
  transition: all 0.12s;
}
.dfp-quarter-btn:hover { border-color: var(--text); }
.dfp-quarter-btn.active { background: #1A3A6B; color: #fff; border-color: #1A3A6B; }

/* Action footer */
.dfp-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  padding-top: 14px;
  border-top: 0.5px solid var(--border);
  margin-top: 4px;
}

/* Mobile */
@media (max-width: 600px) {
  .dfp-popover {
    position: fixed;
    top: auto; bottom: 0; left: 0; right: 0;
    width: 100%; max-width: 100%;
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -8px 30px rgba(0,0,0,0.25);
  }
  .dfp-row { grid-template-columns: 1fr; }
}

/* ═══════════════════════════════════════════
   PAY TYPE BUTTONS (amortization)
═══════════════════════════════════════════ */
.pay-type-btn {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 6px;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
  text-align: center;
  transition: all 0.15s;
  font-family: inherit;
  min-height: var(--touch-min);
  -webkit-tap-highlight-color: transparent;
}
.pay-type-btn:hover  { background: var(--surface2); border-color: var(--border2); }
.pay-type-btn.active { background: #185FA5; color: #fff; border-color: #185FA5; }

/* ═══════════════════════════════════════════
   ██████  RESPONSIVE BREAKPOINTS  ██████
═══════════════════════════════════════════ */

/* ── Large tablet / small laptop (≤1024px) ── */
@media (max-width: 1024px) {
  .overview-grid { grid-template-columns: repeat(3,1fr); }
  .ov-card:nth-child(3) { border-right: none; }
  .ov-card:nth-child(3) ~ .ov-card { border-top: 0.5px solid rgba(255,255,255,0.15); }
}

/* ── Tablet portrait (≤768px) ─────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }

  /* Show hamburger, hide sidebar by default */
  .hamburger { display: flex; }
  .sidebar {
    transform: translateX(-220px);
    width: 220px;
  }
  .sidebar.open { transform: translateX(0); }
  .main-wrap { margin-left: 0; }

  /* Content tighter */
  .content { padding: 12px; }
  .top-bar { padding: 0 12px; }

  /* Metrics: 2 columns on tablet */
  .metrics   { grid-template-columns: repeat(2,1fr); gap: 8px; }
  .metrics-3 { grid-template-columns: repeat(2,1fr); }

  /* Grid stacks */
  .grid-2 { grid-template-columns: 1fr; gap: 12px; }

  /* Form rows collapse */
  .form-row-2, .form-row-3 { grid-template-columns: 1fr; gap: 10px; }

  /* Overview grid: 2 columns */
  .overview-grid { grid-template-columns: repeat(2,1fr); }
  .ov-card { border-right: none; border-bottom: 0.5px solid rgba(255,255,255,0.15); }
  .ov-card:nth-child(odd)  { border-right: 0.5px solid rgba(255,255,255,0.15); }
  .ov-card:last-child      { border-bottom: none; }

  /* Hide date on top bar */
  .top-date { display: none; }

  /* Card head wraps */
  .card-head { flex-wrap: wrap; gap: 8px; }

  /* Section head stacks */
  .section-head { flex-direction: column; align-items: stretch; }
  .section-head > * { width: 100%; }
  .section-head .btn { text-align: center; justify-content: center; }
}

/* ── Mobile landscape / large phone (≤600px) ─ */
@media (max-width: 600px) {
  .metrics { grid-template-columns: repeat(2,1fr); gap: 6px; margin-bottom: 12px; }
  .metric-value { font-size: 18px; }
  .metric { padding: 10px 12px; }

  /* Overview panel presets scroll horizontally */
  .overview-presets { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
  .overview-header  { flex-direction: column; }
  .overview-date-form > div { flex-direction: column; gap: 8px; }
  .overview-date-form input[type=date] { width: 100%; }

  /* Filter bar stacks */
  .filter-bar { gap: 6px; }

  /* Modal on mobile — keep centered but compact */
  .modal-overlay { padding: 12px; }
  .modal { padding: 18px 16px 24px; max-height: 88vh; }
  .modal-footer { flex-direction: column-reverse; }
  .modal-footer .btn { width: 100%; justify-content: center; }

  /* Pagination smaller */
  .page-btn { min-width: 32px; height: 32px; font-size: 12px; }
  .page-info { width: 100%; text-align: center; margin-left: 0; margin-top: 4px; }

  /* Login card full width */
  .login-card { padding: 24px 20px; }
}

/* ── Small phone portrait (≤390px) ────────── */
@media (max-width: 390px) {
  .content { padding: 10px; }
  .metrics { grid-template-columns: 1fr 1fr; gap: 6px; }
  .metric-value { font-size: 16px; }
  .metric-label { font-size: 9px; }

  /* Overview grid: single column on tiny screens */
  .overview-grid { grid-template-columns: 1fr; }
  .ov-card { border-right: none !important; border-bottom: 0.5px solid rgba(255,255,255,0.15); }

  /* Table font smaller */
  table { font-size: 12px; }
  th, td { padding: 8px; }

  .btn-sm { padding: 5px 8px; font-size: 11px; }
  .top-bar { padding: 0 10px; }
  .page-title { font-size: 14px; }
}

/* ── Landscape phone (short + wide) ───────── */
@media (max-height: 500px) and (orientation: landscape) {
  :root { --topbar-h: 48px; }
  .content { padding: 10px; }
  .modal { max-height: 85vh; border-radius: 10px; }
  .modal-overlay { align-items: center; }
  .metrics { grid-template-columns: repeat(4,1fr); gap: 6px; }
  .metric-value { font-size: 16px; }
}

/* ── Touch device enhancements ─────────────── */
@media (hover: none) and (pointer: coarse) {
  .btn       { min-height: var(--touch-min); }
  .nav-item  { min-height: var(--touch-min); }
  .pill-filter { min-height: 36px; padding: 8px 14px; }
  .page-btn  { min-width: 40px; height: 40px; }
  input[type=text], input[type=number], input[type=email],
  input[type=password], input[type=month], input[type=date],
  select, textarea { font-size: 16px; } /* prevents iOS zoom on focus */
}

/* ── Toast notifications ────────────────────────────────── */
.toast-container { position:fixed; bottom:24px; right:24px; z-index:1000; display:flex; flex-direction:column; gap:8px; pointer-events:none; }
.toast { display:flex; align-items:center; gap:10px; padding:12px 16px; border-radius:10px; font-size:13px; font-weight:500; color:#fff; min-width:260px; max-width:380px; box-shadow:0 4px 20px rgba(0,0,0,0.18); pointer-events:all; animation:toastIn 0.25s ease; }
.toast-success { background:#2D6A0F; }
.toast-danger  { background:#8B1A1A; }
.toast-warn    { background:#7A4500; }
.toast-info    { background:#0C447C; }
.toast-icon    { font-size:16px; flex-shrink:0; }
.toast-close   { margin-left:auto; background:none; border:none; color:rgba(255,255,255,0.7); cursor:pointer; font-size:16px; padding:0; line-height:1; }
.toast-close:hover { color:#fff; }
@keyframes toastIn  { from { transform:translateX(120%); opacity:0; } to { transform:translateX(0); opacity:1; } }
@keyframes toastOut { from { transform:translateX(0); opacity:1; } to { transform:translateX(120%); opacity:0; } }
@media (max-width:600px) { .toast-container { bottom:16px; right:12px; left:12px; } .toast { min-width:0; } }

/* ── Confirm dialog ─────────────────────────────────────── */
.confirm-overlay { display:none; position:fixed; inset:0; background:rgba(0,0,0,0.5); z-index:500; align-items:center; justify-content:center; padding:16px; }
.confirm-overlay.open { display:flex; }
.confirm-box  { background:var(--surface); border-radius:12px; padding:24px; max-width:380px; width:100%; box-shadow:0 8px 32px rgba(0,0,0,0.2); animation:fadeScaleIn 0.15s ease; }
.confirm-icon { font-size:32px; text-align:center; margin-bottom:12px; }
.confirm-msg  { font-size:14px; color:var(--text); text-align:center; margin-bottom:20px; line-height:1.5; }
.confirm-btns { display:flex; gap:8px; justify-content:center; }
.confirm-btns .btn { min-width:100px; }

/* ── Better action button group ─────────────────────────── */
.btn-group    { display:inline-flex; gap:4px; flex-wrap:wrap; }
.btn-icon     { padding:6px 8px; min-width:32px; }

/* ── Table row hover highlight ──────────────────────────── */
tbody tr { transition: background 0.1s; }

/* ── Sticky table header ─────────────────────────────────  */
.card-table { position:relative; }

/* ── Better form feedback ────────────────────────────────── */
input:invalid { border-color: var(--danger); }
input:valid:not(:placeholder-shown) { border-color: var(--success); }

/* ── Loading state on buttons ────────────────────────────── */
.btn.loading { opacity:0.7; pointer-events:none; }
.btn.loading::after { content:' ⟳'; display:inline-block; animation:spin 1s linear infinite; }
@keyframes spin { to { transform:rotate(360deg); } }

/* ── Breadcrumb ──────────────────────────────────────────── */
.breadcrumb { font-size:12px; color:var(--muted); margin-bottom:14px; display:flex; align-items:center; gap:6px; flex-wrap:wrap; }
.breadcrumb a { color:var(--accent); text-decoration:none; }
.breadcrumb a:hover { text-decoration:underline; }
.breadcrumb-sep { color:var(--border2); }

/* ── Loan type pill labels ───────────────────────────────── */
.loan-type-cash    { background:#E6F1FB; color:#185FA5; }
.loan-type-product { background:#EEEDFE; color:#534AB7; }

/* ── Status dot indicator ────────────────────────────────── */
.status-dot { display:inline-block; width:8px; height:8px; border-radius:50%; margin-right:5px; flex-shrink:0; }
.dot-active      { background:#3B6D11; }
.dot-completed   { background:#B4B2A9; }
.dot-delinquent  { background:#A32D2D; }
.dot-overdue     { background:#854F0B; }
.dot-recalculated{ background:#534AB7; }

/* ── Money input styling ─────────────────────────────────── */
.money-input {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.3px;
  text-align: right;
}
.money-input::placeholder { text-align: left; letter-spacing: normal; }
.money-wrap {
  position: relative;
}
.money-wrap::before {
  content: '₱';
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 13px;
  pointer-events: none;
  z-index: 1;
}
.money-wrap input {
  padding-left: 24px !important;
}