:root {
  --bg: #0b101b;
  --bg-card: rgba(18, 25, 40, 0.82);
  --bg-elev: rgba(25, 35, 56, 0.9);
  --border: rgba(148, 163, 184, 0.16);
  --border-strong: rgba(56, 189, 248, 0.42);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #818cf8;
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --radius: 14px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", "Fira Code", Consolas, monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  overflow-x: hidden;
  position: relative;
}

/* Subtle engineering grid background */
.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(56, 189, 248, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(56, 189, 248, 0.04) 1px, transparent 1px);
  background-size: 36px 36px;
  pointer-events: none;
  z-index: -2;
}

.bg-glow {
  position: fixed;
  width: 520px;
  height: 520px;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.18;
  pointer-events: none;
  z-index: -1;
}

.glow-1 { top: -160px; left: -120px; background: #0ea5e9; }
.glow-2 { bottom: -180px; right: -120px; background: #6366f1; }

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header */
.topbar {
  border-bottom: 1px solid var(--border);
  background: rgba(11, 16, 27, 0.78);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 30;
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 14px;
  padding-bottom: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, #0284c7, #6366f1);
  display: grid;
  place-items: center;
  font-size: 20px;
  box-shadow: 0 0 24px rgba(56, 189, 248, 0.28);
}

.brand-title {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.brand-title .accent { color: var(--accent); }
.brand-sub { font-size: 0.78rem; color: var(--muted); }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pill-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: 999px;
  font-size: 0.84rem;
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--border);
  background: rgba(30, 41, 59, 0.55);
  transition: all 0.2s ease;
}

.pill-link:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.pill-link.primary {
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.22), rgba(99, 102, 241, 0.24));
  border-color: rgba(56, 189, 248, 0.45);
}

/* Tabs */
.tabbar-wrap {
  padding: 18px 0 6px;
}

.tabbar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 6px;
  scrollbar-width: thin;
}

.tab-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 0.92rem;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  color: var(--text);
  border-color: rgba(148, 163, 184, 0.35);
}

.tab-btn.active {
  color: #fff;
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.25), rgba(99, 102, 241, 0.28));
  border-color: var(--accent);
  box-shadow: 0 4px 18px rgba(14, 165, 233, 0.18);
}

/* Panels & Cards */
.main-content {
  padding-top: 12px;
  padding-bottom: 56px;
}

.panel { display: none; animation: fadeIn 0.22s ease; }
.panel.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  backdrop-filter: blur(10px);
  box-shadow: 0 12px 32px rgba(2, 6, 23, 0.36);
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.card-head h2 {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.muted { color: var(--muted); font-size: 0.88rem; }

.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.psu-layout {
  grid-template-columns: 1.2fr 0.9fr;
}

/* Form Elements */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 18px;
}

.subnet-inputs {
  grid-template-columns: 1.3fr 1fr 1fr;
}

.cmd-inputs {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 0.84rem;
  color: var(--muted);
  font-weight: 500;
}

.field label strong { color: var(--accent); font-family: var(--font-mono); }

input[type="text"],
input[type="number"],
input[type="search"],
select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.85);
  color: var(--text);
  font-size: 0.92rem;
  font-family: var(--font-mono);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

select { font-family: var(--font-sans); }

input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
  margin-top: 8px;
}

/* Chips & Buttons */
.quick-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(30, 41, 59, 0.65);
  color: var(--muted);
  font-size: 0.8rem;
  padding: 5px 11px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.16s ease;
}

.chip:hover, .chip.active {
  color: #fff;
  border-color: var(--accent);
  background: rgba(14, 165, 233, 0.2);
}

.btn-ghost {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: rgba(14, 165, 233, 0.12);
  color: var(--accent);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
}

.btn-ghost:hover {
  background: rgba(14, 165, 233, 0.25);
  color: #fff;
}

/* Stat Cards */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.stat-grid.compact {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stat-item {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  position: relative;
  cursor: pointer;
  transition: border-color 0.16s ease;
}

.stat-item:hover { border-color: var(--border-strong); }

.stat-label {
  font-size: 0.76rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 0.98rem;
  font-weight: 700;
  color: #f8fafc;
  word-break: break-all;
}

.stat-value.accent { color: var(--accent); }
.stat-value.green { color: var(--green); }
.stat-value.amber { color: var(--amber); }

/* Binary Visualizer */
.binary-box {
  margin-top: 18px;
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}

.binary-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 12px;
}

.legend { display: flex; gap: 14px; }
.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 5px;
}
.dot.net { background: var(--accent); }
.dot.host { background: var(--green); }

.binary-bits {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.octet {
  display: flex;
  gap: 3px;
  justify-content: space-between;
  background: rgba(30, 41, 59, 0.5);
  padding: 6px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.bit {
  flex: 1;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 700;
  padding: 4px 0;
  border-radius: 5px;
}

.bit.net {
  background: rgba(56, 189, 248, 0.18);
  color: #7dd3fc;
}

.bit.host {
  background: rgba(52, 211, 153, 0.18);
  color: #6ee7b7;
}

/* Tables */
.split-wrap { margin-top: 22px; }
.sub-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.sub-head h3 { font-size: 0.98rem; }

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

.data-table th,
.data-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  background: rgba(15, 23, 42, 0.9);
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.data-table tbody tr:hover {
  background: rgba(56, 189, 248, 0.06);
}

.mono { font-family: var(--font-mono); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
}

.badge-tcp { background: rgba(56, 189, 248, 0.16); color: #7dd3fc; }
.badge-udp { background: rgba(129, 140, 248, 0.2); color: #a5b4fc; }
.badge-both { background: rgba(52, 211, 153, 0.18); color: #6ee7b7; }
.badge-danger { background: rgba(248, 113, 113, 0.2); color: #fca5a5; }

/* Ports Toolbar */
.port-toolbar {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* PSU Panel */
.psu-hero {
  text-align: center;
  padding: 22px 14px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.14), rgba(99, 102, 241, 0.16));
  border: 1px solid rgba(56, 189, 248, 0.35);
}

.psu-hero-label { font-size: 0.82rem; color: var(--muted); }
.psu-hero-watt {
  font-family: var(--font-mono);
  font-size: 2.8rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1.15;
  margin: 6px 0;
}
.psu-hero-badge {
  display: inline-block;
  font-size: 0.78rem;
  color: #e0f2fe;
  background: rgba(15, 23, 42, 0.55);
  padding: 4px 10px;
  border-radius: 999px;
}

.meter-wrap { margin-top: 18px; }
.meter-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.84rem;
  margin-bottom: 6px;
}
.meter-track {
  height: 10px;
  background: rgba(15, 23, 42, 0.9);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.meter-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--accent), var(--amber));
  border-radius: 999px;
  transition: width 0.25s ease;
}

.psu-breakdown {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.breakdown-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  padding: 7px 10px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.6);
}

/* Commands List */
.cmd-list {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.cmd-card {
  background: rgba(15, 23, 42, 0.82);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 13px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cmd-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.cmd-title { font-size: 0.88rem; font-weight: 600; color: #f1f5f9; }
.cmd-code {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: #7dd3fc;
  background: rgba(2, 6, 23, 0.72);
  padding: 9px 10px;
  border-radius: 7px;
  overflow-x: auto;
  white-space: nowrap;
}

/* Alerts & Toast */
.alert-error {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 9px;
  background: rgba(248, 113, 113, 0.14);
  border: 1px solid rgba(248, 113, 113, 0.45);
  color: #fecaca;
  font-size: 0.86rem;
}

.hidden { display: none !important; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #0f172a;
  color: #f8fafc;
  border: 1px solid var(--accent);
  padding: 9px 18px;
  border-radius: 999px;
  font-size: 0.86rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: all 0.22s ease;
  z-index: 99;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Footer */
.footer {
  border-top: 1px solid var(--border);
  padding: 18px 0 28px;
  font-size: 0.82rem;
  color: var(--muted);
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
}

.footer a { color: var(--accent); text-decoration: none; }
.footer a:hover { text-decoration: underline; }

/* Responsive */
@media (max-width: 900px) {
  .two-col, .psu-layout, .subnet-inputs, .cmd-inputs, .cmd-list {
    grid-template-columns: 1fr;
  }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .binary-bits { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 520px) {
  .form-grid { grid-template-columns: 1fr; }
  .topbar-inner { flex-direction: column; align-items: flex-start; }
  .stat-grid, .stat-grid.compact { grid-template-columns: 1fr; }
}
