:root {
  color-scheme: light;
  --bg: #f3f6fa;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --line: #dce4ee;
  --line-strong: #cbd6e2;
  --muted: #667085;
  --text: #182230;
  --brand: #2266d6;
  --brand-strong: #164ca5;
  --accent: #1f9a8a;
  --sidebar: #141b2b;
  --sidebar-soft: #1e293b;
  --success: #127c45;
  --warning: #a15c00;
  --danger: #b42318;
  --ink: #101828;
  --shadow-sm: 0 8px 24px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 18px 48px rgba(15, 23, 42, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  margin: 0;
  min-height: 100vh;
}

body.needs-login .sidebar,
body.needs-login .app-shell,
body.needs-login .modal-backdrop {
  display: none;
}

body:not(.needs-login) .login-screen {
  display: none;
}

button,
input,
select {
  font: inherit;
}

button {
  background: var(--brand);
  border: 1px solid var(--brand);
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  min-height: 36px;
  padding: 0 14px;
  transition: background 160ms ease, border-color 160ms ease, box-shadow 160ms ease, color 160ms ease, transform 160ms ease;
}

button:hover {
  background: var(--brand-strong);
  box-shadow: 0 8px 18px rgba(31, 101, 214, 0.16);
}

button.secondary {
  background: #fff;
  border-color: var(--line);
  color: var(--brand-strong);
}

button.secondary:hover {
  background: #f8fbff;
  border-color: #b7c9e8;
}

button.danger {
  background: #fff;
  border-color: #ff4d4f;
  color: #cf1322;
}

button.danger:hover {
  background: #fff1f0;
}

button:disabled {
  background: #f5f5f5;
  border-color: #d9d9d9;
  color: #b8b8b8;
  cursor: not-allowed;
}

[hidden] {
  display: none !important;
}

input,
select {
  background: #fff;
  border: 1px solid #c9d3df;
  border-radius: 6px;
  color: var(--ink);
  height: 36px;
  min-width: 0;
  padding: 0 10px;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
  width: 100%;
}

input:focus,
select:focus {
  border-color: var(--brand);
  outline: 2px solid rgba(31, 101, 214, 0.18);
}

select[multiple] {
  height: auto;
  min-height: 112px;
  padding: 6px 8px;
}

code {
  background: #eef3fb;
  border-radius: 5px;
  color: var(--brand-strong);
  font-family: "SFMono-Regular", Consolas, monospace;
  padding: 2px 5px;
}

.token-code {
  display: inline-block;
  line-height: 1.5;
  max-width: 360px;
  overflow-wrap: anywhere;
  white-space: normal;
}

.login-screen {
  align-items: center;
  display: grid;
  background:
    linear-gradient(135deg, rgba(34, 102, 214, 0.08), transparent 38%),
    linear-gradient(315deg, rgba(31, 154, 138, 0.12), transparent 34%),
    var(--bg);
  min-height: 100vh;
  padding: 24px;
}

.login-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  display: grid;
  gap: 16px;
  justify-self: center;
  padding: 28px;
  width: min(420px, 100%);
}

.login-card h1 {
  font-size: 34px;
  letter-spacing: 0;
  margin: 4px 0;
}

.login-card p {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  margin: 0;
}

.login-notice {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 6px;
  color: #8a3b00;
  padding: 10px 12px;
}

.sidebar {
  background: var(--sidebar);
  bottom: 0;
  color: #dce6f3;
  display: flex;
  flex-direction: column;
  left: 0;
  position: fixed;
  top: 0;
  width: 264px;
}

.brand {
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  gap: 12px;
  min-height: 78px;
  padding: 18px 18px 16px;
}

.brand-mark {
  align-items: center;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(31, 154, 138, 0.22);
  color: #fff;
  display: inline-flex;
  font-weight: 900;
  height: 38px;
  justify-content: center;
  width: 38px;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: #aebdd0;
  font-size: 12px;
  margin-top: 2px;
}

.nav {
  display: grid;
  gap: 12px;
  overflow: auto;
  padding: 14px 12px;
}

.nav-section {
  display: grid;
  gap: 5px;
}

.nav-section-toggle {
  align-items: center;
  background: transparent;
  border: 0;
  color: #96a5ba;
  display: flex;
  font-size: 12px;
  font-weight: 900;
  justify-content: space-between;
  letter-spacing: 0;
  min-height: 28px;
  padding: 0 8px;
  text-align: left;
}

.nav-section-toggle:hover {
  background: rgba(255, 255, 255, 0.06);
  box-shadow: none;
  color: #dce6f3;
}

.nav-section-toggle i {
  border-bottom: 2px solid currentColor;
  border-right: 2px solid currentColor;
  display: block;
  height: 7px;
  transform: rotate(45deg) translateY(-2px);
  transition: transform 180ms ease;
  width: 7px;
}

.nav-section.collapsed .nav-section-toggle i {
  transform: rotate(-45deg);
}

.nav-section-links {
  display: grid;
  gap: 5px;
  max-height: 180px;
  opacity: 1;
  overflow: hidden;
  transition: max-height 200ms ease, opacity 160ms ease, transform 160ms ease;
}

.nav-section.collapsed .nav-section-links {
  max-height: 0;
  opacity: 0;
  transform: translateY(-4px);
}

.nav a {
  border-radius: 6px;
  color: #d5deea;
  display: block;
  font-weight: 700;
  padding: 10px 12px 10px 14px;
  position: relative;
  text-decoration: none;
  transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}

.nav a:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.nav a.active {
  background: #ffffff;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.18);
  color: var(--sidebar);
}

.nav a.active::before {
  background: var(--accent);
  border-radius: 999px;
  bottom: 9px;
  content: "";
  left: 6px;
  position: absolute;
  top: 9px;
  width: 3px;
}

.sidebar-foot {
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  display: grid;
  gap: 8px;
  margin-top: auto;
  padding: 16px 18px 18px;
}

.sidebar-foot span {
  color: #aebdd0;
  font-size: 12px;
}

.sidebar-token-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
}

.sidebar-token-actions button {
  min-height: 32px;
  padding: 0 8px;
}

.app-shell {
  margin-left: 264px;
  padding: 28px 32px;
}

.topbar {
  align-items: center;
  background: rgba(255, 255, 255, 0.74);
  border: 1px solid rgba(220, 228, 238, 0.78);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
  display: flex;
  justify-content: space-between;
  margin-bottom: 18px;
  padding: 16px 18px;
}

.topbar h1 {
  font-size: 26px;
  letter-spacing: 0;
  line-height: 1.2;
  margin: 2px 0 0;
}

.eyebrow {
  color: var(--brand-strong);
  font-size: 13px;
  font-weight: 800;
  margin: 0;
}

.topbar-actions {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  min-width: 0;
}

.topbar-actions span {
  color: var(--muted);
  font-size: 13px;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.notice {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 6px;
  color: #8a3b00;
  margin-bottom: 16px;
  padding: 10px 12px;
}

.notice.success {
  background: #ecfdf3;
  border-color: #b7e4c7;
  color: var(--success);
}

.band {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 18px;
  overflow: hidden;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

.section-head {
  align-items: end;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 18px;
  justify-content: space-between;
  padding: 18px 20px;
}

.section-head h2 {
  font-size: 18px;
  letter-spacing: 0;
  margin: 0;
}

.section-head p {
  color: var(--muted);
  font-size: 13px;
  margin: 0;
  text-align: left;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
}

.report-summary {
  border-bottom: 1px solid var(--line);
}

.report-split {
  display: grid;
  gap: 18px;
  padding: 18px;
}

.metric {
  background: linear-gradient(180deg, #ffffff, #fbfdff);
  border-right: 1px solid var(--line);
  display: grid;
  gap: 6px;
  min-height: 86px;
  padding: 18px 20px;
}

.metric:last-child {
  border-right: 0;
}

.metric span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.metric strong {
  color: var(--ink);
  font-size: 28px;
  letter-spacing: 0;
}

.toolbar-form {
  align-items: end;
  background: #fbfdff;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(150px, 1fr)) auto;
  padding: 14px 18px;
}

.toolbar-form.wide {
  grid-template-columns: repeat(5, minmax(130px, 1fr)) auto;
}

.filter-bar {
  align-items: end;
  background: #fbfdff;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(240px, 1.2fr) minmax(160px, 0.6fr) minmax(180px, 0.7fr) auto;
  padding: 14px 18px;
}

label {
  display: grid;
  gap: 5px;
}

label span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.table-wrap {
  overflow: auto;
}

table {
  border-collapse: collapse;
  min-width: 760px;
  width: 100%;
}

.license-table {
  min-width: 1280px;
}

.batch-table {
  min-width: 1180px;
}

.batch-table td {
  overflow-wrap: anywhere;
}

th,
td {
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  padding: 13px 16px;
  text-align: left;
  vertical-align: top;
}

th {
  background: #f7f9fc;
  color: #475467;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
}

tbody tr {
  transition: background 140ms ease;
}

tbody tr:hover {
  background: #fbfdff;
}

tbody tr.is-disabled {
  background: #fafafa;
}

tbody tr.is-disabled td {
  color: #6b7280;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.muted {
  color: var(--muted);
}

.stack {
  display: grid;
  gap: 3px;
}

.pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  padding: 5px 8px;
}

.pill.available,
.pill.finished,
.pill.completed,
.pill.admin {
  background: #ecfdf3;
  border-color: #b7e4c7;
  color: var(--success);
}

.pill.claimed,
.pill.in_use,
.pill.ongoing,
.pill.in-use,
.pill.buyer {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: var(--brand-strong);
}

.pill.problem,
.pill.failed,
.pill.abandoned,
.pill.unavailable {
  background: #fef2f2;
  border-color: #fecaca;
  color: var(--danger);
}

.pill.disabled,
.pill.unverified {
  background: #f5f5f5;
  border-color: #e5e7eb;
  color: #3f3f46;
}

.pill.recognition-recognized,
.pill.recognition-verified {
  background: #ecfdf3;
  border-color: #b7e4c7;
  color: var(--success);
}

.pill.recognition-pending {
  background: #fffbeb;
  border-color: #fde68a;
  color: var(--warning);
}

.pill.recognition-failed {
  background: #fef2f2;
  border-color: #fecaca;
  color: var(--danger);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.modal-backdrop {
  align-items: center;
  background: rgba(15, 23, 42, 0.5);
  display: grid;
  inset: 0;
  padding: 24px;
  position: fixed;
  z-index: 50;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 28px 88px rgba(15, 23, 42, 0.28);
  justify-self: center;
  max-height: 90vh;
  overflow: auto;
  width: min(760px, 100%);
}

.modal.wide {
  width: min(1080px, 100%);
}

.modal-header {
  align-items: center;
  background: linear-gradient(180deg, #ffffff, #f8fbff);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 16px 18px;
}

.modal-header h2 {
  font-size: 18px;
  letter-spacing: 0;
  margin: 2px 0 0;
}

.modal-description {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  margin: 6px 0 0;
}

.icon-button {
  align-items: center;
  background: #fff;
  border-color: var(--line);
  color: var(--muted);
  display: inline-flex;
  font-size: 22px;
  height: 36px;
  justify-content: center;
  line-height: 1;
  padding: 0;
  width: 36px;
}

.icon-button:hover {
  background: #f8fafc;
  color: var(--ink);
}

.modal-form {
  display: grid;
}

.modal-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 18px;
}

.field.wide {
  grid-column: 1 / -1;
}

.field-hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.field-action-row {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto;
}

.field-action-row .compact {
  height: 38px;
  padding: 0 14px;
  white-space: nowrap;
}

.modal-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 14px;
  grid-column: 1 / -1;
  padding: 18px;
}

.modal-section[hidden] {
  display: none;
}

.modal-section h3 {
  color: var(--ink);
  font-size: 16px;
  letter-spacing: 0;
  margin: 0;
}

.modal-section-title {
  align-items: start;
  display: flex;
  gap: 14px;
  justify-content: space-between;
}

.modal-section-title p {
  font-size: 12px;
  font-weight: 700;
  margin: 5px 0 0;
}

.opening-groups-editor {
  display: grid;
  gap: 10px;
}

.opening-group-row {
  align-items: end;
  background: #fbfdff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(120px, 1fr) minmax(100px, 0.7fr) minmax(100px, 0.7fr) auto;
  padding: 12px;
}

.opening-group-row .compact {
  height: 36px;
}

.license-preview {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 0;
  padding: 12px;
  position: relative;
}

.license-preview img {
  display: block;
  max-height: 520px;
  object-fit: contain;
  width: 100%;
}

.upload-preview img {
  max-height: 360px;
}

.license-preview a {
  background: rgba(23, 32, 51, 0.78);
  border-radius: 6px;
  bottom: 20px;
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  padding: 8px 10px;
  position: absolute;
  right: 20px;
  text-decoration: none;
}

.license-preview-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
  margin-top: 10px;
}

.license-preview-actions p {
  flex: 1 1 280px;
  margin: 0;
}

.excel-duplicate-list {
  display: grid;
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.excel-duplicate-list li {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 6px;
  display: grid;
  gap: 4px;
  padding: 10px 12px;
}

.excel-duplicate-list strong {
  color: var(--ink);
}

.section-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.check-field {
  align-items: center;
  display: flex;
  gap: 10px;
}

.check-field.wide {
  grid-column: 1 / -1;
}

.check-field input {
  height: 18px;
  margin: 0;
  width: 18px;
}

.check-field span {
  color: #344054;
  font-size: 14px;
  font-weight: 800;
}

.pill.default {
  background: #eef4ff;
  border-color: #c7d7fe;
  color: var(--brand-strong);
}

.modal-actions {
  background: #fbfdff;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 14px 18px;
}

@media (max-width: 920px) {
  .sidebar {
    position: static;
    width: auto;
  }

  .brand {
    min-height: auto;
  }

  .app-shell {
    margin-left: 0;
    padding: 16px;
  }

  .topbar,
  .section-head {
    align-items: start;
    display: grid;
  }

  .topbar-actions {
    justify-content: start;
  }

  .topbar-actions span {
    max-width: none;
    white-space: normal;
  }

  .section-head p {
    text-align: left;
  }

  .summary-grid,
  .toolbar-form,
  .toolbar-form.wide,
  .filter-bar,
  .report-toolbar,
  .modal-grid,
  .section-grid,
  .opening-group-row {
    grid-template-columns: 1fr;
  }

  .metric {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}
