@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=Lexend:wght@700;800;900&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Brand palette — gold + charcoal */
  --primary:           #856c00;
  --primary-container: #ffd700;
  --on-primary-c:      #5c4a00;
  --primary-fixed:     #ffe16d;
  --secondary:         #bc0003;
  --dark:              #2f3131;

  /* Surfaces */
  --bg:          #f9f9f9;
  --surface:     #ffffff;
  --surface-hi:  #e8e8e8;
  --surface-lo:  #f3f3f3;

  /* Text */
  --text:  #1a1c1c;
  --muted: #4d4732;

  /* Borders */
  --border: #d0c6ab;

  /* Legacy aliases (used in inline styles) */
  --green:   #856c00;
  --green-d: #5c4a00;
  --green-l: #fff8d6;
  --red:     #bc0003;
  --red-l:   #fde8e8;
  --orange:  #d97706;
  --orange-l:#fef3c7;
  --grey:    #f9f9f9;

  --sidebar: 220px;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

/* ---------- AUTH ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--dark);
  position: relative;
  overflow: hidden;
}
.auth-wrap::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: 0.05;
  pointer-events: none;
}
.auth-wrap::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='40'%3E%3Cpolyline points='0,20 15,0 30,20 45,0 60,20' fill='none' stroke='%23ffd700' stroke-width='2'/%3E%3Cpolyline points='0,40 15,20 30,40 45,20 60,40' fill='none' stroke='%23ffd700' stroke-width='2'/%3E%3C/svg%3E");
  opacity: 0.05;
  pointer-events: none;
}
.auth-card {
  background: var(--surface);
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
  padding: 32px 36px 36px;
  position: relative;
  z-index: 1;
  border-top: 4px solid var(--primary-container);
}
.auth-logo { text-align: center; margin-bottom: 28px; }
.auth-logo h1 {
  font-family: 'Lexend', sans-serif;
  font-size: 28px;
  font-weight: 900;
  font-style: italic;
  text-transform: uppercase;
  color: var(--primary);
  line-height: 1;
  letter-spacing: -.02em;
}
.auth-logo p {
  font-family: 'Lexend', sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 6px;
}

/* ---------- LAYOUT ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar);
  background: var(--surface);
  border-right: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  box-shadow: 1px 0 8px rgba(0,0,0,.04);
}
.sidebar-brand {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-brand h2 {
  font-family: 'Lexend', sans-serif;
  font-size: 16px;
  font-weight: 900;
  font-style: italic;
  text-transform: uppercase;
  color: var(--primary);
  line-height: 1.1;
  letter-spacing: -.01em;
}
.sidebar-brand span {
  font-family: 'Lexend', sans-serif;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .15em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 2px;
  display: block;
}
.sidebar-nav { flex: 1; padding: 8px 0; overflow-y: auto; }
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  font-family: 'Lexend', sans-serif;
  font-weight: 600;
  border-right: 3px solid transparent;
  transition: all .15s;
}
.sidebar-nav a .material-symbols-outlined {
  font-size: 20px;
  font-variation-settings: 'FILL' 0, 'wght' 300;
}
.sidebar-nav a:hover {
  background: var(--surface-lo);
  color: var(--text);
}
.sidebar-nav a.active {
  background: var(--surface-hi);
  color: var(--primary);
  border-right-color: var(--primary-container);
}
.sidebar-nav a.active .material-symbols-outlined {
  font-variation-settings: 'FILL' 1, 'wght' 400;
}
.sidebar-nav .nav-section {
  padding: 12px 16px 4px;
  font-size: 10px;
  font-family: 'Lexend', sans-serif;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--border);
}
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}
.sidebar-footer button {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-family: 'Lexend', sans-serif;
  font-weight: 600;
  padding: 0;
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.sidebar-footer button:hover { color: var(--secondary); }

.main {
  margin-left: var(--sidebar);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar h1 {
  font-family: 'Lexend', sans-serif;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}
.topbar-right { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }

.content { padding: 24px; flex: 1; }

/* ---------- CARDS ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border-radius: 6px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  border-top: 4px solid var(--primary-container);
}
.stat-card:nth-child(2) { border-top-color: var(--dark); }
.stat-card:nth-child(3) { border-top-color: var(--secondary); }
.stat-card:nth-child(4) { border-top-color: var(--border); }
.stat-card .label {
  font-family: 'Lexend', sans-serif;
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .08em;
}
.stat-card .value {
  font-family: 'Lexend', sans-serif;
  font-size: 32px;
  font-weight: 700;
  color: var(--primary);
  margin: 4px 0;
}
.stat-card:nth-child(2) .value { color: var(--text); }
.stat-card:nth-child(3) .value { color: var(--secondary); }
.stat-card .sub { font-size: 12px; color: var(--muted); }

.card {
  background: var(--surface);
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  border-top: 4px solid var(--primary-container);
  margin-bottom: 20px;
}
.card-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-header h3 {
  font-family: 'Lexend', sans-serif;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}
.card-body { padding: 20px; }

/* ---------- TABLE ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  background: var(--surface-lo);
  padding: 10px 12px;
  text-align: left;
  font-family: 'Lexend', sans-serif;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
td { padding: 11px 12px; border-bottom: 1px solid #f0f0f0; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-lo); }

/* ---------- BADGES ---------- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 3px;
  font-family: 'Lexend', sans-serif;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-ok   { background: var(--green-l); color: var(--primary); }
.badge-warn { background: var(--orange-l); color: var(--orange); }
.badge-err  { background: var(--red-l); color: var(--secondary); }
.badge-grey { background: #eee; color: #555; }
.badge-admin { background: var(--dark); color: var(--primary-fixed); }

/* ---------- FORMS ---------- */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-family: 'Lexend', sans-serif;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: 5px;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
input, select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 2px solid var(--border);
  border-radius: 4px;
  font-size: 14px;
  font-family: 'Inter', sans-serif;
  outline: none;
  background: var(--surface);
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary-container); }

/* ---------- BUTTONS ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 4px;
  font-family: 'Lexend', sans-serif;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: filter .15s, transform .1s;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:hover { filter: brightness(.93); }
.btn-primary {
  background: var(--primary-container);
  color: var(--on-primary-c);
  border-bottom: 3px solid var(--primary);
}
.btn-danger  { background: var(--secondary); color: #fff; border-bottom: 3px solid #800002; }
.btn-warning { background: var(--orange); color: #fff; border-bottom: 3px solid #b85d00; }
.btn-outline {
  background: var(--surface);
  color: var(--muted);
  border: 2px solid var(--border);
}
.btn-sm { padding: 5px 10px; font-size: 11px; }

/* ---------- ALERTS ---------- */
.alert {
  padding: 12px 16px;
  border-radius: 4px;
  margin-bottom: 16px;
  font-size: 14px;
  border-left: 4px solid;
}
.alert-err  { background: var(--red-l); color: var(--secondary); border-color: var(--secondary); }
.alert-ok   { background: var(--green-l); color: var(--primary); border-color: var(--primary-container); }
.alert-warn { background: var(--orange-l); color: var(--orange); border-color: var(--orange); }
#flash { display: none; }

/* ---------- MODAL ---------- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border-top: 4px solid var(--primary-container);
  border-radius: 4px;
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.modal h3 {
  font-family: 'Lexend', sans-serif;
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 20px;
}
.modal-close {
  position: absolute;
  top: 16px; right: 16px;
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--muted);
}
.modal-close:hover { color: var(--text); }

/* ---------- SPINNER ---------- */
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary-container);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
}

/* ---------- MISC ---------- */
.text-muted { color: var(--muted); font-size: 13px; }
.text-right  { text-align: right; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.gap-1 { display: flex; gap: 6px; align-items: center; }
hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

@media (max-width: 768px) {
  :root { --sidebar: 0px; }
  .sidebar { display: none; }
  .main { margin-left: 0; }
}
