/* ─── Variables ─────────────────────────────────────────────── */
:root {
  --primary:      #1E3A5F;
  --primary-dark: #152b47;
  --accent:       #F97316;
  --accent-dark:  #ea6a10;
  --bg:           #f1f5f9;
  --white:        #ffffff;
  --text:         #1e293b;
  --muted:        #64748b;
  --border:       #e2e8f0;
  --danger:       #ef4444;
  --success:      #22c55e;
  --warn:         #f59e0b;
  --radius:       8px;
  --shadow:       0 2px 12px rgba(0,0,0,.10);
}

/* ─── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body { font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; display: flex; flex-direction: column; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ─── Top Nav ────────────────────────────────────────────────── */
.navbar {
  background: var(--primary);
  color: white;
  padding: 0 1.2rem;
  display: flex;
  align-items: center;
  height: 58px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.navbar-brand {
  display: flex;
  align-items: center;
  gap: .55rem;
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: .02em;
  flex-shrink: 0;
}
.navbar-brand .brand-dot {
  display: inline-block;
  width: 8px; height: 8px;
  background: var(--accent);
  border-radius: 50%;
}
.navbar-links {
  display: flex;
  align-items: center;
  gap: .25rem;
  margin-left: 1.5rem;
  flex: 1;
}
.navbar-links a {
  color: rgba(255,255,255,.78);
  padding: .4rem .75rem;
  border-radius: var(--radius);
  font-size: .875rem;
  font-weight: 500;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.navbar-links a:hover,
.navbar-links a.active { background: rgba(255,255,255,.14); color: white; }
.navbar-links a.active { background: var(--accent); color: white; }
.navbar-user {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-left: auto;
  font-size: .82rem;
  color: rgba(255,255,255,.8);
}
.navbar-user strong { color: white; }
.btn-logout {
  background: rgba(255,255,255,.12);
  border: none;
  color: white;
  padding: .3rem .75rem;
  border-radius: var(--radius);
  font-size: .82rem;
  font-weight: 600;
  transition: background .15s;
}
.btn-logout:hover { background: rgba(249,115,22,.75); }
.hamburger {
  display: none;
  background: none;
  border: none;
  color: white;
  font-size: 1.5rem;
  margin-left: auto;
  padding: .3rem;
}

/* ─── Mobile Nav ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .navbar-links { display: none; flex-direction: column; position: absolute; top: 58px; left: 0; right: 0; background: var(--primary-dark); padding: .5rem; gap: .15rem; }
  .navbar-links.open { display: flex; }
  .navbar-links a { padding: .65rem 1rem; border-radius: var(--radius); }
  .hamburger { display: block; }
  .navbar-user span { display: none; }
}

/* ─── Main Layout ────────────────────────────────────────────── */
main { flex: 1; padding: 1.5rem 1.2rem 2.5rem; max-width: 1100px; margin: 0 auto; width: 100%; }

/* ─── Page Header ────────────────────────────────────────────── */
.page-header { margin-bottom: 1.25rem; }
.page-header h1 { font-size: 1.45rem; font-weight: 700; color: var(--primary); }
.page-header p  { color: var(--muted); font-size: .875rem; margin-top: .2rem; }

/* ─── Cards ──────────────────────────────────────────────────── */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: .3rem;
}
.card-label { font-size: .78rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.card-value { font-size: 1.9rem; font-weight: 700; color: var(--primary); line-height: 1; }
.card-value.accent { color: var(--accent); }
.card-sub   { font-size: .78rem; color: var(--muted); }
.card.primary { background: var(--primary); }
.card.primary .card-label, .card.primary .card-sub { color: rgba(255,255,255,.65); }
.card.primary .card-value { color: white; }
.card.accent-card { background: var(--accent); }
.card.accent-card .card-label, .card.accent-card .card-sub { color: rgba(255,255,255,.75); }
.card.accent-card .card-value { color: white; }

/* ─── Section Box ────────────────────────────────────────────── */
.box {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 1.5rem;
}
.box-header {
  background: var(--primary);
  color: white;
  padding: .75rem 1.2rem;
  font-weight: 700;
  font-size: .9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.box-body { padding: 1.2rem; }

/* ─── Tables ─────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
thead tr { background: var(--primary); color: white; }
thead th { padding: .65rem .9rem; text-align: left; font-weight: 600; white-space: nowrap; }
tbody tr { border-bottom: 1px solid var(--border); transition: background .12s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
tbody td { padding: .6rem .9rem; vertical-align: middle; }
tbody tr:nth-child(even) { background: #f8fafc; }
tbody tr:nth-child(even):hover { background: #eff3f8; }

.units-table th { background: var(--primary); color: white; font-size: .8rem; padding: .5rem .7rem; }
.units-table td { padding: .45rem .7rem; font-size: .875rem; }

/* ─── Badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .2rem .65rem;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 600;
}
.badge-success { background: #dcfce7; color: #15803d; }
.badge-warn    { background: #fef3c7; color: #b45309; }
.badge-info    { background: #dbeafe; color: #1d4ed8; }
.badge-muted   { background: #f1f5f9; color: #64748b; }

/* ─── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1.1rem;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: .875rem;
  border: none;
  transition: background .15s, box-shadow .15s, transform .1s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-accent  { background: var(--accent); color: white; }
.btn-accent:hover  { background: var(--accent-dark); }
.btn-outline { background: white; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover { background: #eff4fb; }
.btn-danger  { background: var(--danger); color: white; }
.btn-danger:hover  { background: #dc2626; }
.btn-sm { padding: .3rem .75rem; font-size: .8rem; }
.btn-ghost { background: none; border: none; color: var(--muted); padding: .3rem .5rem; font-size: .82rem; }
.btn-ghost:hover { color: var(--text); background: var(--bg); border-radius: var(--radius); }
.btn-group { display: flex; gap: .6rem; flex-wrap: wrap; }

/* ─── Forms ──────────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.form-group { display: flex; flex-direction: column; gap: .35rem; }
.form-group label { font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.form-group input,
.form-group select,
.form-group textarea {
  padding: .55rem .8rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
  color: var(--text);
  background: white;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
.form-group input:focus,
.form-group select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(30,58,95,.12); }
.form-group.full { grid-column: 1 / -1; }

.filter-bar { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1.2rem; }
.filter-bar .form-group { flex: 1; min-width: 160px; }
.filter-bar label { font-size: .75rem; }

/* ─── Login Page ─────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary) 0%, #0f2440 100%);
  padding: 1rem;
}
.login-card {
  background: white;
  border-radius: 14px;
  width: 100%;
  max-width: 420px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.login-header {
  background: var(--primary);
  padding: 2rem 2rem 1.5rem;
  text-align: center;
  color: white;
}
.login-header .logo-text { font-size: 2rem; font-weight: 900; letter-spacing: .06em; }
.login-header .logo-bar {
  display: block;
  width: 40px; height: 4px;
  background: var(--accent);
  border-radius: 2px;
  margin: .5rem auto;
}
.login-header p { font-size: .82rem; color: rgba(255,255,255,.7); margin-top: .25rem; }
.login-body { padding: 2rem; }
.login-body .form-group { margin-bottom: 1rem; }
.login-body .form-group label { font-size: .82rem; font-weight: 600; color: var(--muted); display: block; margin-bottom: .35rem; }
.login-body input {
  width: 100%;
  padding: .65rem .9rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: .95rem;
  outline: none;
  transition: border-color .15s;
}
.login-body input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(30,58,95,.12); }
.btn-login {
  width: 100%;
  padding: .75rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, transform .1s;
  margin-top: .5rem;
}
.btn-login:hover { background: var(--accent-dark); }
.btn-login:active { transform: scale(.98); }
.login-error {
  background: #fee2e2;
  color: #dc2626;
  border-radius: var(--radius);
  padding: .6rem .9rem;
  font-size: .85rem;
  margin-top: .75rem;
  display: none;
}

/* ─── Alert / Toast ──────────────────────────────────────────── */
.alert {
  padding: .75rem 1rem;
  border-radius: var(--radius);
  font-size: .875rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: .6rem;
}
.alert-success { background: #dcfce7; color: #15803d; border-left: 4px solid #22c55e; }
.alert-danger  { background: #fee2e2; color: #dc2626; border-left: 4px solid #ef4444; }
.alert-warn    { background: #fef3c7; color: #b45309; border-left: 4px solid #f59e0b; }

#toast-container { position: fixed; top: 1.2rem; right: 1.2rem; z-index: 9999; display: flex; flex-direction: column; gap: .5rem; }
.toast {
  min-width: 260px;
  background: white;
  border-radius: var(--radius);
  padding: .85rem 1.1rem;
  box-shadow: 0 4px 20px rgba(0,0,0,.18);
  border-left: 4px solid var(--primary);
  font-size: .875rem;
  animation: slideIn .25s ease;
}
.toast.success { border-color: var(--success); }
.toast.error   { border-color: var(--danger); }
@keyframes slideIn { from { transform: translateX(120%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ─── Footer ─────────────────────────────────────────────────── */
footer {
  background: var(--primary);
  color: rgba(255,255,255,.7);
  text-align: center;
  padding: .85rem 1rem;
  font-size: .78rem;
  margin-top: auto;
}

/* ─── Spinner ────────────────────────────────────────────────── */
.spinner { display: inline-block; width: 22px; height: 22px; border: 3px solid rgba(30,58,95,.2); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; justify-content: center; padding: 3rem; }

/* ─── Empty state ────────────────────────────────────────────── */
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty .empty-icon { font-size: 2.5rem; margin-bottom: .75rem; }

/* ─── Responsive ──────────────────────────────────────────────── */
@media (max-width: 600px) {
  main { padding: 1rem .75rem 2rem; }
  .cards { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .filter-bar { flex-direction: column; }
  .filter-bar .form-group { min-width: 100%; }
  .btn-group { gap: .4rem; }
}

/* ─── Misc ───────────────────────────────────────────────────── */
.divider { border: none; border-top: 1px solid var(--border); margin: 1.2rem 0; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.hidden { display: none !important; }
