:root {
  color-scheme: light;
  --ink: #182024;
  --muted: #657177;
  --line: #d8dfe1;
  --paper: #ffffff;
  --wash: #f3f6f5;
  --accent: #087f6b;
  --accent-dark: #056353;
  --danger: #b43838;
  --warning: #9b6b00;
  --nav: #20282c;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--wash);
  color: var(--ink);
  font-family: "Segoe UI", "Microsoft YaHei UI", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}
button, input { font: inherit; letter-spacing: 0; }
button, .button { min-height: 38px; border-radius: 4px; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
a { color: inherit; }
[hidden] { display: none !important; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-panel {
  width: min(400px, 100%);
  background: var(--paper);
  border: 1px solid var(--line);
  border-top: 4px solid var(--accent);
  padding: 34px;
  box-shadow: 0 16px 42px rgba(24, 32, 36, .10);
}
.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: #fff;
  border-radius: 4px;
  font-weight: 800;
}
.brand-mark.small { width: 38px; height: 38px; }
.eyebrow { margin: 20px 0 4px; color: var(--accent); font-size: 11px; font-weight: 800; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
.login-panel h1 { margin-bottom: 28px; font-size: 26px; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 12px; }
input {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #bfc9cc;
  border-radius: 3px;
  outline: none;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(8, 127, 107, .12); }
.login-panel label + label { margin-top: 16px; }
.login-panel .primary { width: 100%; margin-top: 22px; }
.form-status { min-height: 20px; margin: 12px 0 0; color: var(--danger); font-size: 12px; }
.back-link { display: block; margin-top: 16px; color: var(--muted); text-align: center; text-decoration: none; }
.back-link:hover { color: var(--accent); }

.primary { border: 1px solid var(--accent); background: var(--accent); color: #fff; padding: 8px 16px; font-weight: 700; }
.primary:hover { background: var(--accent-dark); }
.ghost, .button.ghost { border: 1px solid #b9c4c7; background: transparent; color: inherit; padding: 8px 13px; text-decoration: none; display: inline-grid; place-items: center; }
.ghost:hover { border-color: var(--accent); color: var(--accent); }
.danger { border: 1px solid #d9aaaa; background: #fff; color: var(--danger); padding: 6px 10px; }

.topbar {
  height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 24px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.brand-lockup { display: flex; align-items: center; gap: 12px; }
.brand-lockup div { display: grid; gap: 3px; }
.brand-lockup small { color: var(--muted); font-size: 10px; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.workspace { min-height: calc(100vh - 66px); display: grid; grid-template-columns: 190px minmax(0, 1fr); }
.sidebar { background: var(--nav); padding: 24px 14px; }
.sidebar button {
  width: 100%;
  margin-bottom: 6px;
  border: 0;
  background: transparent;
  color: #c5ced1;
  padding: 10px 13px;
  text-align: left;
}
.sidebar button:hover, .sidebar button.active { background: #334044; color: #fff; }
.sidebar button.active { box-shadow: inset 3px 0 var(--accent); }
.content { min-width: 0; padding: 30px clamp(20px, 4vw, 54px) 54px; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.page-heading .eyebrow { margin-top: 0; }
.page-heading h1 { margin-bottom: 0; font-size: 28px; }
.operator { color: var(--muted); font-size: 12px; }
.page { display: none; }
.page.active { display: block; }

.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); margin-bottom: 24px; }
.metrics article { min-height: 112px; background: var(--paper); padding: 22px; display: grid; align-content: space-between; }
.metrics small { color: var(--muted); }
.metrics strong { font-size: 32px; }
.sheet, .issued-codes { background: var(--paper); border: 1px solid var(--line); margin-top: 22px; }
.sheet > header, .issued-codes > header { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.sheet header small, .issued-codes header small { color: var(--accent); font-size: 10px; font-weight: 800; }
.sheet header h2, .issued-codes header h2 { margin: 3px 0 0; font-size: 17px; }
.command-strip { display: grid; grid-template-columns: 110px minmax(160px, 1fr) 110px minmax(180px, 1fr) auto; gap: 12px; align-items: end; padding: 18px; background: var(--paper); border: 1px solid var(--line); }
.row-actions { display: flex; gap: 8px; }
.search { width: min(280px, 45vw); }
.table { overflow-x: auto; }
.table-row { min-width: 820px; display: grid; align-items: center; gap: 12px; padding: 13px 20px; border-bottom: 1px solid #e7ebec; }
.table-row:last-child { border-bottom: 0; }
.table-row.license { grid-template-columns: minmax(170px, 1.6fr) 110px 100px 170px minmax(260px, auto); }
.table-row.device { grid-template-columns: minmax(160px, 1.3fr) minmax(180px, 1.5fr) 120px 180px; }
.table-row.audit { grid-template-columns: 170px 150px minmax(180px, 1fr); }
.table-row:hover { background: #f8faf9; }
.table-row b, .table-row code, .table-row small { display: block; }
.table-row code { margin-top: 4px; color: var(--muted); font-family: Consolas, monospace; word-break: break-all; }
.table-row small { color: var(--muted); }
.empty { padding: 30px 20px; color: var(--muted); text-align: center; }
.status { justify-self: start; padding: 4px 8px; border-radius: 3px; font-size: 11px; font-weight: 800; }
.status.active { background: #e2f4ee; color: #096451; }
.status.disabled { background: #f5e4e4; color: #973737; }
.status.expired { background: #f5edd8; color: var(--warning); }
.actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 6px; }
.actions button { min-height: 32px; border: 1px solid #c7d0d2; background: #fff; padding: 5px 8px; }
.actions button:hover { border-color: var(--accent); color: var(--accent); }
.actions button.danger:hover { border-color: var(--danger); color: var(--danger); }
.issued-codes { border-left: 4px solid var(--accent); }
.code-list { max-height: 280px; overflow: auto; padding: 12px 20px; }
.code-item { display: flex; justify-content: space-between; gap: 18px; padding: 9px 0; border-bottom: 1px solid #e8ecec; }
.code-item:last-child { border-bottom: 0; }
.code-item code { font-family: Consolas, monospace; font-weight: 700; }
.toast { position: fixed; right: 22px; bottom: 22px; max-width: min(380px, calc(100vw - 44px)); padding: 12px 16px; background: var(--ink); color: #fff; border-radius: 4px; opacity: 0; transform: translateY(8px); pointer-events: none; transition: .16s ease; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .sidebar { display: flex; overflow-x: auto; padding: 10px 14px; }
  .sidebar button { width: auto; min-width: 90px; margin: 0 5px 0 0; text-align: center; }
  .sidebar button.active { box-shadow: inset 0 -3px var(--accent); }
  .command-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .command-strip .primary { grid-column: 1 / -1; }
}

@media (max-width: 620px) {
  .topbar { height: auto; padding: 12px 14px; align-items: flex-start; }
  .top-actions { flex-wrap: wrap; justify-content: flex-end; }
  .top-actions .button { display: none; }
  .content { padding: 22px 14px 40px; }
  .page-heading { align-items: flex-start; }
  .page-heading h1 { font-size: 23px; }
  .metrics { grid-template-columns: 1fr; }
  .metrics article { min-height: 86px; }
  .command-strip { grid-template-columns: 1fr; }
  .command-strip .primary { grid-column: auto; }
  .sheet > header, .issued-codes > header { align-items: flex-start; flex-direction: column; }
  .search { width: 100%; }
}
