/* ---------------------------------------------------------------------------
   Design tokens — the retint surface.

   Everything hub-specific lives in this block. To match ffadzlia.app, replace
   these values and nothing else; no rule below hard-codes a colour, font or
   radius.
   --------------------------------------------------------------------------- */

:root {
  color-scheme: light dark;

  --bg: #f2f4f7;
  --surface: #ffffff;
  --surface-sunken: #f7f8fa;
  --text: #152033;
  --muted: #5b667a;
  --faint: #8b95a8;
  --border: rgba(21, 32, 51, 0.10);
  --border-strong: rgba(21, 32, 51, 0.18);

  --accent: #1d4f91;
  --accent-ink: #ffffff;
  --accent-soft: rgba(29, 79, 145, 0.08);
  --grid-line: rgba(29, 79, 145, 0.06);

  --ok: #0a7c4a;
  --warn: #8a5a00;
  --warn-soft: rgba(170, 115, 0, 0.10);
  --danger: #b42318;
  --danger-soft: rgba(180, 35, 24, 0.08);

  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;

  --r-lg: 8px;
  --r: 6px;
  --r-sm: 4px;

  --topbar: 48px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1018;
    --surface: #121826;
    --surface-sunken: #0e1420;
    --text: #e6ebf3;
    --muted: #9aa6b8;
    --faint: #6d7a8f;
    --border: rgba(230, 235, 243, 0.08);
    --border-strong: rgba(230, 235, 243, 0.14);

    --accent: #6ea0e0;
    --accent-ink: #0b1018;
    --accent-soft: rgba(110, 160, 224, 0.12);
    --grid-line: rgba(110, 160, 224, 0.07);

    --ok: #46c98a;
    --warn: #dda54c;
    --warn-soft: rgba(221, 165, 76, 0.12);
    --danger: #ff8f80;
    --danger-soft: rgba(255, 143, 128, 0.11);
  }
}

/* --------------------------------------------------------------------------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background-color: var(--bg);
  background-image:
    linear-gradient(180deg, var(--accent-soft), transparent 220px),
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: auto, 24px 24px, 24px 24px;
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* --- shell ---------------------------------------------------------------- */

.app {
  display: grid;
  grid-template-rows: var(--topbar) 1fr;
  height: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(6px);
}

.back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: var(--r-sm);
  color: var(--muted);
  text-decoration: none;
  transition: background 120ms ease, color 120ms ease;
}

.back:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.wordmark {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.01em;
  margin: 0;
}

.wordmark span {
  color: var(--faint);
  padding: 0 2px;
}

.engine {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-left: auto;
  font-size: 11px;
  font-family: var(--mono);
  color: var(--muted);
  text-transform: lowercase;
}

.engine i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--faint);
  flex: 0 0 auto;
}

.engine[data-state="ready"] i {
  background: var(--ok);
}

.engine[data-state="busy"] i {
  background: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}

.engine[data-state="error"] i {
  background: var(--danger);
}

@keyframes pulse {
  50% {
    opacity: 0.25;
  }
}

/* --- 30 / 70 workspace ---------------------------------------------------- */

.workspace {
  display: grid;
  grid-template-columns: 30% 70%;
  min-height: 0;
}

.pane-left {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border-right: 1px solid var(--border);
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}

.pane-right {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--surface-sunken);
}

/* --- brand ---------------------------------------------------------------- */

.brand {
  padding: 2px 2px 0;
  flex: 0 0 auto;
}

.brand-kicker {
  margin: 0 0 6px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
}

.brand-title {
  margin: 0 0 4px;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.brand-sub {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.45;
}

/* --- 50 / 50 stack (dropzone + file props) -------------------------------- */

.stack {
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 12px;
  flex: 1 1 auto;
  min-height: 0;
}

/* --- dropzone ------------------------------------------------------------- */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 0;
  height: 100%;
  padding: 20px;
  background:
    linear-gradient(180deg, var(--accent-soft), transparent 70%),
    var(--surface-sunken);
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-lg);
  text-align: center;
  transition: border-color 120ms ease, background 120ms ease;
}

.dropzone:hover:not([aria-disabled="true"]) {
  border-color: var(--accent);
}

.dropzone.is-dragging {
  border-color: var(--accent);
  border-style: solid;
  background:
    linear-gradient(180deg, var(--accent-soft), transparent 50%),
    var(--surface-sunken);
}

.dropzone[aria-disabled="true"] {
  opacity: 0.55;
  pointer-events: none;
}

.dropzone strong {
  font-size: 15px;
  font-weight: 550;
}

.dropzone small {
  color: var(--muted);
  font-size: 12.5px;
}

.dropzone-mark {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: var(--r-sm);
  padding: 4px 8px;
  margin-bottom: 8px;
}

/* --- file properties panel ------------------------------------------------ */

.props {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface-sunken);
  overflow: hidden;
}

.props-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 1;
  padding: 20px;
  text-align: center;
}

.props-empty p {
  margin: 0;
  font-size: 13px;
  font-weight: 550;
  color: var(--muted);
}

.props-empty small {
  color: var(--faint);
  font-size: 12px;
  line-height: 1.45;
  max-width: 28ch;
}

.props-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px;
}

/* --- file + metadata ------------------------------------------------------ */

.file {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
}

.file strong {
  font-size: 13px;
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.file span {
  color: var(--muted);
  font-size: 12px;
  font-family: var(--mono);
  flex: 0 0 auto;
}

.file button {
  margin-left: auto;
  flex: 0 0 auto;
  background: none;
  border: 0;
  padding: 2px 4px;
  color: var(--muted);
  font-size: 12px;
  border-radius: var(--r-sm);
}

.file button:hover {
  color: var(--danger);
}

.meta {
  display: grid;
  gap: 1px;
  margin: 0;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
}

.meta div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  background: var(--surface);
}

.meta dt {
  color: var(--muted);
  font-size: 12px;
}

.meta dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  text-align: right;
}

.meta dd[data-type="Scanned"],
.meta dd[data-type="ImageBased"] {
  color: var(--warn);
}

.meta dd[data-type="TextBased"] {
  color: var(--ok);
}

.structure {
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 10px 12px;
  background: var(--surface);
}

.structure h2 {
  margin: 0 0 8px;
  font-size: 10px;
  font-family: var(--mono);
  font-weight: 500;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--faint);
}

.structure ul {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.structure li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.structure b {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 550;
  color: var(--text);
}

.structure li[data-zero="true"] b {
  color: var(--faint);
}

.trust {
  margin-top: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-top: 0;
  flex: 0 0 auto;
}

.trust span {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--faint);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 9px;
  background: var(--surface-sunken);
}

/* --- unlock --------------------------------------------------------------- */

.unlock {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 12px;
  background: var(--warn-soft);
  border: 1px solid color-mix(in srgb, var(--warn) 28%, transparent);
  border-radius: var(--r);
}

.unlock label {
  font-size: 12.5px;
  font-weight: 550;
  color: var(--warn);
}

.unlock div {
  display: flex;
  gap: 6px;
}

.unlock input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 13px;
  padding: 6px 9px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
}

.unlock input::placeholder {
  color: var(--faint);
}

.unlock button {
  flex: 0 0 auto;
  padding: 6px 12px;
  font-size: 12.5px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
}

.unlock button:hover {
  border-color: var(--warn);
  color: var(--warn);
}

.unlock small {
  font-size: 11px;
  color: var(--muted);
}

/* --- decrypt -------------------------------------------------------------- */

.decrypt {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--r);
}

.decrypt p {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
}

.decrypt button {
  padding: 7px 12px;
  font-size: 12.5px;
  font-weight: 550;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  transition: border-color 120ms ease, color 120ms ease, opacity 120ms ease;
}

.decrypt button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.decrypt button:disabled {
  opacity: 0.55;
  cursor: progress;
}

/* --- notices -------------------------------------------------------------- */

.notice {
  padding: 10px 12px;
  border-radius: var(--r);
  font-size: 12.5px;
  border: 1px solid transparent;
}

.notice[data-tone="info"] {
  color: var(--muted);
  padding: 0;
}

.notice[data-tone="warn"] {
  color: var(--warn);
  background: var(--warn-soft);
  border-color: color-mix(in srgb, var(--warn) 25%, transparent);
}

.notice[data-tone="error"] {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 25%, transparent);
}

/* --- result pane ---------------------------------------------------------- */

.result-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  min-height: 48px;
}

.tabs {
  display: inline-flex;
  padding: 2px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--r);
}

.tabs button {
  border: 0;
  background: none;
  padding: 4px 12px;
  border-radius: var(--r-sm);
  font-size: 12.5px;
  color: var(--muted);
  transition: background 120ms ease, color 120ms ease;
}

.tabs button[aria-selected="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.actions {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

.actions button {
  padding: 5px 11px;
  font-size: 12.5px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  transition: background 120ms ease, border-color 120ms ease, opacity 120ms ease;
}

.actions button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.actions button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.actions button[data-variant="primary"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.actions button[data-variant="primary"]:hover:not(:disabled) {
  color: var(--accent-ink);
  filter: brightness(1.08);
}

.progress {
  height: 2px;
  background: var(--border);
  overflow: hidden;
}

.progress i {
  display: block;
  height: 100%;
  width: 35%;
  background: var(--accent);
  animation: slide 1.1s ease-in-out infinite;
}

@keyframes slide {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(400%);
  }
}

.output {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 20px 24px 48px;
}

.source {
  margin: 0;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 1;
  color: var(--faint);
  text-align: center;
  padding: 24px;
}

.empty code {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--faint);
}

/* --- rendered markdown ---------------------------------------------------- */

.rendered {
  max-width: 74ch;
  font-size: 14px;
  line-height: 1.65;
}

.rendered > *:first-child {
  margin-top: 0;
}

.rendered h1,
.rendered h2,
.rendered h3,
.rendered h4,
.rendered h5,
.rendered h6 {
  line-height: 1.3;
  margin: 1.6em 0 0.5em;
  font-weight: 600;
}

.rendered h1 {
  font-size: 1.5em;
  letter-spacing: -0.015em;
}

.rendered h2 {
  font-size: 1.24em;
  letter-spacing: -0.01em;
}

.rendered h3 {
  font-size: 1.08em;
}

.rendered h4,
.rendered h5,
.rendered h6 {
  font-size: 1em;
  color: var(--muted);
}

.rendered p {
  margin: 0 0 0.9em;
}

.rendered ul,
.rendered ol {
  margin: 0 0 0.9em;
  padding-left: 1.4em;
}

.rendered li {
  margin-bottom: 0.25em;
}

.rendered a {
  color: var(--accent);
  text-underline-offset: 2px;
}

.rendered code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--accent-soft);
  padding: 0.12em 0.36em;
  border-radius: var(--r-sm);
}

.rendered pre {
  margin: 0 0 1em;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow-x: auto;
}

.rendered pre code {
  background: none;
  padding: 0;
  font-size: 12.5px;
  line-height: 1.6;
}

.rendered blockquote {
  margin: 0 0 1em;
  padding-left: 14px;
  border-left: 2px solid var(--border-strong);
  color: var(--muted);
}

.rendered hr {
  margin: 1.6em 0;
  border: 0;
  border-top: 1px solid var(--border);
}

.rendered img {
  max-width: 100%;
  height: auto;
  border-radius: var(--r-sm);
}

.table-scroll {
  overflow-x: auto;
  margin: 0 0 1em;
  border: 1px solid var(--border);
  border-radius: var(--r);
}

.rendered table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}

.rendered th,
.rendered td {
  padding: 7px 11px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.rendered th {
  background: var(--surface);
  font-weight: 600;
  white-space: nowrap;
}

.rendered tbody tr:last-child td {
  border-bottom: 0;
}

/* --- responsive ----------------------------------------------------------- */

@media (max-width: 900px) {
  body {
    overflow: auto;
  }

  .app {
    height: auto;
    min-height: 100%;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .pane-left {
    border-right: 0;
    border-bottom: 1px solid var(--border);
    overflow: visible;
  }

  .stack {
    grid-template-rows: minmax(160px, 1fr) minmax(160px, 1fr);
    min-height: 360px;
  }

  .pane-right {
    min-height: 60vh;
  }

  .result-bar {
    position: sticky;
    top: 0;
    z-index: 1;
    flex-wrap: wrap;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
