/* ── Design tokens ─────────────────────────────────────────────────────── */
:root {
  --bg:           #f5f7fb;
  --surface:      #ffffff;
  --surface-2:    #fafbfd;
  --border:       #e5e8ef;
  --border-2:     #d8dce4;
  --text:         #1a2233;
  --text-muted:   #6b7384;
  --text-soft:    #95a0b2;

  --brand:        #2451c7;
  --brand-strong: #1b3fa3;
  --brand-soft:   #e8eefc;
  --accent:       #14b8a6;
  --danger:       #d8324a;
  --danger-soft:  #fde8ec;
  --warning:      #f5a524;
  --success:      #16a34a;

  --shadow-sm:    0 1px 2px rgba(15, 22, 41, .04), 0 1px 3px rgba(15, 22, 41, .05);
  --shadow-md:    0 2px 6px rgba(15, 22, 41, .06), 0 8px 24px rgba(15, 22, 41, .08);
  --shadow-lg:    0 4px 12px rgba(15, 22, 41, .08), 0 24px 48px rgba(15, 22, 41, .12);

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 22px; font-weight: 600; letter-spacing: -.01em; margin: 0 0 16px 0; }
h2 { font-size: 15px; font-weight: 600; margin: 14px 0 10px 0; color: var(--text); }

/* ── Topbar ────────────────────────────────────────────────────────────── */
#topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 0 22px; height: 56px;
  background: linear-gradient(180deg, #1f2a4e 0%, #1a2342 100%);
  color: #fff;
  box-shadow: var(--shadow-sm);
  position: sticky; top: 0; z-index: 10;
}
#topbar strong { font-size: 15px; letter-spacing: .02em; }
#topbar nav { display: flex; gap: 4px; }
#topbar nav a {
  color: #c6cde0; text-decoration: none;
  padding: 7px 12px; border-radius: var(--r-sm);
  font-weight: 500; transition: background .15s, color .15s;
}
#topbar nav a:hover { background: rgba(255, 255, 255, .08); color: #fff; }
#topbar nav a.active {
  background: rgba(255, 255, 255, .12); color: #fff;
}
#topbar .spacer { flex: 1; }
#topbar #who {
  color: #c6cde0; font-size: 13px;
  display: inline-flex; align-items: center; gap: 8px;
}
#topbar #who::before {
  content: ""; width: 28px; height: 28px;
  border-radius: 50%; background: rgba(255, 255, 255, .15);
  display: inline-block;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23ffffff'><path d='M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z'/></svg>");
  background-size: 18px; background-position: center; background-repeat: no-repeat;
}
#topbar button {
  background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .15);
  color: #fff; padding: 6px 14px; border-radius: var(--r-sm); cursor: pointer;
  font: inherit; transition: background .15s;
}
#topbar button:hover { background: rgba(255, 255, 255, .18); }

/* ── Layout ────────────────────────────────────────────────────────────── */
main { padding: 24px; max-width: 1280px; margin: 0 auto; }
.loading { color: var(--text-muted); padding: 20px 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

/* ── Form controls ─────────────────────────────────────────────────────── */
input, select, textarea {
  padding: 8px 10px;
  border: 1px solid var(--border-2);
  border-radius: var(--r-sm);
  font: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
input:hover, select:hover, textarea:hover { border-color: #bcc1cd; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
input:disabled, textarea:disabled { background: var(--surface-2); color: var(--text-muted); }
select { appearance: none; -webkit-appearance: none; -moz-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%236b7384'><path d='M7 10l5 5 5-5z'/></svg>");
  background-repeat: no-repeat; background-position: right 6px center;
  padding-right: 28px;
}

/* ── Buttons ───────────────────────────────────────────────────────────── */
button {
  padding: 7px 14px;
  border: 1px solid var(--border-2);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--r-sm);
  cursor: pointer;
  font: inherit; font-weight: 500;
  transition: background .15s, border-color .15s, transform .05s;
}
button:hover { background: var(--surface-2); border-color: #bcc1cd; }
button:active { transform: translateY(1px); }
button.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
button.primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
button.danger { background: var(--surface); color: var(--danger); border-color: var(--danger); }
button.danger:hover { background: var(--danger-soft); }
button:disabled { opacity: .5; cursor: not-allowed; }

/* ── Filters ───────────────────────────────────────────────────────────── */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px 14px; align-items: end; }
.filters label { display: flex; flex-direction: column; gap: 4px;
  font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-muted);
}
.filters .actions { display: flex; gap: 8px; align-items: end; grid-column: 1 / -1; flex-wrap: wrap; }
.filters .actions a { text-decoration: none; }

/* ── Table ─────────────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); font-size: 13.5px; }
table th, table td { padding: 10px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
table th {
  background: var(--surface-2);
  font-weight: 600; color: var(--text-muted);
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  cursor: pointer; user-select: none;
  position: sticky; top: 0; z-index: 1;
}
table th:hover { color: var(--text); }
table th.sorted-asc::after  { content: " ↑"; color: var(--brand); font-weight: 700; }
table th.sorted-desc::after { content: " ↓"; color: var(--brand); font-weight: 700; }
table tbody tr { transition: background .1s; }
table tbody tr:hover { background: var(--brand-soft); }
table tbody tr:last-child td { border-bottom: none; }
table td.actions { white-space: nowrap; text-align: right; }
table td.actions a { text-decoration: none; }

/* ── Pager ─────────────────────────────────────────────────────────────── */
.pager {
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border);
  display: flex; gap: 10px; align-items: center;
}
.pager .info { color: var(--text-muted); font-size: 12.5px; }
.pager button { min-width: 36px; }

/* ── Form grid ─────────────────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.form-grid label { display: flex; flex-direction: column; gap: 5px;
  font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-muted);
}
.form-grid label.full { grid-column: 1 / -1; }
.form-grid textarea { min-height: 90px; resize: vertical; font-family: inherit; }
.form-actions { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border);
  display: flex; gap: 10px; }

/* ── Login ─────────────────────────────────────────────────────────────── */
body:has(.login-screen) {
  background:
    radial-gradient(1200px 600px at 90% -10%, rgba(36, 81, 199, .18), transparent 60%),
    radial-gradient(900px 600px at -10% 110%, rgba(20, 184, 166, .15), transparent 60%),
    linear-gradient(180deg, #f5f7fb 0%, #eef1f8 100%);
  min-height: 100vh;
}
.login-screen {
  max-width: 400px; margin: 0 auto;
  min-height: 100vh; display: flex; flex-direction: column; justify-content: center;
  padding: 24px;
}
.login-screen h1 {
  text-align: center; margin: 0 0 6px 0;
  font-size: 24px; font-weight: 700; letter-spacing: -.02em;
}
.login-screen .subtitle {
  text-align: center; color: var(--text-muted); font-size: 13px;
  margin: 0 0 28px 0;
}
.login-screen .card {
  box-shadow: var(--shadow-lg);
  padding: 28px;
  border: none;
  border-radius: var(--r-lg);
}
.login-screen .card form { display: flex; flex-direction: column; gap: 14px; }
.login-screen .card label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 12px; font-weight: 500; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .05em;
}
.login-screen .card input { padding: 10px 12px; font-size: 14px; }
.login-screen .card button.primary { margin-top: 6px; padding: 11px; font-size: 14px; font-weight: 600; }
.login-screen .card .error {
  color: var(--danger); font-size: 13px; min-height: 18px;
  display: flex; align-items: center; gap: 6px;
}
.login-screen .card .error:not(:empty)::before {
  content: "⚠"; font-size: 14px;
}

/* ── Toast ─────────────────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 20px; right: 20px;
  background: #1f2a4e; color: #fff;
  padding: 11px 16px; border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
  max-width: 380px; font-size: 13.5px;
  animation: toast-in .25s ease;
}
#toast.error { background: var(--danger); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Utilities ─────────────────────────────────────────────────────────── */
.muted { color: var(--text-muted); }
.right { text-align: right; }
