:root {
  --ink: #f8f2e7;
  --muted: #b9ab98;
  --bg: #0b0908;
  --panel: #191410;
  --line: rgba(255, 238, 214, 0.12);
  --brass: #ff8f42;
  --brass-dark: #c0561d;
  --danger: #ef5f4a;
  --ok: #63d6d0;
  --font-display: "Bricolage Grotesque", sans-serif;
  --font-body: "Be Vietnam Pro", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background:
    radial-gradient(70% 50% at 8% -8%, rgba(255, 143, 66, 0.18), transparent 58%),
    radial-gradient(50% 40% at 100% 110%, rgba(99, 214, 208, 0.08), transparent 52%),
    var(--bg);
}

h1, h2, h3, strong { font-family: var(--font-display); font-weight: 700; letter-spacing: -0.02em; }
.tab h2 { font-size: 28px; }
.tab > p { font-size: 14.5px; line-height: 1.55; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card, .app-shell main, .issue-grid, .stack, dialog {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
}
.login-card {
  width: min(440px, 100%);
  padding: 36px 32px;
  background:
    linear-gradient(180deg, rgba(255, 238, 214, 0.06), transparent 32%),
    var(--panel);
  box-shadow: 0 40px 90px -36px rgba(0, 0, 0, 0.9);
}
.login-card h1 { font-size: 40px; margin: 4px 0 8px; }
.mark { width: 52px; height: 52px; padding: 6px; object-fit: contain; border-radius: 14px; background: #fffdf9; }
.eyebrow {
  font-family: var(--font-mono);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-size: 10px;
  color: var(--brass);
}
.lede { color: var(--muted); line-height: 1.55; }

label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); margin: 12px 0; }
input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: #12100d;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
.btn {
  font: inherit;
  cursor: pointer;
  border-radius: 999px;
  border: 1px solid var(--line);
  padding: 10px 16px;
  background: transparent;
  color: var(--ink);
}
.btn.primary { background: var(--brass); color: #1a1008; border-color: var(--brass); font-weight: 700; }
code, .key-cell, .device code { font-family: var(--font-mono); }
.btn.ghost { width: 100%; }
.btn.tiny { padding: 6px 10px; font-size: 12px; margin: 2px; }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.actions { display: flex; flex-wrap: wrap; gap: 6px; overflow: visible; white-space: normal; }
.data-table td.actions { overflow: visible; }
.btn.tiny { padding: 7px 11px; font-size: 12.5px; margin: 0; }
.device {
  font-size: 12.5px;
  color: var(--muted);
}
.key-cell {
  font-variant-numeric: tabular-nums;
  font-size: 13.5px;
  letter-spacing: 0.02em;
}
menu { display: flex; gap: 8px; justify-content: flex-end; padding: 0; margin: 12px 0 0; }

.app-shell { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
aside {
  padding: 22px 16px;
  border-right: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.22);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
nav { display: grid; gap: 4px; margin: 18px 0 auto; }
nav button {
  text-align: left;
  background: transparent;
  color: var(--muted);
  border: 0;
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  font: inherit;
}
nav button:hover { color: var(--ink); background: rgba(255, 238, 214, 0.04); }
nav button.active { color: #1a1008; background: var(--brass); font-weight: 600; }
aside strong { font-size: 18px; }
main { padding: 28px 32px; }
.tab h2 { margin: 0 0 8px; }
.issue-card {
  margin: 18px 0;
  padding: 18px 20px 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(255, 238, 214, 0.04), transparent 40%),
    rgba(0, 0, 0, 0.18);
}
.issue-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.issue-head strong { font-size: 18px; }
.issue-head p { margin: 4px 0 0; }
.mode-toggle {
  display: flex;
  gap: 6px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.28);
}
.mode-toggle button {
  border: 0;
  border-radius: 999px;
  padding: 8px 14px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.mode-toggle button.active {
  background: var(--brass);
  color: #1a1008;
  font-weight: 600;
}
.issue-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1.3fr auto;
  gap: 12px 16px;
  align-items: end;
}
.issue-grid .span-note { grid-column: 1 / 3; }
.issue-duration {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  grid-column: 1 / -2;
}
#issue-days { grid-template-columns: 220px; }
.issue-submit { min-width: 132px; min-height: 44px; }
.table-wrap {
  overflow: auto;
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.22);
}
.data-table {
  width: 100%;
  min-width: 1080px;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.4;
}
.keys-table .col-buyer { width: 14%; }
.keys-table .col-contact { width: 12%; }
.keys-table .col-key { width: 12%; }
.keys-table .col-exp { width: 16%; }
.keys-table .col-note { width: 12%; }
.keys-table .col-device { width: 16%; }
.keys-table { min-width: 1240px; }
.keys-table .col-status { width: 12%; }
.keys-table .col-actions { width: 22%; }
.logs-table { min-width: 980px; }
#log-dialog { width: min(820px, calc(100vw - 32px)); }
#log-dialog .job-detail .span-all dd {
  max-height: none;
  padding: 0;
  background: transparent;
  overflow: visible;
}
.log-body {
  margin: 0;
  padding: 12px;
  max-height: 240px;
  overflow: auto;
  background: rgba(0, 0, 0, 0.28);
  border-radius: 10px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.jobs-table .col-time { width: 16%; }
.jobs-table .col-buyer { width: 14%; }
.jobs-table .col-device { width: 22%; }
.jobs-table .col-kind { width: 12%; }
.jobs-table .col-count { width: 8%; }
.jobs-table .col-status { width: 12%; }
.jobs-table .col-job-act { width: 10%; }
.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid rgba(255, 238, 214, 0.06);
  background: #1f1914;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
  text-align: left;
}
.data-table th:last-child,
.data-table td:last-child { border-right: 0; }
.data-table td {
  padding: 12px;
  border-bottom: 1px solid rgba(255, 238, 214, 0.08);
  border-right: 1px solid rgba(255, 238, 214, 0.06);
  vertical-align: middle;
  color: var(--ink);
  overflow: hidden;
}
.data-table tbody tr:nth-child(even) td {
  background: rgba(255, 238, 214, 0.025);
}
.data-table tbody tr:hover td {
  background: rgba(255, 238, 214, 0.055);
}
.data-table tbody tr:last-child td {
  border-bottom: 0;
}
.cell-stack {
  display: grid;
  gap: 2px;
  min-width: 0;
}
.cell-stack .muted { font-size: 12.5px; }
.clip,
.key-cell,
.device {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  background: rgba(255, 143, 66, 0.12);
  color: var(--brass);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.status.active { background: rgba(99, 214, 208, 0.12); color: var(--ok); }
.status.unused { background: rgba(255, 238, 214, 0.06); color: var(--muted); }
.status.revoked, .status.expired, .status.disabled { background: rgba(239, 95, 74, 0.12); color: var(--danger); }
.status.unused { background: rgba(255, 238, 214, 0.06); color: var(--muted); }
.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  border-radius: 999px;
  padding: 4px 10px 4px 6px;
  font-size: 12px;
  cursor: pointer;
  width: fit-content;
}
.switch-ui {
  position: relative;
  width: 34px;
  height: 18px;
  border-radius: 999px;
  background: rgba(239, 95, 74, 0.45);
  flex: 0 0 auto;
}
.switch-ui::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fffdf9;
  transition: transform 0.16s ease;
}
.switch[aria-pressed="true"] { border-color: rgba(99, 214, 208, 0.45); color: var(--ok); }
.switch[aria-pressed="true"] .switch-ui { background: rgba(99, 214, 208, 0.7); }
.switch[aria-pressed="true"] .switch-ui::after { transform: translateX(16px); }
.switch[aria-pressed="false"] { border-color: rgba(239, 95, 74, 0.45); color: var(--danger); }
.log-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 14px;
  align-items: center;
}
.log-filter input[type="text"],
.log-filter input:not([type="checkbox"]) {
  min-width: 140px;
  flex: 1;
}
.log-error { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.stack { padding: 16px; display: grid; }
dialog {
  padding: 24px;
  color: var(--ink);
  margin: auto;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  overflow: auto;
}
dialog[open] { display: block; }
dialog::backdrop {
  background: rgba(8, 6, 5, 0.72);
}
dialog code {
  display: block;
  margin: 16px 0;
  padding: 12px;
  background: #12100d;
  border-radius: 10px;
  word-break: break-all;
}

#job-dialog {
  width: min(640px, calc(100vw - 32px));
  padding: 28px 32px 22px;
}
.job-detail {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 18px;
  margin: 18px 0 8px;
}
.job-detail div { min-width: 0; }
.job-detail .span-all { grid-column: 1 / -1; }
.job-detail dt {
  margin: 0 0 4px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.job-detail dd {
  margin: 0;
  overflow: auto;
  max-height: 180px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.28);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
}
#job-dialog,
#account-dialog { width: min(920px, calc(100vw - 32px)); }
.job-trace-title { margin: 16px 0 6px; font-size: 16px; }
.job-trace-wrap { max-height: 280px; }
.job-pager { display: flex; align-items: center; gap: 10px; margin-top: 10px; }

#key-dialog {
  width: min(560px, calc(100vw - 32px));
}

#edit-dialog {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  padding: 32px 36px 28px;
  overflow: auto;
}
#edit-dialog h3 {
  margin: 0 0 6px;
  font-size: 30px;
}
#edit-dialog > .lede {
  margin: 0 0 20px;
}

.edit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 20px;
  padding: 0;
}
.edit-grid label {
  margin: 8px 0;
}
.edit-grid .span-all,
.edit-grid menu {
  grid-column: 1 / -1;
}
.edit-grid input,
.edit-grid textarea {
  min-height: 44px;
  font-size: 15px;
}

.toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 80;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #241c16;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.4;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.4);
  animation: toast-in 0.18s ease;
}
.toast-ok { border-color: rgba(99, 214, 208, 0.35); }
.toast-err { border-color: rgba(239, 95, 74, 0.45); color: #ffd4cc; }
.toast-out { opacity: 0; transform: translateY(8px); transition: 0.2s ease; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .issue-grid { grid-template-columns: 1fr; }
  .issue-grid .span-note,
  .issue-duration { grid-column: 1; }
  #issue-days { grid-template-columns: 1fr; }
  .edit-grid { grid-template-columns: 1fr; }
  #edit-dialog { padding: 22px 18px 18px; }
  .job-detail { grid-template-columns: 1fr; }
}
