:root {
  --ink: #171a1d;
  --muted: #687078;
  --line: #dce0e3;
  --line-strong: #c5cbd0;
  --paper: #f4f5f3;
  --surface: #ffffff;
  --charcoal: #202529;
  --green: #16764a;
  --green-soft: #e7f4ed;
  --amber: #a05b08;
  --amber-soft: #fff2dd;
  --red: #b33131;
  --red-soft: #faeaea;
  --focus: #2d6cdf;
  --sidebar: 236px;
  color: var(--ink);
  font-family: Inter, "Segoe UI", "Microsoft YaHei UI", sans-serif;
  font-size: 15px;
  font-synthesis: none;
  letter-spacing: 0;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--paper); }
button, input, select, textarea { color: inherit; font: inherit; letter-spacing: 0; }
button, select { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--surface);
  padding: 10px 11px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus { border-color: var(--focus); box-shadow: 0 0 0 3px rgb(45 108 223 / 13%); }
textarea { resize: vertical; }
button:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.eyebrow { margin: 0 0 5px; color: #7b838a; font: 700 10px/1.2 Consolas, monospace; letter-spacing: 1.4px; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 28px; background: #e9ece9; }
.login-panel { width: min(100%, 400px); border-top: 4px solid var(--charcoal); background: var(--surface); padding: 42px; box-shadow: 0 18px 48px rgb(29 35 39 / 12%); }
.brand-mark { width: 48px; height: 48px; display: grid; place-items: center; margin-bottom: 28px; background: var(--charcoal); color: #fff; font: 800 15px/1 Consolas, monospace; }
.brand-mark.small { width: 38px; height: 38px; margin: 0; background: #f4f6f5; color: var(--charcoal); }
.login-panel h1 { margin: 0; font-size: 29px; line-height: 1.2; }
.login-subtitle { margin: 8px 0 28px; color: var(--muted); }
.form-stack { display: grid; gap: 10px; }
.form-stack label, .form-grid label { color: #454b50; font-size: 13px; font-weight: 650; }
.form-stack input { margin-top: 2px; }
.login-meta { display: flex; align-items: center; gap: 8px; margin: 28px 0 0; border-top: 1px solid var(--line); padding-top: 18px; color: var(--muted); font-size: 12px; }
.status-dot { display: inline-block; flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: #28a169; box-shadow: 0 0 0 3px rgb(40 161 105 / 15%); }

.app-shell { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 20; width: var(--sidebar); display: flex; flex-direction: column; background: var(--charcoal); color: #e7ebe9; }
.sidebar-brand { height: 86px; display: flex; align-items: center; gap: 12px; padding: 0 22px; border-bottom: 1px solid #353b3f; }
.sidebar-brand div:last-child { display: grid; gap: 3px; }
.sidebar-brand strong { font-size: 17px; }
.sidebar-brand span { color: #9fa8a5; font-size: 11px; }
.sidebar nav { display: grid; gap: 3px; padding: 22px 12px; }
.nav-item { min-height: 44px; display: flex; align-items: center; justify-content: space-between; border: 0; border-radius: 4px; background: transparent; color: #aeb6b4; padding: 0 12px; text-align: left; }
.nav-item:hover { background: #2c3236; color: #fff; }
.nav-item.active { background: #f0f2f1; color: #171a1d; font-weight: 700; }
.nav-item kbd { color: #707a78; font: 10px/1 Consolas, monospace; }
.nav-item b { min-width: 22px; border-radius: 10px; background: var(--amber); color: #fff; padding: 3px 6px; font-size: 10px; text-align: center; }
.sidebar-foot { display: flex; align-items: center; gap: 11px; margin-top: auto; padding: 20px 22px; border-top: 1px solid #353b3f; }
.sidebar-foot div { display: grid; gap: 3px; min-width: 0; }
.sidebar-foot strong { font-size: 12px; }
.sidebar-foot span:last-child { overflow: hidden; color: #909a97; font: 10px/1.2 Consolas, monospace; text-overflow: ellipsis; }

.workspace { min-height: 100vh; margin-left: var(--sidebar); }
.topbar { position: sticky; top: 0; z-index: 10; height: 86px; display: flex; align-items: center; justify-content: space-between; gap: 22px; border-bottom: 1px solid var(--line); background: rgb(244 245 243 / 96%); padding: 0 clamp(20px, 4vw, 52px); backdrop-filter: blur(10px); }
.topbar h1 { margin: 0; font-size: 22px; line-height: 1.2; }
.topbar-actions { display: flex; align-items: center; gap: 9px; }
.clock { margin-right: 8px; color: var(--muted); font: 12px/1 Consolas, monospace; }
#menu-button { display: none; }
.content { padding: 34px clamp(20px, 4vw, 52px) 56px; }
.view { display: none; }
.view.active { display: block; animation: reveal .18s ease-out; }
@keyframes reveal { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.button, .icon-button, .text-button { border: 0; border-radius: 4px; background: transparent; }
.button { min-height: 38px; padding: 8px 14px; font-size: 13px; font-weight: 700; }
.button.primary { background: var(--charcoal); color: #fff; }
.button.primary:hover { background: #343a3e; }
.button.ghost { border: 1px solid var(--line-strong); background: var(--surface); }
.button.ghost:hover, .button.quiet:hover { background: #e9ecea; }
.button.quiet { color: #535b61; }
.button.danger { background: var(--red); color: #fff; }
.button.danger:hover { background: #942727; }
.button.wide { width: 100%; margin-top: 5px; }
.button.small { min-height: 30px; padding: 5px 9px; font-size: 12px; }
.icon-button { width: 38px; height: 38px; display: grid; place-items: center; color: #4c555b; font-size: 21px; }
.icon-button:hover { background: #e7eae8; }
.text-button { color: var(--green); padding: 6px 0; font-size: 13px; font-weight: 700; }
.button-row { display: flex; flex-wrap: wrap; gap: 9px; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); background: var(--surface); }
.metric { position: relative; min-height: 155px; display: flex; flex-direction: column; padding: 24px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric::before { content: ""; position: absolute; inset: 0 auto auto 0; width: 100%; height: 3px; background: #8b949a; }
.metric.good::before { background: var(--green); }
.metric.warn::before { background: var(--amber); }
.metric.dark { background: var(--charcoal); color: #fff; }
.metric.dark::before { background: #52b788; }
.metric span { color: var(--muted); font-size: 12px; font-weight: 700; }
.metric.dark span, .metric.dark small { color: #aeb6b4; }
.metric strong { margin: 15px 0 11px; font-size: 36px; line-height: 1; }
.metric small { margin-top: auto; color: #8a9298; }
.metric small b { color: inherit; }
.section-heading, .section-intro { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin: 38px 0 16px; }
.section-heading h2, .section-intro h2, .toolbar-title h2, .settings-section h2 { margin: 0; font-size: 18px; }
.section-intro { align-items: end; margin-top: 0; }
.section-intro p:not(.eyebrow) { margin: 6px 0 0; color: var(--muted); font-size: 13px; }

.toolbar { min-height: 66px; display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.search-field { min-width: 240px; flex: 1; }
.select-field { display: flex; align-items: center; gap: 8px; white-space: nowrap; color: var(--muted); font-size: 12px; }
.select-field select { min-width: 108px; padding: 9px 30px 9px 10px; }
.toolbar-title { margin-right: auto; }
.toolbar-title .eyebrow { margin-bottom: 4px; }
.table-frame { overflow-x: auto; border: 1px solid var(--line); background: var(--surface); }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th, td { padding: 14px 15px; border-bottom: 1px solid #e8eaec; text-align: left; vertical-align: middle; }
th { background: #f8f9f8; color: #727a80; font-size: 11px; font-weight: 750; text-transform: uppercase; }
td { font-size: 13px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfa; }
.align-right { text-align: right; }
.cell-title { display: grid; gap: 4px; min-width: 160px; }
.cell-title strong { font-size: 13px; }
.cell-title span, .secondary { max-width: 340px; overflow: hidden; color: var(--muted); font: 11px/1.3 Consolas, monospace; text-overflow: ellipsis; }
.actions { display: flex; justify-content: flex-end; gap: 5px; }
.tag { display: inline-flex; align-items: center; min-height: 24px; border-radius: 3px; background: #edf0ef; color: #4f585e; padding: 3px 7px; font-size: 11px; font-weight: 700; }
.tag.good { background: var(--green-soft); color: var(--green); }
.tag.warn { background: var(--amber-soft); color: var(--amber); }
.tag.bad { background: var(--red-soft); color: var(--red); }
.empty-state { padding: 62px 20px; color: var(--muted); text-align: center; }

.settings-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 26px; }
.settings-section { min-width: 0; border-top: 3px solid var(--charcoal); background: var(--surface); padding: 28px; }
.settings-layout > .span-2 { grid-column: 1 / -1; }
.settings-section.danger-zone { border-top-color: var(--red); }
.definition-list { margin: 25px 0; border-top: 1px solid var(--line); }
.definition-list div { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 18px; padding: 16px 0; border-bottom: 1px solid var(--line); }
.definition-list dt { color: var(--muted); font-size: 12px; }
.definition-list dd { min-width: 0; margin: 0; font-size: 13px; }
.definition-list code { display: block; overflow-wrap: anywhere; white-space: normal; }

.dialog { width: min(680px, calc(100% - 30px)); max-height: calc(100vh - 34px); overflow: auto; overscroll-behavior: contain; border: 0; border-radius: 6px; padding: 0; box-shadow: 0 24px 70px rgb(17 22 25 / 28%); }
.dialog::backdrop { background: rgb(24 29 32 / 54%); backdrop-filter: blur(2px); }
.dialog form { padding: 26px; }
.dialog-head { display: flex; align-items: start; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.dialog-head h2 { margin: 0; font-size: 20px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 17px; }
.form-grid label { display: grid; gap: 7px; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid.compact { margin-top: 24px; }
.toggle-label { align-content: start; }
.toggle { display: flex; align-items: center; gap: 8px; min-height: 40px; }
.toggle input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.toggle i { position: relative; width: 38px; height: 22px; border-radius: 12px; background: #adb4b8; transition: background .15s; }
.toggle i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; }
.toggle input:checked + i { background: var(--green); }
.toggle input:checked + i::after { transform: translateX(16px); }
.toggle input:focus-visible + i { outline: 2px solid var(--focus); outline-offset: 2px; }
.toggle b { color: var(--muted); font-size: 12px; }
.dialog-actions, .form-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.form-error { min-height: 18px; margin: 4px 0 0; color: var(--red); font-size: 12px; }
.form-actions .form-error { margin-right: auto; }
.confirm-dialog { width: min(440px, calc(100% - 30px)); }
.confirm-dialog p:not(.eyebrow) { margin: 0; color: var(--muted); line-height: 1.7; }
.toast-region { position: fixed; z-index: 100; right: 22px; bottom: 22px; display: grid; gap: 8px; pointer-events: none; }
.toast { min-width: 240px; max-width: 380px; border-left: 4px solid var(--green); border-radius: 4px; background: var(--charcoal); color: #fff; padding: 13px 15px; box-shadow: 0 12px 30px rgb(18 22 25 / 24%); animation: toast-in .2s ease-out; }
.toast.error { border-left-color: #ef7777; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

@media (max-width: 1050px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .settings-layout { grid-template-columns: 1fr; }
  .settings-layout > .span-2 { grid-column: 1; }
}

@media (max-width: 760px) {
  :root { --sidebar: 250px; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: 10px 0 30px rgb(20 25 28 / 24%); }
  .app-shell.nav-open .sidebar { transform: none; }
  .workspace { margin-left: 0; }
  .topbar { height: 76px; padding: 0 16px; }
  #menu-button { display: grid; flex: 0 0 auto; }
  .topbar > div:nth-child(2) { margin-right: auto; }
  .clock, #refresh-button { display: none; }
  .content { padding: 22px 14px 40px; }
  .toolbar { flex-wrap: wrap; }
  .search-field { flex-basis: 100%; }
  .toolbar .select-field { flex: 1; }
  .toolbar .select-field select { min-width: 0; }
  .section-intro { align-items: start; }
  .login-panel { padding: 32px 26px; }
}

@media (max-width: 520px) {
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .metric { min-height: 128px; padding: 18px; }
  .metric strong { font-size: 30px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: span 1; }
  .definition-list div { grid-template-columns: 1fr; gap: 6px; }
  .section-heading, .section-intro { align-items: start; }
  .dialog form { padding: 20px; }
  .dialog-head { margin-bottom: 16px; }
  .form-grid { gap: 12px; }
  .dialog-actions { margin-top: 14px; padding-top: 14px; }
  .topbar h1 { font-size: 18px; }
  .topbar .eyebrow { display: none; }
}
