:root {
  --navy-900: #071b33;
  --navy-800: #0b2545;
  --navy-700: #14355c;
  --blue-600: #1f5fbf;
  --blue-500: #2b6fd6;
  --blue-100: #e8f0fb;
  --ink-900: #172033;
  --ink-700: #3b4658;
  --ink-500: #697386;
  --line: #dfe4ec;
  --surface: #ffffff;
  --canvas: #f3f5f9;
  --red-700: #a51f2d;
  --red-100: #fdecee;
  --orange-700: #9a5a00;
  --orange-100: #fff4df;
  --green-700: #146c43;
  --green-100: #e7f6ee;
  --gray-100: #eef1f5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 32, 56, 0.06), 0 8px 24px rgba(15, 32, 56, 0.05);
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink-900);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.55;
}
h1, h2, h3 { margin: 0; font-weight: 650; line-height: 1.3; }
p { margin: 0 0 8px; }
a { color: var(--blue-600); }
a:hover { color: var(--blue-500); }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid #7aa7ea; outline-offset: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 12px; top: -80px; z-index: 100; background: #fff;
  color: var(--navy-800); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow);
}
.skip-link:focus { top: 12px; }

/* ---------------------------------------------------------------- login */
.login-shell {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(circle at 15% 10%, #163d6e 0, #0a2140 42%, #06172b 100%);
}
.login-card {
  width: 100%; max-width: 430px; background: var(--surface); border-radius: 16px;
  padding: 32px; box-shadow: 0 24px 70px rgba(0, 0, 0, 0.32);
}
.login-brand { display: flex; align-items: center; gap: 10px; color: var(--blue-600); font-weight: 700; letter-spacing: .04em; }
.login-mark {
  width: 34px; height: 34px; border-radius: 9px; background: var(--navy-800); color: #fff;
  display: grid; place-items: center; font-size: 16px; font-weight: 700;
}
.login-card h1 { margin-top: 22px; font-size: 26px; }
.login-subtitle { color: var(--ink-500); margin-top: 6px; margin-bottom: 22px; }
.login-env { margin-top: 18px; color: var(--ink-500); font-size: 12px; overflow-wrap: anywhere; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label, .field-label { font-weight: 600; color: var(--ink-700); }
.field input, .field select, .field textarea,
input[type="text"], input[type="password"], input[type="search"], input[type="date"], input[type="datetime-local"],
select, textarea {
  width: 100%; border: 1px solid #c9d1de; border-radius: 8px; background: #fff;
  padding: 9px 11px; color: var(--ink-900); min-height: 40px;
}
.field textarea, textarea { min-height: 96px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--blue-500); }
.field-hint { color: var(--ink-500); font-size: 12px; margin: 0; }
.checkline { display: flex; align-items: center; gap: 8px; min-height: 40px; }
.checkline input { width: 18px; height: 18px; }

.btn, .btn-primary, .btn-secondary, .btn-danger, .link-button {
  border: 1px solid transparent; border-radius: 8px; padding: 8px 14px; min-height: 40px;
  background: var(--surface); color: var(--ink-900); display: inline-flex; align-items: center;
  justify-content: center; gap: 6px; text-decoration: none;
}
.btn-primary { background: var(--blue-600); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--blue-500); color: #fff; }
.btn-secondary { border-color: #c9d1de; background: #fff; color: var(--ink-700); }
.btn-secondary:hover { border-color: var(--blue-500); color: var(--blue-600); }
.btn-danger { background: var(--red-700); color: #fff; }
.btn-danger:hover { color: #fff; opacity: .92; }
.btn-small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
button:disabled { cursor: not-allowed; opacity: .55; }
.link-button { background: none; color: var(--blue-600); padding: 6px 8px; min-height: 36px; }
.link-button:hover { color: var(--blue-500); text-decoration: underline; }

.notice {
  border: 1px solid #c9d8ee; background: var(--blue-100); color: #173b6b;
  border-radius: 8px; padding: 10px 12px; margin: 0 0 14px; overflow-wrap: anywhere;
}
.notice-warning { border-color: #efcf95; background: var(--orange-100); color: var(--orange-700); }
.notice-danger { border-color: #f0b7bd; background: var(--red-100); color: var(--red-700); }
.notice-success { border-color: #b9e2cc; background: var(--green-100); color: var(--green-700); }
.form-error {
  border: 1px solid #f0b7bd; background: var(--red-100); color: var(--red-700);
  border-radius: 8px; padding: 9px 11px; margin-bottom: 12px; overflow-wrap: anywhere;
}
.form-success { color: var(--green-700); background: var(--green-100); border: 1px solid #b9e2cc;
  border-radius: 8px; padding: 9px 11px; margin: 12px 0; }

/* ---------------------------------------------------------------- shell */
.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 240px; z-index: 30; background: var(--navy-800);
  color: #dbe7f7; display: flex; flex-direction: column; padding: 20px 14px; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; border-bottom: 1px solid rgba(255,255,255,.12); }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; background: #fff; color: var(--navy-800);
  display: grid; place-items: center; font-weight: 800;
}
.brand-text { font-weight: 700; letter-spacing: .04em; color: #fff; }
.brand-sub { display: block; font-size: 11px; color: #9fb6d6; font-weight: 500; letter-spacing: .02em; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; margin-top: 18px; }
.sidebar nav a {
  color: #cfe0f5; text-decoration: none; padding: 10px 12px; border-radius: 8px;
  display: flex; align-items: center; min-height: 42px; border: 1px solid transparent;
}
.sidebar nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar nav a[aria-current="page"] { background: #fff; color: var(--navy-800); font-weight: 700; }
.sidebar-footer { margin-top: auto; padding-top: 16px; border-top: 1px solid rgba(255,255,255,.12); display: flex; flex-direction: column; gap: 4px; }
.sidebar-footer a { color: #cfe0f5; text-decoration: none; padding: 10px 12px; border-radius: 8px; min-height: 42px; display: flex; align-items: center; }
.sidebar-footer a[aria-current="page"] { background: rgba(255,255,255,.14); color: #fff; }
.sidebar-footer .link-button { color: #cfe0f5; justify-content: flex-start; }
.sidebar-footer .link-button:hover { color: #fff; background: rgba(255,255,255,.08); }
.app-main { margin-left: 240px; min-height: 100vh; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 64px; min-height: 64px; background: #fff; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 14px; padding: 0 24px; position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-weight: 700; color: var(--navy-800); white-space: nowrap; }
.topbar-meta { margin-left: auto; display: flex; align-items: center; gap: 14px; color: var(--ink-500); font-size: 13px; min-width: 0; }
.topbar-admin { color: var(--ink-900); font-weight: 600; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-time { white-space: nowrap; }
.scope-select-wrap { display: inline-flex; min-width: 0; }
.scope-select { max-width: 260px; min-height: 32px; border: 1px solid #c9d1de; border-radius: 8px; background: #fff; color: var(--ink-900); padding: 4px 8px; font-size: 12px; }
.env-badge { background: var(--navy-800); color: #fff; border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.env-badge.dev { background: var(--orange-700); }
.nav-toggle { display: none; border: 1px solid #c9d1de; background: #fff; border-radius: 8px; min-height: 38px; padding: 6px 12px; }
.content { padding: 24px; max-width: 1440px; width: 100%; margin: 0 auto; }
.global-alert {
  margin: 16px 24px 0; border: 1px solid #f0b7bd; background: var(--red-100); color: var(--red-700);
  border-radius: 8px; padding: 10px 12px; overflow-wrap: anywhere;
}
.global-alert.info { border-color: #c9d8ee; background: var(--blue-100); color: #173b6b; }
.page-head { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { font-size: 22px; color: var(--navy-800); }
.page-subtitle { color: var(--ink-500); margin-top: 4px; }
.page-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; min-width: 0; }
.panel + .panel { margin-top: 18px; }
.panel-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.panel-head h2 { font-size: 16px; color: var(--navy-800); }
.panel-head .panel-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.muted { color: var(--ink-500); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; overflow-wrap: anywhere; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid { display: grid; gap: 18px; }
.overview-layout { grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr); }
.ticket-layout { grid-template-columns: minmax(0, 1.35fr) minmax(0, 0.65fr); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; align-items: center; }
.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { margin: 0; min-width: 160px; flex: 1 1 160px; }

/* ---------------------------------------------------------------- data */
.kpi-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.kpi-label { color: var(--ink-500); font-size: 13px; }
.kpi-value { font-size: 28px; font-weight: 700; color: var(--navy-800); line-height: 1.2; margin-top: 4px; }
.kpi-note { color: var(--ink-500); font-size: 12px; margin-top: 4px; overflow-wrap: anywhere; }
.dep-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.dep-card { border: 1px solid var(--line); border-radius: 8px; padding: 12px; background: #fbfcfe; min-width: 0; }
.dep-name { font-weight: 600; }
.badge {
  display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 2px 9px;
  font-size: 12px; font-weight: 600; border: 1px solid transparent; white-space: nowrap;
}
.badge-ok { background: var(--green-100); color: var(--green-700); border-color: #b9e2cc; }
.badge-warn { background: var(--orange-100); color: var(--orange-700); border-color: #efcf95; }
.badge-danger { background: var(--red-100); color: var(--red-700); border-color: #f0b7bd; }
.badge-neutral { background: var(--gray-100); color: var(--ink-700); border-color: var(--line); }
.badge-info { background: var(--blue-100); color: #173b6b; border-color: #c9d8ee; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; min-width: 620px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #f8fafc; color: var(--ink-700); font-size: 12px; font-weight: 650; white-space: nowrap; }
tbody tr:hover { background: #fafcff; }
tbody tr:last-child td { border-bottom: 0; }
td .cell-sub { display: block; color: var(--ink-500); font-size: 12px; margin-top: 2px; }
.empty-state, .loading-state, .error-state {
  padding: 28px 16px; text-align: center; color: var(--ink-500); border: 1px dashed #c9d1de; border-radius: 8px;
}
.error-state { color: var(--red-700); border-color: #f0b7bd; background: var(--red-100); }
.loading-state { color: var(--ink-700); }
.pager { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 14px; color: var(--ink-500); font-size: 13px; }
.pager .spacer { flex: 1; }
.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filters .field { margin: 0; min-width: 150px; flex: 1 1 150px; }
.filters .field-wide { min-width: 220px; flex: 2 1 220px; }
.filters .checkline { flex: 0 0 auto; }
.detail-meta { display: flex; flex-wrap: wrap; gap: 8px 18px; color: var(--ink-500); font-size: 13px; margin-top: 10px; }
.detail-meta strong { color: var(--ink-900); font-weight: 600; }
.badge-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.description { white-space: pre-wrap; overflow-wrap: anywhere; background: #fbfcfe; border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.timeline li { border-left: 3px solid #c9d8ee; padding-left: 12px; }
.timeline .timeline-head { font-weight: 600; }
.comment-list { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.comment-list li { background: #fbfcfe; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.comment-body { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 4px; }
.kv { display: grid; grid-template-columns: minmax(90px, auto) minmax(0, 1fr); gap: 6px 12px; margin: 0; }
.kv dt { color: var(--ink-500); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
pre.result { margin: 0; padding: 12px; background: #0c1f37; color: #d9e7f8; border-radius: 8px; overflow: auto; max-height: 340px; white-space: pre-wrap; overflow-wrap: anywhere; }
details > summary { cursor: pointer; color: var(--blue-600); }
.detail-aside { display: flex; flex-direction: column; gap: 14px; }
.detail-aside .panel { margin-top: 0; }
.action-block { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }
.action-block:first-of-type { border-top: 0; padding-top: 0; margin-top: 0; }
.action-block h3 { font-size: 14px; margin-bottom: 8px; color: var(--navy-800); }
.sticky-note { color: var(--ink-500); font-size: 12px; }
#dev-mfa-notice { margin: 16px 24px 0; }
.boot { min-height: 100vh; display: grid; place-items: center; padding: 24px; color: var(--ink-500); }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1120px) {
  .overview-layout, .ticket-layout { grid-template-columns: minmax(0, 1fr); }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%); visibility: hidden;
    transition: transform .18s ease, visibility 0s linear .18s;
    box-shadow: 12px 0 40px rgba(0,0,0,.22);
  }
  .sidebar.open {
    transform: translateX(0); visibility: visible;
    transition: transform .18s ease, visibility 0s linear 0s;
  }
  .app-main { margin-left: 0; }
  .nav-toggle { display: inline-flex; }
  .topbar { padding: 0 14px; gap: 10px; }
  .topbar-time { display: none; }
  .content { padding: 18px 14px 32px; }
  .global-alert { margin: 12px 14px 0; }
  #dev-mfa-notice { margin: 12px 14px 0; }
}
@media (max-width: 640px) {
  /* Give the native scope selector its own full-width row so the selected application
     code stays readable on narrow phones instead of collapsing to a few characters. */
  .topbar { height: auto; min-height: 64px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; row-gap: 6px; }
  .topbar-meta { flex: 1 1 240px; flex-wrap: wrap; gap: 6px 10px; }
  .scope-select-wrap { order: -1; flex: 1 1 100%; }
  .scope-select { width: 100%; max-width: none; }
  .topbar-admin { max-width: none; flex: 1 1 160px; min-width: 0; }
  .topbar-title { display: none; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .dep-grid { grid-template-columns: minmax(0, 1fr); }
  .kpi-grid { grid-template-columns: minmax(0, 1fr); }
  .login-shell { padding: 14px; }
  .login-card { padding: 24px 20px; }
  .page-head h1 { font-size: 20px; }
  .page-actions { margin-left: 0; }
}
@media (max-width: 420px) {
  .content { padding: 14px 10px 28px; }
  .panel { padding: 14px; }
  .topbar { padding: 8px 10px; }
  .env-badge { max-width: 112px; overflow: hidden; text-overflow: ellipsis; }
  .topbar-meta { gap: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
