:root {
  color-scheme: light;
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f0;
  --ink: #17211d;
  --muted: #68756f;
  --line: #d9e0dc;
  --accent: #087f6b;
  --accent-dark: #056655;
  --accent-soft: #e1f3ee;
  --danger: #b42318;
  --danger-soft: #feeceb;
  --warning: #9a6700;
  --warning-soft: #fff3d4;
  --info: #1769aa;
  --shadow: 0 10px 30px rgba(23, 33, 29, .08);
  --sidebar: 248px;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; color: var(--ink); background: var(--bg); font-size: 14px; line-height: 1.45; }
button, input, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 24px; line-height: 1.2; letter-spacing: 0; }
h2 { margin-bottom: 3px; font-size: 16px; line-height: 1.3; letter-spacing: 0; }
h3 { margin-bottom: 4px; font-size: 14px; letter-spacing: 0; }
p { margin-bottom: 0; }
small { display: block; color: var(--muted); font-size: 12px; }
svg { width: 18px; height: 18px; stroke-width: 2; }

.app-shell { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 40; display: flex; width: var(--sidebar); flex-direction: column; padding: 18px 14px; border-right: 1px solid #29332f; color: #eef5f2; background: #17211d; }
.brand { display: flex; align-items: center; gap: 11px; min-height: 46px; padding: 0 8px 18px; }
.brand strong { display: block; font-size: 15px; }
.brand small { color: #9eaca6; }
.brand-mark { display: grid; width: 36px; height: 36px; flex: 0 0 36px; place-items: center; border-radius: 6px; color: #fff; background: var(--accent); font-size: 18px; font-weight: 800; }
.sidebar nav { display: grid; gap: 4px; }
.nav-button { display: flex; width: 100%; min-height: 42px; align-items: center; gap: 11px; padding: 9px 11px; border: 0; border-radius: 6px; color: #b9c5c0; background: transparent; text-align: left; text-decoration: none; }
.nav-button:hover { color: #fff; background: #22302a; }
.nav-button.active { color: #fff; background: #28453b; }
.nav-button svg { flex: 0 0 auto; }
.sidebar-footer { display: grid; gap: 4px; margin-top: auto; padding-top: 16px; border-top: 1px solid #34403b; }

.main-area { min-width: 0; margin-left: var(--sidebar); padding: 0 28px 42px; }
.topbar { display: flex; min-height: 92px; align-items: center; justify-content: space-between; gap: 18px; border-bottom: 1px solid var(--line); }
.top-actions { display: flex; align-items: center; gap: 10px; }
.eyebrow { margin-bottom: 2px; color: var(--accent); font-size: 11px; font-weight: 750; text-transform: uppercase; }
.muted { color: var(--muted); }
.compact { font-size: 12px; }
.mobile-only { display: none !important; }

.view { display: none; padding-top: 24px; }
.view.active { display: block; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.metric { display: flex; min-height: 88px; align-items: center; gap: 13px; padding: 16px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.metric-icon { display: grid; width: 38px; height: 38px; flex: 0 0 38px; place-items: center; border-radius: 6px; color: var(--accent); background: var(--accent-soft); }
.metric small { margin-bottom: 5px; }
.metric strong { display: block; font-size: 19px; line-height: 1.1; }
.content-grid { display: grid; gap: 16px; }
.content-grid.two-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.panel { padding: 18px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.panel + .panel, .content-grid + .panel { margin-top: 16px; }
.content-grid .panel + .panel { margin-top: 0; }
.panel-heading { display: flex; min-height: 40px; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.panel-heading p { color: var(--muted); font-size: 12px; }

.status-list, .network-list, .interface-list { display: grid; gap: 8px; }
.status-row, .network-row, .interface-row { display: flex; min-height: 48px; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); }
.status-row > div, .network-row > div, .interface-row > div { min-width: 0; }
.status-main { display: flex; min-width: 0; align-items: center; gap: 10px; }
.status-dot { width: 8px; height: 8px; flex: 0 0 8px; border-radius: 50%; background: #9ca8a3; }
.status-dot.ok { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.status-dot.bad { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.network-row strong, .interface-row strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-actions { display: flex; flex: 0 0 auto; align-items: center; gap: 6px; }
.signal { display: flex; width: 28px; height: 22px; align-items: flex-end; gap: 2px; }
.signal i { width: 4px; border-radius: 1px 1px 0 0; background: #c5cec9; }
.signal i:nth-child(1) { height: 5px; }.signal i:nth-child(2) { height: 9px; }.signal i:nth-child(3) { height: 14px; }.signal i:nth-child(4) { height: 20px; }
.signal.s1 i:nth-child(-n+1), .signal.s2 i:nth-child(-n+2), .signal.s3 i:nth-child(-n+3), .signal.s4 i:nth-child(-n+4) { background: var(--accent); }

.badge { display: inline-flex; min-height: 24px; align-items: center; gap: 5px; padding: 3px 8px; border-radius: 999px; color: var(--muted); background: var(--surface-2); font-size: 11px; font-weight: 700; white-space: nowrap; }
.badge.success { color: var(--accent-dark); background: var(--accent-soft); }
.badge.danger { color: var(--danger); background: var(--danger-soft); }
.badge.warning { color: var(--warning); background: var(--warning-soft); }
.badge.info { color: var(--info); background: #e6f1fb; }
.badge svg { width: 13px; height: 13px; }
.details-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; margin: 0; }
.details-grid div { min-width: 0; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.details-grid dt { margin-bottom: 4px; color: var(--muted); font-size: 12px; }
.details-grid dd { overflow: hidden; margin: 0; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }

.button, .icon-button, .text-button { display: inline-flex; min-height: 36px; align-items: center; justify-content: center; gap: 7px; border: 1px solid transparent; border-radius: 5px; font-weight: 700; }
.button { padding: 7px 12px; }
.button.primary { color: #fff; background: var(--accent); }
.button.primary:hover { background: var(--accent-dark); }
.button.secondary { border-color: var(--line); color: var(--ink); background: var(--surface); }
.button.secondary:hover { background: var(--surface-2); }
.button.danger { border-color: #e8b6b1; color: var(--danger); background: var(--danger-soft); }
.button.danger:hover { border-color: var(--danger); }
.button.wide { width: 100%; }
.icon-button { width: 36px; flex: 0 0 36px; padding: 0; border-color: var(--line); color: var(--ink); background: var(--surface); }
.icon-button:hover { background: var(--surface-2); }
.icon-button.danger { color: var(--danger); }
.text-button { min-height: 30px; padding: 3px 0; color: var(--accent); background: transparent; }
.text-button:hover { color: var(--accent-dark); }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { min-height: 44px; padding: 11px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: 11px; font-weight: 750; text-transform: uppercase; white-space: nowrap; }
td { font-size: 13px; }
tbody tr:hover { background: #f8faf9; }
.actions-cell { width: 1%; text-align: right; white-space: nowrap; }
.actions-cell .icon-button { display: inline-flex; margin-left: 4px; }
.mono { font-family: "Cascadia Mono", Consolas, monospace; }
.empty-state { padding: 26px 12px; color: var(--muted); text-align: center; }

label { display: grid; gap: 6px; color: #4c5953; font-size: 12px; font-weight: 700; }
input, select { width: 100%; min-height: 40px; padding: 8px 10px; border: 1px solid #cbd5d0; border-radius: 5px; outline: none; color: var(--ink); background: var(--surface); }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type="checkbox"] { width: 18px; min-height: 18px; accent-color: var(--accent); }
.form-stack, .form-panel { display: grid; gap: 15px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 6px; }
.form-error { padding: 9px 10px; border-radius: 5px; color: var(--danger); background: var(--danger-soft); font-size: 12px; }
.warning-box { display: flex; align-items: flex-start; gap: 9px; padding: 10px 11px; border: 1px solid #ead49f; border-radius: 5px; color: #6f4f00; background: var(--warning-soft); font-size: 12px; }
.warning-box svg { width: 17px; height: 17px; flex: 0 0 17px; margin-top: 1px; }
.check-row { display: flex; align-items: center; gap: 8px; }
.toggle-row { display: flex; min-height: 58px; grid-template-columns: none; align-items: center; justify-content: space-between; gap: 18px; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.toggle-row > span:first-child { min-width: 0; }
.toggle-row input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.toggle { position: relative; width: 40px; height: 22px; flex: 0 0 40px; border-radius: 12px; background: #bbc5c0; transition: background .15s; }
.toggle::after { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; content: ""; transition: transform .15s; }
.toggle-row input:checked + .toggle { background: var(--accent); }
.toggle-row input:checked + .toggle::after { transform: translateX(18px); }
.toggle-row input:focus-visible + .toggle { box-shadow: 0 0 0 3px var(--accent-soft); }
.repeat-list { display: grid; gap: 7px; }
.repeat-row { display: grid; grid-template-columns: minmax(0, 1fr) 36px; gap: 7px; }
.copy-field { display: grid; grid-template-columns: minmax(0, 1fr) 36px; gap: 7px; }
.search-box { position: relative; display: block; width: min(280px, 100%); }
.search-box svg { position: absolute; top: 10px; left: 10px; color: var(--muted); }
.search-box input { padding-left: 36px; }

.tabbar { display: flex; gap: 4px; margin-bottom: 16px; padding: 4px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.tab { display: inline-flex; min-height: 38px; flex: 1 1 0; align-items: center; justify-content: center; gap: 7px; border: 0; border-radius: 4px; color: var(--muted); background: transparent; font-weight: 700; }
.tab.active { color: var(--ink); background: var(--surface-2); }
.network-view { display: none; }
.network-view.active { display: block; }
.network-grid { align-items: start; }

.stage-list { display: grid; gap: 9px; }
.stage-row { display: grid; grid-template-columns: 34px minmax(180px, 1fr) 110px 36px; align-items: center; gap: 9px; padding: 10px; border: 1px solid var(--line); border-radius: 5px; }
.stage-number { display: grid; width: 28px; height: 28px; place-items: center; border-radius: 50%; color: var(--accent-dark); background: var(--accent-soft); font-weight: 800; }
.member-checks { display: flex; flex-wrap: wrap; gap: 6px; }
.member-check { display: inline-flex; min-height: 30px; grid-template-columns: none; align-items: center; gap: 5px; padding: 4px 7px; border: 1px solid var(--line); border-radius: 4px; color: var(--ink); background: var(--surface); font-size: 12px; }

dialog { width: min(460px, calc(100vw - 28px)); max-height: calc(100vh - 28px); padding: 0; overflow: auto; border: 0; border-radius: 7px; color: var(--ink); background: var(--surface); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(15, 23, 20, .58); }
.dialog-form { display: grid; gap: 15px; padding: 20px; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; }
.dialog-heading p { color: var(--muted); font-size: 12px; }
.countdown { display: grid; width: 80px; height: 80px; margin: 4px auto; place-items: center; border: 5px solid var(--warning-soft); border-radius: 50%; color: var(--warning); font-size: 27px; font-weight: 800; }

.toast-region { position: fixed; right: 18px; bottom: 18px; z-index: 100; display: grid; width: min(360px, calc(100vw - 36px)); gap: 8px; }
.toast { display: flex; align-items: flex-start; gap: 9px; padding: 12px 13px; border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 6px; background: var(--surface); box-shadow: var(--shadow); }
.toast.error { border-left-color: var(--danger); }

.login-page { display: grid; min-height: 100vh; place-items: center; padding: 20px; background: #e9eeeb; }
.login-shell { width: min(390px, 100%); }
.login-panel { display: grid; gap: 18px; padding: 30px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); box-shadow: var(--shadow); }
.login-panel .brand-mark { width: 44px; height: 44px; }
.login-panel h1 { font-size: 28px; }

@media (max-width: 1050px) {
  :root { --sidebar: 218px; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .content-grid.two-columns { grid-template-columns: 1fr; }
  .network-grid .panel + .panel { margin-top: 0; }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { width: min(280px, calc(100vw - 48px)); transform: translateX(-102%); transition: transform .18s ease-out; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .main-area { margin-left: 0; padding: 0 14px 28px; }
  .topbar { min-height: 76px; justify-content: flex-start; }
  .topbar > div:nth-child(2) { min-width: 0; }
  .topbar h1 { overflow: hidden; font-size: 19px; text-overflow: ellipsis; white-space: nowrap; }
  .top-actions { margin-left: auto; }
  .top-actions .compact { display: none; }
  .mobile-only { display: inline-flex !important; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .metric { min-height: 78px; padding: 11px; }
  .metric-icon { display: none; }
  .metric strong { font-size: 16px; }
  .view { padding-top: 15px; }
  .panel { padding: 14px; }
  .panel-heading { align-items: center; }
  .panel-heading .button span { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .stage-row { grid-template-columns: 30px minmax(0, 1fr) 36px; }
  .stage-row .stage-timeout { grid-column: 2 / 3; }
  .search-box { width: 170px; }
  .details-grid { gap: 10px; }
}

@media (max-width: 430px) {
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .metric { min-width: 0; }
  .metric strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .panel-heading { gap: 8px; }
  .panel-heading h2 { font-size: 14px; }
  .tab { font-size: 12px; }
  .tab svg { width: 15px; }
  .details-grid { grid-template-columns: 1fr; }
  .form-actions { flex-wrap: wrap; }
  .form-actions .button { flex: 1 1 auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
