/* ── Tokens ──────────────────────────────────────────────────────────────── */
:root {
  --bg:        oklch(97% 0.003 260);
  --surface:   oklch(100% 0 0);
  --raised:    oklch(94% 0.005 260);
  --border:    oklch(88% 0.006 260);
  --muted:     oklch(58% 0.012 260);
  --body:      oklch(18% 0.010 260);
  --accent:    oklch(50% 0.18  260);
  --accent-hv: oklch(44% 0.18  260);
  --accent-lt: oklch(94% 0.04  260);
  --danger:    oklch(52% 0.20  25);
  --danger-lt: oklch(95% 0.04  25);
  --success:   oklch(52% 0.16  155);
  --success-lt:oklch(95% 0.04  155);

  --r-sm: 4px;
  --r-md: 8px;
  --r-lg: 12px;

  --shadow-sm: 0 1px 3px oklch(0% 0 0 / .08);
  --shadow-md: 0 4px 12px oklch(0% 0 0 / .10);

  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", "Fira Mono", monospace;
}

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

html { font-size: 15px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--body);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Layout ───────────────────────────────────────────────────────────────── */
.page-wrap {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

.content {
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

/* ── Nav ──────────────────────────────────────────────────────────────────── */
nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.nav-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 24px;
}

.nav-brand {
  font-weight: 600;
  font-size: .95rem;
  letter-spacing: .02em;
  color: var(--body);
  text-decoration: none;
}

.nav-links {
  display: flex;
  gap: 4px;
  flex: 1;
}

.nav-links a {
  padding: 5px 12px;
  border-radius: var(--r-sm);
  font-size: .875rem;
  color: var(--muted);
  transition: background 140ms, color 140ms;
}

.nav-links a:hover, .nav-links a.active {
  background: var(--raised);
  color: var(--body);
  text-decoration: none;
}

.nav-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: .8rem;
  color: var(--muted);
}

.nav-meta .logout {
  padding: 4px 10px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  font-size: .8rem;
  color: var(--muted);
  transition: border-color 140ms, color 140ms;
}

.nav-meta .logout:hover { color: var(--danger); border-color: var(--danger); text-decoration: none; }

/* ── Login ────────────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  padding: 40px 36px;
  width: 100%;
  max-width: 360px;
}

.login-card h1 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 28px;
  color: var(--body);
}

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  padding: 24px;
  margin-bottom: 24px;
}

/* ── Page heading ─────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}

.page-header h1 {
  font-size: 1.15rem;
  font-weight: 600;
}

/* ── Forms ────────────────────────────────────────────────────────────────── */
.field { margin-bottom: 16px; }

label {
  display: block;
  font-size: .8rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 5px;
  letter-spacing: .03em;
  text-transform: uppercase;
}

input[type="text"],
input[type="password"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 8px 12px;
  font-family: var(--font);
  font-size: .9rem;
  color: var(--body);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  transition: border-color 140ms, box-shadow 140ms;
  outline: none;
  appearance: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-lt);
}

input::placeholder, textarea::placeholder { color: var(--muted); }

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2394a3b8' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

/* ── Filter bar ───────────────────────────────────────────────────────────── */
.filter-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px 20px;
  margin-bottom: 20px;
}

.filter-bar form {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  align-items: end;
}

.filter-bar .field { margin-bottom: 0; }

.filter-actions {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding-bottom: 1px;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--r-sm);
  font-family: var(--font);
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background 140ms, opacity 140ms;
  white-space: nowrap;
  min-height: 36px;
}

.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  background: var(--accent);
  color: oklch(99% 0 0);
}
.btn-primary:hover { background: var(--accent-hv); text-decoration: none; }

.btn-secondary {
  background: var(--raised);
  color: var(--body);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); text-decoration: none; }

.btn-danger {
  background: var(--danger-lt);
  color: var(--danger);
  border: 1px solid oklch(85% 0.06 25);
}
.btn-danger:hover { background: oklch(90% 0.08 25); text-decoration: none; }

.btn-sm {
  padding: 4px 10px;
  font-size: .8rem;
  min-height: 28px;
}

.btn-icon {
  padding: 5px 8px;
  min-height: 28px;
}

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

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

thead {
  background: var(--raised);
  position: sticky;
  top: 0;
  z-index: 1;
}

thead th {
  padding: 10px 14px;
  text-align: left;
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--raised); }

td {
  padding: 10px 14px;
  vertical-align: middle;
}

.td-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.empty-row td {
  text-align: center;
  padding: 32px;
  color: var(--muted);
  font-size: .875rem;
}

/* ── Alerts / Flashes ─────────────────────────────────────────────────────── */
.flash-list { list-style: none; margin-bottom: 20px; }

.flash {
  padding: 10px 14px;
  border-radius: var(--r-sm);
  font-size: .875rem;
  margin-bottom: 8px;
}

.flash-success {
  background: var(--success-lt);
  color: var(--success);
  border: 1px solid oklch(82% 0.07 155);
}

.flash-error {
  background: var(--danger-lt);
  color: var(--danger);
  border: 1px solid oklch(85% 0.08 25);
}

.form-error {
  background: var(--danger-lt);
  color: var(--danger);
  border: 1px solid oklch(85% 0.08 25);
  border-radius: var(--r-sm);
  padding: 10px 14px;
  font-size: .875rem;
  margin-bottom: 16px;
}

/* ── Badge ────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 500;
}

.badge-admin {
  background: var(--accent-lt);
  color: var(--accent);
}

.badge-operator {
  background: var(--raised);
  color: var(--muted);
  border: 1px solid var(--border);
}

/* ── Misc ─────────────────────────────────────────────────────────────────── */
.text-muted { color: var(--muted); font-size: .8rem; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.flex  { display: flex; }
.gap-8 { gap: 8px; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .content { padding: 20px 16px 48px; }
  .login-card { padding: 28px 20px; }
  .filter-bar form { grid-template-columns: 1fr 1fr; }
  .page-header { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0ms !important; }
}
