*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:    #1a4f8a;
  --primary-dk: #133a68;
  --accent:     #e8f0fb;
  --success:    #2e7d32;
  --warning:    #e65100;
  --neutral:    #f57c00;
  --danger:     #c62828;
  --text:       #1e2a3a;
  --muted:      #607080;
  --border:     #d0d8e4;
  --bg:         #f4f6fa;
  --white:      #ffffff;
  --radius:     8px;
  --shadow:     0 2px 8px rgba(0,0,0,.10);
  --shadow-lg:  0 8px 32px rgba(0,0,0,.18);
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Header ─────────────────────────────────────────── */
.site-header {
  background: var(--primary);
  color: var(--white);
  padding: 0 2rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  height: 62px;
  box-shadow: var(--shadow);
}
.site-header .logo { font-size: 1.4rem; font-weight: 700; letter-spacing: .4px; }
.site-header .subtitle { font-size: .85rem; opacity: .75; margin-top: 2px; }
.header-text { flex: 1; }
.header-back {
  color: var(--white);
  text-decoration: none;
  font-size: .9rem;
  opacity: .85;
  display: flex;
  align-items: center;
  gap: .4rem;
  transition: opacity .15s;
}
.header-back:hover { opacity: 1; }

/* ── Home page ───────────────────────────────────────── */
.home-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 62px);
  gap: 2rem;
  padding: 2rem;
}
.home-title {
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--primary);
  text-align: center;
}
.home-cards {
  display: flex;
  gap: 2rem;
  flex-wrap: wrap;
  justify-content: center;
}
.home-public-note {
  text-align: center;
  font-size: 0.88rem;
  color: var(--muted);
  max-width: 36rem;
  line-height: 1.5;
  margin: 0;
}
.home-public-note a {
  color: var(--primary);
  font-weight: 600;
}
.home-card {
  background: var(--white);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  width: 260px;
  padding: 2.5rem 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2rem;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  border: 2px solid transparent;
  transition: border-color .2s, transform .15s, box-shadow .2s;
}
.home-card:hover {
  border-color: var(--primary);
  transform: translateY(-4px);
  box-shadow: 0 12px 36px rgba(0,0,0,.18);
}
.home-card .card-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
}
.home-card .card-label { font-size: 1.15rem; font-weight: 700; color: var(--primary); text-align: center; }
.home-card .card-desc  { font-size: .85rem; color: var(--muted); text-align: center; }

/* ── Page container ──────────────────────────────────── */
.page-container { max-width: 1200px; margin: 0 auto; padding: 2rem 1.5rem; }
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.page-header h1 { font-size: 1.5rem; font-weight: 700; color: var(--primary); }

/* ── Toolbar ─────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
}
.search-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
  max-width: 360px;
}
.search-wrap input {
  width: 100%;
  padding: .55rem 1rem .55rem 2.4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
  background: var(--white);
  outline: none;
  transition: border-color .2s;
}
.search-wrap input:focus { border-color: var(--primary); }
.search-icon {
  position: absolute;
  left: .75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 1rem;
}

/* ── Buttons ─────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem 1.1rem;
  border: none;
  border-radius: var(--radius);
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}
.btn-primary  { background: var(--primary);  color: var(--white); }
.btn-primary:hover  { background: var(--primary-dk); }
.btn-danger   { background: #fdecea; color: var(--danger); border: 1px solid #f5c6c5; }
.btn-danger:hover   { background: #fbc9c7; }
.btn-edit     { background: var(--accent);   color: var(--primary); border: 1px solid var(--border); }
.btn-edit:hover     { background: #d0e0f8; }
.btn-secondary { background: #f0f0f0; color: #333; border: 1px solid #ccc; }
.btn-secondary:hover { background: #e0e0e0; }
.btn-sm { padding: .3rem .7rem; font-size: .8rem; }

/* ── Table ───────────────────────────────────────────── */
.table-wrap {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
thead { background: var(--primary); color: var(--white); }
thead th {
  padding: .75rem 1rem;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
thead th:hover { background: var(--primary-dk); }
thead th .sort-arrow { margin-left: .3rem; opacity: .5; font-size: .75rem; }
thead th.sorted .sort-arrow { opacity: 1; }
tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--accent); }
tbody td { padding: .65rem 1rem; vertical-align: middle; }
.actions-cell { white-space: nowrap; display: flex; gap: .4rem; }
.empty-row td { text-align: center; color: var(--muted); padding: 3rem; font-size: .95rem; }

/* ── Status badges ───────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .2rem .65rem;
  border-radius: 99px;
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .3px;
}
.badge-active  { background: #e8f5e9; color: var(--success); }
.badge-expired { background: #ffebee; color: var(--danger);  }
.badge-pending { background: #fff3e0; color: var(--neutral); }

/* ── Record count ────────────────────────────────────── */
.record-count { font-size: .85rem; color: var(--muted); margin-bottom: .75rem; }

/* ── Modal ───────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--white);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: slideUp .2s ease;
}
@keyframes slideUp {
  from { transform: translateY(30px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h2 { font-size: 1.1rem; font-weight: 700; color: var(--primary); }
.modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
  padding: .2rem;
  transition: color .15s;
}
.modal-close:hover { color: var(--text); }
/* Hint bar: how “Updated date” works (dept add/edit modal) */
.modal-updated-hint {
  margin: 0;
  padding: .65rem 1.5rem;
  background: linear-gradient(180deg, #e8f4fc 0%, #dceef9 100%);
  border-bottom: 1px solid var(--border);
  font-size: .82rem;
  line-height: 1.45;
  color: #2c4a63;
}
.modal-updated-hint strong { color: var(--primary); font-weight: 700; }

.modal-body { padding: 1.25rem 1.5rem; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: .75rem;
}

/* ── Form ────────────────────────────────────────────── */
.form-grid { display: grid; gap: 1rem; grid-template-columns: 1fr 1fr; }
.form-group { display: flex; flex-direction: column; gap: .35rem; }
.form-group.full { grid-column: 1 / -1; }
.form-group label { font-size: .825rem; font-weight: 600; color: var(--muted); }
.form-group input,
.form-group select,
.form-group textarea {
  padding: .55rem .8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
  font-family: inherit;
  outline: none;
  transition: border-color .2s;
  background: var(--white);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--primary); }
.form-group textarea { resize: vertical; min-height: 70px; }

/* ── Toast ───────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: #1e2a3a;
  color: var(--white);
  padding: .75rem 1.25rem;
  border-radius: var(--radius);
  font-size: .875rem;
  box-shadow: var(--shadow-lg);
  z-index: 2000;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .25s, transform .25s;
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translateY(0); }

/* ── Confirm dialog ──────────────────────────────────── */
.confirm-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1500;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.confirm-overlay.open { display: flex; }
.confirm-box {
  background: var(--white);
  border-radius: 12px;
  padding: 2rem;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.confirm-box h3 { font-size: 1.1rem; margin-bottom: .6rem; color: var(--danger); }
.confirm-box p  { font-size: .9rem; color: var(--muted); margin-bottom: 1.5rem; }
.confirm-actions { display: flex; gap: .75rem; justify-content: center; }

/* ── Form section labels ─────────────────────────────── */
.form-section-label {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--primary);
  border-bottom: 2px solid var(--accent);
  padding-bottom: .3rem;
  margin: 1.25rem 0 .75rem;
}
.form-section-label:first-child { margin-top: 0; }
.form-group.full-2 { grid-column: span 2; }

/* ── Officer row + Info button (dept contact cards) ─── */
.dc-field-officer {
  align-items: center;
  flex-wrap: wrap;
}
.dc-value-officer {
  display: flex;
  align-items: center;
  gap: .35rem;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
  color: #111;
}
.btn-officer-info {
  font-size: .68rem;
  font-weight: 700;
  padding: .12rem .45rem;
  border-radius: 4px;
  border: 1px solid #90a4c4;
  background: #fff;
  color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1.2;
}
.btn-officer-info:hover {
  background: var(--accent);
  border-color: var(--primary);
}

/* ── Officer contact info modal ─────────────────────── */
.modal-officer { max-width: 460px; }
.modal-officer.modal-officer-wide { max-width: 640px; }

/* Officer contact edit form (Info modal) */
.officer-edit-form .officer-edit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .65rem 1rem;
}
.officer-edit-form .form-group {
  display: flex;
  flex-direction: column;
  gap: .25rem;
}
.officer-edit-form .form-group.full { grid-column: 1 / -1; }
.officer-edit-form label {
  font-size: .72rem;
  font-weight: 600;
  color: var(--muted);
}
.officer-edit-form input,
.officer-edit-form textarea {
  font-size: .85rem;
  padding: .4rem .55rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
}
.officer-edit-form input:disabled {
  background: #f0f0f0;
  color: #666;
}
.officer-edit-form textarea { min-height: 4rem; resize: vertical; }
.officer-edit-hint {
  font-size: .78rem;
  line-height: 1.4;
  border-radius: 0;
}
.officer-info-grid {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: .4rem .75rem;
  font-size: .88rem;
}
.officer-info-grid dt {
  color: var(--muted);
  font-weight: 600;
  font-size: .78rem;
  text-transform: uppercase;
}
.officer-info-grid dd {
  margin: 0;
  word-break: break-word;
}
.officer-info-grid dd a { color: var(--primary); }
.officer-info-empty { color: var(--muted); font-style: italic; padding: 1rem 0; text-align: center; }

@media (max-width: 600px) {
  .form-grid { grid-template-columns: 1fr; }
  .home-cards { flex-direction: column; align-items: center; }
  .page-header { flex-direction: column; align-items: flex-start; }
}
