:root {
  --ink: #111611;
  --panel: #171d17;
  --panel-2: #1d241d;
  --line: #313b31;
  --paper: #ecebdc;
  --muted: #91998d;
  --acid: #c8f04b;
  --orange: #ff9c55;
  --red: #ff705e;
  --cyan: #72d4c7;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--paper);
  background: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--ink); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.grain { position: fixed; inset: 0; pointer-events: none; opacity: .24; background-image: repeating-linear-gradient(0deg, transparent, transparent 3px, rgba(255,255,255,.018) 3px, rgba(255,255,255,.018) 4px); z-index: 20; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 76px 1fr; }
.rail { position: sticky; top: 0; height: 100vh; border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; padding: 22px 0; background: #121712; z-index: 10; }
.rail-brand, .brand-mark { width: 42px; height: 42px; display: grid; place-items: center; color: var(--ink); background: var(--acid); font: 800 14px/1 ui-monospace, monospace; text-decoration: none; transform: rotate(-3deg); }
.rail nav { margin-top: 56px; display: grid; gap: 14px; }
.rail-button { width: 42px; height: 42px; border: 1px solid transparent; color: var(--muted); background: transparent; font-size: 20px; }
.rail-button:hover, .rail-button.active { color: var(--paper); border-color: var(--line); background: var(--panel); }
.rail-bottom { margin-top: auto; }
main { width: min(1500px, 100%); margin: 0 auto; padding: 38px clamp(24px, 5vw, 76px) 80px; }
.masthead { display: flex; justify-content: space-between; gap: 24px; align-items: end; margin-bottom: 30px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(38px, 5vw, 66px); line-height: .92; letter-spacing: -.055em; font-weight: 650; }
h2 { margin-bottom: 0; font-size: 25px; letter-spacing: -.025em; }
.eyebrow { margin-bottom: 10px; color: var(--acid); font: 700 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .15em; }
.muted, .form-note { color: var(--muted); }
.header-actions, .form-actions { display: flex; gap: 10px; justify-content: flex-end; }
button.primary, button.ghost { min-height: 42px; border: 1px solid var(--line); padding: 0 17px; color: var(--paper); background: transparent; font-weight: 650; }
button.primary { color: var(--ink); background: var(--acid); border-color: var(--acid); }
button.primary:hover { background: #d8ff5b; }
button.ghost:hover { border-color: var(--muted); background: var(--panel-2); }
.warning { padding: 14px 18px; margin: 0 0 20px; color: #23160d; background: var(--orange); border-left: 5px solid var(--red); }
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line); margin-bottom: 22px; }
.metrics article { padding: 19px 22px; border-right: 1px solid var(--line); background: var(--panel); }
.metrics article:last-child { border-right: 0; }
.metrics span { display: block; margin-bottom: 9px; color: var(--muted); font: 11px ui-monospace, monospace; text-transform: uppercase; letter-spacing: .1em; }
.metrics strong { font: 600 30px/1 ui-monospace, monospace; }
.metrics .signal strong { font-size: 12px; color: var(--orange); }
.metrics .signal strong.connected { color: var(--acid); }
.toolbar { display: flex; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.search { flex: 1; max-width: 480px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); }
.search input { width: 100%; padding: 12px 0; border: 0; outline: 0; color: var(--paper); background: transparent; }
.filters { display: flex; gap: 4px; }
.filter { padding: 9px 12px; border: 0; color: var(--muted); background: transparent; font: 12px ui-monospace, monospace; text-transform: uppercase; }
.filter.active, .filter:hover { color: var(--ink); background: var(--paper); }
.tunnel-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.tunnel-card { position: relative; min-width: 0; border: 1px solid var(--line); background: var(--panel); overflow: hidden; }
.tunnel-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--state-color, var(--muted)); }
.state-healthy { --state-color: var(--acid); }
.state-degraded, .state-reconnecting { --state-color: var(--orange); }
.state-failed { --state-color: var(--red); }
.state-checking, .state-starting { --state-color: var(--cyan); }
.state-stopping, .state-restarting { --state-color: var(--orange); }
.state-stopped { --state-color: var(--muted); }
.state-starting .state::before, .state-checking .state::before, .state-reconnecting .state::before, .state-stopping .state::before, .state-restarting .state::before { animation: state-pulse 1s ease-in-out infinite; }
.tunnel-card.is-transitioning::after { content: ""; position: absolute; inset: 0 100% auto 0; height: 2px; background: linear-gradient(90deg, transparent, var(--state-color), transparent); animation: card-scan 1.15s ease-in-out infinite; }
.card-head { display: flex; justify-content: space-between; gap: 16px; padding: 20px 20px 13px 24px; }
.card-head h2 { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.state { flex: none; display: inline-flex; align-items: center; gap: 7px; color: var(--state-color); font: 700 10px ui-monospace, monospace; text-transform: uppercase; letter-spacing: .1em; }
.state::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 12px currentColor; }
.route { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; margin: 0 20px 17px 24px; padding: 14px; background: #111611; border: 1px solid #283128; }
.endpoint { min-width: 0; }
.endpoint small { display: block; margin-bottom: 5px; color: var(--muted); font: 9px ui-monospace, monospace; letter-spacing: .12em; }
.endpoint strong { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font: 12px ui-monospace, monospace; }
.route-arrow { color: var(--acid); }
.checks { display: flex; gap: 16px; padding: 0 20px 16px 24px; color: var(--muted); font: 11px ui-monospace, monospace; }
.checks .ok { color: var(--cyan); }
.checks .bad { color: var(--red); }
.card-error { margin: 0 20px 16px 24px; min-height: 16px; color: var(--orange); font: 11px/1.4 ui-monospace, monospace; overflow-wrap: anywhere; }
.card-actions { display: flex; flex-wrap: wrap; border-top: 1px solid var(--line); }
.card-actions button { flex: 1; min-width: 67px; padding: 11px 8px; border: 0; border-right: 1px solid var(--line); color: var(--muted); background: transparent; font: 11px ui-monospace, monospace; text-transform: uppercase; }
.card-actions button:last-child { border-right: 0; }
.card-actions button:hover { color: var(--paper); background: var(--panel-2); }
.card-actions button:disabled { cursor: wait; color: #60685e; background: #141914; }
.button-spinner { display: inline-block; width: 9px; height: 9px; margin-right: 7px; border: 1px solid currentColor; border-top-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
.empty { padding: 80px 20px; text-align: center; border: 1px dashed var(--line); }
.empty-glyph { margin-bottom: 15px; color: var(--acid); font-size: 48px; }
.empty p { color: var(--muted); }
dialog { width: min(660px, calc(100% - 28px)); max-height: calc(100vh - 32px); padding: 0; color: var(--paper); background: var(--panel); border: 1px solid var(--line); box-shadow: 0 28px 100px #000b; }
dialog::backdrop { background: #060906d9; backdrop-filter: blur(4px); }
.wide-dialog { width: min(880px, calc(100% - 28px)); }
.dialog-head { display: flex; justify-content: space-between; align-items: start; padding: 24px 26px; border-bottom: 1px solid var(--line); }
.icon-close { width: 36px; height: 36px; border: 1px solid var(--line); color: var(--muted); background: transparent; font-size: 24px; }
.form-grid, #importForm { display: grid; grid-template-columns: 1fr 1fr; gap: 17px; padding: 25px 26px 28px; }
#importForm { grid-template-columns: 1fr; }
label { display: grid; gap: 8px; color: var(--muted); font: 11px ui-monospace, monospace; text-transform: uppercase; letter-spacing: .06em; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 0; padding: 11px 12px; outline: 0; color: var(--paper); background: #101510; text-transform: none; }
input:focus, select:focus, textarea:focus { border-color: var(--acid); box-shadow: 0 0 0 1px var(--acid); }
textarea { resize: vertical; font-family: ui-monospace, monospace; line-height: 1.5; }
.span-2 { grid-column: span 2; }
.check { display: flex; align-items: center; grid-template-columns: auto 1fr; text-transform: none; }
.check input { width: 18px; height: 18px; accent-color: var(--acid); }
.error { min-height: 16px; margin: 0; color: var(--red); font: 12px/1.4 ui-monospace, monospace; }
.profile-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; max-height: 230px; padding: 20px 26px; overflow: auto; border-bottom: 1px solid var(--line); }
.profile-item { padding: 14px; border: 1px solid var(--line); background: #121712; }
.profile-item strong, .profile-item span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-item span { margin: 6px 0 12px; color: var(--muted); font: 11px ui-monospace, monospace; }
.profile-item div { display: flex; gap: 8px; }
.profile-item button { border: 0; padding: 0; color: var(--acid); background: none; font: 11px ui-monospace, monospace; text-transform: uppercase; }
.profile-item button.danger { color: var(--red); }
.logs-dialog { width: min(900px, calc(100% - 28px)); }
.logs-output { min-height: 330px; max-height: 65vh; margin: 0; padding: 22px; overflow: auto; color: #cdd9c9; background: #090d09; font: 12px/1.65 ui-monospace, monospace; white-space: pre-wrap; }
.toast { position: fixed; right: 24px; bottom: 24px; max-width: 360px; padding: 13px 18px; color: var(--ink); background: var(--acid); transform: translateY(100px); opacity: 0; transition: .2s ease; z-index: 30; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error-toast { background: var(--red); }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(430px, 100%); padding: 38px; border: 1px solid var(--line); background: var(--panel); }
.login-card .brand-mark { margin-bottom: 38px; }
.login-card h1 { margin-bottom: 17px; font-size: 46px; }
.login-card label { margin: 28px 0 12px; }
.login-card .primary { width: 100%; margin-top: 10px; }
@keyframes state-pulse { 50% { opacity: .35; transform: scale(.72); box-shadow: 0 0 2px currentColor; } }
@keyframes card-scan { 0% { left: 0; right: 100%; } 50% { left: 0; right: 0; } 100% { left: 100%; right: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .state::before, .tunnel-card.is-transitioning::after, .button-spinner { animation: none !important; }
}
@media (max-width: 900px) {
  .tunnel-grid { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .metrics article:nth-child(2) { border-right: 0; }
  .metrics article:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
}
@media (max-width: 650px) {
  .app-shell { display: block; }
  .rail { position: fixed; inset: auto 0 0; width: 100%; height: 58px; flex-direction: row; justify-content: space-around; padding: 7px 14px; border: 0; border-top: 1px solid var(--line); }
  .rail-brand { display: none; }
  .rail nav { display: flex; margin: 0; }
  .rail-bottom { margin: 0; }
  main { padding: 28px 16px 90px; }
  .masthead { display: block; }
  .header-actions { margin-top: 24px; justify-content: stretch; }
  .header-actions button { flex: 1; }
  .toolbar { display: block; }
  .search { max-width: none; margin-bottom: 12px; }
  .filters { overflow-x: auto; }
  .metrics article { padding: 15px; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .profile-list { grid-template-columns: 1fr; }
  .route { grid-template-columns: 1fr; }
  .route-arrow { transform: rotate(90deg); }
}
