:root {
  --navy: #0f2440;
  --navy-light: #16345c;
  --gold: #b8943f;
  --red: #b3261e;
  --green: #2e7d32;
  --bg: #f4f6f8;
  --border: #d9dee3;
  --text: #1d2733;
  --text-muted: #5b6773;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--navy-light); }

/* ── Auth pages ── */
body.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--navy);
}
.auth-card {
  background: #fff;
  padding: 36px 40px;
  border-radius: 10px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  overflow: hidden;
  box-sizing: border-box;
}
.auth-card .auth-logo { display: block; width: 160px; max-width: 100%; height: auto; margin: 0 auto 18px; }
.auth-card h1 { font-size: 1.3rem; margin: 0 0 4px; color: var(--navy); text-align: center; }
.auth-card .subtitle { margin: 0 0 24px; color: var(--text-muted); font-size: 0.9rem; text-align: center; }
.auth-card label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 4px; }
.auth-card input {
  width: 100%; padding: 10px 12px; margin-bottom: 16px;
  border: 1px solid var(--border); border-radius: 6px; font-size: 0.95rem;
}
.auth-card button {
  width: 100%; padding: 11px; background: var(--navy); color: #fff;
  border: none; border-radius: 6px; font-size: 0.95rem; font-weight: 600; cursor: pointer;
}
.auth-card button:hover { background: var(--navy-light); }
.auth-footer { text-align: center; margin-top: 18px; font-size: 0.85rem; }

.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; font-size: 0.88rem; }
.alert-error { background: #fdecea; color: var(--red); border: 1px solid #f5c6c2; }
.alert-warning { background: #fff8e1; color: #8a6d00; border: 1px solid #ffe8a3; }
.alert-success { background: #eaf6ea; color: var(--green); border: 1px solid #c3e6c3; }

/* ── App shell ── */
/* ── Topbar ── */
.topbar {
  background: var(--navy);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 56px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-left { flex-shrink: 0; }
.topbar-brand {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none;
}
/* Logo — hard constraint so it never renders at native size regardless of CSS load order */
.topbar-brand img {
  height: 34px !important;
  width: auto !important;
  max-width: 160px !important;
  display: block;
}
.topbar-gfi {
  font-size: 1.1rem; font-weight: 800; letter-spacing: 2px;
  color: #fff; font-family: inherit;
}

/* Desktop nav */
.topbar-nav {
  display: flex; align-items: center; gap: 2px;
  flex: 1; justify-content: center; flex-wrap: wrap;
}
.topbar-link {
  color: #c5cfd9;
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 500;
  padding: 6px 11px;
  border-radius: 5px;
  transition: color 0.15s, background 0.15s;
  white-space: nowrap;
}
.topbar-link:hover { color: #fff; background: rgba(255,255,255,0.08); }
.topbar-link.active {
  color: var(--gold);
  background: rgba(184,148,63,0.12);
  font-weight: 700;
}

/* User info */
.topbar-user {
  display: flex; align-items: center; gap: 10px; flex-shrink: 0;
  border-left: 1px solid rgba(255,255,255,0.1);
  padding-left: 14px;
}
.topbar-user-info { text-align: right; line-height: 1.2; }
.topbar-username { display: block; color: #fff; font-size: 0.82rem; font-weight: 600; }
.topbar-role { display: block; color: var(--gold); font-size: 0.7rem; font-weight: 600; letter-spacing: 0.5px; text-transform: uppercase; }

/* Logout button — gold, prominent */
.topbar-logout {
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  text-decoration: none;
  background: var(--gold);
  border: none;
  border-radius: 5px;
  padding: 6px 13px;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
  letter-spacing: 0.2px;
}
.topbar-logout:hover {
  background: #8a6a28;
  color: var(--navy);
}

/* Hamburger button — hidden on desktop */
.topbar-hamburger {
  display: none;
  background: none;
  border: 1.5px solid rgba(184,148,63,0.6);
  border-radius: 5px;
  cursor: pointer;
  padding: 7px 8px;
  flex-direction: column;
  gap: 5px;
  flex-shrink: 0;
  transition: border-color 0.15s;
}
.topbar-hamburger:hover { border-color: var(--gold); }
.topbar-hamburger span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--gold);
  border-radius: 2px;
  transition: transform 0.2s, opacity 0.2s;
}
.topbar-hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.topbar-hamburger.open span:nth-child(2) { opacity: 0; }
.topbar-hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* Mobile nav drawer — always hidden until .open is toggled via JS */
.topbar-mobile-nav {
  display: none !important;
  position: absolute;
  top: 56px;
  left: 0; right: 0;
  background: #0a1c35;
  border-top: 1px solid rgba(255,255,255,0.08);
  z-index: 99;
  padding: 8px 0 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}
.topbar-mobile-nav.open { display: block !important; }
.topbar-mobile-nav a {
  display: block;
  padding: 11px 20px;
  color: #c5cfd9;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.topbar-mobile-nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.topbar-mobile-nav a.active {
  color: var(--gold);
  border-left-color: var(--gold);
  background: rgba(184,148,63,0.1);
  font-weight: 700;
}
.topbar-mobile-nav .mobile-divider {
  border: none; border-top: 1px solid rgba(255,255,255,0.08);
  margin: 8px 0;
}
.topbar-mobile-nav .mobile-logout {
  display: block;
  margin: 8px 16px 0;
  padding: 10px 16px;
  background: var(--gold);
  color: #fff;
  font-weight: 700;
  font-size: 0.88rem;
  text-align: center;
  border-radius: 6px;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.topbar-mobile-nav .mobile-logout:hover { background: #8a6a28; color: var(--navy); }

/* ── Responsive — hamburger at 1024px catches all tablets in portrait ── */
@media (max-width: 1024px) {
  .topbar { height: 56px; padding: 0 16px; }
  .topbar-nav { display: none; }
  .topbar-user { border-left: none; padding-left: 0; }
  .topbar-logout { display: none; }
  .topbar-hamburger { display: flex; }
}
@media (max-width: 480px) {
  .topbar-gfi { display: none; }
  .topbar-brand img { height: 26px !important; }
  .topbar-username { font-size: 0.78rem; }
  .topbar-role { font-size: 0.65rem; }
}

.container { max-width: 1100px; margin: 0 auto; padding: 24px; }

/* ── Search ── */
.search-box {
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  padding: 20px; margin-bottom: 20px;
}
.search-box form { display: flex; gap: 10px; flex-wrap: wrap; }
.search-box input[type=text] {
  flex: 1; min-width: 220px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px;
}
.search-box button {
  padding: 10px 22px; background: var(--navy); color: #fff; border: none;
  border-radius: 6px; font-weight: 600; cursor: pointer;
}

.usage-bar { font-size: 0.82rem; color: var(--text-muted); margin-top: 10px; }

table.results { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--border); }
table.results th, table.results td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; font-size: 0.88rem; }
table.results th { background: #eef1f4; font-weight: 600; }
table.results tr:hover { background: #f8f9fb; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 0.75rem; font-weight: 600; }
.badge-pep { background: #e7eefb; color: #1a4a8a; }
.badge-sanctioned { background: #fdecea; color: var(--red); }
.badge-active { background: #eaf6ea; color: var(--green); }
.badge-inactive { background: #eee; color: #666; }

.btn { display: inline-block; padding: 8px 16px; border-radius: 6px; border: none; cursor: pointer; font-weight: 600; font-size: 0.85rem; text-decoration: none; }
.btn-primary { background: var(--navy); color: #fff; }
.btn-secondary { background: #eee; color: var(--text); }
.btn-danger { background: var(--red); color: #fff; }

.record-detail { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 24px; }

/* Back / Prev / Next record navigation */
.record-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 10px;
}
.record-nav-back {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--navy-light);
  font-size: 0.88rem;
  font-weight: 600;
}
.record-nav-back:hover { color: var(--navy); }
.record-nav-count {
  background: var(--navy);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 12px;
  letter-spacing: 0.3px;
}
.record-nav-arrows { display: flex; gap: 8px; }
.record-nav-arrow {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.84rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--navy);
  background: #fff;
  transition: background 0.12s, border-color 0.12s;
}
.record-nav-arrow:hover { background: #eef1f4; border-color: #b0bac4; }
.record-nav-arrow.disabled { color: #bbb; cursor: default; background: #f8f9fb; }
.record-detail dt { font-weight: 600; color: var(--text-muted); font-size: 0.78rem; text-transform: uppercase; margin-top: 14px; }
.record-detail dd { margin: 4px 0 0; }

.admin-table { width: 100%; border-collapse: collapse; background: #fff; }
.admin-table th, .admin-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 0.85rem; }

@media print {
  .topbar, .no-print { display: none !important; }
}

/* ── Mobile responsiveness ── */
@media (max-width: 640px) {
  .auth-card { padding: 28px 22px; max-width: 92vw; }
  .auth-card .auth-logo { width: 130px; }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 16px;
  }
  .topbar nav { display: flex; flex-wrap: wrap; gap: 10px; }
  .topbar nav a { margin-left: 0; }

  .container { padding: 14px; }

  .search-box { padding: 14px; }
  .search-box form { flex-direction: column; align-items: stretch; }
  .search-box input[type=text] { min-width: 0; width: 100%; }
  .search-box button, .search-box a.btn { width: 100%; text-align: center; }

  /* Tables don't reflow well on narrow screens — let them scroll
     horizontally inside their own box instead of squashing/overflowing
     the page. */
  table.results, .admin-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }

  .record-detail { padding: 16px; }
  .record-detail > div[style*="display:flex"] {
    flex-direction: column;
    align-items: center !important;
    text-align: center;
  }

  /* Full-width buttons for standalone CTAs, but not action buttons that
     live inline inside table rows (those need to stay compact). */
  .record-detail .btn, .auth-card button {
    width: 100%; text-align: center;
  }
}
