:root {
  --bg: #f3f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #edf3f7;
  --line: #dbe4ed;
  --line-strong: #c8d5e1;
  --text: #172230;
  --muted: #68788c;
  --cyan: #0c8b7a;
  --cyan-dark: #076d61;
  --cyan-soft: #e7f7f3;
  --amber: #a96713;
  --amber-soft: #fff7e6;
  --red: #bf3d55;
  --red-soft: #fff0f3;
  --blue: #2d67d8;
  --blue-soft: #edf4ff;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(23, 34, 48, .05), 0 8px 24px rgba(23, 34, 48, .045);
  --shadow-lg: 0 26px 70px rgba(42, 59, 78, .16);
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 92% -5%, #dff5ef 0, transparent 28rem), linear-gradient(180deg, #f8fafc 0, var(--bg) 28rem); }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 3px solid rgba(45, 103, 216, .22); outline-offset: 2px; }
code, pre, .code { font-family: var(--mono); }
[hidden] { display: none !important; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(135deg, rgba(231,247,243,.75), transparent 48%); }
.login-card { width: min(440px, 100%); padding: 40px; background: rgba(255,255,255,.96); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow-lg); }
.login-security { display: flex; align-items: center; gap: 9px; margin-top: 22px; padding: 11px 12px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; font-size: 12px; }
.brand-mark { width: 54px; height: 54px; border-radius: 15px; display: grid; place-items: center; font: 700 25px var(--mono); color: #fff; background: linear-gradient(145deg, #11a38f, var(--cyan-dark)); box-shadow: 0 12px 30px rgba(12,139,122,.2); margin-bottom: 24px; }
.brand-mark.small { width: 38px; height: 38px; border-radius: 11px; font-size: 18px; margin: 0; }
h1 { margin: 5px 0 12px; font-size: 34px; letter-spacing: -.04em; }
h2 { margin: 2px 0 0; font-size: 28px; letter-spacing: -.035em; }
h3 { margin: 2px 0 0; font-size: 17px; }
p { line-height: 1.55; }
.muted { color: var(--muted); }
.eyebrow { margin: 0; color: var(--cyan-dark); text-transform: uppercase; letter-spacing: .14em; font: 700 10px var(--mono); }
.stack { display: grid; gap: 16px; margin-top: 26px; }
label { display: grid; gap: 7px; color: #47576a; font-size: 13px; font-weight: 600; }
input, select, textarea { width: 100%; color: var(--text); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 10px; padding: 11px 12px; outline: none; transition: border-color .15s ease, box-shadow .15s ease, background .15s ease; }
input:hover, select:hover, textarea:hover { border-color: #aebdcc; }
input:focus, select:focus, textarea:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(12,139,122,.1); }
textarea { resize: vertical; line-height: 1.5; }

.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line-strong); background: var(--surface); color: #314154; border-radius: 10px; padding: 10px 14px; font-weight: 700; text-decoration: none; white-space: nowrap; box-shadow: 0 1px 1px rgba(23,34,48,.03); transition: .15s ease; }
.button:hover { border-color: #9fb0c1; background: var(--surface-2); transform: translateY(-1px); }
.button.primary { border-color: var(--cyan); background: var(--cyan); color: #fff; box-shadow: 0 7px 18px rgba(12,139,122,.16); }
.button.primary:hover { background: var(--cyan-dark); border-color: var(--cyan-dark); }
.button.danger { border-color: #efbcc5; color: var(--red); background: var(--red-soft); }
.text-button, .icon-button { border: 0; background: transparent; color: var(--muted); }
.text-button:hover { color: var(--text); }
.icon-button { font-size: 21px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.icon-button:hover { color: var(--cyan-dark); border-color: #a9cfc8; background: var(--cyan-soft); }
.form-error { color: var(--red); margin: 0; font-size: 13px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 242px 1fr; }
.sidebar { position: sticky; top: 0; height: 100vh; border-right: 1px solid var(--line); background: rgba(255,255,255,.96); padding: 24px 16px 18px; display: flex; flex-direction: column; z-index: 5; box-shadow: 8px 0 28px rgba(23,34,48,.025); }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 10px 24px; }
.brand strong, .brand span { display: block; }
.brand strong { color: var(--text); }
.brand span { color: var(--muted); font: 10px var(--mono); margin-top: 3px; text-transform: uppercase; letter-spacing: .12em; }
nav { display: grid; gap: 4px; }
nav button { position: relative; text-align: left; border: 0; border-radius: 10px; padding: 11px 12px; color: #596a7e; background: transparent; font-weight: 650; transition: .15s ease; }
nav button span { font: 10px var(--mono); color: #93a2b2; margin-right: 11px; }
nav button:hover { background: var(--surface-2); color: var(--text); }
nav button.active { background: var(--cyan-soft); color: var(--cyan-dark); box-shadow: inset 3px 0 0 var(--cyan); }
nav button.active span { color: var(--cyan); }
.sidebar-footer { margin-top: auto; display: flex; align-items: center; gap: 8px; padding: 14px 8px 0; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.sidebar-footer .text-button { margin-left: auto; }
.live-dot { width: 7px; height: 7px; background: var(--cyan); border-radius: 50%; box-shadow: 0 0 0 4px rgba(12,139,122,.1); }

main { min-width: 0; padding: 0 34px 60px; }
.topbar { position: sticky; top: 0; z-index: 4; min-height: 104px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); margin-bottom: 28px; background: rgba(248,250,252,.9); backdrop-filter: blur(14px); }
.top-actions { display: flex; align-items: center; gap: 14px; color: var(--muted); font: 12px var(--mono); }
.view { display: none; animation: fade .18s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: .35; transform: translateY(3px); } }

.metric-grid { display: grid; grid-template-columns: repeat(6, minmax(120px, 1fr)); gap: 14px; margin-bottom: 20px; }
.metric { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-height: 105px; box-shadow: var(--shadow-sm); }
.metric .value { display: block; color: var(--text); font-size: 28px; font-weight: 750; letter-spacing: -.04em; margin-top: 13px; }
.metric .label { color: var(--muted); font-size: 12px; }
.grid { display: grid; gap: 18px; margin-bottom: 18px; }
.grid.two-wide { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.grid.console-layout { grid-template-columns: minmax(430px, .9fr) minmax(380px, 1.1fr); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; overflow: hidden; box-shadow: var(--shadow-sm); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 17px; }
.section-actions { display: flex; justify-content: space-between; align-items: center; gap: 24px; margin: -8px 0 22px; padding: 16px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.section-actions p { color: var(--muted); max-width: 680px; margin: 0; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.station-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 19px; box-shadow: var(--shadow-sm); }
.station-card.online { border-color: #8dd0c4; box-shadow: 0 0 0 3px rgba(12,139,122,.07), var(--shadow-sm); }
.station-title { display: flex; justify-content: space-between; gap: 12px; align-items: start; }
.station-title h3 { font-size: 19px; }
.station-id { color: var(--muted); font: 11px var(--mono); margin-top: 5px; }
.badge { border: 1px solid var(--line-strong); border-radius: 999px; padding: 4px 8px; color: var(--muted); background: var(--surface-2); font: 700 10px var(--mono); text-transform: uppercase; }
.badge.ok { border-color: #9ad6ca; color: var(--cyan-dark); background: var(--cyan-soft); }
.badge.warn { border-color: #eed29b; color: var(--amber); background: var(--amber-soft); }
.badge.error { border-color: #efbcc5; color: var(--red); background: var(--red-soft); }
.meta-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 19px 0; }
.meta-grid div { border-top: 1px solid var(--line); padding-top: 9px; }
.meta-grid span { display: block; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.meta-grid strong { display: block; font: 12px var(--mono); margin-top: 5px; overflow-wrap: anywhere; }
.connector-row, .list-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 12px; }
.connector-row:first-child, .list-item:first-child { border-top: 0; }
.connector-row .badge { margin-left: auto; }
.list { min-height: 80px; }
.list.tall { max-height: 580px; overflow: auto; }
.list-item { align-items: flex-start; }
.list-main { flex: 1; min-width: 0; }
.list-main strong { display: block; }
.list-main small { color: var(--muted); display: block; margin-top: 4px; font-family: var(--mono); overflow-wrap: anywhere; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.button-row { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.validation-hint { color: #4e6480; background: var(--blue-soft); border-left: 3px solid var(--blue); border-radius: 6px; padding: 10px 12px; font: 11px/1.5 var(--mono); }
.validation-hint.error { border-color: var(--red); color: var(--red); background: var(--red-soft); }
.security-notice { margin: -8px 0 18px; padding: 14px 16px; color: #3d536d; background: var(--blue-soft); border: 1px solid #cbdcf9; border-left: 4px solid var(--blue); border-radius: 10px; font-size: 13px; line-height: 1.55; }
.security-notice strong { color: #214f9f; }

.table-panel { padding: 0; }
.table-panel .panel-head { padding: 19px 20px 0; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
thead { background: var(--surface-2); }
th { color: var(--muted); font: 700 10px var(--mono); text-transform: uppercase; letter-spacing: .08em; text-align: left; padding: 11px 14px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
td { padding: 12px 14px; border-bottom: 1px solid #edf1f5; vertical-align: top; }
tbody tr:hover { background: #fbfcfd; }
.inline-select { width: auto; min-width: 180px; }

.compact-log, .protocol-log { font-family: var(--mono); font-size: 11px; }
.compact-row { display: grid; grid-template-columns: 62px 72px 1fr; gap: 8px; padding: 9px 0; border-top: 1px solid var(--line); }
.compact-row:first-child { border-top: 0; }
.compact-row .dir.in { color: var(--cyan-dark); }
.compact-row .dir.out { color: var(--blue); }
.compact-row span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filter-row { display: grid; grid-template-columns: 180px 150px 180px 1fr auto; gap: 9px; margin-bottom: 15px; }
.protocol-log { border: 1px solid var(--line); border-radius: 10px; max-height: calc(100vh - 260px); min-height: 420px; overflow: auto; background: var(--surface-2); }
.wire-log-output { border: 1px solid #cad6e2; border-radius: 10px; min-height: 260px; max-height: 50vh; margin: 0 0 15px; padding: 14px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; color: #26384d; background: #f7f9fc; font: 11px/1.55 var(--mono); box-shadow: inset 0 1px 4px rgba(23,34,48,.04); }
.log-entry { border-bottom: 1px solid var(--line); padding: 12px 14px; }
.log-entry summary { display: grid; grid-template-columns: 70px 78px 150px 1fr 85px; gap: 12px; align-items: center; cursor: pointer; list-style: none; }
.log-entry summary::-webkit-details-marker { display: none; }
.log-entry pre { margin: 12px 0 0; white-space: pre-wrap; word-break: break-word; color: #31455c; background: #f1f5f9; border: 1px solid var(--line); border-radius: 8px; padding: 12px; max-height: 360px; overflow: auto; }
.endpoint-box { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 10px; }
.endpoint-box span { color: var(--muted); display: block; font-size: 11px; margin-bottom: 8px; }
.endpoint-box code { color: var(--cyan-dark); overflow-wrap: anywhere; font-weight: 700; }

dialog { color: var(--text); background: transparent; border: 0; padding: 0; width: min(540px, calc(100% - 30px)); }
dialog::backdrop { background: rgba(31,42,55,.42); backdrop-filter: blur(5px); }
.dialog-card { display: grid; gap: 15px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 18px; padding: 24px; box-shadow: var(--shadow-lg); }
.credential-output { white-space: pre-wrap; overflow-wrap: anywhere; background: #f3f8f7; color: var(--cyan-dark); padding: 15px; border-radius: 10px; border: 1px solid #c8e6e0; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 100; min-width: 260px; max-width: 440px; padding: 13px 16px; color: #fff; background: #26384d; border: 1px solid #334a62; border-radius: 11px; box-shadow: 0 16px 55px rgba(23,34,48,.25); transform: translateY(30px); opacity: 0; pointer-events: none; transition: .2s ease; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { background: #9d3046; border-color: var(--red); }
.empty { color: var(--muted); padding: 24px 4px; text-align: center; }

@media (max-width: 1100px) {
  .metric-grid { grid-template-columns: repeat(3, 1fr); }
  .grid.console-layout { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
  .app-shell { display: block; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 14px; }
  .brand { padding-bottom: 12px; }
  nav { display: flex; overflow-x: auto; padding-bottom: 3px; }
  nav button { white-space: nowrap; }
  .sidebar-footer { display: none; }
  main { padding: 0 16px 40px; }
  .topbar { min-height: 90px; }
  .grid.two-wide { grid-template-columns: 1fr; }
  .filter-row { grid-template-columns: 1fr 1fr; }
  .filter-row input { grid-column: 1 / -1; }
  .log-entry summary { grid-template-columns: 60px 70px 1fr; }
  .log-entry summary span:nth-child(4), .log-entry summary span:nth-child(5) { display: none; }
}
@media (max-width: 520px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .section-actions { align-items: stretch; flex-direction: column; }
  .login-card { padding: 28px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
