:root {
  --ink: #2b2b2b;
  --ink-2: #3a3a3a;
  --teal: #09757a;
  --teal-2: #0b8a90;
  --teal-soft: #e3f2f2;
  --paper: #ffffff;
  --cream: #f6f6f6;
  --line: #e2e2e2;
  --line-2: #d6d6d6;
  --text: #111111;
  --text-2: #555555;
  --text-3: #8a8a8a;
  --good: #12784f;
  --good-soft: #e6f7ef;
  --bad: #b3261e;
  --bad-soft: #fdeceb;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 12px 28px -12px rgba(0, 0, 0, 0.18);
  --shadow-lg: 0 4px 10px rgba(0, 0, 0, 0.08), 0 30px 60px -20px rgba(0, 0, 0, 0.25);
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--cream);
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1040px; margin: 0 auto; padding: 0 24px; }

h1, h2, h3 { margin: 0; letter-spacing: -0.01em; line-height: 1.15; }
p { margin: 0; line-height: 1.55; }

.hidden { display: none !important; }

.wordmark {
  flex: 0 0 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--teal);
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  white-space: nowrap;
  box-shadow: var(--shadow);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  font-size: 14.5px;
  font-weight: 700;
  padding: 13px 22px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.btn-primary {
  background: var(--teal);
  color: #fff;
  box-shadow: var(--shadow);
}
.btn-primary:hover { background: var(--teal-2); box-shadow: var(--shadow-lg); }
.btn-ghost-light {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.35);
  color: #fff;
}
.btn-ghost-light:hover { background: rgba(255, 255, 255, 0.18); }
.btn-outline {
  background: var(--paper);
  border-color: var(--line-2);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.btn-block { width: 100%; }

/* ---------------- login ---------------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--ink);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 20px;
  padding: 40px 32px;
  backdrop-filter: blur(8px);
  color: #fff;
}
.login-card .brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}
.login-card .brand-row span { font-weight: 800; font-size: 17px; }
.login-card h1 { font-size: 22px; color: #fff; }
.login-card p.lead { margin-top: 8px; font-size: 13.8px; color: #c2c2c2; }
.field { margin-top: 20px; }
.field label { display: block; font-size: 12.5px; font-weight: 700; color: #d4d4d4; margin-bottom: 6px; }
.field input {
  width: 100%;
  font: inherit;
  font-size: 15px;
  padding: 12px 14px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.07);
  color: #fff;
}
.field input::placeholder { color: #8f8f8f; }
.field input:focus { outline: 2px solid var(--teal-2); outline-offset: 1px; }
.login-card .btn { margin-top: 24px; }
.login-note { margin-top: 16px; font-size: 12px; color: #a0a0a0; text-align: center; }
.login-error {
  margin-top: 16px;
  padding: 10px 14px;
  border-radius: 9px;
  background: rgba(179, 38, 30, 0.2);
  border: 1px solid rgba(179, 38, 30, 0.4);
  color: #ffb4af;
  font-size: 13px;
  display: none;
}
.login-error.show { display: block; }
.dev-code-hint {
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: 9px;
  background: rgba(9, 117, 122, 0.18);
  border: 1px solid rgba(9, 117, 122, 0.45);
  color: #5fc6cb;
  font-size: 12.5px;
  display: none;
}
.dev-code-hint.show { display: block; }

/* ---------------- dashboard shell ---------------- */
header.app-header {
  background: var(--ink);
  color: #fff;
}
header.app-header .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
}
.app-header .brand-row { display: flex; align-items: center; gap: 12px; }
.app-header .brand-row b { font-size: 15px; }
.app-header .user-row { display: flex; align-items: center; gap: 14px; font-size: 13.5px; color: #cfcfcf; }
.app-header .user-row button { background: none; border: none; color: #cfcfcf; font: inherit; cursor: pointer; text-decoration: underline; }

main.dashboard { padding: 32px 0 64px; }

.stat-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--ink);
  border-radius: 16px;
  padding: 22px 24px;
  color: #fff;
  position: relative;
  overflow: hidden;
}
.stat-card .label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: #a8a8a8; }
.stat-card .value { margin-top: 10px; font-size: 30px; font-weight: 800; color: #4fd1d6; }

.tabs-nav { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.tabs-nav button {
  font: inherit;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  padding: 10px 18px;
  border-radius: 999px;
  cursor: pointer;
}
.tabs-nav button.is-active { background: var(--ink); border-color: var(--ink); color: #fff; }

.panel {
  display: none;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}
.panel.is-active { display: block; }

table.records { width: 100%; min-width: 480px; border-collapse: collapse; }
table.records th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-3);
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
table.records td {
  padding: 14px 18px;
  font-size: 13.8px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
}
table.records tr:last-child td { border-bottom: none; }
.amount-positive { color: var(--good); font-weight: 700; }
.amount-negative { color: var(--bad); font-weight: 700; }
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  text-transform: capitalize;
}
.badge-paid, .badge-approved, .badge-closed, .badge-accepted, .badge-active { background: var(--good-soft); color: var(--good); }
.badge-pending_approval, .badge-pending, .badge-disbursed, .badge-repaying { background: var(--teal-soft); color: var(--teal); }
.badge-rejected, .badge-reversed, .badge-defaulted, .badge-declined, .badge-suspended { background: var(--bad-soft); color: var(--bad); }
.empty-state { padding: 40px 18px; text-align: center; color: var(--text-3); font-size: 13.5px; }

.officer-panel {
  margin-top: 28px;
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 24px;
}
.officer-panel h3 { font-size: 15px; }
.officer-panel .eyebrow {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--teal);
}

/* ---------------- main section tabs ---------------- */
.maintab { display: none; }
.maintab.is-active { display: block; }

.section-block { margin-bottom: 36px; scroll-margin-top: 20px; }
.section-block h3 { font-size: 16px; margin-bottom: 4px; }
.section-subheading { margin-top: 32px; font-size: 16px; }
.section-hint { font-size: 13px; color: var(--text-2); margin-bottom: 14px; }

.quick-nav {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 28px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.quick-nav a {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink);
  background: var(--cream);
  border: 1px solid var(--line);
  padding: 7px 14px;
  border-radius: 999px;
  text-decoration: none;
}
.quick-nav a:hover { border-color: var(--teal); }

/* ---------------- forms ---------------- */
.officer-form { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 12px; margin-top: 14px; align-items: end; }
.officer-form .field { margin-top: 0; }
.officer-form label { display: block; font-size: 12.5px; font-weight: 700; color: var(--text-2); margin-bottom: 6px; }
.officer-form input, .officer-form select,
#requestLoanForm input, #requestLoanForm select {
  width: 100%;
  font: inherit;
  font-size: 13.8px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--line-2);
  background: var(--paper);
  color: var(--text);
}
.officer-form input:focus, .officer-form select:focus,
#requestLoanForm input:focus, #requestLoanForm select:focus {
  outline: 2px solid var(--teal);
  outline-offset: 1px;
  border-color: transparent;
}

/* ---------------- guarantor rows ---------------- */
.guarantor-rows { margin-top: 18px; display: flex; flex-direction: column; gap: 10px; }
.guarantor-row {
  display: grid;
  grid-template-columns: 1fr 140px auto;
  gap: 10px;
  align-items: center;
}
.guarantor-row label { font-size: 11px; font-weight: 700; color: var(--text-2); display: block; margin-bottom: 4px; }
.guarantor-row select, .guarantor-row input {
  width: 100%;
  font: inherit;
  font-size: 13.5px;
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--line-2);
  background: var(--paper);
}
.guarantor-row .remove-row {
  background: none;
  border: 1px solid var(--line-2);
  color: var(--bad);
  width: 34px;
  height: 34px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}
.guarantor-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; gap: 12px; flex-wrap: wrap; }

/* ---------------- chips ---------------- */
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  background: var(--teal-soft);
  color: var(--teal);
  padding: 6px 12px;
  border-radius: 999px;
}
.role-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  background: var(--teal-soft);
  color: var(--teal);
  padding: 3px 8px 3px 10px;
  border-radius: 999px;
  margin: 2px 3px 2px 0;
}
.role-chip button {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0;
}

/* ---------------- small action buttons (table cells) ---------------- */
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-sm {
  font-size: 12px;
  font-weight: 700;
  padding: 7px 12px;
  border-radius: 7px;
  border: 1px solid var(--line-2);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}
.btn-sm:hover { border-color: var(--teal); }
.btn-sm:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-sm.danger { color: var(--bad); border-color: var(--bad-soft); }
.role-assign-select { padding: 5px 8px; }
.btn-sm.link { border: none; background: none; color: var(--teal); text-decoration: underline; padding: 4px 0; }

/* ---------------- export ---------------- */
.export-row { display: flex; gap: 12px; flex-wrap: wrap; }
.export-row .btn { text-decoration: none; }

/* ---------------- reconciliation ---------------- */
.reconciliation-preview {
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 20px;
  font-size: 14px;
  margin-bottom: 18px;
}
.reconciliation-preview b { color: var(--ink); }
.variance-positive { color: var(--good); font-weight: 700; }
.variance-negative { color: var(--bad); font-weight: 700; }

/* ---------------- modal (loan detail) ---------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 20px;
  overflow-y: auto;
  z-index: 100;
}
.modal {
  width: 100%;
  max-width: 640px;
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 28px 30px;
}
.modal h2 { font-size: 19px; }
.modal .close-modal {
  float: right;
  background: none;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  cursor: pointer;
  font-size: 16px;
  color: var(--text-2);
}
.modal-section { margin-top: 20px; }
.modal-section h4 {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  margin-bottom: 10px;
}
.modal-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13.5px;
  gap: 10px;
}
.modal-row:last-child { border-bottom: none; }
.modal-actions { margin-top: 22px; display: flex; gap: 10px; flex-wrap: wrap; }
.inline-amount-form { display: flex; gap: 8px; margin-top: 16px; }
.inline-amount-form input {
  flex: 1;
  font: inherit;
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--line-2);
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 13.5px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.toast.show { opacity: 1; }

@media (max-width: 640px) {
  .stat-row { grid-template-columns: 1fr; }
  .officer-form { grid-template-columns: 1fr; }
  table.records { font-size: 12.5px; }
  header.app-header .wrap { flex-wrap: wrap; row-gap: 8px; padding: 14px 20px; }
  .app-header .user-row { width: 100%; justify-content: space-between; }
  .guarantor-row { grid-template-columns: 1fr; }
  .guarantor-row .remove-row { width: 100%; }
  .modal { padding: 22px 18px; }
  .modal-backdrop { padding: 16px; }
}
