/* DIVERSITY Tagger - look.
   Structure, sizes and states come from the references listed in REFERENCES_TAKEN.md (RES-QUILL panels, buttons, help bubble;
   meta-tagging waves; the ODE page footer). The COLOURS are the palette below (Shir's request): ONE PLACE TO TUNE THEM. */

/* ===================================================================================================================
   PALETTE - edit only this block to retune the colours of the whole app (both themes and the waves).
   One palette, two themes: pink-tinted backgrounds, pink / purple / wine waves and accents. The ONE exception is the primary buttons
   (and the active tab): turquoise, --pal-btn-primary. Wine, wine highlight and the warning red are the secondary, tertiary and danger buttons.
   =================================================================================================================== */
:root {
  /* brand colours (theme independent) */
  --pal-primary:     #B5179E;   /* pinkish purple: accents, panel wash, waves, checkbox (no longer a button colour) */
  --pal-btn-primary: #0E7C7B;   /* turquoise: primary buttons and the active tab (white text 5.01:1) */
  --hover-primary:   rgba(0, 0, 0, 0.12);   /* primary hover darkens: a white overlay would drop white text on turquoise below AA */
  --pal-wine:        #7B1E3A;   /* red wine / bordeaux: secondary actions */
  --pal-wine-hi:     #9E2A4F;   /* wine highlight: tertiary actions, theme button */
  --pal-danger:      #C62828;   /* clear warning red: delete, forget key */
  --pal-btn-text:    #FFFFFF;   /* text on every filled button (AA on all four fills) */
  --pal-wave-1:      #FF4DB8;   /* wave: pink */
  --pal-wave-2:      #B5179E;   /* wave: purple */
  --pal-wave-3:      #9E2A4F;   /* wave: wine */
  --newest-edge:     #2EC4B6;   /* the newest exchange in the chat: turquoise border and glow (dark view) */
  --newest-bg:       rgba(255, 255, 255, 0.07);   /* ...on a slightly brighter background */
  --paper-bg:        #F6EEDF;   /* the paper view's page in the dark view: warm cream, never pure white (js/theme.js tints the paper document the same way) */

  /* dark theme (default): deep plum */
  --bg:            #1E0F1C;
  --surface-rgb:   46, 22, 42;           /* panels, drawn at 62 % over the background */
  --surface-strong:#3A1D35;
  --text:          #F5E9F2;
  --title:         #FFFFFF;
  --card-text:     #FFFFFF;
  --muted:         #E6D2E1;
  --muted-soft:    #CDB3C7;
  --line:          rgba(255, 255, 255, 0.14);
  --line-strong:   rgba(255, 255, 255, 0.28);
  --field-bg:      rgba(30, 15, 28, 0.78);
  --field-text:    #FFFFFF;
  --shadow:        rgba(0, 0, 0, 0.45);
  --accent-text:   #F29AE0;              /* accent used as TEXT / borders on the dark background */
  --accent-rgb:    181, 23, 158;
  --error:         #FF9A9A;
  --warning:       #FACC15;
  --bubble-bg:     #170A15;
  --wash:          0.10;
  --wave-opacity:  0.14;
  --footer-text:   rgba(255, 255, 255, 0.55);
}

/* light theme: soft pink tint */
html[data-theme="light"] {
  --bg:            #FBEFF6;
  --surface-rgb:   255, 248, 238;        /* warm cream panels (no pure white in the bright view) */
  --surface-strong:#F6DCEB;
  --text:          #3A1432;
  --title:         #2B0D26;
  --card-text:     #3A1432;
  --muted:         #5E3355;
  --muted-soft:    #6F4766;
  --line:          rgba(43, 13, 38, 0.14);
  --line-strong:   rgba(43, 13, 38, 0.28);
  --field-bg:      rgba(255, 252, 246, 0.95);   /* inputs: a touch lighter cream */
  --field-text:    #2B0D26;
  --shadow:        rgba(123, 30, 58, 0.18);
  --accent-text:   #8E1280;
  --accent-rgb:    181, 23, 158;
  --error:         #B42318;
  --warning:       #8A5A00;
  --bubble-bg:     #FFF8EE;
  --paper-bg:      #FFF8EE;              /* the paper view's page in the bright view (js/theme.js tints the paper document the same way) */
  --newest-edge:   #0E7C7B;
  --newest-bg:     rgba(255, 252, 246, 0.80);
  --wash:          0.06;
  --wave-opacity:  0.30;
  --footer-text:   rgba(43, 13, 38, 0.66);
}
/* =================================================================================================================== */

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; overflow: hidden; }          /* one-screen app: the page itself never scrolls */
body {
  /* RES-QUILL: fontFamily 'Segoe UI'; the fallbacks after it are the builder's (other systems). */
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg); color: var(--text); position: relative;
}
.sr-only, .visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- Wave background: meta-tagging shell.css rules, strokes recoloured; layer pinned LTR so it covers the viewport in any direction ---------- */
.animated-background {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  z-index: 0; pointer-events: none; opacity: var(--wave-opacity);
  direction: ltr;                                       /* waves are geometry, not text: never mirrored */
  overflow: hidden;
}
.wave-container { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
.wave { position: absolute; top: 0; left: 0; width: 200%; height: 100%; opacity: 0.6; }   /* left:0 explicit */
.wave path { fill: none; stroke-width: 2; }
.wave-teal path { stroke: var(--pal-wave-1); animation: wave-drift-1 25s ease-in-out infinite; }
.wave-pink path { stroke: var(--pal-wave-2); animation: wave-drift-2 30s ease-in-out infinite; }
.wave-wine path { stroke: var(--pal-wave-3); animation: wave-drift-3 35s ease-in-out infinite; }
@keyframes wave-drift-1 { 0%, 100% { transform: translateX(0) translateY(0); } 50% { transform: translateX(-25%) translateY(-5%); } }
@keyframes wave-drift-2 { 0%, 100% { transform: translateX(0) translateY(0); } 50% { transform: translateX(-30%) translateY(8%); } }
@keyframes wave-drift-3 { 0%, 100% { transform: translateX(0) translateY(0); } 50% { transform: translateX(-20%) translateY(-8%); } }
@media (prefers-reduced-motion: reduce) { .wave path { animation: none; } }

/* ---------- Shell: fills the viewport, bottom reserve for the fixed footer ---------- */
.shell {
  position: relative; z-index: 1; height: 100vh; height: 100dvh; display: flex; flex-direction: column;
  padding: 0 14px 30px; max-width: 1920px; margin: 0 auto; overflow: hidden;
}
.top { display: flex; align-items: center; gap: 12px; padding: 10px 2px 8px; flex: 0 0 auto; }
.brand { flex: 1 1 auto; min-width: 0; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.brand h1 { color: var(--title); font-size: 26px; font-weight: 800; line-height: 1.05; }   /* _BrandCard title 39 -> compact header */
.schema { color: var(--muted); }
.badge { color: var(--muted); font-size: 12px; font-weight: 700; border: 1px solid var(--line-strong); border-radius: 999px; padding: 4px 9px; white-space: nowrap; }

.work { flex: 1 1 auto; min-height: 0; display: grid; gap: 14px;
  grid-template-columns: minmax(300px, 28%) minmax(0, 1fr) minmax(330px, 31%); }
.work.cons-closed { grid-template-columns: 200px minmax(0, 1fr) minmax(330px, 31%); }
.tabs { display: none; gap: 8px; padding: 0 2px 8px; flex: 0 0 auto; }

/* ---------- Glass panel: RES-QUILL _GlassPanel (surface 62 %, line border, radius 16, shadow, accent wash) ---------- */
.panel {
  position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column;
  background: rgba(var(--surface-rgb), 0.62);
  border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 18px 46px var(--shadow); overflow: hidden;
}
.panel::before { content: ""; position: absolute; inset: 0; background: var(--pal-primary); opacity: var(--wash); pointer-events: none; }
.panel-body { position: relative; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 8px; padding: 14px; overflow: hidden; }
.panel-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; flex: 0 0 auto; }
.section-title { color: var(--title); font-size: 20px; font-weight: 700; line-height: 1.18; }   /* _SectionTop 22 -> compact */
.sub-title { color: var(--title); font-size: 15px; font-weight: 700; flex: 0 0 auto; }
.grow { flex: 1 1 auto; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Buttons: RES-QUILL _ActionButton (radius 8, 14.5 px w700, hover overlay, no border) with filled palette colours ---------- */
.btn {
  min-height: 46px; padding: 13px 18px; border-radius: 8px; border: 0; cursor: pointer;
  font: 700 14.5px 'Segoe UI', system-ui, -apple-system, sans-serif; text-align: center; color: var(--pal-btn-text);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; line-height: 1.1;
}
.btn-sm { min-height: 38px; padding: 8px 14px; }                       /* compact size so every feature fits one screen */
.btn:hover:not(:disabled) { box-shadow: inset 0 0 0 999px rgba(255, 255, 255, 0.14); }
.btn-primary:hover:not(:disabled) { box-shadow: inset 0 0 0 999px var(--hover-primary); }
.btn:active:not(:disabled) { box-shadow: inset 0 0 0 999px rgba(0, 0, 0, 0.12); }
.btn:focus-visible, .file-button:focus-within { outline: 3px solid var(--accent-text); outline-offset: 2px; }
.btn-primary   { background: var(--pal-btn-primary); }  /* primary actions: turquoise */
.btn-secondary { background: var(--pal-wine); }         /* save, export, other secondary actions */
.btn-accent    { background: var(--pal-wine-hi); }      /* tertiary: theme, restore */
.btn-danger    { background: var(--pal-danger); }       /* delete, forget key */
.btn:disabled { background: rgba(var(--surface-rgb), 0.5); color: var(--muted-soft); cursor: not-allowed; outline: 1px solid var(--line); }
.file-button { cursor: pointer; position: relative; }
.linklike { background: none; border: 0; padding: 0; color: var(--accent-text); font: 700 inherit; text-decoration: underline; cursor: pointer; }
.linklike:focus-visible { outline: 3px solid var(--accent-text); outline-offset: 2px; }

/* ---------- Fields: InputDecorationTheme (filled, radius 8, line-strong border, focus 2 px accent) ---------- */
label { display: block; color: var(--card-text); font-size: 12px; font-weight: 700; }
.field {
  width: 100%; background: var(--field-bg); color: var(--field-text);
  border: 1px solid var(--line-strong); border-radius: 8px;
  padding: 7px 10px; font: 14px 'Segoe UI', system-ui, -apple-system, sans-serif;
}
.field::placeholder { color: var(--muted-soft); }
.field:focus { outline: none; border-color: var(--accent-text); box-shadow: 0 0 0 1px var(--accent-text); }
.field.narrow { width: 120px; }
::selection { background: rgba(var(--accent-rgb), 0.30); }
textarea.field { resize: none; }
/* bright view: the list boxes of the tag panel were pure white too; they take the cream input colour (dark view: unchanged) */
html[data-theme="light"] select { background: var(--field-bg); color: var(--field-text); }
/* dark view: the six value lists were pure white; they take the same warm cream as the paper page, with dark text (14.78:1) and a clearly visible selected option (white on turquoise, 5.01:1) */
html:not([data-theme="light"]) #facets select { background: var(--paper-bg); color: #1C1C1C; }
html:not([data-theme="light"]) #facets select option:checked { background-color: var(--pal-btn-primary); background-image: linear-gradient(var(--pal-btn-primary), var(--pal-btn-primary)); color: #FFFFFF; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; flex: 0 0 auto; }
.mono { font-family: 'Consolas', ui-monospace, monospace; font-size: 12.5px; color: var(--muted); }
.check { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-size: 13.5px; font-weight: 600; }
.check input { width: 17px; height: 17px; accent-color: var(--pal-primary); }
.notice { border: 1px solid var(--line-strong); border-radius: 12px; padding: 7px 10px; color: var(--card-text); font-size: 13.5px; flex: 0 0 auto; }
.notice.warn { border-color: var(--warning); }
.notice.err { border-color: var(--error); color: var(--error); }

/* ---------- "?" help button: RES-QUILL guide button skin (radius 6, 1 px accent border, w800) ---------- */
.qm {
  flex: 0 0 auto; min-width: 26px; height: 26px; padding: 0 6px; border-radius: 6px; cursor: pointer;
  background: var(--bubble-bg); color: var(--title); border: 1px solid var(--accent-text);
  font: 800 13px 'Segoe UI', system-ui, sans-serif; line-height: 1;
}
.qm:hover { box-shadow: 0 0 0 2px rgba(var(--accent-rgb), 0.35); }
.qm:focus-visible, .qm[aria-expanded="true"] { outline: 3px solid var(--accent-text); outline-offset: 2px; }

/* ---------- Help bubble: RES-QUILL _GuideBubble (padding 18, 2 px accent border, radius 12, shadow blur 30 / 16, title 17 w800, body 15) ---------- */
.bubble {
  position: fixed; z-index: 60; width: min(340px, calc(100vw - 24px)); max-height: calc(100vh - 24px); overflow: auto; padding: 18px;
  background: var(--bubble-bg); border: 2px solid var(--accent-text); border-radius: 12px; box-shadow: 0 16px 30px var(--shadow);
}
.bubble[hidden], .pop[hidden] { display: none; }
.bubble-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.bubble-title { color: var(--title); font-size: 17px; font-weight: 800; line-height: 1.18; }
.bubble-body p { color: var(--card-text); font-size: 15px; line-height: 1.4; margin: 0 0 8px; }
.bubble-close { flex: 0 0 auto; min-height: 30px; padding: 5px 10px; border: 0; border-radius: 6px; cursor: pointer; background: var(--pal-wine); color: var(--pal-btn-text); font: 800 11px 'Segoe UI', system-ui, sans-serif; }
.bubble-close:focus-visible { outline: 3px solid var(--accent-text); outline-offset: 2px; }

/* ---------- Key settings popover ---------- */
.pop {
  position: fixed; z-index: 40; width: min(350px, calc(100vw - 24px)); max-height: calc(100vh - 24px); overflow: auto; padding: 14px;
  background: var(--bubble-bg); border: 1px solid var(--line-strong); border-radius: 12px; box-shadow: 0 16px 30px var(--shadow);
  display: flex; flex-direction: column; gap: 8px;
}
.pop-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.lbl { font-size: 12px; font-weight: 700; color: var(--card-text); }

/* ---------- Digital Friend box (pattern of the DF helper box: accent border, rounded, message cards, close/open) ---------- */
.df { border-color: rgba(var(--accent-rgb), 0.65); }
.df-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; flex: 0 0 auto; }
.df-toggle { display: inline-flex; align-items: center; gap: 8px; background: none; border: 0; cursor: pointer; padding: 2px 4px; border-radius: 8px; color: var(--title); }
.df-toggle:focus-visible { outline: 3px solid var(--accent-text); outline-offset: 2px; }
.df-title { font-size: 20px; font-weight: 700; }
.df-caret { width: 0; height: 0; border-left: 6px solid transparent; border-right: 6px solid transparent; border-top: 8px solid var(--accent-text); transition: transform .15s; }
.df:not(.is-open) .df-caret { transform: rotate(-90deg); }
.df-body { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.df:not(.is-open) .df-body { display: none; }
.df:not(.is-open) { align-self: start; }
.log { flex: 1 1 auto; min-height: 90px; overflow: auto; display: flex; flex-direction: column; gap: 8px; }
.msg { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; line-height: 1.5; background: var(--field-bg); color: var(--card-text); }
.msg.user { border-color: rgba(var(--accent-rgb), 0.55); }
/* chat history: one box per exchange. The newest is highlighted at full strength; older ones fade step by step; hover or focus brings one back to full strength */
.xchg { display: flex; flex-direction: column; gap: 6px; border: 1px solid transparent; border-radius: 12px; padding: 6px; outline: none; }
.xchg.newest { border-color: var(--newest-edge); background: var(--newest-bg); box-shadow: 0 0 0 1px var(--newest-edge), 0 0 14px color-mix(in srgb, var(--newest-edge) 55%, transparent); }
.xchg.age-1 { opacity: 0.85; }
.xchg.age-2 { opacity: 0.70; }
.xchg.age-3 { opacity: 0.55; }
.xchg.age-4 { opacity: 0.45; }
.xchg:hover, .xchg:focus, .xchg:focus-within { opacity: 1; }
.xchg:focus-visible { box-shadow: 0 0 0 3px var(--accent-text); }
.msg.greeting { border-style: dashed; }
.msg.pending > span:empty::before { content: ""; display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line-strong); border-top-color: var(--accent-text); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; }
.msg small { display: block; margin-top: 4px; color: var(--muted-soft); font-size: 11.5px; }
.df-input { flex: 0 0 auto; }
/* question box at the TOP of the Digital Friend box: large, 6-8 lines, comfortable font (height follows the window; never below ~4 lines) */
.df-ask { font-size: 15.5px; line-height: 1.5; padding: 10px 12px; height: clamp(104px, 26vh, 186px); }
.df-body > .row .btn { min-height: 44px; }
.df-foot { flex: 0 0 auto; display: flex; flex-direction: column; gap: 6px; }
.df-foot .notice { font-size: 12.5px; padding: 4px 9px; }
.usage { margin-left: auto; font-size: 12px; white-space: nowrap; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--line-strong); border-top-color: var(--accent-text); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Paper view ---------- */
.paper-frame { flex: 1 1 auto; min-height: 0; width: 100%; border: 1px solid var(--line-strong); border-radius: 12px; background: var(--paper-bg); }

/* ---------- Tag panel (ported tagger controls) ---------- */
.status { flex: 0 0 auto; min-height: 18px; font-size: 13px; color: var(--card-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status[role="alert"] { color: var(--error); }
.editor { flex: 0 0 auto; display: flex; flex-direction: column; gap: 8px; }
.capture-row { display: flex; gap: 8px; align-items: stretch; }
#quote { flex: 1 1 auto; min-width: 0; height: 38px; overflow: auto; white-space: pre-wrap; background: var(--field-bg); color: var(--field-text);
  border-inline-start: 3px solid var(--pal-primary); border-radius: 8px; padding: 6px 10px; font-size: 13px; line-height: 1.35; }
.entity-row { display: flex; align-items: center; gap: 8px; }
.entity-row label { flex: 0 0 auto; }
.entity-row select { flex: 1 1 auto; min-width: 0; }
#facets { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 4px 8px; }
#facets label { margin: 0; font-size: 11.5px; }
#facets select { display: block; width: 100%; height: 58px; margin-top: 2px; font-size: 12.5px; padding: 3px 4px; }
.notes-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.notes-row label { margin: 0; font-size: 11.5px; }
.notes-row textarea { display: block; margin-top: 2px; height: 48px; }
.tag-list { flex: 1 1 auto; min-height: 60px; overflow: auto; }
.user-card { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 8px; overflow-wrap: anywhere; }
.user-card b { color: var(--title); }
.user-card blockquote { max-height: 70px; overflow: auto; margin: 4px 0; font-size: 13px; color: var(--card-text); }
.user-card p { font-size: 12.5px; color: var(--card-text); margin: 3px 0; }
.user-card button { min-height: 32px; padding: 5px 11px; border-radius: 8px; border: 0; cursor: pointer; color: var(--pal-btn-text);
  font: 700 12.5px 'Segoe UI', system-ui, sans-serif; margin: 4px 6px 0 0; background: var(--pal-wine); }
.user-card button:nth-of-type(2) { background: var(--pal-wine-hi); }
.user-card button:nth-of-type(3) { background: var(--pal-danger); }
.user-card button:hover { box-shadow: inset 0 0 0 999px rgba(255, 255, 255, 0.14); }
.user-card button:focus-visible { outline: 3px solid var(--accent-text); outline-offset: 2px; }

/* ---------- Footer: the ODE page footer (.8rem, no weight, translucent), pinned bottom-left ---------- */
.site-footer {
  position: fixed; left: 0; bottom: 0; z-index: 30; padding: 4px 12px 5px; font-size: 0.8rem; line-height: 1.4; font-weight: 400;
  color: var(--footer-text); pointer-events: none; white-space: nowrap;
}

/* ---------- Tabs mode: narrow windows (and high zoom) show one panel at a time ---------- */
@media (max-width: 999px) {
  .tabs { display: flex; }
  .tab { flex: 1 1 0; min-height: 40px; border: 0; border-radius: 8px; cursor: pointer; background: var(--pal-wine); color: var(--pal-btn-text); font: 700 14px 'Segoe UI', system-ui, sans-serif; }
  .tab.is-active { background: var(--pal-btn-primary); }
  .tab:focus-visible { outline: 3px solid var(--accent-text); outline-offset: 2px; }
  .work, .work.cons-closed { display: block; }
  .work .panel { display: none; height: 100%; }
  .work .panel.is-tab-active { display: flex; }
  .df:not(.is-open) { align-self: auto; }
  .brand h1 { font-size: 22px; }
  .shell { padding: 0 10px 30px; }
}
@media (max-width: 560px) {
  .top { flex-wrap: wrap; }
  .badge { font-size: 11px; }
}

/* ---------- Small windows (phone width, high browser zoom, short screens): the page still never scrolls.
   Whatever does not fit inside a panel scrolls INSIDE that panel, so no control can ever sit under the fixed footer. ---------- */
@media (max-width: 999px), (max-height: 560px) {
  .panel-body { overflow-x: hidden; overflow-y: auto; }
  .paper-frame { min-height: 160px; }
}
@media (max-height: 560px) {
  .top { padding: 4px 2px 4px; gap: 8px; }
  .brand h1 { font-size: 19px; }
  .tabs { padding-bottom: 4px; }
  .tab { min-height: 32px; }
  .btn { min-height: 34px; padding: 6px 12px; }
  .panel-body { padding: 8px 10px; gap: 6px; }
  .log { min-height: 40px; }
  .df-title, .section-title { font-size: 17px; }
}
