/* ─── Variables — Dark theme (default) ───────────────────────────────────── */
:root {
  --bg:             #0f172a;
  --card:           #1e293b;
  --border:         #334155;
  --accent:         #38bdf8;
  --accent-glow:    rgba(56, 189, 248, 0.15);
  --text:           #e2e8f0;
  --muted:          #64748b;
  --danger:         #f87171;
  --success:        #4ade80;
  --warning:        #fbbf24;
  --radius:         8px;
  --radius-lg:      12px;
  /* Surface helpers — differ between themes */
  --head-bg:        rgba(255,255,255,0.04);
  --row-hover:      rgba(255,255,255,0.03);
  --row-even:       rgba(255,255,255,0.015);
  --row-even-hover: rgba(255,255,255,0.04);
  --ghost-hover:    rgba(255,255,255,0.05);
  --overlay:        rgba(0,0,0,0.55);
  --shadow:         0 20px 60px rgba(0,0,0,0.5);
}

/* ─── Variables — Light theme ────────────────────────────────────────────── */
html[data-theme="light"] {
  --bg:             #f1f5f9;
  --card:           #ffffff;
  --border:         #e2e8f0;
  --accent:         #0284c7;
  --accent-glow:    rgba(2, 132, 199, 0.15);
  --text:           #0f172a;
  --muted:          #64748b;
  --danger:         #dc2626;
  --success:        #16a34a;
  --warning:        #d97706;
  --head-bg:        rgba(0,0,0,0.04);
  --row-hover:      rgba(0,0,0,0.03);
  --row-even:       rgba(0,0,0,0.015);
  --row-even-hover: rgba(0,0,0,0.04);
  --ghost-hover:    rgba(0,0,0,0.05);
  --overlay:        rgba(0,0,0,0.45);
  --shadow:         0 20px 60px rgba(0,0,0,0.15);
}

/* ─── Reset & Base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 0.9rem;
  line-height: 1.5;
}

/* ─── Layout ─────────────────────────────────────────────────────────────── */
.app-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.main-content {
  flex: 1;
  padding: 1.5rem;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

/* ─── Header ─────────────────────────────────────────────────────────────── */
.app-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  gap: 1rem;
  flex-shrink: 0;
}

.app-header .brand {
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.username-badge {
  font-size: 0.8rem;
  color: var(--muted);
}

/* ─── Nav Tabs ───────────────────────────────────────────────────────────── */
.nav-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  background: var(--card);
}

.nav-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.75rem 1rem;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}

.nav-tab:hover { color: var(--text); }

.nav-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ─── Login ──────────────────────────────────────────────────────────────── */
.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  padding-bottom: 14vh;
  background: var(--bg);
}

.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
}

.login-logo {
  font-size: 1.75rem;
  margin-bottom: 0.5rem;
}

.login-card h1 {
  font-size: 1.4rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.login-card .subtitle {
  color: var(--muted);
  font-size: 0.875rem;
  margin-bottom: 2rem;
}

/* ─── Form Elements ──────────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

.form-control {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
  padding: 0.625rem 0.875rem;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}

.form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-control::placeholder { color: var(--muted); }

input[type="date"].form-control { color-scheme: dark; }
html[data-theme="light"] input[type="date"].form-control { color-scheme: light; }

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
  transition: opacity 0.15s, background 0.15s;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #ffffff;
}
.btn-primary:hover:not(:disabled) { opacity: 0.88; }

.btn-danger {
  background: var(--danger);
  color: #ffffff;
}
.btn-danger:hover:not(:disabled) { opacity: 0.88; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-ghost:hover:not(:disabled) { background: var(--ghost-hover); }

.btn-sm { font-size: 0.8rem; padding: 0.35rem 0.7rem; }

.btn-full { width: 100%; }

/* ─── Alerts / Error messages ────────────────────────────────────────────── */
.alert {
  border-radius: var(--radius);
  font-size: 0.875rem;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
}

.alert-error {
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.3);
  color: var(--danger);
}

.alert-success {
  background: rgba(74, 222, 128, 0.1);
  border: 1px solid rgba(74, 222, 128, 0.25);
  color: var(--success);
}

/* ─── Card / Section ─────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.section-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

/* ─── Toolbar (search + actions) ─────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.toolbar .form-control { max-width: 260px; }

/* ─── Table ──────────────────────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead th {
  background: var(--head-bg);
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  padding: 0.75rem 1rem;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

tbody tr:last-child { border-bottom: none; }

tbody tr:hover { background: var(--row-hover); }

tbody tr:nth-child(even)       { background: var(--row-even); }
tbody tr:nth-child(even):hover { background: var(--row-even-hover); }

td {
  padding: 0.75rem 1rem;
  vertical-align: middle;
}

.td-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* ─── Badges ─────────────────────────────────────────────────────────────── */
.badge {
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.6rem;
  text-transform: uppercase;
}

.badge-success {
  background: rgba(74, 222, 128, 0.15);
  color: var(--success);
  border: 1px solid rgba(74, 222, 128, 0.25);
}

.badge-danger {
  background: rgba(248, 113, 113, 0.15);
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.25);
}

.badge-warning {
  background: rgba(251, 191, 36, 0.15);
  color: var(--warning);
  border: 1px solid rgba(251, 191, 36, 0.25);
}

.badge-muted {
  background: rgba(100, 116, 139, 0.15);
  color: var(--muted);
  border: 1px solid rgba(100, 116, 139, 0.25);
}

/* ─── Toggle switch ──────────────────────────────────────────────────────── */
.toggle {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  cursor: pointer;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 999px;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  left: 3px;
  top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); }

/* ─── Pagination ─────────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1rem;
  font-size: 0.8rem;
  color: var(--muted);
}

/* ─── Modal ──────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.modal-header h3 {
  font-size: 1rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 1;
  padding: 0.2rem;
  transition: color 0.15s;
}

.modal-close:hover { color: var(--text); }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

/* ─── Filters row ────────────────────────────────────────────────────────── */
.filters {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
  align-items: flex-end;
}

.filters .form-group { margin-bottom: 0; }
.filters label { margin-bottom: 0.3rem; }

/* ─── Misc helpers ───────────────────────────────────────────────────────── */
.text-muted { color: var(--muted); }
.font-mono  { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 0.82rem; }
[x-cloak]   { display: none !important; }

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .main-content { padding: 1rem; }
  .app-header   { padding: 0 1rem; }
  .nav-tabs      { padding: 0 1rem; }
  .toolbar       { flex-direction: column; align-items: stretch; }
  .toolbar .form-control { max-width: 100%; }
  .filters       { flex-direction: column; }
  .section-header { flex-direction: column; align-items: flex-start; }
}
