/* Tokens lifted from Brain3/design.md, adapted to the LIGHT "momento claro"
   variant for this portal (design.md is dark-first and only reserves a
   handful of tokens — surface/surface-card/ink — for light moments; the
   rest is derived here the same way product/brain-flow-v2.html already
   derived its own light skin: --neutral-900/800/700 and --on-hi/mid/low
   keep their NAMES from the dark-mode system but now hold light-mode
   values (gray page / white card / light border, dark ink text) so every
   existing rule that references them below just works. --error/--success
   are likewise swapped for the readable-on-white shades brain-flow-v2 uses
   (its --danger-fg/--ok), since the original neon dark-mode values fail
   contrast on white. One blue scale, Roboto Mono for display/label/data,
   zero border-radius everywhere (design.md "Do's and Don'ts": corners are
   always square) — none of that changes. */
:root {
  --primary: #1E2BFF;
  --secondary: #2438E6;
  --accent-data: #00CFFF;
  --accent-synapse: #3DFF6E;
  --neutral-900: #F1F3F8;
  --neutral-800: #FFFFFF;
  --neutral-700: #E3E8F3;
  --line: #D3DAEA;
  --raised: #F1F4FA;
  --surface: #F1F3F8;
  --surface-card: #FFFFFF;
  --ink: #0C1230;
  --on-hi: #0C1230;
  --on-mid: #4A5578;
  --on-low: #697393;
  --error: #B32338;
  --success: #0B7A3D;
  --mono: "Roboto Mono", ui-monospace, monospace;
  --sans: "Inter", -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--neutral-900);
  color: var(--on-hi);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
}

/* accent-data (cyan) reads fine on navy but fails contrast on this light
   background, so link/accent roles use secondary (Azul Royal) instead —
   accent-data stays defined above for whatever still wants the brand cyan. */
a { color: var(--secondary); }

h1, h2, h3 {
  font-family: var(--mono);
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 .5em;
}
h1 { font-size: 26px; }
h2 { font-size: 17px; text-transform: uppercase; letter-spacing: .08em; color: var(--on-mid); font-weight: 500; }

.overline {
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--on-mid);
}

/* Topbar is a fixed Azul Royal bar regardless of the page's light theme, so
   its own text/logo use literal white/light values below instead of the
   theme-relative --on-hi/--on-mid (same reasoning as the solid .btn — a
   vivid, always-dark-enough background needs text that doesn't flip). */
header.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: var(--secondary);
}
header.app-header .brand { display: flex; align-items: center; gap: 10px; color: #fff; }
/* The served logo file is the solid-white mark (server.js only wires up
   logo_brain_0000_logo_branco.png) — it reads natively on this dark-blue bar. */
header.app-header img.logo { height: 22px; display: block; }
header.app-header .wordmark { font-family: var(--mono); font-weight: 700; font-size: 15px; }
header.app-header .session { font-family: var(--mono); font-size: 13px; color: rgba(255,255,255,.75); display: flex; align-items: center; gap: 4px; }
header.app-header .session a { color: rgba(255,255,255,.75); }
header.app-header .session-profile { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; color: #fff; }
header.app-header .session-profile:hover { color: #fff; opacity: .8; }

/* Avatar — square corners per design.md, like everything else in this app. */
.avatar { display: inline-block; object-fit: cover; background: var(--neutral-700); flex-shrink: 0; }
.avatar-fallback { display: inline-flex; align-items: center; justify-content: center; font-family: var(--mono); font-weight: 700; color: var(--on-hi); }
.avatar-sm { width: 22px; height: 22px; font-size: 11px; }
.avatar-lg { width: 72px; height: 72px; font-size: 26px; }
.profile-avatar-row { display: flex; align-items: center; gap: 16px; margin-top: 8px; }
.profile-avatar-row form { display: flex; align-items: center; gap: 8px; }

.success-msg { color: var(--success); font-size: 13px; }

main { max-width: 1100px; margin: 0 auto; padding: 32px 24px 64px; }

/* Buttons — always square corners, solid Azul Royal (secondary), hover
   brightens to primary. Text is a literal white, not var(--on-hi): the
   button's own background is always this vivid blue regardless of the
   page's light/dark theme, so its text must not flip with that theme. */
.btn {
  font-family: var(--mono);
  font-size: 13px;
  background: var(--secondary);
  color: #fff;
  border: none;
  border-radius: 0;
  padding: 10px 18px;
  cursor: pointer;
}
.btn:hover { background: var(--primary); }
.btn.btn-ghost {
  background: var(--secondary);
  color: #fff;
  border: none;
}
.btn.btn-ghost:hover { background: var(--primary); }
.btn.btn-danger { background: transparent; color: var(--error); border: 1px solid var(--error); }

/* Native <input type=file> "Choose File" control — no .btn class applies to
   it directly (it's a browser-rendered control), so it's restyled via the
   standard file-selector-button pseudo-element to match every other button.
   Same literal-white reasoning as .btn above. */
input[type=file]::file-selector-button,
input[type=file]::-webkit-file-upload-button {
  font-family: var(--mono);
  font-size: 13px;
  background: var(--secondary);
  color: #fff;
  border: none;
  border-radius: 0;
  padding: 8px 14px;
  margin-right: 10px;
  cursor: pointer;
}
input[type=file]::file-selector-button:hover,
input[type=file]::-webkit-file-upload-button:hover { background: var(--primary); }
input[type=file] { color: var(--on-mid); font-size: 13px; }

select, input[type=email], input[type=password], input[type=text], input[type=search], textarea {
  font-family: var(--sans);
  font-size: 14px;
  background: var(--raised);
  color: var(--ink);
  border: 1px solid var(--neutral-700);
  border-radius: 0;
  padding: 8px 10px;
}
textarea { width: 100%; min-height: 4.5rem; resize: vertical; }

/* Badges */
.badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .04em;
  padding: 3px 9px;
  border-radius: 0;
  margin-left: 6px;
}
.badge-solid { background: var(--primary); color: #fff; }
.badge-outline { background: transparent; color: var(--on-hi); border: 1px solid var(--neutral-700); }
.badge-outline[data-vis="public"] { border-color: var(--success); color: var(--success); }
.badge-outline[data-vis="grupo-arka"] { border-color: var(--primary); color: var(--primary); }
.badge-outline[data-vis="brain003"] { border-color: var(--secondary); color: var(--secondary); }
.badge-outline[data-vis="restricted"] { border-color: var(--on-low); color: var(--on-mid); }
/* Tag pills keep their own fixed dark chip + neon-green text regardless of
   the page theme (design.md: accent-synapse is decorative-only and needs a
   dark chip to read at all — it fails contrast on any light background). */
.badge-tag { background: #161D40; color: var(--accent-synapse); border: 1px solid var(--accent-synapse); }

/* Tag filter (home) — white pills on the gray page, like small buttons. */
.tag-filter { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 24px; }
.tag-pill {
  font-family: var(--mono); font-size: 12px;
  background: var(--neutral-800); color: var(--on-mid);
  border: 1px solid var(--neutral-700);
  border-radius: 0;
  padding: 6px 14px;
  cursor: pointer;
}
.tag-pill.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.tag-pill[data-tag="all"].active { background: var(--neutral-700); border-color: var(--on-mid); color: var(--on-hi); }

/* Tag editor (artifact page) */
.tag-checks { display: flex; flex-wrap: wrap; gap: 12px; margin: 10px 0; }
.tag-check { font-size: 13px; display: flex; align-items: center; gap: 6px; }

/* Home listing — content card: white on the gray page, thin light border,
   square corners, no shadow at rest (matches product/brain-flow-v2.html's
   own light "momento claro" cards — --surface/--line-soft/--muted). */
.folder { margin-bottom: 40px; }
.folder ul { list-style: none; padding: 0; margin: 12px 0 0; }
.folder li {
  display: flex; flex-direction: column;
  background: var(--neutral-800);
  border: 1px solid var(--neutral-700);
  padding: 14px 18px;
  margin-bottom: 8px;
}
.folder li .item-main { display: flex; align-items: center; justify-content: space-between; width: 100%; }
.folder li a { color: var(--on-hi); text-decoration: none; font-weight: 600; }
.folder li a:hover { color: var(--secondary); }
.item-description { color: var(--on-mid); font-size: 13px; margin: 6px 0 0; }
.empty { color: var(--on-mid); }

/* Login */
.login-card {
  max-width: 360px;
  margin: 10vh auto 0;
  background: var(--neutral-800);
  border: 1px solid var(--neutral-700);
  padding: 32px;
}
.login-card input { width: 100%; margin-bottom: 12px; }
.error-msg { color: var(--error); font-size: 13px; }

/* Artifact frame */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 16px; align-items: center;
  background: var(--neutral-800);
  border: 1px solid var(--neutral-700);
  padding: 14px 18px;
  margin-bottom: 16px;
}
.toolbar form { display: flex; align-items: center; gap: 8px; margin: 0; }

.access-panel {
  background: var(--neutral-800);
  border: 1px solid var(--neutral-700);
  padding: 14px 18px;
  margin-bottom: 16px;
}
.access-panel .chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: 12px;
  background: var(--neutral-700); color: var(--on-hi);
  padding: 4px 4px 4px 10px;
  margin: 4px 6px 0 0;
}
.access-panel .chip button {
  background: none; border: none; color: var(--on-mid); cursor: pointer; font-size: 14px; line-height: 1;
  padding: 2px 6px;
}
.access-panel .chip button:hover { color: var(--error); }
.access-panel form.add-access { margin-top: 10px; gap: 8px; }

.workspace { display: flex; gap: 16px; align-items: flex-start; }
.iframe-wrap { flex: 1; min-width: 0; position: relative; }
.iframe-wrap iframe {
  width: 100%; height: 72vh;
  border: 1px solid var(--neutral-700);
  background: #fff;
  display: block;
}

.sidebar {
  width: 320px; flex-shrink: 0;
  background: var(--neutral-800);
  border: 1px solid var(--neutral-700);
  padding: 14px;
  max-height: 72vh;
  overflow-y: auto;
}
.sidebar .controls { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.sidebar .controls select { flex: 1; }
.composer { display: none; margin-bottom: 14px; padding: 10px; background: var(--neutral-700); }
.composer.active { display: block; }
.composer .target-label { font-family: var(--mono); font-size: 12px; color: var(--secondary); margin-bottom: 6px; }
.composer textarea { margin-bottom: 8px; }

.comment-card {
  background: var(--neutral-700);
  padding: 10px 12px;
  margin-bottom: 10px;
  border-left: 3px solid var(--secondary);
  transition: background .3s;
}
.comment-card.orphan { border-left-color: var(--on-low); }
.comment-card .meta { font-family: var(--mono); font-size: 11px; color: var(--on-mid); margin-bottom: 4px; }
.comment-card .target { font-size: 12px; color: var(--on-mid); font-style: italic; margin-top: 4px; }
.comment-card.ah-flash { background: var(--secondary); color: #fff; }

/* Fullscreen / presentation mode */
body.presenting header.app-header,
body.presenting .toolbar,
body.presenting .access-panel,
body.presenting .sidebar,
body.presenting main > h1 {
  display: none !important;
}
body.presenting main { max-width: none; padding: 0; }
body.presenting .iframe-wrap {
  position: fixed; inset: 0; z-index: 1000; background: var(--neutral-900);
}
body.presenting .iframe-wrap iframe { height: 100vh; border: none; }
.back-btn {
  display: none;
  position: fixed; top: 16px; right: 16px; z-index: 1001;
}
body.presenting .back-btn { display: inline-block; }

/* Rendered markdown artifacts (.md files, served as HTML — see
   sendArtifactFile in server.js). Body background/color/fonts are already
   set globally above; this just gives the article sensible reading width
   and styles the elements marked() produces. Code/table-header blocks use
   --raised (one step off white) so they still read as distinct blocks now
   that the page itself is light instead of navy. */
.md-body {
  max-width: 780px;
  margin: 0 auto;
  padding: 48px 24px 96px;
}
.md-body h1, .md-body h2, .md-body h3, .md-body h4 { margin-top: 1.6em; }
.md-body h1:first-child, .md-body h2:first-child { margin-top: 0; }
.md-body h1 { font-size: 30px; }
.md-body h2 { font-size: 20px; text-transform: none; letter-spacing: normal; color: var(--on-hi); border-bottom: 1px solid var(--neutral-700); padding-bottom: .3em; }
.md-body h3 { font-size: 16px; color: var(--on-hi); }
.md-body p, .md-body li { color: var(--on-mid); }
.md-body strong { color: var(--on-hi); }
.md-body a { color: var(--secondary); }
.md-body code {
  font-family: var(--mono);
  background: var(--raised);
  padding: 2px 5px;
  font-size: .9em;
}
.md-body pre {
  background: var(--raised);
  border: 1px solid var(--neutral-700);
  padding: 14px 16px;
  overflow-x: auto;
}
.md-body pre code { background: none; padding: 0; }
.md-body blockquote {
  margin: 0;
  padding: 4px 16px;
  border-left: 3px solid var(--secondary);
  color: var(--on-mid);
}
.md-body hr { border: none; border-top: 1px solid var(--neutral-700); margin: 2em 0; }
.md-body table { border-collapse: collapse; width: 100%; margin: 1em 0; }
.md-body th, .md-body td {
  border: 1px solid var(--neutral-700);
  padding: 8px 12px;
  text-align: left;
  font-size: 14px;
}
.md-body th { color: var(--on-hi); font-family: var(--mono); font-weight: 500; background: var(--raised); }
.md-body img { max-width: 100%; }
