:root {
  --bg: #0e1117;
  --bg-2: #151a22;
  --bg-3: #1c222c;
  --border: #262d3a;
  --text: #e6e9ef;
  --muted: #8a93a6;
  --accent: #4f8cff;
  --accent-2: #6ee7b7;
  --danger: #ff6b6b;
  --warn: #f59e0b;
  --ok: #22c55e;
  --row-hover: #1f2632;
  --row-sel: #243559;
  --shadow: 0 4px 18px rgba(0,0,0,0.35);
}
[data-theme="light"] {
  --bg: #f6f7fb;
  --bg-2: #ffffff;
  --bg-3: #f0f2f7;
  --border: #e3e6ee;
  --text: #1a1f2c;
  --muted: #5b6478;
  --accent: #2b6cff;
  --accent-2: #10b981;
  --row-hover: #eef2fb;
  --row-sel: #d9e4ff;
  --shadow: 0 4px 14px rgba(15,23,42,0.08);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 22px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: 0.2px; }
.logo { width: 22px; height: 22px; color: var(--accent); }

.actions { display: flex; align-items: center; gap: 8px; }
.btn {
  border: 1px solid var(--border);
  background: var(--bg-3);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--row-hover); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.icon { width: 36px; height: 36px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.theme-ic { width: 16px; height: 16px; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, var(--text) 50%, transparent 51%);
  box-shadow: inset 0 0 0 1px var(--text);
}

main { flex: 1; padding: 22px; max-width: 1400px; width: 100%; margin: 0 auto; }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: 14px;
  padding: 60px 24px;
  text-align: center;
  background: var(--bg-2);
  transition: border-color .15s, background .15s;
}
.dropzone.drag { border-color: var(--accent); background: var(--bg-3); }
.dz-inner { display: inline-flex; flex-direction: column; align-items: center; gap: 10px; }
.dz-ic { width: 48px; height: 48px; color: var(--accent); }
.dropzone h2 { margin: 4px 0; font-weight: 600; }
.dropzone p { margin: 4px 0; color: var(--muted); }
.hint { font-size: 12px; }

.loading {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 80px;
}
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }

.summary {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 16px;
}
.card {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 16px;
}
.card .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.6px; }
.card .v { font-size: 20px; font-weight: 600; margin-top: 6px; }

.charts { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.panel {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.panel-h {
  padding: 10px 14px; font-weight: 600; font-size: 13px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-3);
}
.panel-h.with-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.panel-b { padding: 12px 14px; }

.bar-row { display: grid; grid-template-columns: 90px 1fr 60px; align-items: center; gap: 8px; margin: 6px 0; font-size: 12px; }
.bar-row .lbl { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row .num { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.bar { height: 8px; background: var(--bg-3); border-radius: 4px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

.filters { display: flex; gap: 8px; }
.filters input, .filters select {
  background: var(--bg-3); color: var(--text); border: 1px solid var(--border);
  padding: 6px 10px; border-radius: 6px; font-size: 12px; min-width: 200px;
  outline: none;
}
.filters input:focus, .filters select:focus { border-color: var(--accent); }

.split { display: grid; grid-template-columns: 1.4fr 1fr; min-height: 480px; }
.pkt-list-wrap { overflow: auto; max-height: 70vh; border-right: 1px solid var(--border); }
.pkt-list { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
.pkt-list thead th {
  position: sticky; top: 0;
  background: var(--bg-3); text-align: left; padding: 8px 10px;
  border-bottom: 1px solid var(--border); font-weight: 600; color: var(--muted);
}
.pkt-list tbody tr { cursor: pointer; }
.pkt-list tbody tr:hover { background: var(--row-hover); }
.pkt-list tbody tr.sel { background: var(--row-sel); }
.pkt-list td { padding: 6px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 280px; }

.proto-tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.p-TCP { background: rgba(79,140,255,0.18); color: var(--accent); }
.p-UDP { background: rgba(110,231,183,0.18); color: var(--accent-2); }
.p-DNS { background: rgba(245,158,11,0.18); color: var(--warn); }
.p-HTTP { background: rgba(34,197,94,0.18); color: var(--ok); }
.p-TLS { background: rgba(168,85,247,0.20); color: #c084fc; }
.p-ICMP { background: rgba(255,107,107,0.18); color: var(--danger); }
.p-ARP { background: rgba(148,163,184,0.20); color: #94a3b8; }
.p-IPv6 { background: rgba(56,189,248,0.18); color: #38bdf8; }
.p-Other { background: var(--bg-3); color: var(--muted); }

.pkt-detail { display: flex; flex-direction: column; min-height: 0; }
.detail-tabs { display: flex; border-bottom: 1px solid var(--border); background: var(--bg-3); }
.tab { background: transparent; border: none; color: var(--muted); padding: 10px 14px; cursor: pointer; font-size: 12px; font-weight: 600; }
.tab.active { color: var(--text); border-bottom: 2px solid var(--accent); }
.detail-body { padding: 12px 14px; overflow: auto; max-height: 70vh; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

.tree details { margin: 4px 0; }
.tree summary { cursor: pointer; padding: 4px 6px; border-radius: 6px; font-size: 13px; }
.tree summary:hover { background: var(--row-hover); }
.tree .field { font-size: 12px; padding: 2px 6px 2px 22px; color: var(--muted); }
.tree .field b { color: var(--text); font-weight: 600; }

.hex { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12px; line-height: 1.6; white-space: pre; }
.hex .off { color: var(--muted); }
.hex .ascii { color: var(--accent-2); }

.muted { color: var(--muted); font-size: 12px; }

.footer {
  text-align: center; padding: 16px; color: var(--muted); font-size: 12px;
  border-top: 1px solid var(--border); background: var(--bg-2);
}
.footer a { color: var(--accent); text-decoration: none; }
.footer a:hover { text-decoration: underline; }

@media (max-width: 1000px) {
  .summary { grid-template-columns: repeat(2, 1fr); }
  .charts { grid-template-columns: 1fr; }
  .split { grid-template-columns: 1fr; }
  .pkt-list-wrap { border-right: none; border-bottom: 1px solid var(--border); }
}
