/* FinBot Audit Web — technical brutalism, native mobile shell
   Palette: #000 / #FFF / #FF5E00 */

:root {
  --bg: #000000;
  --surface: #000000;
  --text: #ffffff;
  --muted: #aaaaaa;
  --accent: #ff5e00;
  --accent-dark: #cc4b00;
  --danger: #ff5e00;
  --border: #ffffff;
  --border-dim: #444444;
  --radius: 0;
  --nav-h: 56px;
  --header-h: 64px;
  --composer-h: 48px;
  --control-h: 48px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  font-family: "IBM Plex Mono", "JetBrains Mono", "Space Mono", ui-monospace, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0;
  min-height: 100dvh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
}

body.is-authenticated {
  overflow: hidden;
}

/* ── Auth gate (critical — works before JS) ───────────────────────────── */
#login-screen {
  display: flex;
  min-height: 100dvh;
  width: 100%;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-top)) calc(16px + var(--safe-right))
           calc(24px + var(--safe-bottom)) calc(16px + var(--safe-left));
  background: var(--bg);
}

#app-shell {
  display: none;
  width: 100%;
  max-width: 100%;
  height: 100dvh;
  min-height: 100dvh;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  padding-top: var(--safe-top);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

body.is-authenticated #login-screen {
  display: none !important;
}

body.is-authenticated #app-shell {
  display: flex !important;
}

body:not(.is-authenticated) #app-shell {
  display: none !important;
}

body:not(.is-authenticated) #login-screen {
  display: flex !important;
}

/* ── Login ─────────────────────────────────────────────────────────────── */
.login-card {
  width: 100%;
  max-width: 400px;
}

.login-card h2 {
  margin: 0 0 8px;
  font-size: 1rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.login-card .field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 14px 0 0;
}

.login-card .field span {
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.login-error {
  color: var(--danger);
  margin: 0 0 8px;
  font-size: 0.8rem;
}

/* ── App shell ─────────────────────────────────────────────────────────── */
.top-bar {
  flex-shrink: 0;
  padding: 12px 16px;
  min-height: var(--header-h);
  background: var(--bg);
  border-bottom: 2px solid var(--accent);
}

.top-bar h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.top-bar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.app-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  width: 100%;
}

.panel {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  width: 100%;
  overflow: hidden;
}

.panel.active {
  display: flex;
}

.panel-scroll {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 12px 16px;
  width: 100%;
}

/* ── Cards & typography ────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 14px 16px;
  margin-bottom: 12px;
  width: 100%;
}

.card h2, .card h3 {
  margin: 0 0 8px;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.muted { color: var(--muted); font-size: 0.8rem; }

/* ── Controls (unified height) ─────────────────────────────────────────── */
.btn,
input[type="text"],
input[type="password"],
select.field-control,
.composer-bar input,
.composer-bar button,
.lang-toggle button {
  min-height: var(--control-h);
  height: var(--control-h);
  line-height: 1.2;
  font-family: inherit;
  font-size: 0.8rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  border: 2px solid var(--accent);
  background: var(--accent);
  color: #000000;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  width: 100%;
  margin-top: 8px;
}

.btn:active { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn.secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

.btn.secondary:active { background: #111111; }

.btn.small {
  min-height: 40px;
  height: 40px;
  font-size: 0.7rem;
  width: auto;
  margin-top: 0;
  padding: 0 12px;
  white-space: nowrap;
  flex-shrink: 0;
}

.field-control,
select.field-control {
  width: 100%;
  padding: 0 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  appearance: none;
  margin: 8px 0 12px;
}

input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 0 14px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

input[type="text"]:focus,
input[type="password"]:focus,
.field-control:focus,
.composer-bar input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.lang-toggle {
  display: flex;
  gap: 0;
  margin-top: 8px;
  border: 1px solid var(--border);
  width: 100%;
}

.lang-toggle button {
  flex: 1;
  border: none;
  border-right: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}

.lang-toggle button:last-child { border-right: none; }
.lang-toggle button.active { background: var(--accent); color: #000000; }

/* ── Chat & discovery ──────────────────────────────────────────────────── */
.chat-log {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.chat-log.compact {
  max-height: 240px;
  border: 1px solid var(--border-dim);
  padding: 8px;
  overflow-y: auto;
}

.bubble {
  max-width: 92%;
  padding: 12px 14px;
  font-size: 0.85rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid var(--border);
}

.bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: #000000;
  border-color: var(--accent);
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--bg);
  color: var(--text);
}

.composer-bar,
.chat-input-row {
  flex-shrink: 0;
  display: flex;
  width: 100%;
  gap: 0;
  border-top: 1px solid var(--border);
  background: var(--bg);
  padding-bottom: var(--safe-bottom);
}

.composer-bar input,
.chat-input-row input {
  flex: 1;
  min-width: 0;
  border: none;
  border-right: 1px solid var(--border);
  border-radius: 0;
  margin: 0;
}

.composer-bar button,
.chat-input-row button {
  flex-shrink: 0;
  min-width: 80px;
  border: none;
  background: var(--accent);
  color: #000000;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  margin: 0;
  padding: 0 14px;
}

.composer-bar[hidden],
.chat-input-row[hidden] {
  display: none !important;
}

.discovery-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 16px 8px;
  width: 100%;
}

#discovery-active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

#discovery-active[hidden] {
  display: none !important;
}

#discovery-active .panel-scroll {
  padding-bottom: 0;
}

/* ── Reports ───────────────────────────────────────────────────────────── */
.run-group { margin-bottom: 16px; width: 100%; }

.run-group h3 {
  font-size: 0.7rem;
  color: var(--accent);
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.report-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-dim);
  width: 100%;
}

.report-row:last-child { border-bottom: none; }

.report-meta {
  min-width: 0;
  overflow: hidden;
}

.report-name {
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  display: inline-block;
  margin-top: 4px;
  font-size: 0.65rem;
  padding: 2px 6px;
  border: 1px solid var(--border);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ── Workbooks list ────────────────────────────────────────────────────── */
#workbooks-list {
  list-style: none;
  margin: 0;
  padding: 0;
  width: 100%;
}

#workbooks-list li {
  padding: 10px 0;
  border-bottom: 1px solid var(--border-dim);
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#workbooks-list li:last-child { border-bottom: none; }

/* ── Bottom nav ────────────────────────────────────────────────────────── */
.bottom-nav {
  flex-shrink: 0;
  width: 100%;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: var(--bg);
  border-top: 2px solid var(--accent);
  z-index: 100;
}

.bottom-nav button {
  flex: 1;
  min-width: 0;
  border: none;
  border-right: 1px solid var(--border-dim);
  background: transparent;
  color: var(--muted);
  font-size: 0.55rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  padding: 4px 2px 0;
}

.bottom-nav button:last-child { border-right: none; }
.bottom-nav button .icon { font-size: 1.1rem; filter: grayscale(1); line-height: 1; }
.bottom-nav button span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.bottom-nav button.active {
  color: var(--accent);
  background: #0a0a0a;
}

.bottom-nav button.active .icon { filter: none; }

/* ── Misc ──────────────────────────────────────────────────────────────── */
.status-pill {
  display: inline-block;
  padding: 4px 8px;
  border: 1px solid var(--border);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.status-pill.running { border-color: var(--accent); color: var(--accent); }
.status-pill.completed { border-color: var(--text); color: var(--text); }
.status-pill.failed { border-color: var(--accent); color: var(--accent); background: #1a0a00; }

.security-banner {
  background: var(--bg);
  border: 1px solid var(--accent);
  padding: 12px 14px;
  font-size: 0.8rem;
  line-height: 1.5;
}

input[type="file"] { display: none; }

.question-card { border-left: 4px solid var(--accent); }

.question-card .severity {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 8px;
  border: 1px solid var(--accent);
  margin-bottom: 8px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.severity.CRITICAL { border-color: var(--accent); color: var(--accent); }
.severity.HIGH { border-color: var(--text); color: var(--text); }
.severity.MEDIUM { border-color: var(--muted); color: var(--muted); }
.severity.LOW { border-color: var(--border-dim); color: var(--border-dim); }

.stack-gap { display: flex; flex-direction: column; gap: 8px; width: 100%; }
