/* Xorra File — styles. Shell conventions are shared with the other tools;
   see xorra-web/docs/TOOLS-STYLE-GUIDE.md. */

/* Xorra brand fonts: light wordmark, heavy modifier (see xorra-web) */
@font-face {
  font-family: "Logo Light";
  src: url("Oxanium-ExtraLight.woff2") format("woff2");
  font-display: swap;
}

@font-face {
  font-family: "Logo Heavy";
  src: url("Oxanium-Bold.woff2") format("woff2");
  font-display: swap;
}

:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #16202b;
  --text-dim: #5b6875;
  --accent: #0d6efd;
  --brand-bar: #212529;
  --accent-text: #ffffff;
  --ok: #12a150;
  --border: #d7dee6;
  --shadow: 0 4px 24px rgb(16 32 48 / 0.08);
  --radius: 14px;
  --edited: #b35c00;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101418;
    --surface: #1a2027;
    --surface-2: #232b34;
    --text: #e8edf2;
    --text-dim: #93a1af;
    --accent: #3ea0ff;
    --accent-text: #06121f;
    --brand-bar: #16191d;
    --ok: #2fd379;
    --border: #2c3540;
    --shadow: 0 4px 24px rgb(0 0 0 / 0.35);
    --edited: #f2b46a;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding: 0 env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Dark brand bar, matching the navbar on www/tools.xorra.com */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: calc(0.9rem + env(safe-area-inset-top)) 1.2rem 0.9rem;
  flex-wrap: wrap;
  background: var(--brand-bar);
  color: #fff;
}

/* Brand cluster: "xorra tools" (hub link) | icon + tool name (tool home).
   font-family here sets the flex items' line-box struts: left to the body
   font (taller ascent than Oxanium), the hub link's box outgrows the tool
   link's and align-items:center skews the two text baselines apart. */
.brand {
  display: flex; align-items: center; gap: 0.75rem;
  font-size: 1.4rem; font-family: "Logo Heavy", sans-serif;
}
.brand-link { color: inherit; text-decoration: none; }
.brand-sep { width: 1px; height: 1.4em; background: rgb(255 255 255 / 0.35); flex: none; }
.tool-name { display: flex; align-items: center; gap: 0.35rem; }
/* Box-centered is optically low: Oxanium's caps sit high in its line box.
   Nudge to center the glyph on the cap-to-baseline band. */
.brand-icon { width: 1.2em; height: 1.2em; color: #fff; transform: translateY(-0.08em); }

.logo { font-family: "Logo Light", sans-serif; }
.logo-minor { font-family: "Logo Heavy", sans-serif; }

main {
  flex: 1;
  width: min(900px, 100%);
  margin: 0 auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.stage {
  position: relative;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 180px;
  padding: 1rem;
}

.stage-message { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; }
.stage-message p { margin: 0; }

.dropzone { cursor: pointer; border: 2px dashed var(--border); background: var(--surface); }
.dropzone.dragover { border-color: var(--accent); background: var(--surface-2); }
.dropzone:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.drop-icon { width: 44px; height: 44px; opacity: 0.6; }

/* Once a file lands, the dropzone shrinks to a slim strip — the whole
   window stays a drop target; the card is only the visual cue. */
.dropzone.compact { min-height: 0; padding: 0.45rem 1rem; }
.dropzone.compact .stage-message {
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
}
.dropzone.compact .drop-icon { display: none; }
.dropzone.compact p { font-size: 0.9rem; }
.dropzone.compact button.primary { padding: 0.3rem 1rem; font-size: 0.9rem; }
.dropzone.compact .drop-formats { display: none; }

/* Empty-state capabilities blurb: what renders natively, what's browsable.
   Quiet on purpose — the drop affordance stays dominant. */
.drop-formats {
  margin-top: 1rem;
  max-width: 42rem;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.drop-lede { margin: 0; }
/* .stage-message p zeroes margins with higher specificity; match it. */
.drop-formats .drop-groups-head { margin: 1rem 0 0; text-align: left; font-weight: 600; }
.drop-groups {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.3rem 1.25rem;
  margin: 0.4rem 0 0;
  text-align: left;
}
.drop-groups dt { font-weight: 600; white-space: nowrap; }
.drop-groups dd { margin: 0; }
@media (max-width: 560px) {
  .drop-groups { grid-template-columns: 1fr; gap: 0; }
  .drop-groups dd { margin-bottom: 0.4rem; }
}

button.primary {
  border: 0;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 700;
  padding: 0.55rem 1.4rem;
  border-radius: 999px;
  cursor: pointer;
}

button.primary:hover { filter: brightness(1.08); }
button.primary:active { transform: scale(0.97); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
}

#file-panel { display: flex; flex-direction: column; gap: 1rem; }
#file-panel[hidden] { display: none; }

.mono { font-family: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace; }

button.ghost {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  padding: 0.25rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
}

/* ------------------------------------------------------ identification */

#ident-card p { margin: 0; }
.ident-name { font-weight: 700; overflow-wrap: anywhere; }
.ident-size { color: var(--text-dim); font-size: 0.9rem; }
.ident-desc { margin-top: 0.5rem !important; }
.ident-mime { color: var(--text-dim); font-size: 0.9rem; overflow-wrap: anywhere; }
.ident-error { color: var(--text-dim); }

/* ---------------------------------------------------------- view tabs */

.view-tabs { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.view-tabs .chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font: inherit;
  font-weight: 600;
  padding: 0.35rem 1.1rem;
  border-radius: 999px;
  cursor: pointer;
}

.view-tabs .chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.view-note { color: var(--text-dim); margin: 0; }

/* --------------------------------------------------------- hex viewer */

.hex-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}

.hex-toolbar input,
.hex-toolbar select {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.hex-toolbar input.mono { font-family: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace; }
.hex-toolbar button { font-size: 0.85rem; }
.hex-toolbar button:disabled { opacity: 0.45; cursor: default; }
.hex-spring { flex: 1; }
.hex-status { color: var(--text-dim); }

.hex-scroller {
  position: relative;
  overflow: auto;
  height: min(60vh, 34rem); /* fallback; fitViewer() sizes to the viewport */
  background: var(--surface-2);
  border-radius: calc(var(--radius) - 6px);
}

/* Shared scroller affordances: an always-visible thin scrollbar, plus
   inset shadows (shade-top/-bottom classes, kept current by JS) hinting
   at content beyond the fold — overlay scrollbars often leave no cue
   that a listing continues. */
.hex-scroller, .strings-list, .browse-list, .text-scroller, .media-panel {
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--text-dim) 65%, transparent) transparent;
  --shade: rgb(16 32 48 / 0.28);
}

@media (prefers-color-scheme: dark) {
  .hex-scroller, .strings-list, .browse-list, .text-scroller, .media-panel {
    --shade: rgb(0 0 0 / 0.6);
  }
}

/* Firefox-only persistent scroll thumbs (see makeScrollThumb in app.js):
   Gecko's overlay scrollbars fade out and cannot be pinned via CSS. The
   wrap exists only on Firefox, and its scroller hides the native bars so
   they can't appear alongside the thumbs. */
.scroll-wrap { position: relative; min-height: 0; }
.scroll-wrap > .hex-scroller,
.scroll-wrap > .strings-list,
.scroll-wrap > .browse-list,
.scroll-wrap > .text-scroller,
.scroll-wrap > .media-panel { scrollbar-width: none; }

.scroll-thumb {
  position: absolute;
  top: 0;
  right: 3px;
  width: 6px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--text-dim) 55%, transparent);
  z-index: 1;
  touch-action: none;
}

.scroll-thumb-h {
  top: auto;
  right: auto;
  bottom: 3px;
  left: 0;
  height: 6px;
  width: auto;
}

.scroll-thumb:hover, .scroll-thumb.dragging {
  background: color-mix(in srgb, var(--text-dim) 85%, transparent);
}

.scroll-thumb:not(.scroll-thumb-h):hover,
.scroll-thumb:not(.scroll-thumb-h).dragging { width: 8px; }

.scroll-thumb-h:hover, .scroll-thumb-h.dragging { height: 8px; }

.shade-top { box-shadow: inset 0 16px 14px -14px var(--shade); }
.shade-bottom { box-shadow: inset 0 -16px 14px -14px var(--shade); }
.shade-top.shade-bottom {
  box-shadow: inset 0 16px 14px -14px var(--shade),
              inset 0 -16px 14px -14px var(--shade);
}

.hex-scroller:focus-visible { outline: 2px solid var(--accent); }

.hex-spacer { width: 1px; }

.hex-rows {
  position: absolute;
  top: 0;
  left: 0;
  min-width: 100%;
  width: max-content;
  will-change: transform;
  font-family: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
  font-size: 13px;
  cursor: default;
}

.hex-row {
  display: flex;
  gap: 2ch;
  height: 20px; /* must match ROW_HEIGHT in hexview.js */
  line-height: 20px;
  padding: 0 0.75rem;
}

.hex-off { color: var(--text-dim); }

.hex-bytes { display: flex; }
.hb { width: 2ch; margin-right: 1ch; text-align: center; }
.hb:nth-child(8) { margin-right: 2ch; }
.hb:last-child { margin-right: 0; }

.hex-ascii { display: flex; }
.ha { width: 1ch; text-align: center; }

.hb.edited, .ha.edited { color: var(--edited); font-weight: 700; }

.hb.sel, .ha.sel {
  background: color-mix(in srgb, var(--accent) 25%, transparent);
  border-radius: 3px;
}

.hb.sel-active, .ha.sel-active {
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 3px;
}

/* ------------------------------------------------------------ strings */

.strings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.strings-status { margin: 0; color: var(--text-dim); font-size: 0.9rem; }

.strings-list {
  height: min(60vh, 34rem); /* fallback; fitViewer() sizes to the viewport */
  overflow: auto;
  background: var(--surface-2);
  border-radius: calc(var(--radius) - 6px);
  font-size: 13px;
  padding: 0.25rem 0;
}

.strings-row {
  display: flex;
  gap: 1rem;
  padding: 0 0.75rem;
  white-space: pre;
}

.strings-offset { color: var(--text-dim); flex: none; }

/* ------------------------------------------------- text / media views */

/* Text toolbar: Formatted|Raw chips (JSON), encoding, wrap, status. */
.text-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}

.text-bar [hidden] { display: none !important; }

.text-encoding {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.text-wrap {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--text-dim);
}

.text-scroller {
  height: min(60vh, 34rem); /* fallback; fitViewer() sizes to the viewport */
  overflow: auto;
  background: var(--surface-2);
  border-radius: calc(var(--radius) - 6px);
  padding: 0.25rem 0;
}

.text-scroller:focus-visible { outline: 2px solid var(--accent); }
.text-scroller > [hidden] { display: none !important; }

.text-pre {
  margin: 0;
  padding: 0.25rem 0.75rem;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.text-scroller.nowrap .text-pre { white-space: pre; overflow-wrap: normal; }

/* Formatted JSON tokens, on the existing theme palette. */
.json-key { color: var(--accent); }
.json-str { color: var(--ok); }
.json-num { color: var(--edited); }
.json-lit { color: var(--text-dim); font-weight: 600; }

.media-status { margin-bottom: 0.5rem; }

/* Flex + margin:auto centers small content but keeps oversized content
   reachable by scrolling (justify/align center would clip its start). */
.media-panel {
  height: min(60vh, 34rem); /* fallback; fitViewer() sizes to the viewport */
  overflow: auto;
  background: var(--surface-2);
  border-radius: calc(var(--radius) - 6px);
  display: flex;
}

.media-image,
.media-panel > button { margin: auto; }

.media-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  cursor: zoom-in;
  /* checkerboard so transparency reads as transparency */
  background:
    repeating-conic-gradient(rgb(128 128 128 / 0.18) 0% 25%, transparent 0% 50%)
    0 0 / 16px 16px;
}

.media-image.zoomed {
  max-width: none;
  max-height: none;
  cursor: zoom-out;
}

.pdf-frame { flex: 1; border: 0; display: block; }

/* ------------------------------------------------- breadcrumbs + browse */

.crumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem;
  font-size: 0.9rem;
}

.crumb {
  border: 0;
  background: none;
  padding: 0.1rem 0.3rem;
  font: inherit;
  color: var(--accent);
  cursor: pointer;
  border-radius: 6px;
  overflow-wrap: anywhere;
}

button.crumb:hover { background: var(--surface-2); }
.crumb-here { color: var(--text-dim); cursor: default; }
.crumb-sep { color: var(--text-dim); }

.browse-list {
  height: min(60vh, 34rem); /* fallback; fitViewer() sizes to the viewport */
  overflow: auto;
  background: var(--surface-2);
  border-radius: calc(var(--radius) - 6px);
  padding: 0.25rem 0;
  display: flex;
  flex-direction: column;
}

/* Browse toolbar: mode chips, filter, ZIP download, status. */
.browse-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}

.browse-bar [hidden] { display: none !important; }

.browse-modes { display: flex; gap: 0.35rem; }

.browse-modes .chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.2rem 0.8rem;
  border-radius: 999px;
  cursor: pointer;
}

.browse-modes .chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.browse-filter {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.25rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  width: 14ch;
}

.browse-filter:focus { outline: 2px solid var(--accent); border-color: var(--accent); }

.browse-bar button.ghost { font-size: 0.85rem; }

.browse-row.selected {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  outline: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: -1px;
}

/* Dimmed directory prefix on All-files rows; clickable. */
.browse-path { color: var(--text-dim); }
.browse-path:hover { color: var(--accent); text-decoration: underline; }

.browse-more { justify-content: center; color: var(--accent); font-weight: 600; }

.browse-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.3rem 0.75rem;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
}

.browse-row:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.browse-row:disabled { color: var(--text-dim); cursor: default; }

.browse-icon { width: 1.1em; height: 1.1em; flex: none; color: var(--text-dim); }
.browse-name { overflow-wrap: anywhere; }
.browse-detail { color: var(--text-dim); font-size: 0.8rem; overflow-wrap: anywhere; }
.browse-size { margin-left: auto; color: var(--text-dim); white-space: nowrap; }
.browse-mtime { color: var(--text-dim); white-space: nowrap; font-size: 0.8rem; }
.browse-empty { padding: 0.5rem 0.75rem; }

.ident-save { margin-top: 0.6rem; }

@media (max-width: 480px) {
  .browse-mtime { display: none; }
}

/* Static prose pages (attributions.html) */
.prose { display: block; }
.prose h1 { font-size: 1.5rem; margin: 0.5rem 0; }
.prose h2 { font-size: 1.15rem; margin: 1.5rem 0 0.5rem; }
.prose a { color: var(--accent); }

.prose details {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 1rem;
  margin: 0.6rem 0;
}

.prose summary { cursor: pointer; font-weight: 600; }
.prose .src { font-size: 0.85rem; color: var(--text-dim); margin: 0.6rem 0 0.2rem; }

.prose pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin: 0.4rem 0 0.2rem;
}

footer {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.8rem;
  padding: 0.8rem 1rem 1.2rem;
}

footer p { margin: 0; }
footer a { color: var(--text-dim); }
footer .made-in { margin-top: 0.4rem; }
footer .colorado { width: 30px; vertical-align: -4px; }

@media (max-width: 480px) {
  header { padding: 0.7rem 0.9rem; }
}
