/* OneOryx UI — responsive (phone / laptop / widescreen), light + dark themes. */

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef2f8;
  --text: #0f1b33;
  --muted: #5a6680;
  --border: #dde3ee;
  --navy: #13235b;
  --navy-2: #1c2f73;
  --side-bg: #13235b;
  --side-text: #c9d3ee;
  --side-active: #ffffff;
  --primary: #3d8a24;
  --primary-hover: #33761e;
  --primary-ink: #ffffff;
  --accent-text: #3d8a24;
  --focus: #5b8cff;
  --danger: #c0392b;
  --danger-bg: #fdecea;
  --warn: #9a6400;
  --warn-bg: #fff4e0;
  --ok: #2b7a3d;
  --ok-bg: #e7f6ea;
  --info-bg: #e9efff;
  --shadow: 0 1px 2px rgba(15, 27, 51, .06), 0 4px 16px rgba(15, 27, 51, .06);
  --radius: 12px;
  --radius-sm: 8px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --sidebar-w: 256px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a1020; --surface: #111a2e; --surface-2: #18233b; --text: #e7ecf6; --muted: #9ba7c0;
    --border: #25324f; --side-bg: #0c1530; --side-text: #a9b6d6; --side-active: #ffffff;
    --primary: #6cc04a; --primary-hover: #7fd25d; --primary-ink: #0b1a06; --accent-text: #7fd25d;
    --danger: #ff7b6e; --danger-bg: #3a1714; --warn: #f2b84b; --warn-bg: #3a2a0c;
    --ok: #74d68b; --ok-bg: #12301b; --info-bg: #182650;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0a1020; --surface: #111a2e; --surface-2: #18233b; --text: #e7ecf6; --muted: #9ba7c0;
  --border: #25324f; --side-bg: #0c1530; --side-text: #a9b6d6; --side-active: #ffffff;
  --primary: #6cc04a; --primary-hover: #7fd25d; --primary-ink: #0b1a06; --accent-text: #7fd25d;
  --danger: #ff7b6e; --danger-bg: #3a1714; --warn: #f2b84b; --warn-bg: #3a2a0c;
  --ok: #74d68b; --ok-bg: #12301b; --info-bg: #182650;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.55 var(--font); }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-family: var(--font-display); font-weight: 600; font-size: clamp(1.5rem, 1.2rem + 1vw, 2rem); }
h2 { font-size: 1.1rem; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 650; }
p { margin: 0 0 1rem; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- App shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: var(--side-bg); color: var(--side-text); padding: 20px 14px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 18px;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; letter-spacing: .04em; padding: 4px 8px; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 30px; height: 30px; flex: none; }
.brand small { display: block; font-weight: 500; letter-spacing: 0; color: var(--side-text); font-size: .78rem; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; opacity: .65; padding: 12px 10px 4px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--side-text); font-weight: 500;
}
.nav a:hover { background: rgba(255, 255, 255, .07); color: #fff; text-decoration: none; }
.nav a.is-active { background: rgba(255, 255, 255, .12); color: var(--side-active); box-shadow: inset 3px 0 0 #6cc04a; }
.nav a.is-soon { opacity: .55; }
.nav svg { width: 18px; height: 18px; flex: none; }
.badge-soon { margin-left: auto; font-size: .65rem; border: 1px solid currentColor; border-radius: 999px; padding: 0 6px; }
.sidebar-foot { margin-top: auto; font-size: .82rem; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 12px clamp(16px, 3vw, 32px);
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.nav-toggle { display: none; }
.content { padding: clamp(16px, 3vw, 32px); width: 100%; max-width: 1280px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-bottom: 20px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: .9rem; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--navy-2); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: .8rem; flex: none;
}

.impersonation-bar {
  background: var(--warn-bg); color: var(--warn); border-bottom: 1px solid var(--border);
  padding: 8px clamp(16px, 3vw, 32px); display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-size: .9rem;
}
.impersonation-bar form { margin-left: auto; }

/* ---------- Components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 20px; }
.grid > .card + .card, .grid > * + .card { margin-top: 0; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-head h2 { margin: 0; }
.card-head .actions { margin-left: auto; }
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.stack > * + * { margin-top: 20px; }

.stat { padding: 18px 20px; }
.stat-label { color: var(--muted); font-size: .82rem; font-weight: 500; }
.stat-value { font-size: 1.9rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; margin-top: 4px; }
.stat-note { font-size: .8rem; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 8px 16px;
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger:hover { background: var(--danger-bg); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { min-height: 32px; padding: 4px 10px; font-size: .85rem; }
.btn-block { width: 100%; }
.icon-btn { min-height: 38px; min-width: 38px; padding: 6px 10px; }
.btn svg { width: 18px; height: 18px; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 6px; }
.field .hint { font-size: .8rem; color: var(--muted); margin-top: 4px; }
.field .error { font-size: .82rem; color: var(--danger); margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], input[type=tel], select, textarea {
  width: 100%; min-height: 42px; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
.input-group { display: flex; align-items: stretch; }
.input-group input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group .addon { display: flex; align-items: center; padding: 0 12px; border: 1px solid var(--border); border-left: 0; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.check { display: flex; align-items: center; gap: 10px; padding: 8px 0; font-weight: 500; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 20px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.toolbar input[type=search] { flex: 1 1 240px; }
.toolbar select { flex: 0 1 180px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-ok { background: var(--ok-bg); color: var(--ok); }
.pill-warn { background: var(--warn-bg); color: var(--warn); }
.pill-danger { background: var(--danger-bg); color: var(--danger); }
.pill-info { background: var(--info-bg); color: var(--accent-text); }
.pill.no-dot::before { display: none; }

.flash-stack { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.flash { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); }
.flash-success { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.flash-error { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.flash [data-dismiss] { margin-left: auto; background: none; border: 0; color: inherit; cursor: pointer; font-size: 1.1rem; line-height: 1; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list .when { margin-left: auto; color: var(--muted); font-size: .8rem; white-space: nowrap; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; margin: 0; }
.kv dt { color: var(--muted); font-size: .88rem; }
.kv dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.module { display: flex; flex-direction: column; gap: 6px; }
.module .pill { align-self: flex-start; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.pagination { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* ---------- Auth & public pages ---------- */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.auth-side {
  background: var(--navy); color: #e6ebf8; padding: clamp(32px, 5vw, 64px); display: flex; flex-direction: column; justify-content: space-between;
  background-image: radial-gradient(circle at 85% 15%, rgba(108, 192, 74, .18), transparent 45%);
}
.auth-side h2 { font-family: var(--font-display); font-size: clamp(1.8rem, 1.2rem + 2vw, 2.8rem); font-weight: 500; color: #fff; }
.auth-side h2 em { color: #8fd36e; }
.auth-main { display: grid; place-items: center; padding: 32px 16px; position: relative; }
.auth-card { width: 100%; max-width: 420px; }
.auth-card h1 { margin-bottom: 4px; }
.auth-card .field + .field { margin-top: 14px; }
.corner-actions { position: absolute; top: 16px; right: 16px; }

.site-header { display: flex; align-items: center; gap: 16px; padding: 16px clamp(16px, 4vw, 48px); background: var(--surface); border-bottom: 1px solid var(--border); }
.site-header .brand { color: var(--text); }
.site-header .brand small { color: var(--muted); }
.site-header nav { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.hero { background: var(--navy); color: #e6ebf8; padding: clamp(48px, 8vw, 112px) clamp(16px, 4vw, 48px); }
.hero-inner { max-width: 1200px; margin: 0 auto; }
.eyebrow { text-transform: uppercase; letter-spacing: .14em; font-size: .75rem; font-weight: 700; color: #8fd36e; }
.hero h1 { font-size: clamp(2.2rem, 1.4rem + 3.5vw, 4rem); color: #fff; font-weight: 500; max-width: 16ch; margin: 12px 0 16px; }
.hero h1 em { color: #8fd36e; }
.hero p { max-width: 56ch; font-size: 1.08rem; color: #c9d3ee; }
.section { padding: clamp(40px, 6vw, 80px) clamp(16px, 4vw, 48px); }
.section-inner { max-width: 1200px; margin: 0 auto; }
.site-footer { padding: 24px clamp(16px, 4vw, 48px); border-top: 1px solid var(--border); color: var(--muted); font-size: .85rem; }

.center-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; text-align: center; }
.center-page .card { max-width: 480px; width: 100%; }
.error-code { font-family: var(--font-display); font-size: 3.5rem; color: var(--accent-text); line-height: 1; }

.scrim { display: none; }

/* ---------- Responsive ---------- */
@media (min-width: 1600px) {
  :root { --sidebar-w: 280px; }
  body { font-size: 16px; }
  .content { max-width: 1600px; }
  .grid-4-wide { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(84vw, 300px); z-index: 50;
    transform: translateX(-100%); transition: transform .2s ease;
  }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .35); }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(5, 10, 25, .5); z-index: 40; }
  .nav-toggle { display: inline-flex; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .auth-wrap { grid-template-columns: minmax(0, 1fr); }
  .auth-side { display: none; }
  .user-chip .who { display: none; }
}
@media (max-width: 600px) {
  .grid-4 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .page-head .actions { margin-left: 0; width: 100%; }
  .page-head .actions .btn { flex: 1; }
  .stat-value { font-size: 1.5rem; }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .kv dd { margin-bottom: 10px; }
  .card { padding: 16px; }
  .hide-sm { display: none; }
  .site-header nav .btn-ghost { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print { .sidebar, .topbar, .impersonation-bar { display: none; } .shell { display: block; } }
