:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #262b36;
  --text: #e6e9ef;
  --muted: #8b93a7;
  --accent: #5b8cff;
  --accent-2: #3f6fe0;
  --ok: #38c172;
  --warn: #f2b544;
  --danger: #ef5350;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
}

.hidden { display: none !important; }
.spacer { flex: 1; }
.right { text-align: right; }

/* ---------- 登录 ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #1b2333 0%, var(--bg) 60%);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .45);
}

.login-card h1 { margin: 0 0 6px; font-size: 20px; font-weight: 600; }
.login-card .sub { margin: 0 0 24px; color: var(--muted); font-size: 13px; }
.login-card label { display: block; margin-bottom: 14px; color: var(--muted); font-size: 13px; }
.login-card input {
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.hint { min-height: 18px; margin: 12px 0 0; color: var(--danger); font-size: 13px; }

/* ---------- 布局 ---------- */
.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  padding: 0 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 600; font-size: 15px; letter-spacing: .3px; }
.brand span { color: var(--muted); font-weight: 400; margin-left: 6px; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.who { color: var(--muted); font-size: 13px; }
.proj-filter { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.proj-filter .select { min-width: 160px; }
.badge.project { background: rgba(139, 147, 167, .18); color: #b7c0d4; white-space: nowrap; }

.container { max-width: 1400px; margin: 0 auto; padding: 24px; }

/* ---------- 统计 ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 24px; font-weight: 600; margin-top: 6px; }
.stat.ok .value { color: var(--ok); }
.stat.warn .value { color: var(--warn); }
.stat.bad .value { color: var(--danger); }

/* ---------- 面板与表格 ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.input {
  padding: 8px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.input:focus { border-color: var(--accent); }
#searchInput { width: 260px; }
.select { min-width: 120px; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td {
  padding: 12px 14px;
  border-bottom: 1px solid #1c2028;
  vertical-align: middle;
}
.table tbody tr:hover { background: #1a1e26; }
.code-cell {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  letter-spacing: .4px;
  cursor: pointer;
  white-space: nowrap;
}
.code-cell:hover { color: var(--accent); }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 12px;
  line-height: 18px;
}
.badge.unused { background: rgba(91, 140, 255, .16); color: #8fb0ff; }
.badge.active { background: rgba(56, 193, 114, .16); color: #6fdc9a; }
.badge.expired { background: rgba(242, 181, 68, .16); color: #f2c46a; }
.badge.disabled { background: rgba(239, 83, 80, .16); color: #ff8a88; }

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

.pager {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

/* ---------- 按钮 ---------- */
.btn {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:hover { background: #262b36; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.danger { color: #ff8a88; border-color: rgba(239, 83, 80, .35); }
.btn.danger:hover { background: rgba(239, 83, 80, .12); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.block { width: 100%; padding: 11px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}
.modal-card {
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px;
}
.modal-card h2 { margin: 0 0 18px; font-size: 17px; font-weight: 600; }
.field { margin-bottom: 16px; }
.field-label { display: block; margin-bottom: 8px; color: var(--muted); font-size: 13px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.modal-card .input { width: 100%; }

.presets { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.preset-btn {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.preset-btn:hover { border-color: var(--accent); }
.preset-btn.on { background: rgba(91, 140, 255, .18); border-color: var(--accent); color: #a9c1ff; }

.custom-days { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.custom-days .input { width: 110px; }

.checks { display: flex; flex-wrap: wrap; gap: 10px; }
.checks label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.checks input { accent-color: var(--accent); }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.code-line {
  margin: -8px 0 18px;
  font-family: ui-monospace, Consolas, monospace;
  color: var(--accent);
  letter-spacing: .6px;
}
.machine-list {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
  color: var(--muted);
  max-height: 110px;
  overflow-y: auto;
  padding: 8px 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  word-break: break-all;
}

/* ---------- 项目管理 ---------- */
.modal-card.wide { max-width: 760px; }
.modal-card .sub { margin: -8px 0 18px; color: var(--muted); font-size: 13px; }
.sub-h { margin: 20px 0 12px; font-size: 14px; font-weight: 600; color: var(--muted); }
.project-list { display: flex; flex-direction: column; gap: 8px; }
.project-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.project-item .p-name { font-weight: 500; }
.project-item .p-meta { color: var(--muted); font-size: 12px; }
.project-item .p-main { flex: 1; min-width: 0; }
.project-item .p-actions { display: flex; gap: 6px; }
.project-item.off { opacity: .55; }
.pwd-text {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color: var(--text);
  letter-spacing: .3px;
  margin-right: 6px;
}
.pwd-eye { padding: 2px 8px; font-size: 12px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 40px;
  transform: translateX(-50%);
  padding: 10px 18px;
  background: #232936;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
  z-index: 100;
}
.toast.error { border-color: rgba(239, 83, 80, .5); color: #ff9a98; }

/* ---------- 浅色主题（html[data-theme="light"]） ---------- */
html[data-theme="light"] {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-2: #f1f4f9;
  --line: #e3e8f1;
  --text: #1b2330;
  --muted: #68717f;
  --accent: #2f6bff;
  --accent-2: #2456d6;
  --ok: #1f9d55;
  --warn: #b7791f;
  --danger: #d93636;
}
html[data-theme="light"] .login-wrap {
  background: radial-gradient(1200px 600px at 50% -10%, #e6eefc 0%, var(--bg) 60%);
}
html[data-theme="light"] .login-card { box-shadow: 0 20px 60px rgba(23, 43, 84, .12); }
html[data-theme="light"] .badge.project { background: rgba(47, 107, 255, .10); color: #2456d6; }
html[data-theme="light"] .table td { border-bottom-color: #eef1f7; }
html[data-theme="light"] .table tbody tr:hover { background: #f3f6fc; }
html[data-theme="light"] .badge.unused { background: rgba(47, 107, 255, .12); color: #2456d6; }
html[data-theme="light"] .badge.active { background: rgba(31, 157, 85, .12); color: #167f43; }
html[data-theme="light"] .badge.expired { background: rgba(183, 121, 31, .12); color: #8a5a12; }
html[data-theme="light"] .badge.disabled { background: rgba(217, 54, 54, .10); color: #b32b2b; }
html[data-theme="light"] .btn:hover { background: #eef2f9; }
html[data-theme="light"] .btn.danger { color: #c62f2f; }
html[data-theme="light"] .preset-btn.on { background: rgba(47, 107, 255, .12); color: #2456d6; }
html[data-theme="light"] .toast { background: #ffffff; box-shadow: 0 10px 30px rgba(23, 43, 84, .14); }
html[data-theme="light"] .toast.error { color: #c62f2f; }

@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .container { padding: 14px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar { flex-wrap: wrap; }
  #searchInput { width: 100%; }
  .grid2 { grid-template-columns: 1fr; }
}
