:root {
  --bg: #081018;
  --surface: #0d1822;
  --surface-2: #111f2b;
  --surface-3: #172835;
  --border: #213643;
  --text: #e9f1f5;
  --muted: #8da2ae;
  --teal: #47e0c1;
  --teal-dark: #123f3b;
  --blue: #6ca7ff;
  --amber: #ffbd67;
  --red: #ff7a83;
  --radius: 16px;
  --shadow: 0 20px 55px rgba(0, 0, 0, .25);
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 80% -20%, #133945 0, transparent 35%), var(--bg); color: var(--text); }
a { color: var(--teal); text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 26px 18px 20px; border-right: 1px solid var(--border); background: rgba(8, 16, 24, .9); backdrop-filter: blur(18px); }
.brand { display: flex; align-items: center; gap: 12px; color: var(--text); }
.brand span:last-child { display: flex; flex-direction: column; line-height: 1.2; }
.brand strong { letter-spacing: -.02em; }
.brand small { color: var(--muted); margin-top: 3px; font-size: 11px; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 11px; color: #061410; font-weight: 900; background: linear-gradient(135deg, #69f0d5, #24bda5); box-shadow: 0 9px 25px rgba(71, 224, 193, .18); }
.nav { display: grid; gap: 6px; margin: 42px 0; }
.nav a { position: relative; padding: 11px 14px; border-radius: 10px; color: var(--muted); font-size: 14px; font-weight: 600; transition: .18s ease; }
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a.active { color: var(--teal); background: rgba(71, 224, 193, .09); }
.nav a.active::before { position: absolute; content: ""; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 3px; background: var(--teal); }
.sidebar-footer { margin-top: auto; display: grid; gap: 14px; }
.admin-chip { display: flex; align-items: center; gap: 10px; padding: 10px; border-top: 1px solid var(--border); }
.admin-chip > span:last-child { display: flex; flex-direction: column; min-width: 0; }
.admin-chip strong { overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.admin-chip small { color: var(--muted); font-size: 11px; margin-top: 2px; }
.avatar { display: grid; place-items: center; flex: 0 0 34px; height: 34px; border-radius: 50%; color: var(--teal); background: var(--teal-dark); font-weight: 800; }

.main { min-width: 0; padding: 0 32px 40px; }
.topbar { min-height: 116px; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.topbar h1 { margin: 3px 0 0; font-size: clamp(24px, 3vw, 34px); letter-spacing: -.04em; }
.eyebrow { margin: 0; color: var(--teal); font-size: 10px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
.timezone { color: var(--muted); font-size: 12px; }
.menu-toggle { display: none; color: var(--text); border: 0; background: transparent; font-size: 24px; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }
.metric-card { position: relative; overflow: hidden; min-height: 150px; display: flex; flex-direction: column; padding: 23px; border: 1px solid var(--border); border-radius: var(--radius); background: linear-gradient(145deg, var(--surface-2), var(--surface)); box-shadow: var(--shadow); }
.metric-card::after { position: absolute; content: ""; width: 90px; height: 90px; right: -30px; top: -30px; border-radius: 50%; background: rgba(71, 224, 193, .08); }
.metric-card span { color: var(--muted); font-size: 13px; font-weight: 650; }
.metric-card strong { margin: 13px 0 3px; font-size: 40px; letter-spacing: -.06em; }
.metric-card small { margin-top: auto; color: var(--muted); font-size: 11px; }
.metric-amber strong { color: var(--amber); }
.metric-red strong { color: var(--red); }

.content-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, .85fr); gap: 18px; align-items: start; }
.span-2 { min-width: 0; }
.panel { min-width: 0; padding: 22px; border: 1px solid var(--border); border-radius: var(--radius); background: rgba(13, 24, 34, .86); box-shadow: var(--shadow); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.panel-heading h2 { margin: 4px 0 0; font-size: 18px; letter-spacing: -.025em; }
.panel-heading > a { font-size: 12px; font-weight: 700; }
.panel-heading-wrap { flex-wrap: wrap; }

.notice { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 18px; padding: 16px 18px; border: 1px solid; border-radius: 13px; }
.notice strong { font-size: 13px; }
.notice p { margin: 4px 0 0; font-size: 12px; line-height: 1.5; color: var(--muted); }
.notice-warning { border-color: #59462b; background: rgba(255, 189, 103, .06); }
.notice-warning strong { color: var(--amber); }
.notice-info { border-color: #204d55; background: rgba(71, 224, 193, .05); }
.notice-info strong { color: var(--teal); }
.notice.compact { align-items: flex-start; padding: 13px 15px; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { padding: 10px 12px; color: #718994; font-size: 9px; letter-spacing: .11em; text-align: left; text-transform: uppercase; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 14px 12px; border-bottom: 1px solid rgba(33, 54, 67, .65); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(255, 255, 255, .012); }
.mono { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: .95em; }
.muted { color: var(--muted); }
.cell-sub { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; line-height: 1.4; }
.cell-error { color: var(--red); }
.actions { width: 1%; white-space: nowrap; }
.empty-state { padding: 34px 18px; color: var(--muted); text-align: center; }
.json-line { display: block; max-width: 420px; overflow-wrap: anywhere; color: var(--muted); line-height: 1.45; }
.event-name { padding: 4px 7px; border-radius: 6px; color: var(--blue); background: rgba(108, 167, 255, .08); font-family: "SFMono-Regular", Consolas, monospace; font-size: 10px; }

.status { display: inline-flex; align-items: center; gap: 5px; padding: 5px 8px; border-radius: 999px; color: var(--muted); background: var(--surface-3); font-size: 9px; font-weight: 800; letter-spacing: .035em; text-transform: uppercase; white-space: nowrap; }
.status::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.status-active, .status-available, .status-delivered { color: var(--teal); background: rgba(71, 224, 193, .1); }
.status-received, .status-assigned, .status-delivery_pending, .status-delivering, .status-pending, .status-sending { color: var(--blue); background: rgba(108, 167, 255, .1); }
.status-awaiting_stock, .status-warning { color: var(--amber); background: rgba(255, 189, 103, .1); }
.status-needs_review, .status-failed, .status-revoked { color: var(--red); background: rgba(255, 122, 131, .1); }
.status-expired { color: #a3aeb3; background: rgba(163, 174, 179, .1); }

.button { display: inline-flex; min-height: 38px; align-items: center; justify-content: center; padding: 8px 14px; border: 1px solid transparent; border-radius: 9px; font-size: 12px; font-weight: 750; transition: .18s ease; }
.button:hover { transform: translateY(-1px); }
.button-primary { color: #061410; background: var(--teal); }
.button-secondary { color: var(--text); border-color: var(--border); background: var(--surface-2); }
.button-ghost { color: var(--muted); border-color: var(--border); background: transparent; }
.button-danger { color: var(--red); border-color: rgba(255, 122, 131, .25); background: rgba(255, 122, 131, .07); }
.button-small { min-height: 30px; padding: 5px 9px; font-size: 10px; }
.button-full { width: 100%; }

.form-stack { display: grid; gap: 15px; }
label { display: grid; gap: 7px; color: #b8c6cd; font-size: 11px; font-weight: 700; }
label small { color: var(--muted); font-weight: 500; }
input, select, textarea { width: 100%; color: var(--text); border: 1px solid var(--border); border-radius: 9px; outline: none; background: #0a151e; }
input, select { height: 41px; padding: 0 11px; }
textarea { min-height: 90px; padding: 11px; line-height: 1.5; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(71, 224, 193, .08); }
input::placeholder, textarea::placeholder { color: #526772; }
.check-label, .switch-label { display: flex; align-items: center; gap: 8px; }
.check-label input, .switch-label input { width: 15px; height: 15px; accent-color: var(--teal); }
.form-hint { margin: 0; color: var(--muted); font-size: 10px; line-height: 1.5; }
.filter-bar { display: flex; gap: 8px; align-items: center; }
.filter-bar input { width: 210px; }
.filter-bar select { width: auto; min-width: 145px; }

.stock-list { display: grid; }
.stock-list a { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 0; color: var(--text); border-bottom: 1px solid var(--border); }
.stock-list a:last-child { border-bottom: 0; }
.stock-list span { display: flex; flex-direction: column; gap: 4px; }
.stock-list small { color: var(--muted); font-size: 10px; }
.stock-list b { color: var(--teal); font-size: 22px; }
.stock-cards { display: flex; gap: 12px; overflow-x: auto; margin-bottom: 18px; padding-bottom: 2px; }
.stock-card { min-width: 150px; display: grid; padding: 15px; color: var(--text); border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.stock-card.selected { border-color: var(--teal); }
.stock-card span { color: var(--muted); font-size: 11px; }
.stock-card strong { margin-top: 6px; font-size: 24px; }
.stock-card small { color: var(--muted); font-size: 9px; }
.stock-card-add { place-items: center; color: var(--teal); border-style: dashed; font-weight: 700; }
.countdown { color: var(--teal); font-weight: 750; }
.countdown.expiring { color: var(--amber); }
.countdown.expired { color: var(--red); }

.mapping-list { display: grid; gap: 10px; }
.mapping-row { display: grid; grid-template-columns: 1.1fr 1.4fr 1fr auto auto; gap: 10px; align-items: end; padding: 14px; border: 1px solid var(--border); border-radius: 12px; background: rgba(255,255,255,.012); }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
.panel-wide { grid-column: 1 / -1; }
.definition-list { display: grid; margin: 0; }
.definition-list div { display: grid; grid-template-columns: 130px 1fr; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.definition-list dt { color: var(--muted); font-size: 11px; }
.definition-list dd { margin: 0; text-align: right; font-size: 11px; overflow-wrap: anywhere; }
.queue-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 18px; }
.queue-grid div { display: grid; place-items: center; padding: 12px 6px; border-radius: 9px; background: var(--surface-2); }
.queue-grid strong { font-size: 20px; }
.queue-grid span { margin-top: 3px; color: var(--muted); font-size: 8px; text-transform: uppercase; }
.safeguard-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.safeguard-grid div { display: grid; gap: 7px; padding: 16px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface-2); }
.safeguard-grid strong { color: var(--teal); font-size: 12px; }
.safeguard-grid span { color: var(--muted); font-size: 10px; line-height: 1.5; }

.flash-stack { display: grid; gap: 8px; margin-bottom: 18px; }
.flash { padding: 12px 15px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); font-size: 12px; }
.flash-success { color: var(--teal); border-color: #20574d; }
.flash-error { color: var(--red); border-color: #5a2e35; }
.flash-info { color: var(--blue); border-color: #2c4565; }

dialog { width: min(440px, calc(100vw - 32px)); padding: 0; color: var(--text); border: 1px solid var(--border); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(2, 7, 11, .75); backdrop-filter: blur(4px); }
dialog form { padding: 22px; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; }
.dialog-heading h2 { margin: 0; }
.dialog-heading button { color: var(--muted); border: 0; background: transparent; font-size: 25px; }

.login-body { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.login-card { width: min(420px, 100%); padding: 34px; border: 1px solid var(--border); border-radius: 22px; background: rgba(13, 24, 34, .92); box-shadow: 0 28px 90px rgba(0, 0, 0, .45); }
.login-brand { margin-bottom: 45px; }
.login-heading { margin-bottom: 24px; }
.login-heading h1 { margin: 6px 0 8px; font-size: 32px; letter-spacing: -.045em; }
.login-heading > p:last-child { margin: 0; color: var(--muted); font-size: 13px; }
.login-note { margin: 20px 0 0; color: var(--muted); font-size: 10px; line-height: 1.5; text-align: center; }

@media (max-width: 1100px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .content-grid { grid-template-columns: 1fr; }
  .mapping-row { grid-template-columns: 1fr 1fr; }
  .safeguard-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; z-index: 20; width: 248px; transform: translateX(-100%); transition: transform .2s ease; }
  body.menu-open .sidebar { transform: translateX(0); }
  .main { padding: 0 16px 28px; }
  .topbar { min-height: 92px; justify-content: flex-start; }
  .topbar .timezone { margin-left: auto; font-size: 9px; }
  .menu-toggle { display: block; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .metric-card { min-height: 125px; padding: 17px; }
  .metric-card strong { font-size: 31px; }
  .settings-grid { grid-template-columns: 1fr; }
  .panel-wide { grid-column: auto; }
  .notice { align-items: flex-start; flex-direction: column; }
  .filter-bar { width: 100%; align-items: stretch; flex-direction: column; }
  .filter-bar input, .filter-bar select { width: 100%; }
  .mapping-row { grid-template-columns: 1fr; }
  .safeguard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 460px) {
  .metric-grid { grid-template-columns: 1fr; }
  .metric-card { min-height: 120px; }
  .panel { padding: 17px; }
  .topbar .timezone { display: none; }
  .queue-grid { grid-template-columns: repeat(2, 1fr); }
}
