:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f8f9fa;
  --text: #1c1f23;
  --muted: #62686f;
  --border: #dfe2e6;
  --brand: #2b2f33;
  --brand-ink: #ffffff;
  --accent: #1f5f8b;
  --accent-soft: #e6eff6;
  --ok: #1f7a4d;
  --ok-soft: #e5f4ec;
  --warn: #9a6a00;
  --warn-soft: #fbf1db;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --focus: #1f5f8b;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 32, .06), 0 4px 16px rgba(16, 24, 32, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111315;
    --surface: #1a1d20;
    --surface-2: #202427;
    --text: #e9ebed;
    --muted: #9aa1a8;
    --border: #2d3236;
    --brand: #0c0e10;
    --brand-ink: #e9ebed;
    --accent: #7db4dc;
    --accent-soft: #1b2c38;
    --ok: #6fcf9a;
    --ok-soft: #16281f;
    --warn: #e3b453;
    --warn-soft: #2d2513;
    --danger: #f08a80;
    --danger-soft: #2f1a18;
    --focus: #7db4dc;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.55 "Jost", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1, h2 { font-weight: 500; letter-spacing: .01em; margin: 0; }
h1 { font-size: 28px; }
h2 { font-size: 18px; }
code { font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 14px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .1em; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- logo ---------- */
.logo { display: block; color: currentColor; }
.logo-word { font: 300 46px "Jost", sans-serif; letter-spacing: 6px; fill: currentColor; }
.logo-sub { font: 400 22px "Jost", sans-serif; letter-spacing: 5.5px; fill: currentColor; }
.logo-hex { opacity: .7; }

/* ---------- auth pages ---------- */
.auth-layout { min-height: 100vh; display: grid; grid-template-columns: 1fr; }
.auth-brand {
  background: var(--brand);
  color: var(--brand-ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 40px 16px 32px;
  background-image:
    radial-gradient(ellipse at 30% 20%, rgba(255,255,255,.07), transparent 60%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='64' viewBox='0 0 56 64'%3E%3Cpath d='M28 2 L54 17 L54 47 L28 62 L2 47 L2 17 Z' fill='none' stroke='%23ffffff' stroke-opacity='.035' stroke-width='1.2'/%3E%3C/svg%3E");
}
.logo-hero { width: 150px; height: auto; }
.auth-tagline {
  margin: 18px 0 0; font-size: 13px; letter-spacing: .28em; text-transform: uppercase; opacity: .6;
}
.auth-panel { display: flex; align-items: flex-start; justify-content: center; padding: 32px 16px 48px; }
.auth-card { width: 100%; max-width: 420px; }
.auth-card h1 { margin-bottom: 6px; }
.auth-card > .muted { margin-bottom: 24px; }
.auth-switch { margin: 24px 0 0; text-align: center; color: var(--muted); }
.success-mark {
  width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center;
  background: var(--ok-soft); color: var(--ok); font-size: 26px; margin-bottom: 16px;
}
.auth-card .success-mark + h1 + .muted { margin-bottom: 24px; }

@media (min-width: 900px) {
  .auth-layout { grid-template-columns: minmax(380px, 44%) 1fr; }
  .auth-brand { padding: 48px; }
  .logo-hero { width: 220px; }
  .auth-panel { align-items: center; padding: 48px; }
}

/* ---------- forms ---------- */
.form { display: grid; gap: 16px; }
.form label { display: grid; gap: 6px; font-size: 14px; font-weight: 500; }
.optional { font-weight: 400; color: var(--muted); }
input[type=text], input[type=email], input[type=password], textarea, select {
  width: 100%;
  font: inherit; font-weight: 400; font-size: 16px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px var(--accent-soft);
}
[aria-invalid=true] { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 13px; font-weight: 400; }
.hint { margin: -6px 0 0; font-size: 13px; color: var(--muted); }
.form-row { display: grid; gap: 16px; }
@media (min-width: 520px) { .form-row { grid-template-columns: 1fr 1fr; } }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 500; font-size: 15px;
  padding: 10px 18px; min-height: 44px;
  border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  cursor: pointer; text-decoration: none;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .btn-primary { background: #e9ebed; border-color: #e9ebed; color: #111315; } }
.btn-primary:hover { opacity: .9; border-color: inherit; }
.btn-block { width: 100%; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost-danger { color: var(--danger); }
.btn-ghost-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-sm { min-height: 32px; padding: 4px 12px; font-size: 14px; }
.link-btn {
  font: inherit; font-size: 14px; background: none; border: 0; padding: 6px 4px;
  color: var(--muted); cursor: pointer; text-decoration: underline; text-underline-offset: 3px;
}
.link-btn:hover { color: var(--text); }
.link-btn.danger { color: var(--danger); }

/* ---------- notices ---------- */
.notice { border-radius: 8px; padding: 12px 14px; margin-bottom: 18px; font-size: 15px; border: 1px solid transparent; }
.notice-ok { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.notice-error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.notice-info { background: var(--accent-soft); color: var(--text); border-color: color-mix(in srgb, var(--accent) 30%, transparent); word-break: break-word; }

/* ---------- signed-in shell ---------- */
.topbar { background: var(--brand); color: #fff; position: sticky; top: 0; z-index: 10; }
.topbar-inner {
  max-width: 1080px; margin: 0 auto; padding: 0 16px; min-height: 60px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; margin-right: auto; }
.logo-mark { width: 30px; height: 30px; }
.brand-text { font-weight: 400; letter-spacing: .22em; font-size: 15px; }
.brand-text span { opacity: .6; }
.nav { display: flex; gap: 4px; }
.nav a {
  color: rgba(255,255,255,.72); text-decoration: none; font-size: 15px;
  padding: 8px 12px; border-radius: 8px;
}
.nav a:hover { color: #fff; background: rgba(255,255,255,.08); }
.nav a.active { color: #fff; background: rgba(255,255,255,.14); }
.who { display: flex; align-items: center; gap: 8px; }
.who .link-btn { color: rgba(255,255,255,.72); }
.who .link-btn:hover { color: #fff; }
.who form { margin: 0; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; display: inline-grid; place-items: center;
  background: rgba(255,255,255,.14); color: #fff; font-size: 13px; font-weight: 500; letter-spacing: .04em; flex: none;
}
.avatar-lg { width: 44px; height: 44px; font-size: 15px; background: var(--accent-soft); color: var(--accent); }
.badge {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px; background: #d9822b; color: #fff; font-size: 12px; font-weight: 600; line-height: 1;
}
.count { color: var(--muted); font-size: 14px; }

@media (max-width: 640px) {
  .brand-text { display: none; }
  .topbar-inner { gap: 8px; }
  .nav a { padding: 8px 10px; }
}

.container { max-width: 1080px; margin: 0 auto; padding: 32px 16px 64px; }
.container.narrow { max-width: 560px; }
.page-head { margin-bottom: 24px; }
.page-head h1 { margin-bottom: 4px; }

/* ---------- app launcher ---------- */
.app-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.app-tile {
  display: flex; align-items: center; gap: 16px;
  padding: 20px; background: var(--surface); color: inherit; text-decoration: none;
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  transition: border-color .15s, transform .15s;
}
.app-tile:hover { border-color: var(--accent); transform: translateY(-2px); }
.app-icon {
  width: 52px; height: 52px; flex: none; display: grid; place-items: center;
  font-weight: 500; letter-spacing: .06em; color: #fff; background: var(--brand);
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
}
@media (prefers-color-scheme: dark) { .app-icon { background: #3a4046; } }
.app-body { display: grid; gap: 2px; min-width: 0; flex: 1; }
.app-name { font-weight: 500; font-size: 17px; }
.app-ver { color: var(--muted); font-size: 13px; font-weight: 400; }
.app-desc { color: var(--muted); font-size: 14px; }
.app-go { color: var(--muted); font-size: 20px; transition: transform .15s, color .15s; }
.app-tile:hover .app-go { transform: translateX(3px); color: var(--accent); }
.empty-state {
  padding: 32px; text-align: center; color: var(--muted);
  border: 1px dashed var(--border); border-radius: var(--radius); background: var(--surface);
}
.empty-state p { margin: 0; }

/* ---------- admin ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tabs a {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 14px; color: var(--muted); text-decoration: none; font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--text); border-bottom-color: var(--text); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px;
}
.card > h2 { margin-bottom: 16px; }
.user-card.is-inactive { opacity: .72; }
.user-head { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; }
.user-head > div { flex: 1; min-width: 180px; }
.user-head h2 { font-size: 17px; }
.pill {
  font-size: 12px; font-weight: 500; padding: 3px 10px; border-radius: 999px; white-space: nowrap;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.pill-active { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill-pending { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill-disabled, .pill-rejected { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.reason {
  margin: 14px 0 0; padding: 10px 14px; border-left: 3px solid var(--border);
  background: var(--surface-2); border-radius: 0 8px 8px 0; color: var(--text); font-size: 15px;
}
.user-form {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px 24px;
  margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border);
}
.app-checks { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px 16px; flex: 1; min-width: 220px; }
.app-checks legend { font-size: 13px; color: var(--muted); padding: 0; margin-bottom: 8px; }
.check {
  display: inline-flex; align-items: center; gap: 8px; font-size: 15px;
  padding: 6px 12px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; background: var(--surface-2);
}
.check:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.check input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.role { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.role select { width: auto; min-width: 120px; padding: 8px 10px; }
.actions { display: flex; gap: 8px; }
.secondary-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-top: 12px; }
.secondary-actions form { margin: 0; }
.confirm summary { list-style: none; display: inline-block; }
.confirm summary::-webkit-details-marker { display: none; }
.confirm[open] summary { display: none; }
.confirm form { display: inline-flex; align-items: center; gap: 8px; }
