:root {
  --bg: #f4f6f9; --panel: #ffffff; --side: #111827; --side-2: #1f2937; --side-text: #d1d5db;
  --text: #111827; --muted: #6b7280; --line: #e5e7eb; --accent: #da291c; --accent-2: #b91c1c;
  --good: #16a34a; --warn: #d97706; --bad: #dc2626; --info: #2563eb;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pad { padding: 12px 14px; }
.pad-top { padding-top: 26px; }
.hidden { display: none !important; }

/* top bar */
.topbar { height: 52px; display: flex; align-items: center; gap: 24px; padding: 0 16px;
  background: var(--side); color: #fff; border-bottom: 1px solid #000; }
.brand { color: #fff; font-weight: 700; font-size: 16px; letter-spacing: .3px; }
.brand:hover { text-decoration: none; }
.logo { color: var(--accent); }
.topnav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.topnav a { color: var(--side-text); padding: 6px 10px; border-radius: 6px; white-space: nowrap; }
.topnav a:hover, .topnav a.on { background: var(--side-2); color: #fff; text-decoration: none; }
.who { display: flex; align-items: center; gap: 10px; color: var(--side-text); white-space: nowrap; }
.who form { margin: 0; }
.badge { font-style: normal; font-size: 11px; background: var(--accent); color: #fff; padding: 1px 6px; border-radius: 10px; }

/* layout */
.layout { display: flex; height: calc(100% - 52px); }
.sidebar { width: 290px; flex-shrink: 0; background: var(--side-2); color: var(--side-text);
  display: flex; flex-direction: column; border-right: 1px solid #000; }
.sidebar input[type=search] { margin: 12px; padding: 8px 10px; border-radius: 6px; border: 1px solid #374151;
  background: #111827; color: #fff; }
.fw-list { overflow-y: auto; flex: 1; padding-bottom: 20px; }
.cust summary { cursor: pointer; padding: 8px 14px; font-weight: 600; color: #fff; list-style: none;
  display: flex; justify-content: space-between; align-items: center; }
.cust summary::-webkit-details-marker { display: none; }
.cust summary::before { content: "▸"; margin-right: 6px; color: var(--muted); }
.cust[open] summary::before { content: "▾"; }
.cust summary { justify-content: flex-start; }
.cust summary .count { margin-left: auto; }
.count { font-size: 11px; background: #374151; color: var(--side-text); padding: 0 7px; border-radius: 10px; font-weight: 500; }
.count.big { font-size: 13px; background: var(--side-2); color: #fff; vertical-align: middle; }
.fw-item { display: grid; grid-template-columns: 14px 1fr; grid-template-rows: auto auto; column-gap: 8px;
  padding: 6px 14px 6px 28px; color: var(--side-text); border-left: 3px solid transparent; }
.fw-item:hover { background: #374151; text-decoration: none; }
.fw-item.active { background: #111827; border-left-color: var(--accent); color: #fff; }
.fw-item .dot { grid-row: 1 / 3; align-self: center; }
.fw-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fw-host { font-family: var(--mono); font-size: 11px; color: #9ca3af; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #6b7280; display: inline-block; }
.dot.up { background: var(--good); } .dot.down { background: var(--bad); } .dot.warn { background: var(--warn); }

.content { flex: 1; overflow: auto; padding: 20px 24px; display: flex; flex-direction: column; min-width: 0; }

/* firewall view */
.fw-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.fw-head h2 { margin: 2px 0 0; }
.fw-head .actions { display: flex; gap: 8px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 16px 0 0; }
.tab { border: 0; background: none; padding: 9px 16px; cursor: pointer; font: inherit; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.pane { padding-top: 16px; flex: 1; display: flex; flex-direction: column; min-height: 0; }
#pane-gui { padding-top: 0; }
#gui-diag .flash { margin-top: 14px; }
#gui-diag ol { margin: 8px 0 0; padding-left: 20px; }
#gui-diag li { margin-bottom: 6px; }
#gui-diag code { background: rgba(0,0,0,.06); padding: 1px 4px; border-radius: 3px; }
.gui-bar { padding: 6px 2px; }
#gui-frame { flex: 1; width: 100%; min-height: 600px; border: 1px solid var(--line); border-top: 0; background: #fff; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.kv div { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.kv span { display: block; font-size: 12px; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-top: 12px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 22px; font-weight: 600; }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.bar span { display: block; height: 100%; }
.bar .good { background: var(--good); } .bar .warn { background: var(--warn); } .bar .bad { background: var(--bad); }
h3 { margin: 22px 0 8px; font-size: 15px; }
.notes { white-space: pre-wrap; background: var(--panel); border: 1px solid var(--line); padding: 14px; border-radius: 8px; font: inherit; }
.empty { margin: auto; text-align: center; }

/* license badges */
.lic { white-space: nowrap; }
.lic-badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 10px;
  background: #e5e7eb; color: #374151; }
.lic-badge.good { background: #dcfce7; color: #166534; }
.lic-badge.warn { background: #fef3c7; color: #92400e; }
.lic-badge.bad  { background: #fee2e2; color: #991b1b; }
.lic-refresh { margin-left: 4px; color: var(--muted); text-decoration: none; font-size: 13px; }
.lic-refresh:hover { color: var(--info); text-decoration: none; }

/* tables */
.grid { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.grid th, .grid td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.grid th { background: #f9fafb; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
.grid tr:last-child td { border-bottom: 0; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; white-space: nowrap; }
.row-actions form { margin: 0; }
.ua { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h2 { margin: 0; }

/* buttons & forms */
.btn { display: inline-block; border: 1px solid var(--line); background: var(--panel); color: var(--text);
  padding: 7px 14px; border-radius: 6px; cursor: pointer; font: inherit; font-weight: 500; }
.btn:hover { text-decoration: none; border-color: #9ca3af; }
.btn.small { padding: 4px 10px; font-size: 12.5px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.ghost { background: transparent; }
.topbar .btn.ghost { color: var(--side-text); border-color: #374151; }
.btn.wide { width: 100%; padding: 10px; }
.form { max-width: 760px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 20px; }
.form label { display: block; margin-bottom: 14px; font-weight: 500; }
.form input:not([type=checkbox]), .form select, .form textarea, .login-card input {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 6px; font: inherit; }
.form label.check { font-weight: 400; display: flex; gap: 8px; align-items: center; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-actions { display: flex; gap: 8px; margin-top: 8px; }

.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; border: 1px solid; }
.flash.ok { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.flash.error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.flash.info { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }

/* login */
.login-page { display: flex; align-items: center; justify-content: center; background: var(--side); min-height: 100%; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); padding: 28px; border-radius: 10px; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card label { display: block; margin: 14px 0; font-weight: 500; }

@media (max-width: 800px) {
  .layout { flex-direction: column; height: auto; }
  .sidebar { width: 100%; max-height: 40vh; }
  .row2 { grid-template-columns: 1fr; }
  .who span { display: none; }
  .content { padding: 16px; }
}

/* branding, login options, account pages */
.brand { display: inline-flex; align-items: center; gap: 6px; }
.brand-logo { height: 24px; width: auto; max-width: 140px; object-fit: contain; }
.brand-logo.big { height: 32px; max-width: 200px; vertical-align: middle; }
.login-card h1 { display: flex; align-items: center; gap: 8px; }
.login-card form { margin: 0; }
.btn.ms { display: flex; align-items: center; justify-content: center; gap: 10px; background: #fff; border-color: #8c8c8c;
  color: #1f1f1f; font-weight: 600; padding: 10px; margin-top: 14px; }
.btn.ms:hover { background: #f3f3f3; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 14px 0 0; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.center { text-align: center; }
.code-input { font: 600 22px/1 var(--mono) !important; letter-spacing: 6px; text-align: center; }
.code-input.short { width: 160px !important; display: inline-block !important; font-size: 16px !important; letter-spacing: 3px; }
.inline-form { display: flex; gap: 8px; align-items: center; margin: 0; }
.form + .form { margin-top: 16px; }
.form h3.first { margin-top: 0; }
.mfa-setup ol { padding-left: 20px; } .mfa-setup li { margin-bottom: 14px; }
.qr { margin: 10px 0; } .qr img { border: 1px solid var(--line); border-radius: 8px; image-rendering: pixelated; }
.secret { font: 15px var(--mono); letter-spacing: 1px; background: #f3f4f6; padding: 4px 8px; border-radius: 4px; user-select: all; }
.color-row { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.color-row input[type=color] { width: 44px; height: 36px; padding: 2px; border: 1px solid #d1d5db; border-radius: 6px; }
.color-row input[name=brand_color] { margin-top: 0 !important; font-family: var(--mono); }
.logo-preview { display: flex; align-items: center; gap: 10px; }
.logo-preview img { height: 32px; background: #111827; padding: 4px; border-radius: 4px; }
.check.inline { display: inline-flex !important; margin: 0 0 0 12px !important; }
.indent { margin: -8px 0 14px 24px; }
.who a.me { color: var(--side-text); }
.who a.me:hover { color: #fff; text-decoration: none; }
.fw-alt { color: #fbbf24; }
.indent0 { margin: -8px 0 14px; }
