/* ===== CSS VARIABLES ===== */
:root {
  --primary: #1B4F8A;
  --primary-light: #2A6DBF;
  --primary-dark: #133A6A;
  --accent: #0EA5E9;
  --surface: #F0F4F8;
  --card: #FFFFFF;
  --border: #E2E8F0;
  --text-primary: #1E293B;
  --text-muted: #64748B;
  --text-light: #94A3B8;
  --success: #10B981;
  --danger: #EF4444;
  --warning: #F59E0B;
  --info: #0EA5E9;
  --sidebar-w: 250px;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.12), 0 4px 6px rgba(0,0,0,0.07);
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: 'Inter', system-ui, sans-serif; font-size: 14px; color: var(--text-primary); background: var(--surface); }
a { text-decoration: none; color: inherit; }
button { cursor: pointer; font-family: inherit; border: none; outline: none; }
input, textarea, select { font-family: inherit; font-size: 14px; }
ul { list-style: none; }

/* ===== LAYOUT ===== */
#app-shell { display: flex; min-height: 100vh; }

/* ===== SIDEBAR ===== */
#sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--primary-dark) 0%, var(--primary) 100%);
  min-height: 100vh;
  position: fixed;
  top: 0; left: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
  box-shadow: 2px 0 8px rgba(0,0,0,0.15);
  transition: transform 0.3s ease;
}
.sidebar-logo {
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-logo .logo-icon {
  width: 38px; height: 38px;
  background: rgba(255,255,255,0.15);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 10px;
}
.sidebar-logo .logo-icon svg { width: 22px; height: 22px; }
.sidebar-logo h1 { font-size: 15px; font-weight: 700; color: #fff; line-height: 1.2; }
.sidebar-logo p { font-size: 11px; color: rgba(255,255,255,0.5); margin-top: 2px; text-transform: uppercase; letter-spacing: 0.8px; }

.sidebar-nav { flex: 1; padding: 12px 10px; }
.nav-section-label {
  font-size: 10px;
  color: rgba(255,255,255,0.35);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 8px 10px 4px;
  margin-top: 8px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: 8px;
  color: rgba(255,255,255,0.75);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.18s ease;
  margin-bottom: 2px;
  user-select: none;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.85; }
.nav-item:hover { background: rgba(255,255,255,0.1); color: #fff; }
.nav-item.active { background: rgba(255,255,255,0.18); color: #fff; border-left: 3px solid rgba(255,255,255,0.8); padding-left: 9px; }
.nav-item.active svg { opacity: 1; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
}
.sidebar-footer p { font-size: 11px; color: rgba(255,255,255,0.3); }

/* ===== MAIN CONTENT ===== */
#main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== TOP BAR ===== */
#topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow);
}
#topbar-title { font-size: 17px; font-weight: 600; color: var(--text-primary); }
#topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-badge {
  background: var(--primary);
  color: #fff;
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
#hamburger {
  display: none;
  background: none;
  padding: 6px;
  border-radius: 6px;
  color: var(--text-primary);
}
#hamburger:hover { background: var(--surface); }
#hamburger svg { width: 20px; height: 20px; }

/* ===== PAGE CONTENT ===== */
#page-content { padding: 28px; flex: 1; }

/* ===== VIEWS ===== */
.view { display: none; }
.view.active { display: block; }

/* ===== DASHBOARD ===== */
.page-header {
  margin-bottom: 24px;
}
.page-header h2 { font-size: 22px; font-weight: 700; color: var(--text-primary); }
.page-header p { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 16px;
  border-left: 4px solid transparent;
  transition: transform 0.15s, box-shadow 0.15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-card.blue { border-color: var(--primary); }
.stat-card.green { border-color: var(--success); }
.stat-card.teal { border-color: #14B8A6; }
.stat-card.navy { border-color: #6366F1; }

.stat-icon {
  width: 46px; height: 46px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-icon svg { width: 24px; height: 24px; }
.stat-card.blue .stat-icon { background: rgba(27,79,138,0.1); color: var(--primary); }
.stat-card.green .stat-icon { background: rgba(16,185,129,0.1); color: var(--success); }
.stat-card.teal .stat-icon { background: rgba(20,184,166,0.1); color: #14B8A6; }
.stat-card.navy .stat-icon { background: rgba(99,102,241,0.1); color: #6366F1; }

.stat-info { flex: 1; }
.stat-number { font-size: 28px; font-weight: 700; line-height: 1; color: var(--text-primary); }
.stat-label { font-size: 12.5px; color: var(--text-muted); margin-top: 4px; font-weight: 500; }

.recent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
}
.recent-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.recent-card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.recent-card-header h3 { font-size: 13.5px; font-weight: 600; }
.recent-card-header a { font-size: 12px; color: var(--primary); font-weight: 500; }
.recent-card-header a:hover { text-decoration: underline; }
.recent-list { padding: 6px 0; }
.recent-item {
  display: flex;
  align-items: center;
  padding: 9px 18px;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}
.recent-item:last-child { border-bottom: none; }
.recent-item:hover { background: var(--surface); }
.recent-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  flex-shrink: 0;
  color: #fff;
}
.recent-item-name { font-size: 13px; font-weight: 500; flex: 1; }
.recent-item-sub { font-size: 11px; color: var(--text-muted); margin-top: 1px; }
.recent-empty { padding: 20px 18px; text-align: center; color: var(--text-muted); font-size: 12.5px; }

/* ===== LIST VIEWS ===== */
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  gap: 12px;
  flex-wrap: wrap;
}
.list-header h2 { font-size: 20px; font-weight: 700; }

.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.search-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
  max-width: 340px;
}
.search-wrap svg {
  position: absolute;
  left: 10px; top: 50%;
  transform: translateY(-50%);
  width: 15px; height: 15px;
  color: var(--text-muted);
  pointer-events: none;
}
.search-input {
  width: 100%;
  padding: 8px 12px 8px 33px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  font-size: 13px;
  transition: border-color 0.15s;
}
.search-input:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px rgba(27,79,138,0.08); }

.filter-select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
}
.filter-select:focus { border-color: var(--primary); outline: none; }

.record-count { font-size: 12.5px; color: var(--text-muted); margin-left: auto; }

.table-wrap {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
table { width: 100%; border-collapse: collapse; }
thead { background: var(--surface); }
thead th {
  padding: 11px 14px;
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #F8FAFC; }
tbody td {
  padding: 12px 14px;
  font-size: 13.5px;
  color: var(--text-primary);
  vertical-align: middle;
}
.td-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }
.action-cell { white-space: nowrap; text-align: right; }

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--card);
}
.pagination-info { font-size: 12.5px; color: var(--text-muted); }
.pagination-btns { display: flex; gap: 6px; align-items: center; }
.page-btn {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  font-size: 12.5px;
  color: var(--text-primary);
  transition: all 0.12s;
}
.page-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-indicator { font-size: 12.5px; color: var(--text-muted); padding: 0 4px; }

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 56px 20px;
  color: var(--text-muted);
}
.empty-state svg { width: 56px; height: 56px; margin-bottom: 16px; opacity: 0.35; }
.empty-state h3 { font-size: 15px; font-weight: 600; color: var(--text-primary); margin-bottom: 6px; }
.empty-state p { font-size: 13px; margin-bottom: 18px; }

/* ===== DETAIL VIEW ===== */
.detail-back {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--primary);
  font-weight: 500;
  cursor: pointer;
  margin-bottom: 18px;
  padding: 6px 12px;
  border-radius: 6px;
  transition: background 0.12s;
}
.detail-back:hover { background: rgba(27,79,138,0.07); }
.detail-back svg { width: 16px; height: 16px; }

.detail-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.detail-card-header {
  padding: 22px 26px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.detail-card-header-left { display: flex; align-items: center; gap: 16px; }
.detail-avatar {
  width: 52px; height: 52px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.detail-title h2 { font-size: 20px; font-weight: 700; }
.detail-title p { font-size: 13px; color: var(--text-muted); margin-top: 3px; }
.detail-actions { display: flex; gap: 8px; align-items: center; }

.detail-body { padding: 26px; }
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
}
.detail-field label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 6px;
}
.detail-field .field-value {
  font-size: 14px;
  color: var(--text-primary);
  font-weight: 500;
}
.detail-field .field-value.empty { color: var(--text-light); font-style: italic; font-weight: 400; }
.detail-field.full-width { grid-column: 1 / -1; }

.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  background: rgba(27,79,138,0.08);
  color: var(--primary);
}

/* ===== BADGES ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge--active { background: rgba(16,185,129,0.12); color: #059669; }
.badge--inactive { background: rgba(239,68,68,0.1); color: #DC2626; }
.badge--blue { background: rgba(27,79,138,0.1); color: var(--primary); }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 600;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover { background: var(--primary-light); box-shadow: 0 2px 8px rgba(27,79,138,0.35); }
.btn--secondary { background: var(--surface); color: var(--text-primary); border: 1px solid var(--border); }
.btn--secondary:hover { background: var(--border); }
.btn--danger { background: rgba(239,68,68,0.1); color: var(--danger); }
.btn--danger:hover { background: var(--danger); color: #fff; }
.btn--success { background: rgba(16,185,129,0.1); color: var(--success); }
.btn--success:hover { background: var(--success); color: #fff; }
.btn--sm { padding: 5px 11px; font-size: 12.5px; }
.btn--icon {
  padding: 6px;
  background: transparent;
  border-radius: 6px;
  color: var(--text-muted);
  transition: all 0.12s;
}
.btn--icon:hover { background: var(--surface); color: var(--text-primary); }
.btn--icon.edit:hover { color: var(--primary); background: rgba(27,79,138,0.08); }
.btn--icon.delete:hover { color: var(--danger); background: rgba(239,68,68,0.08); }
.btn--icon svg { width: 16px; height: 16px; }

/* ===== TOGGLE ===== */
.toggle-wrap { display: flex; align-items: center; gap: 10px; }
.toggle {
  position: relative;
  width: 40px; height: 22px;
  display: inline-block;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: #CBD5E1;
  border-radius: 22px;
  cursor: pointer;
  transition: background 0.2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle input:checked + .toggle-slider { background: var(--success); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }
.toggle-label { font-size: 13.5px; font-weight: 500; }

/* ===== MODAL ===== */
#modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.55);
  z-index: 200;
  backdrop-filter: blur(2px);
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#modal-overlay.open { display: flex; }
#modal-box {
  background: var(--card);
  border-radius: 12px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.2s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(-10px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
  background: var(--card);
  z-index: 1;
}
.modal-header h3 { font-size: 17px; font-weight: 700; }
.modal-close {
  background: var(--surface);
  border: none;
  width: 30px; height: 30px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  transition: all 0.12s;
}
.modal-close:hover { background: var(--border); color: var(--text-primary); }
.modal-close svg { width: 16px; height: 16px; }
.modal-body { padding: 22px 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  position: sticky; bottom: 0;
  background: var(--card);
}

/* ===== FORM ===== */
.form-row { margin-bottom: 18px; }
.form-row label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}
.form-row label .req { color: var(--danger); margin-left: 2px; }
.form-input, .form-textarea, .form-select {
  width: 100%;
  padding: 9px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text-primary);
  font-size: 13.5px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-input:focus, .form-textarea:focus, .form-select:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(27,79,138,0.1);
}
.form-input.error, .form-textarea.error { border-color: var(--danger); }
.form-input.error:focus { box-shadow: 0 0 0 3px rgba(239,68,68,0.1); }
.form-textarea { resize: vertical; min-height: 72px; }
.form-error { font-size: 11.5px; color: var(--danger); margin-top: 4px; }
.form-hint { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }
.form-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.radio-group { display: flex; gap: 18px; align-items: center; margin-top: 4px; }
.radio-option { display: flex; align-items: center; gap: 7px; cursor: pointer; }
.radio-option input { accent-color: var(--primary); width: 15px; height: 15px; }
.radio-option span { font-size: 13.5px; }

/* ===== TOAST ===== */
#toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  font-weight: 500;
  color: #fff;
  min-width: 240px;
  animation: toastIn 0.25s ease;
  pointer-events: auto;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: none; }
}
.toast.fadeout { animation: toastOut 0.3s ease forwards; }
@keyframes toastOut {
  to { opacity: 0; transform: translateX(20px); }
}
.toast svg { width: 17px; height: 17px; flex-shrink: 0; }
.toast--success { background: #059669; }
.toast--error { background: var(--danger); }
.toast--info { background: var(--primary); }

/* ===== OVERLAY (mobile sidebar) ===== */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 99;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  #sidebar { transform: translateX(-100%); }
  #sidebar.open { transform: none; }
  #sidebar-overlay.open { display: block; }
  #main-content { margin-left: 0; }
  #hamburger { display: flex; }
  #page-content { padding: 16px; }
  .form-2col { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .recent-grid { grid-template-columns: 1fr; }
  .list-header { flex-direction: column; align-items: flex-start; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
}
