/* 星火互动 SaaS 管理后台
   纯 CSS，无框架 —— 减少依赖，便于后续替换为正式前端 */

:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #e3e6eb;
  --text: #1f2329;
  --text-2: #646a73;
  --text-3: #8f959e;
  --primary: #2563eb;
  --primary-d: #1d4ed8;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .06), 0 1px 2px rgba(0, 0, 0, .04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI",
        "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

.hidden { display: none !important; }

/* ───────────────────────── 登录页 ───────────────────────── */
#login-view {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #eef2ff 0%, #f5f6f8 45%, #f5f6f8 100%);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 36px 32px 28px;
  box-shadow: 0 8px 24px rgba(24, 39, 75, .08);
}

.login-card .brand {
  text-align: center;
  margin-bottom: 26px;
}

.login-card .brand h1 {
  margin: 0 0 6px;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: .2px;
}

.login-card .brand p {
  margin: 0;
  font-size: 13px;
  color: var(--text-3);
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.field .hint {
  margin-top: 5px;
  font-size: 12px;
  color: var(--text-3);
}

button {
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 9px 16px;
  background: #eef0f3;
  transition: background .15s, border-color .15s, opacity .15s;
}

button:hover { background: #e4e7ec; }
button:disabled { opacity: .55; cursor: not-allowed; }

button.primary {
  background: var(--primary);
  color: #fff;
  font-weight: 500;
}

button.primary:hover { background: var(--primary-d); }

button.danger {
  background: #fff;
  border-color: #f3c1c1;
  color: var(--danger);
}

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

button.block { width: 100%; padding: 11px; }

.alert {
  margin-bottom: 16px;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  background: #fef2f2;
  border: 1px solid #f8d4d4;
  color: var(--danger);
}

.alert.ok {
  background: #f0fdf4;
  border-color: #bbf7d0;
  color: var(--ok);
}

.alert.warn {
  background: #fffbeb;
  border-color: #fde68a;
  color: var(--warn);
}

/* ───────────────────────── 主框架 ───────────────────────── */
#app-view {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 56px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.topbar .logo {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .2px;
}

.topbar .logo span {
  color: var(--primary);
}

.topbar .spacer { flex: 1; }

.topbar .who {
  font-size: 13px;
  color: var(--text-2);
}

.topbar .who b {
  color: var(--text);
  font-weight: 500;
}

.content {
  flex: 1;
  padding: 22px;
  /* ★ 不要设 max-width：宽屏下会被卡在固定宽度，右侧留大片空白 */
  width: 100%;
  box-sizing: border-box;
}

/* ───────────────────────── 面包屑 ───────────────────────── */
.crumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--text-3);
}

.crumbs a {
  color: var(--primary);
  text-decoration: none;
  cursor: pointer;
}

.crumbs a:hover { text-decoration: underline; }

/* ───────────────────────── 统计卡 ───────────────────────── */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 17px;
  box-shadow: var(--shadow);
}

.stat .k {
  font-size: 12px;
  color: var(--text-3);
  margin-bottom: 6px;
}

.stat .v {
  font-size: 23px;
  font-weight: 600;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.stat .v small {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-3);
  margin-left: 3px;
}

.stat.warn .v { color: var(--warn); }
.stat.ok .v { color: var(--ok); }

/* ───────────────────────── 面板 ───────────────────────── */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 17px;
  border-bottom: 1px solid var(--border);
}

.panel-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.panel-head .sub {
  font-size: 12px;
  color: var(--text-3);
}

.panel-head .spacer { flex: 1; }

.panel-body { padding: 17px; }
.panel-body.tight { padding: 0; }

/* ───────────────────────── 表格 ───────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-3);
  background: #fafbfc;
}

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

tbody tr:hover { background: #fafbfc; }

td.num { font-variant-numeric: tabular-nums; }

td.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
}

td.actions { text-align: right; }

td.actions button {
  padding: 4px 11px;
  font-size: 12.5px;
  background: #fff;
  border-color: var(--border);
}

td.actions button:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: #f8faff;
}

/* ★ 表格内实心按钮（如「进后台」）。
   不加这段会被上面的 td.actions button 覆盖：白色背景 + 白色文字 = 看不见。
   原因：td.actions button(0,1,2) 优先级高于 button.primary(0,1,1)。 */
td.actions button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

td.actions button.primary:hover {
  background: var(--primary-d);
  border-color: var(--primary-d);
  color: #fff;
}

.empty {
  padding: 44px 20px;
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
}

.empty b {
  display: block;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 6px;
}

/* ───────────────────────── 徽章 ───────────────────────── */
.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 12px;
  line-height: 18px;
  background: #eef0f3;
  color: var(--text-2);
}

.badge.ok { background: #dcfce7; color: #15803d; }
.badge.warn { background: #fef3c7; color: #a16207; }
.badge.danger { background: #fee2e2; color: #b91c1c; }
.badge.info { background: #dbeafe; color: #1d4ed8; }

/* 用量条 */
.usage-cell { min-width: 110px; }

.usage-cell .txt {
  font-size: 12px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  margin-bottom: 3px;
}

.bar {
  height: 4px;
  border-radius: 2px;
  background: #eef0f3;
  overflow: hidden;
}

.bar i {
  display: block;
  height: 100%;
  background: var(--primary);
  border-radius: 2px;
}

.bar i.full { background: var(--danger); }
.bar i.warn { background: var(--warn); }

/* ───────────────────────── 弹窗 ───────────────────────── */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}

.modal {
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow: auto;
  background: var(--panel);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, .25);
}

.modal-head {
  display: flex;
  align-items: center;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}

.modal-head h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.modal-body { padding: 20px 22px; }

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 22px;
  border-top: 1px solid var(--border);
  background: #fafbfc;
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

/* 结果展示（新建公司后的密码） */
.result-box {
  margin-top: 4px;
  padding: 16px;
  border-radius: var(--radius);
  background: #f8faff;
  border: 1px solid #dbeafe;
}

.result-box .line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 9px;
  font-size: 13px;
}

.result-box .line:last-child { margin-bottom: 0; }

.result-box .line .k {
  width: 74px;
  flex: 0 0 auto;
  color: var(--text-3);
}

.result-box .line .v {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: .3px;
  word-break: break-all;
}

.result-box .line .v.big { font-size: 15px; color: var(--primary); }

.copy-btn {
  padding: 1px 8px;
  font-size: 11.5px;
  background: #fff;
  border-color: #dbeafe;
  color: var(--primary);
}

.copy-btn:hover { background: #eff6ff; border-color: var(--primary); }

/* ───────────────────────── 详情页 ───────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.kv {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.kv .k {
  font-size: 12px;
  color: var(--text-3);
  margin-bottom: 5px;
}

.kv .v {
  font-size: 15px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.kv .v.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
}

.todo {
  padding: 30px 20px;
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
  line-height: 1.9;
}

.todo .title {
  display: block;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 8px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 14px;
}

/* ★ 名额 Key 列表 */
.keylist {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  gap: 8px;
}

.keylist .k {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  padding: 7px 10px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid #dbeafe;
  color: #1d4ed8;
  letter-spacing: .4px;
  word-break: break-all;
  display: flex;
  align-items: center;
  gap: 6px;
}

.keylist .k span { flex: 1; }

.keylist .k button {
  padding: 0 6px;
  font-size: 11px;
  background: transparent;
  border: none;
  color: var(--primary);
  cursor: pointer;
  flex: 0 0 auto;
}

.keylist .k button:hover { text-decoration: underline; }

/* Key 状态表格 */
td .kbadge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 9px;
  font-size: 11.5px;
  line-height: 17px;
}
.kbadge.unused { background: #eef0f3; color: #646a73; }
.kbadge.in_use { background: #dcfce7; color: #15803d; }
.kbadge.expired_lease { background: #fef3c7; color: #a16207; }
.kbadge.expired { background: #fee2e2; color: #b91c1c; }
.kbadge.revoked { background: #f3f4f6; color: #9ca3af; }

.chip {
  padding: 4px 12px;
  border-radius: 14px;
  background: #f1f3f6;
  border: 1px dashed #d5d9e0;
  font-size: 12.5px;
  color: var(--text-3);
}

/* ───────────────────────── 提示条 ───────────────────────── */
#toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  transform: translateX(-50%) translateY(20px);
  padding: 10px 20px;
  border-radius: 20px;
  background: rgba(31, 35, 41, .92);
  color: #fff;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 80;
  white-space: nowrap;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#toast.err { background: rgba(185, 28, 28, .95); }

/* ───────────────────────── 加载 ───────────────────────── */
.loading {
  padding: 40px;
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
}

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  margin-right: 8px;
  vertical-align: -3px;
  border: 2px solid #dbe0e7;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 720px) {
  .content { padding: 14px; }
  .row-2 { grid-template-columns: 1fr; }
  .topbar { padding: 0 14px; }
  th, td { padding: 10px 10px; }
  table { font-size: 12.5px; }
}
