:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --subtle-bg: #f8fafc;
  --muted-bg: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --primary-border: #bfdbfe;
  --cyan: #0891b2;
  --green: #10b981;
  --green-dark: #047857;
  --green-soft: #ecfdf5;
  --green-border: #a7f3d0;
  --amber: #f59e0b;
  --amber-dark: #b45309;
  --amber-soft: #fffbeb;
  --amber-border: #fde68a;
  --red: #ef4444;
  --red-dark: #b91c1c;
  --red-soft: #fef2f2;
  --red-border: #fecaca;
  --violet: #7c3aed;
  --sans: -apple-system, BlinkMacSystemFont, "Inter", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font-family: var(--sans); font-size: 14px; line-height: 1.55; -webkit-font-smoothing: antialiased;
}
button, input, select { font-family: inherit; }

/* S1 Shell & Sidebar */
.s1-shell { display: grid; grid-template-columns: 242px minmax(0, 1fr); min-height: 100vh; }
.s1-sidebar {
  background: linear-gradient(180deg, #0b1120 0%, #131c31 100%);
  color: #cbd5e1; padding: 20px 14px 18px; display: flex; flex-direction: column; justify-content: space-between;
  box-shadow: 4px 0 24px rgba(15, 23, 42, 0.08); z-index: 20;
}
.s1-brand {
  display: flex; align-items: center; gap: 11px; padding: 4px 10px 18px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.14); margin-bottom: 16px;
}
.s1-logo {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, #3b82f6 0%, #06b6d4 100%);
  display: flex; align-items: center; justify-content: center; color: #fff;
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.4); flex-shrink: 0;
}
.s1-sec-title { font-size: 11px; font-weight: 700; color: #64748b; letter-spacing: 0.8px; padding: 6px 12px; }
.s1-nav { display: flex; flex-direction: column; gap: 4px; }
.s1-item {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  padding: 10px 12px; border-radius: 10px; border: 1px solid transparent; background: transparent;
  color: #94a3b8; font-size: 13.5px; font-weight: 600; cursor: pointer; transition: all 0.16s ease;
}
.s1-item-left { display: inline-flex; align-items: center; gap: 10px; }
.s1-item svg { width: 17px; height: 17px; opacity: 0.85; }
.s1-item:hover { background: rgba(255, 255, 255, 0.06); color: #f8fafc; }
.s1-item.active {
  background: linear-gradient(90deg, rgba(37, 99, 235, 0.92) 0%, rgba(29, 78, 216, 0.85) 100%);
  border-color: rgba(96, 165, 250, 0.35); color: #ffffff;
  box-shadow: 0 6px 16px -4px rgba(37, 99, 235, 0.5);
}
.s1-pill {
  font-family: var(--mono); font-size: 11px; padding: 1px 7px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.12); color: #e2e8f0;
}
.s1-foot-box {
  background: rgba(30, 41, 59, 0.7); border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 12px; padding: 12px 14px; font-size: 12px; color: #94a3b8;
}
.s1-main { display: flex; flex-direction: column; min-width: 0; }
.s1-topbar {
  background: rgba(255, 255, 255, 0.88); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border); padding: 15px 30px;
  display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 15;
}
.s1-body { padding: 22px 30px 64px; max-width: 1360px; width: 100%; }

/* Login Overlay */
.login-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: radial-gradient(circle at 30% 20%, #1e293b 0%, #0b1120 75%);
  display: flex; align-items: center; justify-content: center; padding: 18px;
}
.login-overlay.hidden { display: none; }
.login-card {
  width: 100%; max-width: 410px; background: #ffffff; border-radius: 18px;
  padding: 28px 30px; box-shadow: 0 24px 56px rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border);
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 9px; font-size: 13px; font-weight: 600;
  border: 1px solid var(--border); background: #fff; color: var(--text);
  cursor: pointer; transition: all 0.16s ease; text-decoration: none; white-space: nowrap;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
}
.btn:hover { background: var(--subtle-bg); border-color: var(--border-strong); transform: translateY(-0.5px); }
.btn-primary {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  border-color: #1d4ed8; color: #fff; box-shadow: 0 4px 12px rgba(37, 99, 235, 0.22);
}
.btn-primary:hover { background: linear-gradient(135deg, #1d4ed8 0%, #1e40af 100%); color: #fff; }
.btn-soft { background: var(--primary-soft); border-color: var(--primary-border); color: var(--primary-hover); }
.btn-soft:hover { background: #dbeafe; }
.btn-ghost-danger { border-color: transparent; background: transparent; color: var(--text-muted); padding: 5px 9px; font-size: 12.5px; box-shadow: none; }
.btn-ghost-danger:hover { background: var(--red-soft); color: var(--red-dark); }
.btn-ghost-edit { border-color: transparent; background: transparent; color: var(--primary); padding: 5px 9px; font-size: 12.5px; box-shadow: none; }
.btn-ghost-edit:hover { background: var(--primary-soft); }
.btn-sm { padding: 5px 11px; font-size: 12px; border-radius: 7px; }

/* Inputs & Selects */
.input, .select {
  border: 1px solid var(--border-strong); background: #fff; color: var(--text);
  border-radius: 8px; padding: 7px 11px; font-size: 13px; outline: none; transition: all 0.15s;
}
.input:focus, .select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12); }

/* Badges & Dots */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px;
  border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.badge-blue { background: var(--primary-soft); color: var(--primary-hover); border: 1px solid var(--primary-border); }
.badge-green { background: var(--green-soft); color: var(--green-dark); border: 1px solid var(--green-border); }
.badge-amber { background: var(--amber-soft); color: var(--amber-dark); border: 1px solid var(--amber-border); }
.badge-red { background: var(--red-soft); color: var(--red-dark); border: 1px solid var(--red-border); }
.badge-gray { background: var(--muted-bg); color: var(--text-secondary); border: 1px solid var(--border); }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot-green { background: var(--green); box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2); }
.dot-gray { background: #94a3b8; }
@keyframes pulseRing {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.45); }
  70% { box-shadow: 0 0 0 7px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}
.dot-pulse { animation: pulseRing 2.2s infinite; }

/* Big-Screen Command Deck Shared Widgets */
.deck-kpi-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px;
}
.deck-kpi-card {
  background: #ffffff; border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px;
  box-shadow: 0 4px 14px -4px rgba(15, 23, 42, 0.05); position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.deck-kpi-num {
  font-size: 25px; font-weight: 800; font-family: var(--mono); letter-spacing: -0.6px;
  color: var(--text); line-height: 1.15; margin: 4px 0; font-variant-numeric: tabular-nums;
}
.deck-kpi-label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.deck-kpi-sub { font-size: 11.5px; color: var(--text-secondary); display: flex; align-items: center; gap: 5px; }

.topo-stage {
  background:
    radial-gradient(circle at 50% 42%, rgba(37, 99, 235, 0.06) 0%, rgba(255, 255, 255, 0) 62%),
    radial-gradient(#cbd5e1 1px, transparent 1px),
    #ffffff;
  background-size: 100% 100%, 20px 20px, 100% 100%;
  border: 1px solid var(--border); border-radius: 16px; padding: 18px 20px; margin-bottom: 18px;
  box-shadow: 0 6px 20px -6px rgba(15, 23, 42, 0.06);
}
.topo-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px;
}
.topo-filter-btns { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.topo-fbtn {
  border: 1px solid var(--border); background: rgba(255, 255, 255, 0.9); color: var(--text-secondary);
  font-size: 12px; font-weight: 600; padding: 4px 11px; border-radius: 999px; cursor: pointer; transition: all 0.15s;
}
.topo-fbtn:hover, .topo-fbtn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

@keyframes flowDash { to { stroke-dashoffset: -36; } }
.flow-anim { stroke-dasharray: 9 9; animation: flowDash 0.9s linear infinite; }
.flow-dim { opacity: 0.16; transition: opacity 0.25s; }
.flow-hi { opacity: 1; transition: opacity 0.25s; }

.deck-bottom-grid {
  display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 18px;
}
.deck-panel {
  background: #ffffff; border: 1px solid var(--border); border-radius: 15px; padding: 18px 20px;
  box-shadow: 0 4px 14px -4px rgba(15, 23, 42, 0.05);
}
.rank-row { margin-bottom: 12px; }
.rank-row:last-child { margin-bottom: 0; }
.rank-top { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 5px; }
.rank-bar-bg { height: 7px; border-radius: 999px; background: var(--muted-bg); overflow: hidden; }
.rank-bar-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, #2563eb, #06b6d4); }

/* Rule Entry Chips & Controls */
.rule-chip {
  display: inline-flex; align-items: center; gap: 4px; font-family: var(--mono);
  font-size: 12px; background: var(--subtle-bg); border: 1px solid var(--border);
  color: #1e293b; padding: 2px 8px; border-radius: 6px; margin: 2px 5px 2px 0;
}
.rule-chip-port { background: #f5f3ff; border-color: #ddd6fe; color: #6d28d9; font-weight: 600; }
.rule-chip .rm-chip { border: none; background: transparent; color: var(--text-muted); cursor: pointer; padding: 0 2px; font-size: 13px; }
.rule-chip .rm-chip:hover { color: var(--red-dark); }

.seg-inline { display: inline-flex; background: var(--muted-bg); padding: 2px; border-radius: 7px; gap: 2px; }
.seg-inline button {
  border: none; background: transparent; color: var(--text-muted); font-size: 12px;
  font-weight: 600; padding: 4px 10px; border-radius: 5px; cursor: pointer; transition: all 0.12s;
}
.seg-inline button.is-allow { background: #fff; color: var(--green-dark); box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08); }
.seg-inline button.is-deny { background: #fff; color: var(--red-dark); box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08); }

.switch-btn { display: inline-flex; align-items: center; gap: 7px; border: none; background: transparent; cursor: pointer; padding: 0; color: var(--text-secondary); font-size: 12.5px; }
.switch-track { width: 34px; height: 19px; border-radius: 999px; background: #cbd5e1; position: relative; transition: background 0.18s; flex-shrink: 0; }
.switch-thumb { width: 15px; height: 15px; border-radius: 50%; background: #fff; position: absolute; top: 2px; left: 2px; transition: transform 0.18s; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18); }
.switch-btn.on .switch-track { background: var(--primary); }
.switch-btn.on .switch-thumb { transform: translateX(15px); }

.gw-toggle {
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; border: 1px solid var(--border); background: #fff;
  color: var(--text-muted); cursor: pointer; margin: 2px 5px 2px 0; transition: all 0.12s; user-select: none;
}
.gw-toggle:hover { border-color: var(--primary-border); color: var(--text); }
.gw-toggle.checked { background: var(--primary-soft); border-color: #93c5fd; color: var(--primary-hover); }

.surface-card {
  background: #ffffff; border: 1px solid var(--border); border-radius: 15px;
  box-shadow: 0 4px 14px -4px rgba(15, 23, 42, 0.04); overflow: hidden;
}
.card-bar {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
}

.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left; padding: 11px 16px; font-size: 12px; font-weight: 600;
  color: var(--text-muted); background: var(--subtle-bg); border-bottom: 1px solid var(--border); white-space: nowrap;
}
.data-table td { padding: 13px 16px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #fafcff; }

.pending-card {
  background: var(--amber-soft); border: 1px solid var(--amber-border); border-radius: 12px;
  padding: 13px 18px; margin-bottom: 12px; display: flex; justify-content: space-between;
  align-items: center; gap: 12px; flex-wrap: wrap;
}

/* Drawers & Modals */
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.3); backdrop-filter: blur(2px);
  z-index: 150; display: none; justify-content: flex-end;
}
.drawer-backdrop.open { display: flex; }
.drawer-panel {
  width: 100%; max-width: 460px; background: #fff; height: 100%; display: flex; flex-direction: column;
  box-shadow: -12px 0 36px rgba(15, 23, 42, 0.15); border-left: 1px solid var(--border);
  animation: slideInRight 0.18s ease-out;
}
@keyframes slideInRight { from { transform: translateX(24px); opacity: 0.6; } to { transform: translateX(0); opacity: 1; } }
.drawer-header { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.drawer-title { margin: 0; font-size: 16px; font-weight: 700; }
.drawer-body { padding: 20px 22px; flex: 1; overflow-y: auto; }
.drawer-footer { padding: 14px 22px; border-top: 1px solid var(--border); background: var(--subtle-bg); display: flex; justify-content: flex-end; gap: 10px; }

.field-group { margin-bottom: 16px; }
.field-label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.field-hint { font-size: 12px; color: var(--text-muted); margin-top: 5px; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.34); backdrop-filter: blur(2px);
  z-index: 160; display: none; align-items: center; justify-content: center; padding: 16px;
}
.modal-backdrop.open { display: flex; }
.modal-card { width: 100%; max-width: 520px; background: #fff; border-radius: 15px; border: 1px solid var(--border); padding: 22px 24px; box-shadow: 0 20px 44px rgba(15, 23, 42, 0.18); }
.cmd-pre { background: #0f172a; color: #e2e8f0; font-family: var(--mono); font-size: 12px; padding: 13px 15px; border-radius: 10px; word-break: break-all; margin: 12px 0; line-height: 1.6; }

.test-step { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; background: var(--subtle-bg); margin-bottom: 10px; }
.test-step-title { font-size: 12px; font-weight: 700; color: var(--text-muted); margin-bottom: 4px; display: flex; align-items: center; justify-content: space-between; }

.ui-toast {
  position: fixed; right: 22px; bottom: 28px; z-index: 600; background: #0f172a; color: #fff;
  padding: 11px 16px; border-radius: 10px; font-size: 13px; box-shadow: 0 10px 25px rgba(15, 23, 42, 0.24);
  border-left: 4px solid var(--green); display: none; max-width: 420px;
}
.ui-toast.show { display: block; }
.ui-toast.err { border-left-color: var(--red); }

@media (max-width: 980px) {
  .deck-kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .deck-bottom-grid { grid-template-columns: 1fr; }
}
@media (max-width: 920px) {
  .s1-shell { grid-template-columns: 100%; }
  .s1-sidebar { min-width: 0; max-width: 100vw; overflow-x: hidden; }
  .s1-nav { flex-direction: row; overflow-x: auto; max-width: 100%; }
  .s1-item { width: auto; white-space: nowrap; flex-shrink: 0; }
  .s1-foot-box, .s1-sec-title { display: none; }
  .s1-topbar, .s1-body { padding: 16px; min-width: 0; max-width: 100vw; overflow-x: hidden; }
}
@media (max-width: 520px) {
  .deck-kpi-grid { grid-template-columns: 1fr; }
  .s1-topbar .btn { padding: 6px 10px; font-size: 12px; }
}
