/* ==========================================================================
   EA 授权管理系统 — 管理端样式
   单页 HTML + 原生 CSS（需求 CH-07）
   ========================================================================== */

:root {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --sidebar: #0f172a;
  --sidebar-2: #1e293b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --info: #0369a1;
  --info-soft: #e0f2fe;
  --muted: #64748b;
  --muted-soft: #f1f5f9;
  --border: #e2e8f0;
  --border-2: #cbd5e1;
  --text: #0f172a;
  --text-2: #475569;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, 0.16);
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei",
    "PingFang SC", "Hiragino Sans GB", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============================ 布局 ============================ */

.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 216px;
  flex: 0 0 216px;
  background: var(--sidebar);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 16px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.16);
}
.brand .mark {
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.brand .btxt { min-width: 0; }
.brand h1 {
  margin: 0;
  font-size: 13.5px;
  font-weight: 600;
  color: #f8fafc;
  letter-spacing: 0.2px;
  white-space: nowrap;
}
.brand span {
  display: block;
  margin-top: 2px;
  font-size: 10px;
  color: #64748b;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  white-space: nowrap;
}

.nav { padding: 12px 10px; flex: 1; }
.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
  color: #cbd5e1;
  font-size: 13.5px;
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
}
.nav a:hover { background: var(--sidebar-2); color: #f8fafc; text-decoration: none; }
.nav a.active { background: var(--primary); color: #fff; font-weight: 500; }
.nav a .ico {
  width: 17px;
  height: 17px;
  flex: 0 0 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.92;
}
.nav a .ico svg { display: block; }

.sidebar-foot {
  padding: 12px 16px 16px;
  border-top: 1px solid rgba(148, 163, 184, 0.16);
  font-size: 12px;
  color: #64748b;
}
.sidebar-foot .who { color: #cbd5e1; margin-bottom: 8px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 56px;
  flex: 0 0 56px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar h2 { margin: 0; font-size: 16px; font-weight: 600; }
.topbar .sub { font-size: 12px; color: var(--muted); margin-left: 10px; font-weight: 400; }

/* 内容区宽度由视口决定，不设上限 —— 否则宽屏（如 2560px）右侧会留大片空白 */
.content { padding: 22px; flex: 1; width: 100%; min-width: 0; }

/* ============================ 按钮 ============================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text-2);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.btn:hover { background: #f8fafc; border-color: var(--muted); color: var(--text); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }

.btn-danger { background: #fff; border-color: #fecaca; color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }

.btn-warn { background: #fff; border-color: #fde68a; color: var(--warn); }
.btn-warn:hover { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.btn[disabled] { pointer-events: none; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ============================ 表单 ============================ */

.field { margin-bottom: 14px; }
.field label {
  display: block;
  margin-bottom: 5px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-2);
}
.field .hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }

input[type="text"],
input[type="password"],
input[type="date"],
input[type="datetime-local"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
textarea { resize: vertical; min-height: 62px; }
input::placeholder, textarea::placeholder { color: #94a3b8; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }

/* ============================ 卡片 ============================ */

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.card-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.card-head h3 { margin: 0; font-size: 14.5px; font-weight: 600; }
.card-body { padding: 18px; }
.card-body.tight { padding: 0; }

/* ============================ 统计卡片 ============================ */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(178px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 17px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.stat::after {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--muted);
}
.stat.ok::after { background: var(--ok); }
.stat.warn::after { background: var(--warn); }
.stat.danger::after { background: var(--danger); }
.stat.info::after { background: var(--info); }
.stat .k {
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: 0.3px;
  margin-bottom: 6px;
}
.stat .v { font-size: 25px; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .v.ok { color: var(--ok); }
.stat .v.warn { color: var(--warn); }
.stat .v.danger { color: var(--danger); }
.stat .v.info { color: var(--info); }

/* ============================ 表格 ============================ */

.table-wrap { overflow-x: auto; }
table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.table th {
  text-align: left;
  padding: 10px 14px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  letter-spacing: 0.2px;
}
table.table td {
  padding: 10px 14px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}
table.table tbody tr:hover { background: #f8fafc; }
table.table tbody tr:last-child td { border-bottom: none; }
table.table td.num { font-variant-numeric: tabular-nums; }
table.table td.actions { white-space: nowrap; }
table.table td.actions .btn { margin-right: 5px; }
table.table td.actions .btn:last-child { margin-right: 0; }
table.table .empty {
  text-align: center;
  padding: 44px 0;
  color: var(--muted);
  font-size: 13px;
}

.mono {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: -0.2px;
}
.key-cell {
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}
.dim { color: var(--muted); }
.nowrap { white-space: nowrap; }
.trunc {
  display: inline-block;
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

.day-left { font-weight: 600; font-variant-numeric: tabular-nums; }
.day-left.warn { color: var(--warn); }
.day-left.danger { color: var(--danger); }
.day-left.ok { color: var(--text-2); }

/* ============================ 徽章 ============================ */

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.7;
  white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.muted { background: var(--muted-soft); color: var(--muted); }

.dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.dot.on { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.18); }
.dot.off { background: #cbd5e1; }

/* ============================ 工具栏 / 分页 ============================ */

.toolbar {
  display: flex;
  gap: 9px;
  align-items: center;
  flex-wrap: wrap;
}
.toolbar .grow { flex: 1; min-width: 160px; }
.toolbar input, .toolbar select { width: auto; min-width: 130px; }
.toolbar .spacer { flex: 1; }

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.pager .info { font-size: 12.5px; color: var(--muted); }
.pager .ctrl { display: flex; gap: 6px; align-items: center; }
.pager .ctrl .page-now {
  font-size: 12.5px;
  color: var(--text-2);
  padding: 0 8px;
  font-variant-numeric: tabular-nums;
}

/* ============================ 登录页 ============================ */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(140deg, #0f172a 0%, #1e293b 45%, #1e3a8a 100%);
}
.login-card {
  width: 100%;
  max-width: 372px;
  background: #fff;
  border-radius: 14px;
  padding: 30px 30px 26px;
  box-shadow: 0 24px 60px rgba(2, 6, 23, 0.45);
}
.login-card .logo {
  width: 46px; height: 46px;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 21px;
  margin-bottom: 16px;
}
.login-card h1 { margin: 0 0 4px; font-size: 19px; font-weight: 600; }
.login-card .desc { margin: 0 0 22px; font-size: 12.5px; color: var(--muted); }
.login-foot { margin-top: 18px; font-size: 11.5px; color: #94a3b8; text-align: center; }

.alert {
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  margin-bottom: 14px;
  border: 1px solid transparent;
}
.alert.err { background: var(--danger-soft); color: var(--danger); border-color: #fecaca; }
.alert.ok { background: var(--ok-soft); color: var(--ok); border-color: #bbf7d0; }
.alert.warn { background: var(--warn-soft); color: var(--warn); border-color: #fde68a; }
.alert.info { background: var(--info-soft); color: var(--info); border-color: #bae6fd; }

/* ============================ 模态框 ============================ */

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
  animation: fade 0.12s ease-out;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: pop 0.15s ease-out;
}
@keyframes pop {
  from { opacity: 0; transform: translateY(8px) scale(0.985); }
  to { opacity: 1; transform: none; }
}
.modal.wide { max-width: 660px; }
.modal-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.modal-head .x {
  border: none;
  background: none;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0 4px;
}
.modal-head .x:hover { color: var(--text); }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 9px;
}

.quick-row { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 10px; }

.kv { font-size: 13px; }
.kv .row {
  display: flex;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px dashed var(--border);
}
.kv .row:last-child { border-bottom: none; }
.kv .row .k { flex: 0 0 84px; color: var(--muted); }
.kv .row .v { flex: 1; min-width: 0; word-break: break-all; }

/* ============================ Toast ============================ */

.toasts {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: #fff;
  border: 1px solid var(--border);
  border-left: 3px solid var(--muted);
  border-radius: var(--radius-sm);
  padding: 10px 15px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  min-width: 220px;
  max-width: 380px;
  animation: slide 0.16s ease-out;
}
@keyframes slide { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }

/* ============================ 其他 ============================ */

.loading { padding: 40px 0; text-align: center; color: var(--muted); font-size: 13px; }
.spinner {
  display: inline-block;
  width: 15px; height: 15px;
  border: 2px solid var(--border-2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  vertical-align: -2px;
  margin-right: 7px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.sec-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.6px;
  text-transform: uppercase;
  margin: 0 0 10px;
}

.code-inline {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--muted-soft);
  padding: 1px 6px;
  border-radius: 4px;
}

/* 内联样式的 CSS 类替代品
   —— 严格 CSP（style-src 'self'）会拦截 style="..." 属性，
      所以这里不写内联样式，统一用类。 */
.alert.m-block { margin: 18px; }
.alert.m-block-lg { margin: 24px; }
.alert.scroll-box { max-height: 150px; overflow: auto; }
.user-chip { font-size: 12.5px; }
.modal-body p.flush { margin: 0; }
.field.mt { margin-top: 14px; }
.req { color: #b91c1c; }

/* ==========================================================================
   自适应断点
   内容区不设 max-width，宽度完全跟随视口；以下断点只调整留白与字号，
   让不同尺寸下的观感保持一致（而不是简单拉伸）。
   ========================================================================== */

/* 宽屏下展示更多列，窄屏自动收起次要列（避免横向滚动太多） */
@media (max-width: 1100px) {
  th.col-md, td.col-md { display: none; }
}
@media (max-width: 760px) {
  th.col-sm, td.col-sm { display: none; }
}

/* 超宽屏（≥1900px，如 2560×1440 的 2K 屏）：放大留白与字号 */
@media (min-width: 1900px) {
  .content { padding: 28px 32px; }
  .topbar { padding: 0 30px; }
  .stats { gap: 18px; margin-bottom: 22px; }
  .stat { padding: 18px 20px; }
  .stat .k { font-size: 12.5px; }
  .stat .v { font-size: 29px; }
  .card-head { padding: 16px 22px; }
  .card-body { padding: 22px; }
  .pager { padding: 14px 22px; }
  table.table th { padding: 12px 18px; }
  table.table td { padding: 13px 18px; }
  .trunc { max-width: 320px; }
}

/* 宽屏（1400–1899px） */
@media (min-width: 1400px) and (max-width: 1899px) {
  .content { padding: 24px 26px; }
  .trunc { max-width: 240px; }
}

/* 窄屏 / 平板（≤760px）：侧栏收起为图标条 */
@media (max-width: 760px) {
  .sidebar { width: 60px; flex: 0 0 60px; }
  .brand { justify-content: center; padding: 14px 0; }
  .brand .btxt { display: none; }
  .nav a span.t, .sidebar-foot { display: none; }
  .nav a { justify-content: center; padding: 10px 0; }
  .topbar { padding: 0 12px; }
  .topbar h2 .sub { display: none; }
  .content { padding: 14px; }
  .grid-2 { grid-template-columns: 1fr; }
  .trunc { max-width: 150px; }
}
