/* ─────────────────────────────────────────────────────────────
   PortRef — style.css
   Self-hosted Network Port Reference
───────────────────────────────────────────────────────────── */

/* ── CSS Variables ── */
:root {
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --font-ui:   'Inter', system-ui, sans-serif;
  --radius:    8px;
  --radius-lg: 12px;
  --header-h:  108px;
  --transition: 0.18s ease;
}

/* DARK THEME */
[data-theme="dark"] {
  --bg:           #0a0d17;
  --bg2:          #0f1322;
  --surface:      #141828;
  --surface2:     #1a2035;
  --surface3:     #202843;
  --border:       rgba(255,255,255,0.07);
  --border2:      rgba(99,102,241,0.3);
  --border3:      rgba(99,102,241,0.6);
  --text:         #e2e8f0;
  --text2:        #8892aa;
  --text3:        #4a5578;
  --accent:       #818cf8;
  --accent-glow:  rgba(129,140,248,0.15);
  --tcp:          #67e8f9;
  --udp:          #86efac;
  --both:         #c4b5fd;
  --warning:      #fbbf24;
  --danger:       #f87171;
  --success:      #4ade80;
  --row-hover:    rgba(99,102,241,0.06);
  --row-selected: rgba(99,102,241,0.12);
  --shadow:       0 4px 24px rgba(0,0,0,0.4);
  --shadow-lg:    0 8px 48px rgba(0,0,0,0.6);
  --scrollbar:    #1e2540;
  --scrollbar-thumb: #2e3a5c;
}

/* LIGHT THEME */
[data-theme="light"] {
  --bg:           #f8fafc;
  --bg2:          #f1f5f9;
  --surface:      #ffffff;
  --surface2:     #f8fafc;
  --surface3:     #f1f5f9;
  --border:       rgba(0,0,0,0.08);
  --border2:      rgba(99,102,241,0.25);
  --border3:      rgba(99,102,241,0.5);
  --text:         #0f172a;
  --text2:        #475569;
  --text3:        #94a3b8;
  --accent:       #4f46e5;
  --accent-glow:  rgba(79,70,229,0.08);
  --tcp:          #0284c7;
  --udp:          #16a34a;
  --both:         #7c3aed;
  --warning:      #d97706;
  --danger:       #dc2626;
  --success:      #16a34a;
  --row-hover:    rgba(99,102,241,0.04);
  --row-selected: rgba(99,102,241,0.08);
  --shadow:       0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg:    0 8px 32px rgba(0,0,0,0.14);
  --scrollbar:    #e2e8f0;
  --scrollbar-thumb: #cbd5e1;
}

/* MILITARY THEME */
[data-theme="military"] {
  --bg:           #0d1208;
  --bg2:          #111a0a;
  --surface:      #162010;
  --surface2:     #1c2a14;
  --surface3:     #22331a;
  --border:       rgba(100,180,50,0.12);
  --border2:      rgba(100,180,50,0.3);
  --border3:      rgba(100,180,50,0.6);
  --text:         #a8d878;
  --text2:        #6b9640;
  --text3:        #3a5520;
  --accent:       #7ec850;
  --accent-glow:  rgba(126,200,80,0.12);
  --tcp:          #7ec850;
  --udp:          #b8e068;
  --both:         #50c878;
  --warning:      #e8c040;
  --danger:       #e85050;
  --success:      #60d050;
  --row-hover:    rgba(100,180,50,0.06);
  --row-selected: rgba(100,180,50,0.12);
  --shadow:       0 4px 20px rgba(0,0,0,0.5);
  --shadow-lg:    0 8px 40px rgba(0,0,0,0.7);
  --scrollbar:    #1c2a14;
  --scrollbar-thumb: #3a5520;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  height: 100%;
  overflow: hidden;
  font-size: 14px;
  line-height: 1.5;
  transition: background var(--transition), color var(--transition);
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--scrollbar); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }

/* ── Header ── */
#header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  background: var(--surface);
  border-bottom: 0.5px solid var(--border);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
}
.header-inner {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px;
  height: 60px;
}

/* Brand */
.brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.brand-mark { width: 32px; height: 32px; flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; }
.brand-name { font-family: var(--font-mono); font-size: 15px; font-weight: 700; letter-spacing: 0.04em; line-height: 1.1; }
.brand-sub { font-size: 10px; color: var(--text2); letter-spacing: 0.06em; text-transform: uppercase; }

/* Search */
.header-search { flex: 1; max-width: 480px; }
.search-wrap {
  position: relative; display: flex; align-items: center;
  background: var(--surface2); border: 0.5px solid var(--border);
  border-radius: var(--radius); height: 38px; padding: 0 12px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.search-wrap:focus-within {
  border-color: var(--border3);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.search-icon { color: var(--text3); font-size: 18px; margin-right: 8px; user-select: none; }
.search-wrap input {
  flex: 1; background: transparent; border: none; outline: none;
  color: var(--text); font-family: var(--font-ui); font-size: 13px;
  min-width: 0;
}
.search-wrap input::placeholder { color: var(--text3); }
.search-shortcut {
  font-family: var(--font-mono); font-size: 10px; color: var(--text3);
  background: var(--surface3); border: 0.5px solid var(--border);
  padding: 2px 6px; border-radius: 4px; white-space: nowrap;
}

/* Header controls */
.header-controls { display: flex; align-items: center; gap: 6px; flex-shrink: 0; margin-left: auto; }
.divider-v { width: 0.5px; height: 24px; background: var(--border); }

.view-toggle { display: flex; gap: 2px; background: var(--surface2); border: 0.5px solid var(--border); border-radius: var(--radius); padding: 3px; }
.view-btn {
  width: 30px; height: 30px; border: none; background: transparent;
  border-radius: 6px; cursor: pointer; color: var(--text2);
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.view-btn:hover { background: var(--surface3); color: var(--text); }
.view-btn.active { background: var(--accent); color: white; }
.view-btn svg { fill: currentColor; }

.icon-btn {
  width: 36px; height: 36px; border: 0.5px solid var(--border);
  background: var(--surface2); border-radius: var(--radius);
  cursor: pointer; color: var(--text2);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; transition: all var(--transition);
  position: relative;
}
.icon-btn:hover { background: var(--surface3); color: var(--text); border-color: var(--border2); }

/* Dropdown */
.dropdown-wrap { position: relative; }
.dropdown-menu {
  position: absolute; top: calc(100% + 6px); right: 0;
  background: var(--surface); border: 0.5px solid var(--border2);
  border-radius: var(--radius-lg); padding: 6px; min-width: 200px;
  box-shadow: var(--shadow-lg); z-index: 200;
  display: none; flex-direction: column; gap: 2px;
}
.dropdown-menu.open { display: flex; }
.dropdown-menu button {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border: none; background: transparent;
  color: var(--text); font-family: var(--font-ui); font-size: 13px;
  cursor: pointer; border-radius: 6px; text-align: left; width: 100%;
  transition: background var(--transition);
}
.dropdown-menu button svg { color: var(--text2); flex-shrink: 0; }
.dropdown-menu button:hover { background: var(--surface2); }
.dropdown-sep { height: 0.5px; background: var(--border); margin: 4px 0; }

/* Filter bar */
.filter-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px 10px; overflow: hidden;
}
.filter-chips {
  display: flex; gap: 6px; overflow-x: auto; flex: 1;
  scrollbar-width: none; padding-bottom: 2px;
}
.filter-chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; padding: 5px 12px; border-radius: 20px;
  font-size: 12px; font-weight: 500; cursor: pointer;
  background: var(--surface2); color: var(--text2);
  border: 0.5px solid var(--border);
  font-family: var(--font-ui); transition: all var(--transition);
  white-space: nowrap;
}
.chip:hover { border-color: var(--border2); color: var(--text); }
.chip.active { background: var(--accent-glow); color: var(--accent); border-color: var(--border2); }
.chip-count { font-family: var(--font-mono); font-size: 10px; margin-left: 4px; opacity: 0.7; }
.filter-meta { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.result-count { font-family: var(--font-mono); font-size: 11px; color: var(--text2); white-space: nowrap; }
.clear-filters-btn {
  font-size: 11px; color: var(--danger); background: none; border: none;
  cursor: pointer; font-family: var(--font-ui); white-space: nowrap;
  opacity: 0.8; transition: opacity var(--transition);
}
.clear-filters-btn:hover { opacity: 1; }

/* ── Main / Views ── */
#main {
  position: fixed; top: var(--header-h); left: 0; right: 0; bottom: 0;
  overflow: hidden;
}
.view-wrap { display: none; height: 100%; overflow: hidden; }
.view-wrap.active { display: flex; flex-direction: column; }

/* ── TABLE VIEW ── */
.table-container { overflow: auto; flex: 1; }
#port-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
  table-layout: fixed;
}
#port-table colgroup { }
.th-port  { width: 80px; }
.th-proto { width: 100px; }
.th-name  { width: 200px; }
.th-desc  { /* flex */ }
.th-cats  { width: 180px; }
.th-range { width: 130px; }

#port-table thead { position: sticky; top: 0; z-index: 10; }
#port-table th {
  background: var(--surface); color: var(--text2);
  font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  padding: 10px 14px; border-bottom: 0.5px solid var(--border);
  text-align: left; white-space: nowrap; user-select: none;
}
#port-table th.sortable { cursor: pointer; }
#port-table th.sortable:hover { color: var(--text); }
.sort-icon { font-size: 10px; margin-left: 4px; opacity: 0.4; }
th.sort-asc .sort-icon, th.sort-desc .sort-icon { opacity: 1; color: var(--accent); }
th.sort-asc .sort-icon::after { content: '↑'; }
th.sort-desc .sort-icon::after { content: '↓'; }
th.sort-asc .sort-icon, th.sort-desc .sort-icon { display: inline; }

#port-table tbody tr {
  border-bottom: 0.5px solid var(--border);
  cursor: pointer; transition: background var(--transition);
}
#port-table tbody tr:hover { background: var(--row-hover); }
#port-table tbody tr.selected { background: var(--row-selected); }
#port-table td { padding: 10px 14px; vertical-align: middle; }

.td-port {
  font-family: var(--font-mono); font-size: 13px; font-weight: 700;
  color: var(--accent); white-space: nowrap;
}
.td-desc {
  color: var(--text2); font-size: 12px; line-height: 1.4;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 0;
}
.td-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.td-range { font-size: 11px; color: var(--text3); white-space: nowrap; }

/* Proto badges */
.badge {
  display: inline-flex; align-items: center;
  font-family: var(--font-mono); font-size: 10px; font-weight: 700;
  padding: 2px 7px; border-radius: 4px; white-space: nowrap; letter-spacing: 0.04em;
}
.badge-tcp  { background: rgba(103,232,249,0.1); color: var(--tcp);  border: 0.5px solid rgba(103,232,249,0.25); }
.badge-udp  { background: rgba(134,239,172,0.1); color: var(--udp);  border: 0.5px solid rgba(134,239,172,0.25); }
.badge-both { background: rgba(196,181,253,0.1); color: var(--both); border: 0.5px solid rgba(196,181,253,0.25); }

/* Cat tags */
.cat-tags { display: flex; gap: 4px; flex-wrap: wrap; }
.cat-tag {
  font-size: 10px; padding: 1px 6px; border-radius: 3px;
  background: var(--surface3); color: var(--text2);
  border: 0.5px solid var(--border);
}

/* Highlight */
.hl { background: rgba(251,191,36,0.2); color: var(--warning); border-radius: 2px; }

/* Section divider rows */
.section-row td {
  background: var(--bg2) !important; color: var(--text3);
  font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;
  font-weight: 700; padding: 6px 14px !important;
  cursor: default;
}
.section-row:hover td { background: var(--bg2) !important; }

/* ── SPLIT VIEW ── */
#view-split-wrap { flex-direction: row !important; }
.split-list {
  width: 360px; flex-shrink: 0; overflow-y: auto;
  border-right: 0.5px solid var(--border);
}
.split-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 16px; border-bottom: 0.5px solid var(--border);
  cursor: pointer; transition: background var(--transition);
}
.split-item:hover { background: var(--row-hover); }
.split-item.active { background: var(--row-selected); border-left: 2px solid var(--accent); }
.split-port { font-family: var(--font-mono); font-size: 13px; font-weight: 700; color: var(--accent); min-width: 46px; }
.split-info { flex: 1; min-width: 0; }
.split-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.split-desc { font-size: 11px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }

.split-detail { flex: 1; overflow-y: auto; padding: 28px 32px; }
.split-placeholder {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; height: 100%; gap: 12px; color: var(--text3);
  text-align: center;
}
.placeholder-icon { font-size: 48px; opacity: 0.3; }
.placeholder-title { font-size: 16px; font-weight: 500; color: var(--text2); }
.placeholder-sub { font-size: 13px; max-width: 260px; line-height: 1.6; }

.detail-port-num { font-family: var(--font-mono); font-size: 48px; font-weight: 700; color: var(--accent); line-height: 1; margin-bottom: 8px; }
.detail-service { font-size: 24px; font-weight: 600; margin-bottom: 20px; }
.detail-section { margin-bottom: 24px; }
.detail-label { font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text2); font-weight: 600; margin-bottom: 6px; }
.detail-value { font-size: 14px; color: var(--text); line-height: 1.6; }
.detail-mono { font-family: var(--font-mono); font-size: 13px; color: var(--accent); }
.detail-divider { height: 0.5px; background: var(--border); margin: 20px 0; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 24px; }
.detail-action-btn {
  padding: 8px 16px; border-radius: var(--radius);
  font-family: var(--font-ui); font-size: 13px; font-weight: 500;
  cursor: pointer; transition: all var(--transition); border: none;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { opacity: 0.9; }
.btn-ghost { background: var(--surface2); color: var(--text2); border: 0.5px solid var(--border); }
.btn-ghost:hover { background: var(--surface3); color: var(--text); }

/* ── CARDS VIEW ── */
#view-cards-wrap { overflow: hidden; }
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px; padding: 16px 20px;
  overflow-y: auto; height: 100%;
  align-content: start;
}
.port-card {
  background: var(--surface); border: 0.5px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px;
  cursor: pointer; transition: all var(--transition);
  display: flex; flex-direction: column; gap: 8px;
  position: relative; overflow: hidden;
}
.port-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, var(--accent), transparent);
  opacity: 0; transition: opacity var(--transition);
}
.port-card:hover { border-color: var(--border2); box-shadow: var(--shadow); transform: translateY(-1px); }
.port-card:hover::before { opacity: 1; }
.card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.card-port { font-family: var(--font-mono); font-size: 20px; font-weight: 700; color: var(--accent); }
.card-name { font-size: 14px; font-weight: 600; line-height: 1.3; }
.card-desc { font-size: 12px; color: var(--text2); line-height: 1.5; flex: 1; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.card-footer { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: auto; padding-top: 4px; border-top: 0.5px solid var(--border); }

/* ── COMPACT VIEW ── */
#view-compact-wrap { overflow: hidden; }
.compact-list { overflow-y: auto; height: 100%; }
.compact-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 20px; border-bottom: 0.5px solid var(--border);
  cursor: pointer; transition: background var(--transition);
}
.compact-item:hover { background: var(--row-hover); }
.compact-port { font-family: var(--font-mono); font-size: 12px; font-weight: 700; color: var(--accent); min-width: 52px; }
.compact-name { font-size: 13px; font-weight: 500; min-width: 170px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.compact-desc { font-size: 12px; color: var(--text2); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.compact-section {
  background: var(--bg2); padding: 4px 20px;
  font-size: 9px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--text3); font-weight: 700; border-bottom: 0.5px solid var(--border);
  position: sticky; top: 0; z-index: 2;
}

/* ── DETAIL MODAL ── */
#modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  z-index: 300; display: none; backdrop-filter: blur(6px);
}
#modal-backdrop.open { display: block; }
#detail-modal {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%) scale(0.97);
  background: var(--surface); border: 0.5px solid var(--border2);
  border-radius: var(--radius-lg); z-index: 301;
  width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 80px);
  overflow-y: auto; display: none; flex-direction: column;
  box-shadow: var(--shadow-lg);
  transition: transform 0.2s ease, opacity 0.2s ease;
  opacity: 0;
}
#detail-modal.open { display: flex; transform: translate(-50%,-50%) scale(1); opacity: 1; }
.modal-header {
  padding: 24px 24px 16px; border-bottom: 0.5px solid var(--border);
  position: sticky; top: 0; background: var(--surface); z-index: 1;
  display: flex; flex-direction: column; gap: 4px; position: relative;
}
.modal-port-num { font-family: var(--font-mono); font-size: 40px; font-weight: 700; color: var(--accent); line-height: 1; }
.modal-service { font-size: 22px; font-weight: 600; }
.modal-close {
  position: absolute; top: 16px; right: 16px;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--surface2); border: 0.5px solid var(--border);
  cursor: pointer; color: var(--text2); font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.modal-close:hover { background: var(--surface3); color: var(--text); }
.modal-body { padding: 20px 24px 28px; display: flex; flex-direction: column; gap: 20px; }
.modal-section { display: flex; flex-direction: column; gap: 6px; }
.modal-label { font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text2); font-weight: 600; }
.modal-value { font-size: 14px; color: var(--text); line-height: 1.65; }
.modal-mono { font-family: var(--font-mono); font-size: 13px; color: var(--accent); }
.modal-tags { display: flex; gap: 8px; flex-wrap: wrap; }
.modal-tag-badge {
  padding: 4px 12px; border-radius: 20px; font-size: 11px; font-weight: 500;
  background: var(--surface2); color: var(--text2); border: 0.5px solid var(--border);
}
.modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.modal-grid-item { background: var(--surface2); border-radius: var(--radius); padding: 12px; }
.modal-grid-label { font-size: 10px; color: var(--text3); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 4px; }
.modal-grid-value { font-family: var(--font-mono); font-size: 14px; color: var(--text); font-weight: 500; }
.modal-actions { display: flex; gap: 8px; padding-top: 8px; flex-wrap: wrap; }

/* ── KEYBOARD SHORTCUTS ── */
#shortcuts-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  z-index: 400; display: none; backdrop-filter: blur(4px);
}
#shortcuts-backdrop.open { display: block; }
#shortcuts-panel {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%);
  background: var(--surface); border: 0.5px solid var(--border2);
  border-radius: var(--radius-lg); z-index: 401;
  width: min(600px, calc(100vw - 32px)); max-height: calc(100vh - 80px);
  overflow-y: auto; display: none; flex-direction: column;
  box-shadow: var(--shadow-lg); padding: 0 0 20px;
}
#shortcuts-panel.open { display: flex; }
.shortcuts-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 0.5px solid var(--border);
  font-weight: 600; font-size: 15px; position: sticky; top: 0;
  background: var(--surface); z-index: 1;
}
.shortcuts-header button {
  background: var(--surface2); border: 0.5px solid var(--border); color: var(--text2);
  width: 28px; height: 28px; border-radius: 50%; cursor: pointer; font-size: 13px;
}
.shortcuts-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 0; padding: 16px 20px; gap: 20px;
}
.shortcut-group { display: flex; flex-direction: column; gap: 8px; }
.sg-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text2); font-weight: 600; margin-bottom: 4px; }
.sc-row { display: flex; align-items: center; gap: 8px; }
.sc-row span { font-size: 12px; color: var(--text2); }
kbd {
  font-family: var(--font-mono); font-size: 10px; font-weight: 700;
  background: var(--surface2); border: 0.5px solid var(--border);
  border-bottom-width: 2px; padding: 2px 7px; border-radius: 4px;
  color: var(--accent);
}

/* ── TOAST ── */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--surface); border: 0.5px solid var(--border2);
  color: var(--text); padding: 10px 20px; border-radius: var(--radius-lg);
  font-size: 13px; box-shadow: var(--shadow-lg);
  opacity: 0; transition: all 0.3s ease; z-index: 500;
  pointer-events: none; white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Theme selector row in modal ── */
.theme-picker { display: flex; gap: 8px; }
.theme-opt {
  padding: 6px 14px; border-radius: var(--radius); border: 0.5px solid var(--border);
  background: var(--surface2); color: var(--text2); font-size: 12px; cursor: pointer;
  font-family: var(--font-ui); transition: all var(--transition);
}
.theme-opt:hover { border-color: var(--border2); color: var(--text); }
.theme-opt.active { border-color: var(--accent); color: var(--accent); background: var(--accent-glow); }

/* ── No results ── */
.no-results-row td {
  text-align: center; padding: 60px !important; color: var(--text3); cursor: default;
}
.no-results-row:hover td { background: transparent !important; }

/* ── Print ── */
@media print {
  #header .header-controls, #header .filter-bar, #modal-backdrop,
  #detail-modal, #shortcuts-panel, #toast { display: none !important; }
  body { overflow: visible !important; background: white !important; color: black !important; }
  #main { position: static !important; overflow: visible !important; }
  .view-wrap { display: block !important; overflow: visible !important; }
  .table-container { overflow: visible !important; }
  #port-table th { background: #f0f0f0 !important; color: #333 !important; }
  #port-table tbody tr { page-break-inside: avoid; }
  .badge-tcp { color: #0284c7 !important; }
  .badge-udp { color: #16a34a !important; }
  .badge-both { color: #7c3aed !important; }
}

/* ── Responsive ── */
@media (max-width: 900px) {
  .th-desc { display: none; }
  .td-desc { display: none; }
  .th-cats { display: none; }
  .td-cats { display: none; }
  .split-detail { display: none; }
  .split-list { width: 100%; border-right: none; }
  .shortcuts-grid { grid-template-columns: 1fr; }
  .brand-sub { display: none; }
  .header-search { max-width: none; }
  :root { --header-h: 108px; }
}
@media (max-width: 600px) {
  .th-range { display: none; }
  .td-range { display: none; }
  .header-inner { padding: 10px 12px; }
  .filter-bar { padding: 0 12px 8px; }
}


/* ── SCAN & STATS PANELS (added) ─────────────────────────────── */
#scan-backdrop, #stats-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 410; display: none; backdrop-filter: blur(5px);
}
#scan-backdrop.open, #stats-backdrop.open { display: block; }
#scan-panel, #stats-panel {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%);
  background: var(--surface); border: 0.5px solid var(--border2);
  border-radius: var(--radius-lg); z-index: 411;
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 80px);
  overflow-y: auto; display: none; flex-direction: column;
  box-shadow: var(--shadow-lg);
}
#scan-panel.open, #stats-panel.open { display: flex; }
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 0.5px solid var(--border);
  font-weight: 600; font-size: 15px; position: sticky; top: 0;
  background: var(--surface); z-index: 1;
}
.panel-header button {
  background: var(--surface2); border: 0.5px solid var(--border); color: var(--text2);
  width: 28px; height: 28px; border-radius: 50%; cursor: pointer; font-size: 13px;
  transition: all var(--transition);
}
.panel-header button:hover { background: var(--surface3); color: var(--text); }

/* Scan */
.scan-body { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.scan-drop {
  border: 1.5px dashed var(--border3); border-radius: var(--radius-lg);
  background: var(--surface2); min-height: 200px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  transition: all var(--transition); padding: 20px; text-align: center;
}
.scan-drop:hover { border-color: var(--accent); background: var(--accent-glow); }
#camera-preview { display: none; max-width: 100%; max-height: 340px; border-radius: var(--radius); }
.scan-icon { font-size: 40px; margin-bottom: 10px; }
.scan-hint { font-size: 13px; color: var(--text2); line-height: 1.5; max-width: 380px; }
.scan-analyze {
  display: none; width: 100%; padding: 12px; border: none; cursor: pointer;
  border-radius: var(--radius); font-family: var(--font-body); font-size: 14px; font-weight: 600;
  color: #fff; background: linear-gradient(135deg, #6d28d9, #06b6d4);
  transition: transform var(--transition), filter var(--transition);
}
.scan-analyze.visible { display: block; }
.scan-analyze:hover { filter: brightness(1.08); }
.scan-analyze:active { transform: scale(0.99); }
.scan-note { font-size: 11px; color: var(--text3); line-height: 1.5; }
.ai-result {
  background: var(--surface2); border: 0.5px solid var(--border);
  border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px;
}
.ai-result-header { font-size: 13px; font-weight: 600; color: var(--accent); }
.ai-result-note { font-size: 12px; color: var(--text2); line-height: 1.5; }
.ai-loading { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text2); }
.ai-spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--border3); border-top-color: var(--accent);
  animation: ai-spin 0.7s linear infinite;
}
@keyframes ai-spin { to { transform: rotate(360deg); } }
.ai-match {
  display: flex; align-items: center; gap: 12px; padding: 10px;
  background: var(--surface); border: 0.5px solid var(--border); border-radius: var(--radius);
}
.ai-match[onclick] { cursor: pointer; }
.ai-match[onclick]:hover { border-color: var(--border2); background: var(--row-hover); }
.ai-match-port { font-family: var(--font-mono); font-size: 18px; font-weight: 700; color: var(--accent); min-width: 52px; }
.ai-match-info { flex: 1; min-width: 0; }
.ai-match-name { font-size: 13px; font-weight: 600; }
.ai-match-desc { font-size: 11px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Stats */
.stats-body { padding: 20px; display: flex; flex-direction: column; gap: 18px; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.stat-card {
  background: var(--surface2); border: 0.5px solid var(--border);
  border-radius: var(--radius); padding: 14px 10px; text-align: center;
}
.stat-value { font-family: var(--font-mono); font-size: 24px; font-weight: 700; line-height: 1.1; }
.stat-label { font-size: 10px; color: var(--text2); margin-top: 5px; letter-spacing: 0.02em; }
.stat-section-title { font-size: 12px; font-weight: 600; color: var(--text); }
.stat-hint { font-weight: 400; color: var(--text3); font-size: 11px; }
.cat-bar { display: flex; flex-direction: column; gap: 7px; }
.cat-row { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 2px 0; }
.cat-row:hover .cat-name { color: var(--text); }
.cat-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.cat-name { font-size: 12px; color: var(--text2); width: 130px; flex-shrink: 0; }
.cat-bar-wrap { flex: 1; height: 8px; background: var(--surface3); border-radius: 6px; overflow: hidden; }
.cat-bar-fill { height: 100%; border-radius: 6px; transition: width 0.4s ease; }
.cat-count { font-family: var(--font-mono); font-size: 12px; color: var(--text2); width: 36px; text-align: right; }

@media (max-width: 560px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .cat-name { width: 92px; }
}
