:root {
  color-scheme: light;
  --bg: #f6f8fa;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --ink: #0f172a;
  --muted: #64748b;
  --muted-2: #94a3b8;
  --line: #dde3ea;
  --line-strong: #cbd5e1;
  --brand: #0f6b78;
  --brand-strong: #0b5560;
  --brand-soft: #e6f2f4;
  --blue: #2563eb;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --shadow: 0 18px 48px rgba(15, 23, 42, 0.14);
}

* {
  box-sizing: border-box;
}

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

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.shell {
  min-height: 100vh;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(440px, 100%);
  display: grid;
  gap: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.login-brand,
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
}

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

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

h1,
h2,
h3,
h4,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 28px;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 6px;
  font-size: 24px;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 8px;
  font-size: 18px;
  letter-spacing: 0;
}

h4 {
  margin-bottom: 8px;
  font-size: 14px;
  letter-spacing: 0;
}

.muted,
.topbar p,
small {
  color: var(--muted);
}

.app-view {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.nav {
  display: grid;
  gap: 4px;
}

.nav-group {
  margin: 16px 0 4px;
  color: var(--muted-2);
  font-size: 12px;
  font-weight: 800;
}

.nav button {
  width: 100%;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #334155;
  padding: 10px 12px;
  text-align: left;
}

.nav button:hover,
.nav button.active {
  background: var(--brand-soft);
  color: var(--brand-strong);
  font-weight: 800;
}

.sidebar > .btn {
  margin-top: auto;
}

.content {
  min-width: 0;
  padding: 24px;
}

.topbar {
  min-height: 68px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-chip {
  display: grid;
  justify-items: end;
  gap: 2px;
  min-width: 220px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.tab {
  display: none;
}

.tab.active {
  display: grid;
  gap: 16px;
}

.panel,
.stat-card,
.table-wrap,
.toolbar,
.empty {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.panel {
  padding: 18px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
}

.toolbar-left,
.toolbar-right,
.filters {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
}

.mini-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.mini-stats article {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 12px 14px;
}

.mini-stats span,
.hint {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.mini-stats strong {
  display: block;
  margin-top: 6px;
  font-size: 22px;
}

.stat-card {
  padding: 16px;
}

.stat-card span {
  color: var(--muted);
}

.stat-card strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
}

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

.mail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(360px, 0.9fr);
  gap: 16px;
  align-items: start;
}

.var-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.var-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border: 1px solid #cfe0e7;
  border-radius: 999px;
  padding: 0 8px;
  background: #f3fafb;
  color: var(--brand-strong);
  font-size: 12px;
}

.template-guide {
  display: grid;
  gap: 8px;
  border: 1px solid #cfe0e7;
  border-radius: 8px;
  padding: 12px 14px;
  background: #f8fbfc;
}

.template-guide span,
.template-guide p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.toolbar.in-panel {
  border: 0;
  border-radius: 0;
  padding: 0 0 12px;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-head h3,
.section-head p {
  margin-bottom: 4px;
}

.panel-rule {
  height: 1px;
  border: 0;
  background: var(--line);
  margin: 18px 0;
}

.check-list {
  display: grid;
  gap: 10px;
}

.check-row {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 9px;
  min-height: 30px;
  color: #334155;
}

.check-row input {
  width: 16px;
  min-height: 16px;
  flex: 0 0 16px;
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  color: #334155;
  font-weight: 800;
}

.inline-check input {
  width: 16px;
  min-height: 16px;
}

.metric-list,
.activity-list {
  display: grid;
  gap: 10px;
}

.metric-row,
.activity-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.metric-row:last-child,
.activity-row:last-child {
  border-bottom: 0;
}

.chart-bars {
  display: flex;
  align-items: stretch;
  min-height: 170px;
  padding-top: 12px;
}

.bar-chart {
  width: 100%;
  height: 160px;
}

.table-wrap {
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  height: 48px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  background: #f8fafc;
  font-size: 12px;
  font-weight: 800;
}

.col-w-8 { width: 8%; }
.col-w-10 { width: 10%; }
.col-w-12 { width: 12%; }
.col-w-14 { width: 14%; }
.col-w-15 { width: 15%; }
.col-w-16 { width: 16%; }
.col-w-18 { width: 18%; }
.col-w-20 { width: 20%; }
.col-w-22 { width: 22%; }
.col-w-23 { width: 23%; }
.col-w-24 { width: 24%; }
.col-w-26 { width: 26%; }
.col-w-28 { width: 28%; }
.col-w-30 { width: 30%; }
.col-w-34 { width: 34%; }

td {
  color: #1e293b;
}

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

.cell-main {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.cell-main strong,
.ellipsis {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-sub {
  color: var(--muted);
  font-size: 12px;
}

.form {
  display: grid;
  gap: 14px;
}

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

label {
  display: grid;
  gap: 6px;
  color: #334155;
  font-size: 13px;
  font-weight: 800;
}

input,
textarea,
select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
  outline: none;
}

.search-input.narrow {
  max-width: 150px;
}

.detail-section {
  display: grid;
  gap: 12px;
  padding: 0 0 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.detail-section:last-child {
  margin-bottom: 0;
  border-bottom: 0;
}

.detail-section h4 {
  margin: 0;
  color: var(--ink);
}

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

.detail-grid > div {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.detail-grid span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.detail-grid strong {
  display: block;
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.hash-box {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

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

.hash-box code {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(15, 107, 120, 0.12);
}

.search-input {
  width: 280px;
}

.btn,
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 6px;
  min-height: 36px;
  padding: 8px 12px;
  font-weight: 800;
  text-decoration: none;
}

.btn-primary {
  background: var(--brand);
  color: #fff;
}

.btn-primary:hover {
  background: var(--brand-strong);
}

.btn-secondary {
  background: #e8f1ff;
  color: var(--blue);
}

.btn-ghost {
  background: #eef3f6;
  color: #334155;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-link {
  min-height: 30px;
  padding: 5px 8px;
  background: transparent;
  color: var(--brand);
}

.icon-btn {
  width: 36px;
  padding: 0;
  background: #eef3f6;
  color: #334155;
  font-size: 22px;
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  max-width: 100%;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.pill.ok {
  background: var(--ok-soft);
  color: #15803d;
}

.pill.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.pill.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.pill.neutral {
  background: #e2e8f0;
  color: #475569;
}

.empty {
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.message {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
  word-break: break-word;
}

.message.ok {
  color: var(--ok);
}

.license-preview,
.generated-license-box {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 14px;
}

.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.preview-head span {
  color: var(--muted);
  font-size: 12px;
}

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

.preview-grid div {
  display: grid;
  gap: 3px;
}

.preview-grid span {
  color: var(--muted);
  font-size: 12px;
}

.preview-grid strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.generated-license-key {
  display: block;
  padding: 12px;
  font-size: 16px;
  text-align: center;
  word-break: break-all;
}

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

code {
  padding: 2px 5px;
  border-radius: 4px;
  background: #eef3f6;
  color: #334155;
  font-size: 12px;
}

td code {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
  white-space: nowrap;
}

.drawer-backdrop,
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(15, 23, 42, 0.34);
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 50;
  width: min(560px, 100vw);
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  background: var(--panel);
  box-shadow: var(--shadow);
}

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

.drawer-head p {
  margin-bottom: 0;
  color: var(--muted);
}

.drawer-body {
  min-height: 0;
  overflow: auto;
  padding: 20px;
}

.modal-backdrop {
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 18px;
}

.modal {
  width: min(420px, 100%);
  border-radius: 10px;
  background: var(--panel);
  padding: 22px;
  box-shadow: var(--shadow);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 90;
  max-width: min(420px, calc(100vw - 44px));
  border-radius: 8px;
  background: #0f172a;
  color: #fff;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.toast.ok {
  background: #14532d;
}

.toast.danger {
  background: #7f1d1d;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: #f8fafc;
}

@media (max-width: 1024px) {
  .app-view {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .nav-group {
    grid-column: 1 / -1;
  }

  .dashboard-grid,
  .report-grid,
  .mail-grid,
  .detail-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .content,
  .sidebar {
    padding: 16px;
  }

  .topbar,
  .toolbar {
    display: grid;
    justify-items: stretch;
  }

  .topbar-actions,
  .toolbar-left,
  .toolbar-right,
  .filters {
    width: 100%;
  }

  .admin-chip,
  .search-input,
  .search-input.narrow {
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  .table-wrap {
    overflow-x: auto;
  }

  table {
    min-width: 920px;
  }
}
