/* Salvage UI - restrained blue/gray/white forensic palette, light + dark. */

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --surface-3: #e4e8ef;
  --border: #d4dae3;
  --border-strong: #b9c2cf;
  --text: #1a2230;
  --text-muted: #5b6676;
  --text-faint: #8a93a3;
  --accent: #1d4ed8;
  --accent-hover: #1a44bd;
  --accent-soft: #e5edff;
  --ok: #0f766e;
  --warn: #b45309;
  --danger: #b91c1c;
  --mono: 'SFMono-Regular', ui-monospace, 'Cascadia Code', Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --row-h: 24px;
  --sel: #d7e4ff;
  --sel-border: #1d4ed8;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141c;
    --surface: #161c26;
    --surface-2: #1c2431;
    --surface-3: #232d3c;
    --border: #2b3545;
    --border-strong: #3a4659;
    --text: #e6ebf2;
    --text-muted: #9aa6b6;
    --text-faint: #6b7686;
    --accent: #4f83ff;
    --accent-hover: #6a97ff;
    --accent-soft: #1b2740;
    --ok: #2dd4bf;
    --warn: #f59e0b;
    --danger: #f87171;
    --sel: #233655;
    --sel-border: #4f83ff;
  }
}

* { box-sizing: border-box; }
/* Ensure the hidden attribute always wins over class display rules
   (e.g. .modal/.tab-panel set display, which would otherwise override it). */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--surface);
  border-bottom: 1px solid var(--border); flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand .logo { display: flex; }
.brand .title { font-weight: 700; font-size: 17px; letter-spacing: 0.2px; }
.brand .tagline { color: var(--text-faint); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actions { display: flex; align-items: center; gap: 8px; }

.btn {
  font-family: inherit; font-size: 13px; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 7px 12px; border-radius: 7px; cursor: pointer; white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-3); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }

.menu { position: relative; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 30;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18); min-width: 180px; padding: 4px;
}
.menu-list button {
  display: block; width: 100%; text-align: left; background: transparent; border: 0;
  color: var(--text); padding: 8px 10px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
.menu-list button:hover { background: var(--surface-2); }

/* Dropzone */
.dropzone {
  flex: 1 1 auto; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.dropzone.dragover .dz-inner { border-color: var(--accent); background: var(--accent-soft); }
.dz-inner {
  text-align: center; max-width: 520px; padding: 48px 40px;
  border: 2px dashed var(--border-strong); border-radius: 16px; color: var(--text-muted);
  background: var(--surface); transition: background .15s, border-color .15s;
}
.dz-inner svg { color: var(--accent); margin-bottom: 8px; }
.dz-inner h1 { font-size: 20px; color: var(--text); margin: 6px 0 10px; }
.dz-inner p { margin: 6px 0; line-height: 1.5; }
.dz-inner code { font-family: var(--mono); background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.dz-inner .btn { margin-top: 12px; }
.dz-note { font-size: 12px; color: var(--text-faint); margin-top: 18px !important; }

/* Progress overlay */
.progress { flex: 1 1 auto; display: flex; align-items: center; justify-content: center; }
.progress-card { width: min(420px, 90%); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 22px; }
.progress-title { font-weight: 600; margin-bottom: 12px; }
.progress-track { height: 8px; background: var(--surface-3); border-radius: 6px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .1s linear; }
.progress-sub { margin-top: 10px; font-size: 12.5px; color: var(--text-muted); min-height: 16px; }

/* Workspace */
#workspace { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }

.filterbar { display: flex; align-items: center; gap: 12px; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border); }
.filter-wrap { position: relative; flex: 1 1 auto; display: flex; }
#filterInput {
  flex: 1; font-family: var(--mono); font-size: 13px; padding: 8px 32px 8px 12px;
  border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface-2); color: var(--text);
}
#filterInput:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
#filterInput.invalid { border-color: var(--danger); outline-color: var(--danger); }
#filterClear { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); padding: 4px 8px; }
.filter-status { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; min-width: 120px; }
.filter-status.error { color: var(--danger); }

.tabs { display: flex; gap: 2px; padding: 0 12px; background: var(--surface); border-bottom: 1px solid var(--border); }
.tab { background: transparent; border: 0; border-bottom: 2px solid transparent; color: var(--text-muted); padding: 10px 14px; cursor: pointer; font-size: 13.5px; font-family: inherit; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.badge { background: var(--surface-3); color: var(--text-muted); border-radius: 10px; padding: 1px 7px; font-size: 11px; margin-left: 4px; }

.tab-panel { flex: 1 1 auto; min-height: 0; display: none; }
.tab-panel.active { display: flex; flex-direction: column; }

/* Packet area */
.pkt-area { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.pkt-list { flex: 1 1 55%; min-height: 120px; display: flex; flex-direction: column; border-bottom: 1px solid var(--border); }
.pkt-header-row, .pkt-row {
  display: grid; grid-template-columns: 70px 180px 160px 160px 90px 72px 1fr;
  align-items: center; column-gap: 0;
}
.pkt-header-row {
  background: var(--surface-2); border-bottom: 1px solid var(--border);
  font-size: 12px; font-weight: 600; color: var(--text-muted); flex: 0 0 auto;
}
.pkt-header-row > span { padding: 7px 8px; border-right: 1px solid var(--border); overflow: hidden; }
.pkt-header-row .num, .pkt-row .num { text-align: right; }
.pkt-scroll { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; position: relative; }
.pkt-spacer { position: relative; width: 100%; }
.pkt-rows { position: absolute; top: 0; left: 0; right: 0; }
.pkt-row {
  height: var(--row-h); font-family: var(--mono); font-size: 12px; cursor: pointer;
  border-bottom: 1px solid var(--surface-2); color: var(--text);
}
.pkt-row > span { padding: 0 8px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.pkt-row:hover { background: var(--surface-2); }
.pkt-row.selected { background: var(--sel); box-shadow: inset 2px 0 0 var(--sel-border); }
.pkt-row .info { color: var(--text-muted); }
.pkt-row.selected .info { color: var(--text); }

/* protocol tint on the proto cell */
.proto-tag { display: inline-block; padding: 0 6px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.p-dns { background: #e0f2fe; color: #075985; }
.p-http { background: #dcfce7; color: #166534; }
.p-tls { background: #ede9fe; color: #5b21b6; }
.p-tcp { background: #e2e8f0; color: #334155; }
.p-udp { background: #fef3c7; color: #92400e; }
.p-arp, .p-icmp, .p-icmpv6 { background: #fee2e2; color: #991b1b; }
.p-dhcp { background: #cffafe; color: #155e75; }
@media (prefers-color-scheme: dark) {
  .p-dns { background: #0c3a52; color: #7dd3fc; }
  .p-http { background: #0f3d24; color: #86efac; }
  .p-tls { background: #2e2259; color: #c4b5fd; }
  .p-tcp { background: #2a3444; color: #cbd5e1; }
  .p-udp { background: #3f2f0a; color: #fcd34d; }
  .p-arp, .p-icmp, .p-icmpv6 { background: #44181a; color: #fca5a5; }
  .p-dhcp { background: #0a3a44; color: #67e8f9; }
}

/* Detail + hex */
.pkt-detail { flex: 1 1 45%; min-height: 110px; display: flex; flex-direction: column; }
.detail-toolbar { display: flex; align-items: center; justify-content: space-between; padding: 6px 10px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.detail-title { font-size: 12.5px; color: var(--text-muted); font-weight: 600; }
.detail-split { flex: 1; display: flex; min-height: 0; }
.tree-pane { flex: 1 1 55%; overflow: auto; padding: 8px 10px; border-right: 1px solid var(--border); font-family: var(--mono); font-size: 12.5px; }
.hex-pane { flex: 1 1 45%; overflow: auto; padding: 8px 10px; font-family: var(--mono); font-size: 12px; white-space: pre; line-height: 1.45; }
.empty { color: var(--text-faint); font-family: var(--sans); }

.tree details { margin: 1px 0; }
.tree summary { cursor: pointer; padding: 2px 4px; border-radius: 4px; list-style: none; }
.tree summary:hover { background: var(--surface-2); }
.tree summary::-webkit-details-marker { display: none; }
.tree summary::before { content: '\25b8'; display: inline-block; width: 12px; color: var(--text-faint); transition: transform .1s; }
.tree details[open] > summary::before { transform: rotate(90deg); }
.tree .node-label { font-weight: 600; color: var(--accent); }
.tree .field { padding: 1px 4px 1px 20px; display: flex; gap: 8px; }
.tree .field:hover { background: var(--surface-2); }
.tree .fname { color: var(--text-muted); }
.tree .fval { color: var(--text); }

/* Generic panels + tables */
.panel-scroll { flex: 1; overflow: auto; padding: 16px 18px; }
.panel-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.panel-head h2 { margin: 0; font-size: 16px; }
.muted { color: var(--text-muted); font-size: 13px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.data-table th, .data-table td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table th { position: sticky; top: 0; background: var(--surface-2); color: var(--text-muted); font-weight: 600; z-index: 2; }
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tr:hover td { background: var(--surface-2); }
.data-table .mono { font-family: var(--mono); font-size: 11.5px; word-break: break-all; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.stats-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.stats-card h3 { margin: 0 0 8px; font-size: 13.5px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.kpi .v { font-size: 20px; font-weight: 700; }
.kpi .l { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.magic-flag { color: var(--accent); font-weight: 600; }
.warn-banner { background: color-mix(in srgb, var(--warn) 14%, var(--surface)); border: 1px solid var(--warn); color: var(--text); padding: 8px 12px; border-radius: 8px; margin-bottom: 12px; font-size: 12.5px; }
.ioc-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.pill { font-family: var(--mono); font-size: 11px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(8,12,20,0.55); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; width: min(560px, 100%); max-height: 86vh; display: flex; flex-direction: column; padding: 16px 18px; }
.modal-wide { width: min(1000px, 100%); height: 82vh; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-head-actions { display: flex; gap: 10px; align-items: center; }
.modal-sub { color: var(--text-muted); font-size: 12.5px; margin-bottom: 8px; font-family: var(--mono); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.seg button { background: var(--surface-2); border: 0; padding: 5px 12px; cursor: pointer; color: var(--text-muted); font-size: 12.5px; }
.seg button.active { background: var(--accent); color: #fff; }
.stream-view { flex: 1; overflow: auto; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px; font-family: var(--mono); font-size: 12px; white-space: pre-wrap; word-break: break-word; margin: 0; }
.stream-view .c2s { color: var(--accent); }
.stream-view .s2c { color: var(--ok); }
.opt-list { display: flex; flex-direction: column; gap: 10px; margin: 14px 0; }
.opt-list label { display: flex; gap: 8px; align-items: center; font-size: 13.5px; }
.modal-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 8px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 13px; z-index: 60; box-shadow: 0 6px 20px rgba(0,0,0,0.25); }

@media (max-width: 720px) {
  .brand .tagline { display: none; }
  .pkt-header-row, .pkt-row { grid-template-columns: 50px 120px 120px 120px 70px 60px 1fr; }
  .detail-split { flex-direction: column; }
}
