:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --bg-elev: #12151a;
  --bg-elev-2: #191d24;
  --border: #262b33;
  --text: #d7dce2;
  --text-dim: #8890a0;
  --text-faint: #5a6070;
  --accent: #4fd1c5;
  --accent-dim: #2a5a55;
  --accent-text: #06120f;
  --warn: #e0a84b;
  --bad: #e0654f;
  --info: #5a9be0;
  --ok: #5fd08a;
  --mono: "SF Mono", "JetBrains Mono", "Fira Code", ui-monospace, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --radius: 8px;
  --sidebar-w: 230px;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f6f8;
  --bg-elev: #ffffff;
  --bg-elev-2: #eceff2;
  --border: #dde1e6;
  --text: #1b1f24;
  --text-dim: #565f6b;
  --text-faint: #8790a0;
  --accent: #147d73;
  --accent-dim: #cdeeea;
  --accent-text: #ffffff;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f5f6f8;
    --bg-elev: #ffffff;
    --bg-elev-2: #eceff2;
    --border: #dde1e6;
    --text: #1b1f24;
    --text-dim: #565f6b;
    --text-faint: #8790a0;
    --accent: #147d73;
    --accent-dim: #cdeeea;
    --accent-text: #ffffff;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  overflow: hidden;
}
#app { height: 100dvh; display: flex; flex-direction: column; }

.muted { color: var(--text-dim); }
.small { font-size: 0.85em; }
a { color: var(--accent); }
code, .mono { font-family: var(--mono); }

/* ---------- topbar ---------- */
#topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  flex: 0 0 auto;
  min-height: 52px;
}
#brand {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
#brand span { color: var(--accent); }
#fileInfo {
  font-family: var(--mono);
  font-size: 0.82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#topbarSpacer { flex: 1; }

.iconBtn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  width: 36px;
  height: 36px;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: 0 0 auto;
}
.hamburger, .hamburger::before, .hamburger::after {
  content: "";
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
  position: relative;
}
.hamburger::before { position: absolute; top: -6px; }
.hamburger::after { position: absolute; top: 6px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  white-space: nowrap;
  user-select: none;
}
.btn.primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
  font-weight: 600;
}
.btn:hover { filter: brightness(1.1); }

/* ---------- layout ---------- */
#layout { flex: 1 1 auto; display: flex; min-height: 0; }

#sidebar {
  flex: 0 0 var(--sidebar-w);
  border-right: 1px solid var(--border);
  background: var(--bg-elev);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
#tabList { list-style: none; margin: 0; padding: 8px; flex: 1; }
.tab {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-bottom: 2px;
}
.tab:hover { background: var(--bg-elev-2); color: var(--text); }
.tab.active { background: var(--accent-dim); color: var(--accent); font-weight: 600; }
.tabIcon { width: 1.4em; text-align: center; opacity: 0.8; font-size: 0.95em; }
.tab.disabled { opacity: 0.4; pointer-events: none; }

#sidebarFooter {
  padding: 12px;
  font-size: 0.72rem;
  line-height: 1.4;
  color: var(--text-faint);
  border-top: 1px solid var(--border);
}
#sidebarScrim { display: none; }

#main {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* ---------- drop zone ---------- */
#dropZone {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  padding: 24px;
}
#dropZoneInner {
  border: 2px dashed var(--border);
  border-radius: 16px;
  padding: 48px 32px;
  text-align: center;
  color: var(--text-dim);
  max-width: 420px;
}
.dropIcon { font-size: 2rem; margin-bottom: 8px; color: var(--accent); }
#app.file-loaded #dropZone { display: none; }
#app.drag-over #dropZoneInner { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }

/* ---------- panels ---------- */
.panel {
  display: none;
  padding: 20px 24px 60px;
  overflow: auto;
  flex: 1 1 auto;
  min-height: 0;
}
.panel.active { display: flex; flex-direction: column; }
#app:not(.file-loaded) .panel.active { display: none; }

.panelHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.panelHeader h2 { margin: 0; font-size: 1.15rem; }

/* ---------- generic components ---------- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.cardGrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border-bottom: 1px solid var(--border); font-size: 0.85rem; }
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--text-dim); }
.kv .v { font-family: var(--mono); text-align: right; word-break: break-all; }

.tableWrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table.dataTable { border-collapse: collapse; width: 100%; font-size: 0.83rem; }
table.dataTable th, table.dataTable td {
  padding: 7px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  font-family: var(--mono);
}
table.dataTable th {
  background: var(--bg-elev-2);
  color: var(--text-dim);
  font-family: var(--sans);
  position: sticky;
  top: 0;
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
table.dataTable tbody tr:hover { background: var(--bg-elev-2); }
table.dataTable tbody tr.clickable { cursor: pointer; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  font-family: var(--sans);
}
.badge.ok { background: rgba(95,208,138,0.15); color: var(--ok); }
.badge.info { background: rgba(90,155,224,0.15); color: var(--info); }
.badge.warn { background: rgba(224,168,75,0.15); color: var(--warn); }
.badge.bad { background: rgba(224,101,79,0.15); color: var(--bad); }

.emptyState { color: var(--text-faint); padding: 40px 0; text-align: center; }

/* entropy bar */
.entropyBar { display: flex; align-items: center; gap: 8px; min-width: 140px; }
.entropyTrack { flex: 1; height: 6px; background: var(--bg-elev-2); border-radius: 4px; overflow: hidden; }
.entropyFill { height: 100%; background: var(--ok); }
.entropyFill.warn { background: var(--warn); }
.entropyFill.bad { background: var(--bad); }

/* findings list */
.finding {
  display: flex;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  background: var(--bg-elev);
}
.finding .sev {
  flex: 0 0 auto;
  width: 8px;
  border-radius: 4px;
  align-self: stretch;
}
.finding.bad .sev { background: var(--bad); }
.finding.warn .sev { background: var(--warn); }
.finding.info .sev { background: var(--info); }
.finding.ok .sev { background: var(--ok); }
.finding .body { flex: 1; }
.finding .title { font-weight: 600; margin-bottom: 3px; }
.finding .detail { color: var(--text-dim); font-size: 0.85rem; line-height: 1.4; }

/* ---------- hex view ---------- */
#hexToolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
#hexToolbar input[type="text"], #hexToolbar select {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-family: var(--mono);
  font-size: 0.82rem;
}
#hexScroller {
  flex: 1;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev);
}
#hexContent {
  font-family: var(--mono);
  font-size: 0.8rem;
  white-space: pre;
  padding: 8px 0;
}
.hexRow { display: flex; padding: 0 12px; }
.hexRow:hover { background: var(--bg-elev-2); }
.hexOffset { color: var(--accent); width: 9ch; flex: 0 0 auto; }
.hexBytes { flex: 0 0 auto; padding: 0 14px; color: var(--text); letter-spacing: 1px; }
.hexBytes .zero { color: var(--text-faint); }
.hexAscii { color: var(--text-dim); border-left: 1px solid var(--border); padding-left: 14px; }
.hexAscii .p { color: var(--text); }

/* ---------- strings ---------- */
#stringsToolbar { display: flex; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; align-items: center; }

/* ---------- disasm ---------- */
.disasmLayout { display: flex; gap: 16px; flex: 1; min-height: 0; }
.funcListCol { flex: 0 0 240px; display: flex; flex-direction: column; min-height: 0; }
.disasmCol { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.funcSearch { margin-bottom: 8px; }
.funcList { overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius); flex: 1; }
.funcItem { padding: 8px 10px; border-bottom: 1px solid var(--border); cursor: pointer; font-family: var(--mono); font-size: 0.8rem; }
.funcItem:last-child { border-bottom: none; }
.funcItem:hover { background: var(--bg-elev-2); }
.funcItem.selected { background: var(--accent-dim); color: var(--accent); }
.funcItem .fname { display: block; }
.funcItem .faddr { color: var(--text-faint); font-size: 0.75rem; }

#disasmListing {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev);
  font-family: var(--mono);
  font-size: 0.8rem;
  flex: 1;
  min-height: 0;
}
.insnRow { display: flex; padding: 3px 12px; white-space: nowrap; }
.insnRow:hover { background: var(--bg-elev-2); }
.insnRow.branchTarget { border-left: 2px solid var(--accent); }
.insnAddr { color: var(--accent); width: 11ch; flex: 0 0 auto; }
.insnBytes { color: var(--text-faint); width: 22ch; flex: 0 0 auto; }
.insnMnem { color: #c48fe0; width: 8ch; flex: 0 0 auto; }
.insnOps { color: var(--text); }
.insnOps .imm { color: var(--info); }
.insnOps .reg { color: var(--ok); }
.insnComment { color: var(--text-faint); margin-left: 14px; }

/* ---------- cfg ---------- */
#cfgToolbar { display: flex; gap: 10px; margin-bottom: 10px; align-items: center; }
#cfgCanvasWrap {
  flex: 1;
  min-height: 300px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  background: var(--bg-elev);
  touch-action: none;
}
#cfgSvg { width: 100%; height: 100%; cursor: grab; }
#cfgSvg.dragging { cursor: grabbing; }
.cfgBlock rect { fill: var(--bg-elev-2); stroke: var(--border); }
.cfgBlock:hover rect { stroke: var(--accent); }
.cfgBlock text { fill: var(--text); font-family: var(--mono); }
.cfgBlock .blockTitle { fill: var(--accent); font-weight: 600; }
.cfgEdge { fill: none; stroke-width: 1.6; }
.cfgEdge.fallthrough { stroke: var(--text-faint); }
.cfgEdge.taken { stroke: var(--ok); }
.cfgEdge.nottaken { stroke: var(--bad); }
.cfgEdge.uncond { stroke: var(--info); }

/* ---------- decompile ---------- */
#decompileOutput {
  font-family: var(--mono);
  font-size: 0.83rem;
  white-space: pre;
  overflow: auto;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  flex: 1;
  line-height: 1.5;
}
.decompileNotice {
  font-size: 0.78rem;
  color: var(--text-faint);
  margin-bottom: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev-2);
}
.kw { color: #c48fe0; }
.cmt { color: var(--text-faint); }
.fn { color: var(--info); }
.num { color: var(--ok); }

.loadingRow { padding: 20px; text-align: center; color: var(--text-dim); }

/* ---------- scrollbars ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ============ responsive / mobile ============ */
@media (max-width: 880px) {
  :root { --sidebar-w: 240px; }
  .iconBtn { display: flex; }
  #brand { font-size: 0.95rem; }
  #fileInfo { display: none; }

  #sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 2px 0 16px rgba(0,0,0,0.4);
  }
  #app.sidebar-open #sidebar { transform: translateX(0); }
  #app.sidebar-open #sidebarScrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 20;
  }

  .panel { padding: 14px 14px 50px; }
  .disasmLayout { flex-direction: column; }
  .funcListCol { flex: 0 0 auto; max-height: 200px; }
  .funcList { max-height: 160px; }

  .cardGrid { grid-template-columns: 1fr; }
  .panelHeader h2 { font-size: 1rem; }
}

@media (max-width: 480px) {
  #topbar { padding: 8px 10px; gap: 8px; }
  .btn { padding: 7px 10px; font-size: 0.8rem; }
  .panel { padding: 10px 10px 44px; }
}
