:root {
  --bg: #0f1419;
  --bg-elev: #171d25;
  --bg-soft: #1e2630;
  --line: #2a3441;
  --text: #e8eef5;
  --muted: #8b9aab;
  --accent: #3db89a;
  --accent-dim: #2a8f78;
  --danger: #e06c75;
  --warn: #d4a24c;
  --ok: #6bcf8e;
  --radius: 10px;
  --font: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 10% -10%, #1a2a28 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #1a2230 0%, transparent 50%),
    var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.brand {
  margin: 0;
  font-family: var(--mono);
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.78rem;
  color: var(--accent);
}
.error { color: var(--danger); font-size: 0.9rem; }

button, input, select {
  font: inherit;
  color: inherit;
}
button {
  border: 1px solid var(--line);
  background: var(--bg-soft);
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  cursor: pointer;
}
button:hover { border-color: #3d4b5c; }
button.primary {
  background: var(--accent);
  border-color: var(--accent-dim);
  color: #06221b;
  font-weight: 600;
}
button.primary:hover { filter: brightness(1.05); }
button.ghost { background: transparent; }
button.danger { color: var(--danger); border-color: #5a3036; }
button.tab.active {
  border-color: var(--accent-dim);
  color: var(--accent);
}

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--muted);
}
input, select, textarea {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  color: var(--text);
}
input:focus, select:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
  border-color: var(--accent-dim);
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.login-card {
  width: min(400px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.5rem;
  display: grid;
  gap: 0.85rem;
}
.login-card h1 { margin: 0.2rem 0 0; font-size: 1.45rem; }

.app-view { min-height: 100vh; }
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar nav { display: flex; gap: 0.4rem; flex-wrap: wrap; }
main { padding: 1.25rem; max-width: 1100px; margin: 0 auto; }
.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: end;
  margin-bottom: 1rem;
}
.panel-head h2 { margin: 0 0 0.25rem; font-size: 1.25rem; }

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elev);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
th, td {
  text-align: left;
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--bg-soft);
}
tr:last-child td { border-bottom: 0; }
.mono { font-family: var(--mono); font-size: 0.85rem; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font-size: 0.75rem;
  border: 1px solid var(--line);
}
.badge.ok { color: var(--ok); border-color: #2f5a40; }
.badge.warn { color: var(--warn); border-color: #5a4a28; }
.badge.bad { color: var(--danger); border-color: #5a3036; }
.row-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }

dialog {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg-elev);
  color: var(--text);
  padding: 0;
  max-width: calc(100vw - 2rem);
}
dialog::backdrop { background: rgb(0 0 0 / 55%); }
.dlg {
  padding: 1.2rem;
  display: grid;
  gap: 0.75rem;
  width: min(460px, 92vw);
}
.dlg.wide { width: min(720px, 94vw); }
.dlg h3 { margin: 0; }
.dlg-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}
.dlg-actions {
  display: flex;
  justify-content: end;
  gap: 0.5rem;
  margin-top: 0.4rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin: 0.5rem 0 1rem;
}
.detail-grid div {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
}
.detail-grid dt {
  margin: 0;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.detail-grid dd {
  margin: 0.2rem 0 0;
  font-family: var(--mono);
  font-size: 0.88rem;
  word-break: break-all;
}
pre.script {
  margin: 0;
  padding: 0.9rem;
  background: #0b1015;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.78rem;
  max-height: 320px;
  white-space: pre-wrap;
}
.winbox-card {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
  display: grid;
  gap: 0.65rem;
}
.winbox-addr {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--accent);
}
.steps {
  margin: 0.25rem 0 0.5rem;
  padding-left: 1.2rem;
  color: var(--muted);
  font-size: 0.9rem;
}
.steps li { margin: 0.25rem 0; }
.script-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}
.script-head h4 { margin: 0; }
.more-detail {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
  background: var(--bg);
}
.more-detail summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.9rem;
}
fieldset.port-box {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.75rem;
  display: grid;
  gap: 0.55rem;
  margin: 0;
}
fieldset.port-box legend {
  padding: 0 0.35rem;
  color: var(--muted);
  font-size: 0.85rem;
}
.check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
}
.check input { width: auto; accent-color: var(--accent); }
.custom-ports { display: grid; gap: 0.45rem; }
.port-row {
  display: grid;
  grid-template-columns: 1fr 1.4fr auto;
  gap: 0.4rem;
  align-items: center;
}
.port-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chip {
  display: inline-flex;
  flex-direction: column;
  gap: 0.05rem;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 8px;
  padding: 0.35rem 0.5rem;
  font-size: 0.78rem;
}
.chip b { font-weight: 600; color: var(--text); }
.access-list { display: grid; gap: 0.45rem; margin: 0.35rem 0 0; }
.access-row {
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
}
.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #06221b;
  font-weight: 600;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  z-index: 40;
  box-shadow: 0 8px 24px rgb(0 0 0 / 35%);
}
.settings-grid { display: grid; gap: 1rem; }
.settings-grid textarea {
  width: 100%;
  min-height: 4.5rem;
  resize: vertical;
}
.empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 720px) {
  .detail-grid { grid-template-columns: 1fr; }
  .panel-head { flex-direction: column; align-items: stretch; }
  .topbar { flex-direction: column; align-items: start; }
}
