/* Blazor-specific styles. Design tokens and components live in vector.css (shared with the mockups). */

/* User menu (opened from the avatar, top-right) */
.menu-scrim { position: fixed; inset: 0; z-index: 65; }
.user-menu { position: fixed; top: calc(var(--top-h) - 4px); right: 12px; }
.user-menu form { margin: 0; }

/* Mobile "More" sheet */
.more-sheet { position: relative; width: 100%; border-radius: 18px 18px 0 0; padding: 12px 8px calc(12px + env(safe-area-inset-bottom)); animation: toastIn .25s var(--ease); }

/* Auth pages */
.auth-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px;
  background: radial-gradient(600px 400px at 50% 30%, var(--primary-soft), transparent 70%); }
.auth-card { width: min(420px, 100%); padding: 28px; box-shadow: var(--shadow-2); }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }

/* Blazor validation */
.validation-message { font-size: .8rem; color: var(--bad); }
.invalid { border-color: var(--bad) !important; }

/* Blazor error UI */
#blazor-error-ui { display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 1000; }
#blazor-error-ui .dismiss { margin-left: auto; }

/* Mobile: hide the disabled search placeholder */
@media (max-width: 820px) { .topbar .search-trigger[disabled] { display: none; } }

/* Sources screen */
.src-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--gap); align-items: start; }
.src-card.is-off .card-h { opacity: .85; }
.src-card .card-h .count { margin-left: auto; }
.src-settings summary { cursor: pointer; font-weight: 500; font-size: .9rem; color: var(--text-2); }
.src-settings summary:hover { color: var(--text); }
.src-settings .switch { font-size: .9rem; }
@media (max-width: 1180px) { .src-grid { grid-template-columns: 1fr; } }

/* Focus immersive mode: hide the shell chrome */
body.immersive .topbar, body.immersive .rail, body.immersive .mobile-nav { display: none; }
body.immersive .app { grid-template-columns: 1fr; grid-template-rows: 1fr; }
body.immersive .main { padding-top: 40px; }

/* Review charts: SVG built by js/charts.js (outside component CSS scope) */
.chart { position: relative; width: 100%; }
.chart svg { width: 100%; overflow: visible; display: block; }
.chart .ax { fill: var(--text-3); font-family: var(--font-mono); font-size: 10.5px; }
.chart .ax-2 { fill: var(--text-2); font-family: var(--font-mono); font-size: 10.5px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .base { stroke: var(--line-2); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .band-hl { fill: var(--surface-2); opacity: 0; transition: opacity var(--t-fast); }
.chart .band:hover .band-hl { opacity: 1; }
.ctip { position: absolute; z-index: 5; pointer-events: none; min-width: 140px; padding: 8px 10px; border-radius: var(--r-s); background: var(--surface-3); border: 1px solid var(--line-2); box-shadow: var(--shadow-1); font-size: .82rem; opacity: 0; transform: translateY(4px); transition: opacity var(--t-fast), transform var(--t-fast); }
.ctip.on { opacity: 1; transform: none; }
.ctip b { display: block; font-family: var(--font-mono); font-weight: 500; font-size: .76rem; color: var(--text-2); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .08em; }
.ctip .r { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.ctip .r span { display: inline-flex; align-items: center; gap: 6px; }
.ctip .r em { font-style: normal; font-family: var(--font-mono); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .84rem; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend .ln { width: 16px; height: 0; border-top: 2px dashed var(--text-3); }
.legend .ar { width: 16px; height: 10px; border-radius: 2px; background: linear-gradient(var(--primary-soft), transparent); border-top: 2px solid var(--primary); }

/* Print (Review "Imprimer / PDF"): light ink-friendly tokens, no chrome or controls */
@media print {
  :root, html[data-theme] {
    --bg: #fff !important; --bg-2: #fff !important; --surface: #fff !important; --surface-2: #f2f2f2 !important; --surface-3: #e8e8e8 !important;
    --line: #d9d9d9 !important; --line-2: #c4c4c4 !important; --text: #111 !important; --text-2: #444 !important; --text-3: #777 !important;
    --shadow-1: none !important; --shadow-2: none !important; color-scheme: light;
  }
  body { background: #fff !important; }
  .topbar, .rail, .mobile-nav, .no-print, .toasts, #blazor-error-ui, .reconnect { display: none !important; }
  .app { display: block !important; }
  .main { padding: 0 !important; }
  .card, .kpi { break-inside: avoid; box-shadow: none !important; }
  .table-wrap { max-height: none !important; overflow: visible !important; }
  a { color: inherit !important; text-decoration: none !important; }
}

/* Notification panel (header bell) */
.notif-pop { position: fixed; top: calc(var(--topbar-h, 56px) + 4px); right: 12px; width: 420px; }
.notif-pop .pb { max-height: min(62vh, 560px); }
@media (max-width: 520px) {
  .notif-pop { left: 8px; right: 8px; width: auto; }
}

/* Settings rows (Preferences, System settings) */
.settings-section { scroll-margin-top: calc(var(--topbar-h, 56px) + 16px); }
.settings-rows { display: flex; flex-direction: column; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 16px 24px; flex-wrap: wrap; padding: 14px 0; border-top: 1px solid var(--line); }
.setting:first-child { border-top: 0; padding-top: 0; }
.setting:last-child { padding-bottom: 0; }
.setting .lbl { display: flex; flex-direction: column; gap: 3px; max-width: 560px; flex: 1 1 280px; }
.setting .lbl b { font-weight: 500; }
.setting .lbl span { font-size: .86rem; color: var(--text-2); line-height: 1.45; }
.setting .ctl { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.setting.stacked { flex-direction: column; align-items: stretch; }
.setting.stacked .lbl { max-width: none; flex: none; }
.setting.stacked .ctl { display: block; }
/* Wide content (tables) scrolls inside its row instead of widening the page. */
.setting > .lbl, .setting > .ctl { min-width: 0; max-width: 100%; }
.setting mark, .settings-nav mark { background: var(--primary-soft); color: var(--text); border-radius: 2px; padding: 0 1px; }
.setting.flash, .settings-section.flash { animation: settingFlash 1.2s var(--ease); }
@keyframes settingFlash { 0%, 40% { background: var(--primary-soft); } 100% { background: transparent; } }

/* Command palette: full screen on phones (no keyboard hints) */
.palette-close { display: none; }
@media (max-width: 520px) {
  .palette-wrap { padding: 0; }
  .palette { width: 100%; height: 100dvh; border-radius: 0; border: 0; display: flex; flex-direction: column; }
  .palette ul { max-height: none; flex: 1; }
  .palette .pf, .palette li kbd { display: none; }
  .palette-close { display: inline-grid; }
}

/* ---------------- Assistant chat ---------------- */
.assistant-wrap.hidden { display: none; }
.assistant { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow: hidden; }
.assistant .dwf { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; gap: 8px; }
.assistant .chat { flex: 1; min-height: 0; overflow: auto; }
.assistant .msg { white-space: pre-wrap; }
.assistant .msg.bot { white-space: normal; max-width: 100%; display: flex; flex-direction: column; gap: 8px; }
.assistant .md p { margin: 0 0 8px; }
.assistant .md p:last-child { margin-bottom: 0; }
.assistant .md ul, .assistant .md ol { margin: 4px 0 8px; padding-left: 20px; }
.assistant .md li { margin: 2px 0; }
.assistant .md code { font-family: var(--font-mono); font-size: .85em; background: var(--surface-3, var(--surface)); padding: 1px 4px; border-radius: 4px; }
.assistant .md pre { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; overflow: auto; margin: 4px 0 8px; }
.assistant .md pre code { background: none; padding: 0; }
.assistant-activity { display: flex; align-items: center; gap: 8px; }
.assistant-hello, .assistant-off { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; margin: auto 0; }
.assistant-hello .chip { white-space: normal; text-align: left; height: auto; min-height: 28px; padding: 4px 10px; }
.assistant-composer { flex-direction: column; align-items: stretch; }
.assistant-composer .textarea { resize: none; max-height: 180px; }
.assistant-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.assistant-trace summary { cursor: pointer; font-size: .78rem; color: var(--text-3); }
.assistant-trace ul { margin: 6px 0 0; padding-left: 18px; font-size: .82rem; }
.ai-action { border: 1px solid var(--primary-line); background: var(--surface); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.ai-action-h { display: flex; align-items: flex-start; gap: 8px; }
.ai-action-h svg { width: 16px; height: 16px; flex: none; margin-top: 2px; color: var(--primary-fg); }
.ai-action-f { gap: 6px; flex-wrap: wrap; align-items: center; }
.ai-action.dismissed, .ai-action.undone { opacity: .7; border-color: var(--line); }
.ai-action.failed { border-color: var(--bad-line, var(--line)); }

.assistant-page { display: grid; grid-template-columns: 280px 1fr; gap: 16px; height: calc(100dvh - 120px); min-height: 420px; }
.assistant-threads { display: flex; flex-direction: column; min-height: 0; }
.assistant-threads .thread-list { list-style: none; margin: 0; padding: 4px; overflow: auto; flex: 1; }
.assistant-threads .thread-list li { display: flex; align-items: center; gap: 4px; border-radius: 8px; }
.assistant-threads .thread-list li.on, .assistant-threads .thread-list li:hover { background: var(--surface-2); }
.assistant-threads .thread-list a { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 8px 10px; color: inherit; text-decoration: none; }
.assistant-threads .thread-list .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .9rem; }
.assistant-main { display: flex; flex-direction: column; min-height: 0; }
.assistant-main .card-h { gap: 10px; min-width: 0; }
.assistant-main .ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.assistant-main .assistant .chat { padding: 18px 20px; }
.assistant-page .show-m { display: none; }
@media (max-width: 820px) {
  .assistant-page { grid-template-columns: 1fr; height: calc(100dvh - 150px); }
  .assistant-page .assistant-threads { display: none; }
  .assistant-page.list-first .assistant-threads { display: flex; }
  .assistant-page.list-first .assistant-main { display: none; }
  .assistant-page .show-m { display: inline-flex; }
}

/* Source content: description and comments */
.md { line-height: 1.6; overflow-wrap: anywhere; }
.md p { margin: 0 0 8px; }
.md > :last-child { margin-bottom: 0; }
.md ul, .md ol { margin: 4px 0 8px; padding-left: 22px; }
.md li { margin: 2px 0; }
.md b, .md strong { font-weight: 600; color: var(--text); }
.md code { font-family: var(--font-mono); font-size: .85em; background: var(--surface-3); padding: 1px 4px; border-radius: var(--r-xs); }
.md pre { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-s); padding: 8px 10px; overflow: auto; margin: 4px 0 8px; white-space: pre; }
.md pre code { background: none; padding: 0; font-size: .82rem; }
.md blockquote { margin: 4px 0 8px; padding: 2px 0 2px 12px; border-left: 3px solid var(--line-2); color: var(--text-2); }
.md a { color: var(--primary-fg); text-decoration: underline; text-underline-offset: 2px; }
.md a:hover { text-decoration-thickness: 2px; }

.desc-block > summary, .comments-block > summary { cursor: pointer; margin-bottom: 8px; user-select: none; }
.desc-block > summary:hover, .comments-block > summary:hover { color: var(--text); }
.desc-block > .md { color: var(--text-2); }
.comments { display: flex; flex-direction: column; gap: 8px; }
.comment { padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-s); background: var(--surface-2); font-size: .93rem; }
.comment-h { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-bottom: 6px; font-size: .86rem; }
.comment-h b { font-weight: 600; }
.comment.internal { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 40%, transparent); border-left: 3px solid var(--warn); }
.comment .internal-badge { height: 20px; background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); font-weight: 600; }
.comments-more { align-self: flex-start; color: var(--primary-fg); }
.comment-composer { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.comment-composer.row-wrap { flex-direction: row; align-items: center; }

/* Phones: their own text size (Preferences › Display › Text size on mobile); everything is in rem, so it all follows. */
@media (max-width: 820px) {
  html:root { font-size: calc(14px * var(--scale-mobile, var(--scale))); }

  /* With bigger text nothing may push the page sideways: meta rows wrap, long values break, wide tables scroll in their card. */
  .inbox-card .row, .bl-item .row { flex-wrap: wrap; }
  main .mono { overflow-wrap: anywhere; }
  .card:has(> table.table), main div:has(> table) { overflow-x: auto; position: relative; }
  main select, main .select { max-width: 100%; }
  main .alert { flex-wrap: wrap; }
}
