:root {
  color-scheme: light;
  --bg: #eef2ef;
  --surface: #ffffff;
  --soft: #f5f7f4;
  --ink: #17201b;
  --muted: #68736c;
  --line: #d9e0da;
  --line-strong: #c4cec6;
  --green: #176b4d;
  --green-deep: #10523b;
  --green-soft: #e7f2eb;
  --blue: #2f6fdf;
  --blue-soft: #eaf1ff;
  --red: #b83e27;
  --red-soft: #fcece8;
  --yellow: #986b13;
  --yellow-soft: #fff5db;
  --radius: 8px;
  --shadow: 0 16px 44px rgba(19, 32, 24, 0.08);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 92% 3%, rgba(47, 111, 223, 0.08), transparent 28rem),
    var(--bg);
  font: 14px/1.5 "Microsoft YaHei UI", "Microsoft YaHei", "Segoe UI", sans-serif;
  letter-spacing: 0;
}
button, input, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
.is-hidden { display: none !important; }

.login-layout {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(390px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: var(--green);
  font-weight: 800;
}
.login-card h1, .toolbar h2, .modal h2 { margin: 0; }
.login-card h1 { font-size: 24px; }
.login-copy { margin: -5px 0 4px; color: var(--muted); }
.eyebrow { margin: 0 0 4px; color: var(--muted); font-size: 10px; font-weight: 800; }

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
input, textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  outline: 0;
  color: var(--ink);
  background: #fff;
}
input:focus, textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(23, 107, 77, 0.1);
}

.primary-button, .secondary-button, .ghost-button, .icon-button, .danger-button {
  min-height: 36px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 700;
}
.primary-button { padding: 0 14px; border: 1px solid var(--green); color: #fff; background: var(--green); }
.primary-button:hover { background: var(--green-deep); }
.secondary-button { padding: 0 13px; border: 1px solid var(--line-strong); background: #fff; }
.secondary-button:hover { background: var(--soft); }
.ghost-button { padding: 0 10px; border: 1px solid transparent; color: var(--muted); background: transparent; }
.ghost-button:hover { border-color: var(--line); color: var(--ink); background: var(--soft); }
.icon-button {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--line);
  color: var(--muted);
  background: var(--soft);
  font-size: 20px;
}
.danger-button { padding: 0 10px; border: 1px solid #e9c1b5; color: var(--red); background: var(--red-soft); }
.danger-button:hover { border-color: var(--red); }
.text-button { padding: 0; border: 0; color: var(--blue); background: transparent; font-size: 12px; }
.text-button:hover { text-decoration: underline; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.form-error { min-height: 18px; margin: 0; color: var(--red); font-size: 11px; }
.topbar {
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand > div { display: flex; flex-direction: column; }
.brand strong { font-size: 16px; }
.brand small { color: var(--muted); font-size: 10px; }
.account { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }

.workspace {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 20px 24px 36px;
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.stat-card, .panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 8px 26px rgba(19, 32, 24, 0.05);
}
.stat-card { padding: 14px 16px; }
.stat-card span { color: var(--muted); font-size: 11px; font-weight: 700; }
.stat-card strong { display: block; margin-top: 3px; font-size: 24px; }
.stat-card.is-alert strong { color: var(--yellow); }
.stat-card.is-danger strong { color: var(--red); }
.panel { overflow: hidden; }
.toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}
.toolbar h2 { font-size: 18px; }
.toolbar-actions { display: flex; align-items: center; gap: 8px; }
.toolbar-actions input { width: 240px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 880px; }
th, td { padding: 12px 14px; border-bottom: 1px solid #edf0ed; text-align: left; vertical-align: middle; }
th { color: var(--muted); background: var(--soft); font-size: 11px; }
td { font-size: 12px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafcfa; }
.empty-state { margin: 0; padding: 38px; color: var(--muted); text-align: center; }
.customer-cell { display: flex; flex-direction: column; gap: 2px; }
.customer-cell strong { font-size: 13px; }
.customer-cell small, .device-copy small { color: var(--muted); font-size: 10px; }
.key-preview { color: var(--muted); font-family: Consolas, monospace; }
.status-pill {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
}
.status-active { color: var(--green); background: var(--green-soft); }
.status-expired, .status-disabled { color: var(--red); background: var(--red-soft); }
.status-expiring { color: var(--yellow); background: var(--yellow-soft); }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(12, 20, 15, 0.48);
  backdrop-filter: blur(3px);
}
.modal {
  width: min(610px, 100%);
  max-height: calc(100vh - 36px);
  overflow-y: auto;
  padding: 20px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(9, 17, 12, 0.24);
}
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 16px; }
.modal h2 { font-size: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.form-grid .wide { grid-column: 1 / -1; }
.key-modal { width: min(500px, 100%); }
.key-note { margin: 0 0 12px; color: var(--muted); }
.key-value {
  padding: 18px;
  border: 1px dashed var(--green);
  border-radius: 7px;
  color: var(--green-deep);
  background: var(--green-soft);
  font: 700 19px/1.5 Consolas, monospace;
  overflow-wrap: anywhere;
  text-align: center;
}
.devices-modal { width: min(760px, 100%); }
.password-modal { width: min(520px, 100%); }
.device-list, .audit-list { display: flex; flex-direction: column; gap: 8px; }
.device-item, .audit-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--soft);
}
.device-copy { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.device-copy strong { font-size: 12px; }
.audit-item { align-items: flex-start; }
.audit-copy { display: flex; flex-direction: column; gap: 2px; }
.audit-copy strong { font-size: 12px; }
.audit-copy small { color: var(--muted); font-size: 10px; }
.audit-time { flex: 0 0 auto; color: var(--muted); font-size: 10px; }
.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 100;
  max-width: 360px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: 0 15px 40px rgba(19, 32, 24, 0.2);
  font-size: 12px;
}
.toast.is-error { border-color: #efc4b9; color: var(--red); background: var(--red-soft); }

@media (max-width: 900px) {
  .topbar, .toolbar { align-items: stretch; flex-direction: column; }
  .account { justify-content: flex-end; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar-actions { flex-wrap: wrap; }
  .toolbar-actions input { width: 100%; }
}
@media (max-width: 560px) {
  .workspace { padding: 12px; }
  .stats-grid, .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .modal { padding: 16px; }
  .toolbar-actions > * { flex: 1 1 auto; }
  .device-item { align-items: stretch; flex-direction: column; }
}
