:root {
  --bg: #f7f5ef;
  --panel: #ffffff;
  --ink: #252823;
  --muted: #63665d;
  --line: #dedbd1;
  --brand: #b44222;
  --brand-soft: #f6e7dd;
  --ok: #059669;
  --ok-soft: #d1fae5;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --sidebar: #252823;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.05);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

a { color: var(--brand); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; }
button, input, select, textarea { font: inherit; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

/* ---------- 登录 ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1000px 500px at 15% -10%, #b86b4333, transparent 60%),
    radial-gradient(900px 500px at 100% 10%, #b4422226, transparent 55%),
    #252823;
}
.login-card {
  width: min(400px, 100%);
  background: var(--panel);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: 0 24px 80px rgba(2, 6, 23, 0.45);
}
.brand-icon { flex: 0 0 auto; display: block; }
.login-card h1 { display: flex; align-items: center; gap: 10px; font-size: 20px; margin-bottom: 10px; }
.login-card p { margin: 0 0 20px; font-size: 13px; color: var(--muted); }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.login-card label:not(:first-of-type) { margin-top: 14px; }
.login-card .login-submit, .login-card .login-switch { width: 100%; margin-top: 12px; min-height: 42px; }
.login-card .error {
  margin-top: 12px;
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--bad-soft);
  color: var(--bad);
  font-size: 13px;
}

/* ---------- 骨架 ---------- */
.shell { display: flex; min-height: 100vh; }
.mobile-bar { display: none; }
.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: linear-gradient(180deg, #252823, #31352e 60%, #252823);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 22px 20px 16px; border-bottom: 1px solid #ffffff12; }
.brand strong { display: block; color: #f8fafc; font-size: 15px; letter-spacing: 0.3px; }
.brand span { font-size: 12px; color: #b8bcb0; }
.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; overflow: auto; }
.nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 9px;
  color: #d5d8ce;
  font-size: 13.5px;
}
.nav a:hover { background: #ffffff0e; color: #fff; }
.nav a.active { background: #b44222; color: #fff; font-weight: 600; }
.nav .tag { font-size: 11px; opacity: 0.7; }
.sidebar-foot { margin-top: auto; padding: 14px 16px 18px; border-top: 1px solid #ffffff12; font-size: 12px; color: #b8bcb0; }
.sidebar-foot button { width: 100%; margin-top: 10px; }

.main { flex: 1; min-width: 0; padding: 22px 26px 48px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.topbar .title { font-size: 20px; font-weight: 700; letter-spacing: 0.2px; }
.topbar .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

/* ---------- 通用组件 ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 7px 13px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.2;
  transition: 0.15s;
}
.btn:hover { border-color: #c7d2e4; background: #f8fafc; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #91351c; }
.btn.danger { color: var(--bad); border-color: #fecaca; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ghost { background: transparent; color: #cbd5e1; border-color: #ffffff26; }
.btn.ghost:hover { background: #ffffff12; }
.btn.sm { padding: 4px 9px; font-size: 12px; border-radius: 7px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

input[type="text"], input[type="password"], input[type="number"], input[type="search"], input[type="date"], select, textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: #bc7054; box-shadow: 0 0 0 3px #b442221f; }
label.field { display: block; }
label.field > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }
label.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink); }
label.check input { width: auto; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.panel-head :is(h2, h3) { font-size: 14.5px; }
.panel-head .hint { font-size: 12px; color: var(--muted); }
.panel-body { padding: 16px 18px; }
.panel-body.tight { padding: 0; }
.panel-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); }
.pager span { margin-right: auto; color: var(--muted); }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.role-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); gap: 12px; }
.role-grid article { border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.role-grid h3 { font-size: 14px; margin-bottom: 10px; }
.role-grid .badge { white-space: normal; }
.role-grid .row-actions { margin-top: 12px; }
.role-meta { margin: -4px 0 10px; font-size: 12px; }
.permission-group { min-width: 0; margin: 0; padding: 4px 10px 8px; border: 1px solid var(--line); border-radius: 10px; }
.permission-group legend { padding: 0 4px; font-weight: 600; }
.permission-option { padding: 4px 0; min-height: 34px; }
.permission-option input { width: 16px; height: 16px; flex: none; margin: 0; accent-color: var(--brand); }
.account-password { max-width: 620px; }
.form-note { margin: 0; }
.multiline { white-space: pre-wrap; }
[data-account-error] { margin: 0; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin-bottom: 18px; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}
.card .label { font-size: 12.5px; color: var(--muted); }
.card .value { font-size: 26px; font-weight: 700; margin: 6px 0 4px; letter-spacing: -0.4px; }
.card .foot { font-size: 12px; color: var(--muted); }
.card.accent { background: linear-gradient(150deg, #91351c, #b44222 55%, #aa4325); border-color: #b44222; color: #fff; }
.card.accent .label, .card.accent .foot { color: #f6e7dd; }

.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; margin-bottom: 14px; }
.toolbar .field { min-width: 150px; }
.toolbar .grow { flex: 1; min-width: 200px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--muted);
  background: #f8fafc;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
tbody td { padding: 10px 14px; border-bottom: 1px solid #eef2f8; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fbff; }
.table-wrap { overflow: auto; }
.empty { padding: 32px 18px; text-align: center; color: var(--muted); font-size: 13px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--brand-soft); color: #91351c; }
.badge.neutral { background: #eef2f7; color: #475569; }

.alert { padding: 10px 14px; border-radius: 9px; margin-bottom: 14px; font-size: 13px; }
.alert.error { background: var(--bad-soft); color: var(--bad); }
.alert.info { background: var(--brand-soft); color: #91351c; }

.split { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); gap: 18px; }
.kv { display: grid; grid-template-columns: 132px 1fr; gap: 8px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- 弹层 ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5);
  display: grid; place-items: center; padding: 24px; z-index: 50;
}
.modal {
  width: min(620px, 100%);
  max-height: 88vh;
  overflow: auto;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 24px 80px rgba(2, 6, 23, 0.35);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head :is(h2, h3) { font-size: 15px; }
.modal-body { padding: 18px 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.modal-body .span-2 { grid-column: span 2; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); }
.x-btn { border: none; background: transparent; font-size: 20px; line-height: 1; color: var(--muted); cursor: pointer; }

.model-editor, .model-order { display: grid; gap: 12px; min-width: 0; }
.model-tabs, .model-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.model-editor > .field, .model-transfer-fields { max-width: 680px; }
.model-editor summary { cursor: pointer; color: var(--muted); }
.model-transfer-fields { padding-top: 10px; }
.model-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.model-name { display: grid; gap: 4px; min-width: 0; overflow-wrap: anywhere; }
.model-enabled { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; min-height: 36px; }
.model-add { display: grid; grid-template-columns: minmax(140px, 1fr) minmax(150px, 2fr) auto; align-items: end; gap: 10px; max-width: 680px; }
.model-catalog { margin: 8px 0; padding-left: 24px; max-height: 220px; overflow: auto; overflow-wrap: anywhere; }
.plan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.plan-card { border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.plan-card h4 { font-size: 14px; margin-bottom: 12px; }
.plan-card .row { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 10px; }

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar { display: none; }
  .mobile-bar {
    z-index: 20; display: flex; position: sticky; top: 0; align-items: center;
    justify-content: space-between; gap: 10px; padding: 8px 12px;
    color: #f8fafc; background: var(--sidebar);
  }
  .mobile-bar > strong { display: flex; align-items: center; gap: 6px; min-width: 0; text-align: center; font-size: 14px; }
  .mobile-bar .brand-icon { height: 22px; width: 22px; }
  .mobile-menu summary {
    display: flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 12px;
    border: 1px solid #ffffff30; border-radius: 9px; list-style: none; cursor: pointer;
  }
  .mobile-menu summary::-webkit-details-marker { display: none; }
  .mobile-menu .nav {
    position: absolute; top: 100%; left: 0; width: min(290px, 100%);
    max-height: min(75dvh, calc(100dvh - 62px)); background: var(--sidebar);
    border-radius: 0 0 12px 0; box-shadow: var(--shadow);
  }
  .mobile-menu .nav a { min-height: 44px; }
  .main { width: 100%; padding: 16px 12px 32px; }
  .topbar { gap: 8px; align-items: flex-start; }
  .topbar > div { min-width: 0; }
  .topbar .btn { flex: none; }
  .cards { grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr)); }
  .login-wrap { min-height: 100dvh; padding: 14px; }
  .login-card { padding: 24px 18px; }
  .btn, .btn.sm { min-height: 44px; padding: 8px 12px; }
  input[type="text"], input[type="password"], input[type="number"], input[type="search"], input[type="date"], select, textarea {
    font-size: 16px; min-height: 44px;
  }
  .toolbar :is(.field, .grow) { min-width: min(130px, 100%); flex: 1 1 130px; }
  .toolbar .grow { flex-basis: 100%; }
  .panel { min-width: 0; }
  .panel-head { padding: 12px; flex-wrap: wrap; }
  .panel-body:not(.tight) { padding: 12px; }
  .kv { grid-template-columns: minmax(64px, 0.35fr) minmax(0, 1fr); }
  .table-wrap { overflow: visible; }
  .responsive-table, .responsive-table tbody, .responsive-table tr { display: block; width: 100%; }
  .responsive-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .responsive-table tbody tr:not(:last-child) { border-bottom: 1px solid var(--line); }
  .responsive-table tbody tr { padding: 6px 0; }
  .responsive-table td {
    display: grid; grid-template-columns: minmax(80px, 28%) minmax(0, 1fr); align-items: start;
    gap: 10px; padding: 6px 12px; border: 0; text-align: left;
  }
  .responsive-table td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: 12px; padding-top: 2px; }
  .responsive-table td[colspan] { display: block; }
  .responsive-table .table-value { min-width: 0; white-space: normal; overflow-wrap: anywhere; }
  .responsive-table .table-value .nowrap { white-space: normal; }
  .account-table td:first-child .table-value { font-size: 14px; }
  .modal-mask { padding: 10px; }
  .modal { max-height: calc(100dvh - 20px); }
  .modal-head { position: sticky; top: 0; z-index: 1; padding: 10px 12px; background: #fff; gap: 8px; }
  .modal-head .x-btn { min-width: 44px; min-height: 44px; }
  .modal-foot { position: sticky; bottom: 0; background: #fff; padding: 10px 12px; }
  .modal-body { grid-template-columns: 1fr; }
  .modal-body .span-2 { grid-column: span 1; }
  .permission-option { min-height: 44px; }
  .plan-grid { grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); }
  .plan-card .row { flex-wrap: wrap; }
  .model-row { flex-direction: column; align-items: stretch; }
  .model-add { grid-template-columns: minmax(0, 1fr); align-items: stretch; }
  .model-enabled { min-height: 44px; }
}
