:root {
  color-scheme: light;
  --ink: #182027;
  --muted: #68727d;
  --line: #dce2e7;
  --soft: #f4f6f7;
  --surface: #ffffff;
  --sidebar: #172126;
  --sidebar-active: #27353b;
  --primary: #067a9c;
  --primary-hover: #056782;
  --green: #147a50;
  --green-soft: #e7f5ed;
  --amber: #9a6400;
  --amber-soft: #fff4d8;
  --red: #b42318;
  --red-soft: #feeceb;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--soft); }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
img { display: block; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 224px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 18px 12px; color: #eef2f3; background: var(--sidebar); display: flex; flex-direction: column; }
.brand, .login-brand { display: flex; align-items: center; gap: 11px; }
.brand { padding: 3px 8px 20px; border-bottom: 1px solid #314047; }
.brand img, .login-brand img { width: 30px; height: 30px; }
.brand img { filter: invert(1); }
.brand strong, .brand span, .login-brand strong, .login-brand span { display: block; }
.brand strong { font-size: 15px; }
.brand span { margin-top: 2px; color: #9dacb2; font-size: 12px; }
nav { padding-top: 14px; display: grid; gap: 4px; }
.nav-item { width: 100%; height: 42px; padding: 0 12px; border: 0; border-radius: 5px; color: #c7d0d4; background: transparent; display: flex; align-items: center; gap: 10px; text-align: left; }
.nav-item:hover, .nav-item.active { color: #fff; background: var(--sidebar-active); }
.nav-item.active { box-shadow: inset 3px 0 0 #26a7c9; }
.nav-item img { width: 18px; height: 18px; filter: invert(90%); }
.sidebar-footer { margin-top: auto; padding: 14px 12px 3px; color: #9dacb2; border-top: 1px solid #314047; }

.main-area { min-width: 0; }
.topbar { min-height: 72px; padding: 14px 28px; border-bottom: 1px solid var(--line); background: var(--surface); display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.topbar h1 { margin: 0 0 3px; font-size: 20px; }
.topbar span { color: var(--muted); font-size: 12px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-button, .icon-text-button, .primary-button, .secondary-button { min-height: 36px; border-radius: 5px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.icon-button { width: 36px; padding: 0; border: 1px solid var(--line); background: #fff; }
.icon-button img, .icon-text-button img, .primary-button img, .secondary-button img { width: 16px; height: 16px; }
.icon-text-button, .secondary-button { padding: 0 13px; color: var(--ink); border: 1px solid var(--line); background: #fff; }
.icon-button:hover, .icon-text-button:hover, .secondary-button:hover { background: var(--soft); }
.primary-button { padding: 0 15px; color: #fff; border: 1px solid var(--primary); background: var(--primary); }
.primary-button img { filter: invert(1); }
.primary-button:hover { background: var(--primary-hover); }
.primary-button.small { min-height: 34px; }

.notice { margin: 18px 28px 0; padding: 10px 12px; border: 1px solid #f0cb70; border-radius: 5px; color: #704c00; background: var(--amber-soft); }
.notice.error { color: var(--red); border-color: #f1aaa5; background: var(--red-soft); }
.view { display: none; padding: 24px 28px 40px; }
.view.active { display: block; }
.metric-strip { margin-bottom: 22px; border: 1px solid var(--line); background: var(--surface); display: grid; grid-template-columns: repeat(6, minmax(110px, 1fr)); }
.metric-strip > div { min-height: 88px; padding: 18px; border-right: 1px solid var(--line); }
.metric-strip > div:last-child { border-right: 0; }
.metric-strip span { display: block; margin-bottom: 8px; color: var(--muted); }
.metric-strip strong { font-size: 24px; font-weight: 650; }
.section-block { border: 1px solid var(--line); background: var(--surface); }
.section-heading { min-height: 58px; padding: 11px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.section-heading h2 { margin: 0; font-size: 16px; }
.section-heading > div > .field-hint { margin-top: 3px; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 14px; border-bottom: 1px solid #e9edef; text-align: left; vertical-align: top; }
th { color: var(--muted); background: #fafbfb; font-size: 12px; font-weight: 600; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafcfc; }
.cell-title { font-weight: 600; }
.mail-subject { width: min(280px, 30vw); min-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-sub { margin-top: 4px; color: var(--muted); font-size: 12px; white-space: pre-line; }
.mono-value { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.row-actions { display: flex; justify-content: flex-end; gap: 6px; white-space: nowrap; }
.row-actions .icon-button { width: 32px; min-height: 32px; height: 32px; }
.empty-row { padding: 34px; color: var(--muted); text-align: center; }
.status { display: inline-flex; align-items: center; min-height: 25px; padding: 3px 8px; border-radius: 4px; font-size: 12px; white-space: nowrap; }
.status.success { color: var(--green); background: var(--green-soft); }
.status.warning { color: var(--amber); background: var(--amber-soft); }
.status.error { color: var(--red); background: var(--red-soft); }
.status.neutral { color: #52616a; background: #edf1f3; }

.failover-status-grid { margin-bottom: 18px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.failover-status-card { min-height: 112px; padding: 17px; border: 1px solid var(--line); background: var(--surface); }
.failover-status-card span, .failover-status-card small { display: block; color: var(--muted); }
.failover-status-card strong { display: block; margin: 9px 0 6px; font-size: 20px; }
.failover-status-card strong.success { color: var(--green); }
.failover-status-card strong.error { color: var(--red); }
.failover-status-card strong.warning { color: var(--amber); }
.failover-form { margin-bottom: 18px; }
.failover-actions { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.failover-actions > div { display: flex; flex-wrap: wrap; gap: 8px; }
.failover-events { margin-top: 18px; }

dialog { padding: 0; border: 1px solid var(--line); border-radius: 7px; color: var(--ink); background: var(--surface); box-shadow: 0 20px 50px rgb(25 36 42 / 24%); }
dialog::backdrop { background: rgb(15 24 28 / 48%); }
.form-dialog { width: min(720px, calc(100vw - 32px)); }
.form-dialog.compact-dialog { width: min(480px, calc(100vw - 32px)); }
.form-dialog.wide, .detail-dialog { width: min(960px, calc(100vw - 32px)); }
.form-dialog form, .detail-dialog { max-height: calc(100vh - 48px); overflow: auto; }
.dialog-heading { position: sticky; top: 0; z-index: 2; min-height: 58px; padding: 11px 18px; border-bottom: 1px solid var(--line); background: #fff; display: flex; align-items: center; justify-content: space-between; }
.dialog-heading h2 { margin: 0; font-size: 17px; }
.form-grid { padding: 18px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px 18px; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
label { color: #3e4950; font-size: 13px; font-weight: 600; }
label input, label select, label textarea { width: 100%; margin-top: 7px; }
input, select, textarea { min-height: 38px; padding: 8px 10px; border: 1px solid #cbd3d8; border-radius: 4px; color: var(--ink); background: #fff; outline: none; }
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgb(6 122 156 / 12%); }
.full { grid-column: 1 / -1; }
.field-hint { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; font-weight: 400; }
.toggle-row { padding: 0 18px 18px; display: flex; flex-wrap: wrap; gap: 18px; }
.toggle-row label, .choice-grid label, .step-list label { display: flex; align-items: center; gap: 7px; }
.toggle-row input, .choice-grid input, .step-list input { width: 16px; min-height: 16px; margin: 0; }
fieldset { margin: 0 18px 18px; padding: 14px; border: 1px solid var(--line); border-radius: 5px; }
legend { padding: 0 6px; font-weight: 650; }
.choice-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 11px; }
.step-list { display: grid; grid-template-columns: repeat(5, minmax(120px, 1fr)); gap: 8px; }
.step-list label { min-height: 44px; padding: 8px; border: 1px solid var(--line); border-radius: 4px; background: #fafbfb; }
.step-list label span { width: 20px; height: 20px; border-radius: 50%; color: #fff; background: #66747c; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; }
.dialog-actions { position: sticky; bottom: 0; z-index: 2; padding: 12px 18px; border-top: 1px solid var(--line); background: #fff; display: flex; justify-content: flex-end; gap: 8px; }

#case-detail { padding: 18px; }
.detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border: 1px solid var(--line); }
.detail-item { min-height: 70px; padding: 12px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.detail-item:nth-child(3n) { border-right: 0; }
.detail-item span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12px; }
.detail-item strong { white-space: pre-wrap; overflow-wrap: anywhere; }
.mail-content, .event-list { margin-top: 18px; }
.mail-content h3, .event-list h3 { margin: 0 0 9px; font-size: 14px; }
.mail-content pre { max-height: 260px; margin: 0; padding: 12px; border: 1px solid var(--line); background: #fafbfb; white-space: pre-wrap; overflow: auto; }
.event-row { display: grid; grid-template-columns: 150px 110px 1fr 150px; gap: 10px; padding: 9px 0; border-bottom: 1px solid #edf0f2; }
.event-row:last-child { border-bottom: 0; }
.event-row span { color: var(--muted); }

.login-page { min-height: 100vh; display: grid; place-items: center; background: #eef2f3; }
.login-shell { width: min(420px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 7px; background: #fff; box-shadow: 0 16px 40px rgb(25 36 42 / 12%); }
.login-brand { padding: 18px 22px; color: #fff; background: var(--sidebar); }
.login-brand img { filter: invert(1); }
.login-brand strong { font-size: 16px; }
.login-brand span { margin-top: 2px; color: #aab6ba; font-size: 12px; }
.login-form { padding: 24px 22px; display: grid; gap: 16px; }
.login-form h1 { margin: 0 0 2px; font-size: 20px; }
.login-form .primary-button { width: 100%; }
.form-error { min-height: 18px; color: var(--red); }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 72px minmax(0, 1fr); }
  .sidebar { padding-inline: 8px; }
  .brand { justify-content: center; padding-inline: 0; }
  .brand div, .nav-item { font-size: 0; }
  .nav-item { justify-content: center; padding: 0; }
  .nav-item img { width: 20px; height: 20px; }
  .sidebar-footer { display: none; }
  .metric-strip { grid-template-columns: repeat(3, 1fr); }
  .metric-strip > div:nth-child(3) { border-right: 0; }
  .metric-strip > div:nth-child(-n+3) { border-bottom: 1px solid var(--line); }
  .step-list { grid-template-columns: 1fr 1fr; }
  .failover-status-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 620px) {
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: 8px; }
  .brand, .sidebar-footer { display: none; }
  nav { padding: 0; grid-template-columns: repeat(auto-fit, minmax(42px, 1fr)); gap: 2px; }
  .nav-item { height: 44px; }
  .topbar { padding: 12px 14px; }
  .topbar h1 { font-size: 17px; }
  .icon-text-button { width: 36px; padding: 0; font-size: 0; }
  .view { padding: 14px; }
  .notice { margin: 12px 14px 0; }
  .metric-strip { grid-template-columns: 1fr 1fr; }
  .metric-strip > div, .metric-strip > div:nth-child(3) { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
  .metric-strip > div:nth-child(2n) { border-right: 0; }
  .metric-strip > div:nth-last-child(-n+2) { border-bottom: 0; }
  .form-grid, .form-grid.three, .detail-grid { grid-template-columns: 1fr; }
  .detail-item, .detail-item:nth-child(3n) { border-right: 0; }
  .choice-grid, .step-list { grid-template-columns: 1fr; }
  .failover-status-grid { grid-template-columns: 1fr; }
  .failover-actions { align-items: stretch; flex-direction: column; }
  .failover-actions > div { display: grid; grid-template-columns: 1fr; }
  .event-row { grid-template-columns: 1fr; gap: 3px; }
  .mail-subject { width: 180px; min-width: 180px; }
}
