/* EMR-DOCS Commit 3 — Informes tab + sign modal + cosign queue
   Loaded once via <link> in index.html. Scoped under .informes-tab
   and the modal-overlay selectors so it cannot leak to other tabs.

   Uses the project-wide --surface / --bg / --border / --text / --accent
   token family (style.css :root + :root[data-theme="dark"]), so dark
   mode just works. The legacy --mv-* fallbacks earlier in this file
   were never themed and rendered white-on-dark in dark mode. */

/* ── Tab container ──────────────────────────────────────────────── */

.informes-tab {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.informes-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.informes-head h3 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--text);
}

.informes-head-actions {
  display: flex;
  gap: 8px;
}

.informes-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.informes-filters .filter-chip {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}

.informes-filters .filter-chip:hover {
  border-color: var(--border-hover);
}

.informes-filters .filter-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

/* Layout (2026-05-18 redesign): the filters + history boxes form a
   centered "control band" above the editor; the editor then takes
   the full window width below them. Old 3-column layout (facets |
   list | editor) squeezed the editor to the right and made writing
   awkward. */

.informes-split {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 16px;
}

.informes-control-band {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(360px, 2fr);
  gap: 16px;
  align-items: stretch;          /* same height for both boxes */
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;                /* centred above the editor */
}

@media (max-width: 900px) {
  .informes-control-band {
    grid-template-columns: 1fr;
  }
}

.informes-facet-sidebar {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  background: var(--surface);
  color: var(--text);
  /* Fixed-height box so both control-band siblings line up. The
     facet column scrolls if it overflows. */
  max-height: 320px;
  overflow-y: auto;
}

/* ── List pane ──────────────────────────────────────────────────── */

.informes-list-pane {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  max-height: 320px;
  overflow-y: auto;
}

.informes-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.informes-list-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.informes-list-row:hover {
  background: var(--bg);
}

.informes-list-row.active {
  background: var(--accent-light);
}

.informes-row-meta {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.informes-row-title {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.informes-row-sub {
  font-size: 0.78rem;
  color: var(--text-mute);
}

/* "Use as template" button on each history row. Sits to the right of
   the row meta, sized small enough not to dominate the row but still
   recognisable as the copy-forward affordance the user asked for. */
.informes-tpl-btn {
  flex-shrink: 0;
  align-self: center;
  font-size: 0.74rem;
  padding: 3px 8px;
}
.informes-tpl-btn:hover {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
}

.informes-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
  background: var(--text-mute);
}

.status-dot-draft           { background: #94a3b8; }
.status-dot-pending_cosign  { background: #f59e0b; }
.status-dot-signed          { background: #16a34a; }
.status-dot-amended         { background: #2563eb; }
.status-dot-entered_in_error { background: #dc2626; }

/* ── Editor pane ────────────────────────────────────────────────── */

.informes-editor-pane {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 20px 24px;
  min-height: 480px;
  /* Editor lives in the row below the control band and takes the
     full window width — the previous 3-column grid pinned it to
     a narrow right column. A4 portrait is 794px at 96dpi; the
     editor body inside .informe-editor-body inherits this width
     so the typing surface stays close to "paper" proportions. */
}

.informe-editor-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.informe-editor-title {
  flex: 1;
  font-size: 1.05rem;
  font-weight: 600;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
}

.informe-editor-title:not(:disabled):hover,
.informe-editor-title:not(:disabled):focus {
  border-color: var(--border);
  background: var(--input);
}

.informe-editor-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 0.82rem;
  color: var(--text-mute);
  margin-bottom: 10px;
}

.informe-meta-pair {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
}

.informe-editor-body {
  width: 100%;
  box-sizing: border-box;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.9rem;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--input);
  color: var(--text);
  resize: vertical;
  min-height: 320px;
}

.informe-editor-body:disabled {
  background: var(--bg);
  color: var(--text);
  cursor: default;
}

.informe-editor-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

/* ── Status badge (scoped to Informes only — there is already a
   .status-badge class elsewhere in the app for ADT/OR/scheduler;
   keep this one private so the uppercase/letter-spacing here doesn't
   leak globally) ─────────────────────────────────────────────────── */

/* List-row chips (M1.4 — specialty chip). `.informe-card-chip` is the
   shared base so future chip types (e.g. language) can inherit the
   pill shape; `.informe-specialty-chip` is the colored modifier. Aligned
   to the start of the meta column so it sits cleanly under the type
   sub-line. */
.informe-card-chip {
  display: inline-block;
  align-self: flex-start;
  margin-top: 4px;
  font-size: 0.72rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  background: var(--bg-soft, #f3f4f6);
  color: var(--text);
}

.informe-specialty-chip {
  background: var(--chip-bg-alt, #eef2ff);
  color: var(--chip-fg-alt, #4338ca);
  font-size: 0.72rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  margin-left: 0.25rem;
}

.informe-status-badge {
  font-size: 0.72rem;
  padding: 3px 8px;
  border-radius: 6px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: #e5e7eb;
  color: #374151;
}
.informe-status-badge-draft           { background: #e2e8f0; color: #475569; }
.informe-status-badge-pending_cosign  { background: #fef3c7; color: #92400e; }
.informe-status-badge-signed          { background: #dcfce7; color: #166534; }
.informe-status-badge-amended         { background: #dbeafe; color: #1e40af; }
.informe-status-badge-entered_in_error { background: #fee2e2; color: #991b1b; }

/* ── Cosign queue card ──────────────────────────────────────────── */

.cosign-queue-card {
  border: 1px solid #fbbf24;
  background: #fffbeb;
  color: #92400e;
  border-radius: 8px;
  padding: 10px 12px;
}

:root[data-theme="dark"] .cosign-queue-card {
  background: rgba(120, 53, 15, 0.35);  /* amber-900 @ 35% over dark surface */
  border-color: #b45309;                /* amber-700 — readable rim */
  color: #fcd34d;                       /* amber-300 — AA on the tinted bg */
}

.cosign-queue-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}

.cosign-queue-title {
  margin: 0;
  font-size: 0.95rem;
  color: inherit;
}

.cosign-queue-count {
  background: var(--warning, #f59e0b);
  color: var(--on-status, #1B1D1B);
  border-radius: 6px;
  padding: 1px 8px;
  font-size: 0.78rem;
  font-weight: 700;
}

.cosign-queue-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.cosign-queue-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
  border-top: 1px solid #fde68a;
}
:root[data-theme="dark"] .cosign-queue-row {
  border-top-color: rgba(252, 211, 77, 0.25);
}
.cosign-queue-row:first-child { border-top: 0; }

.cosign-queue-meta {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.cosign-queue-row-title {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: inherit;
}

.cosign-queue-row-type {
  font-size: 0.76rem;
  color: var(--text-mute);
  text-transform: uppercase;
}

.cosign-queue-requested {
  font-size: 0.76rem;
  color: inherit;
  opacity: 0.85;
}

.cosign-queue-actions {
  display: flex;
  gap: 6px;
}

/* ── Sign modal ─────────────────────────────────────────────────── */

.sign-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.sign-modal-box {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  width: 95%;
  max-width: 420px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.sign-modal-title {
  margin: 0 0 6px 0;
  font-size: 1.05rem;
  color: var(--text);
}

.sign-modal-sub {
  margin: 0 0 10px 0;
  font-size: 0.82rem;
  color: var(--text-mute);
}

.sign-modal-input {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--input);
  color: var(--text);
}

textarea.sign-modal-input {
  resize: vertical;
  min-height: 70px;
  font-family: inherit;
}

.sign-modal-error {
  color: var(--danger);
  font-size: 0.82rem;
  margin-top: 6px;
}

.sign-modal-error.hidden {
  display: none;
}

.sign-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

/* ── EMR-DOCS bells-and-whistles upgrade ────────────────────────── */

/* Editor toolbar (macro picker + preview toggle) */
.informe-editor-toolbar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 8px 0;
}

.informe-editor-toolbar .btn.active {
  background: var(--accent-light, #e0f0ff);
  border-color: var(--accent, #2563eb);
}

/* Editor body styling */
.informe-editor-body {
  width: 100%;
  min-height: 320px;
  padding: 10px 12px;
  font-family: ui-monospace, Menlo, Consolas, "Roboto Mono", monospace;
  font-size: 0.92rem;
  line-height: 1.5;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--input, #fff);
  color: var(--text);
  resize: vertical;
}

.informe-editor-body:focus {
  outline: 2px solid var(--accent, #2563eb);
  outline-offset: 2px;
}

/* Live preview pane styling — match shipped markdown look */
.informe-editor-preview {
  font-family: var(--font);
}

.informe-editor-preview h1,
.informe-editor-preview h2,
.informe-editor-preview h3 {
  margin: 1em 0 0.5em;
  color: var(--text);
}

.informe-editor-preview h1 { font-size: 1.3rem; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
.informe-editor-preview h2 { font-size: 1.1rem; }
.informe-editor-preview h3 { font-size: 1rem; }

.informe-editor-preview p { margin: 0.5em 0; }
.informe-editor-preview ul, .informe-editor-preview ol { margin: 0.5em 0; padding-left: 1.5em; }
.informe-editor-preview code { background: var(--bg-soft, #f5f5f7); padding: 2px 4px; border-radius: 3px; font-size: 0.9em; }
.informe-editor-preview pre { background: var(--bg-soft, #f5f5f7); padding: 8px 10px; border-radius: 4px; overflow-x: auto; }
.informe-editor-preview blockquote { border-left: 3px solid var(--accent-light, #cde); margin: 0.5em 0; padding: 0.3em 0.8em; color: var(--text-mute, #666); }
.informe-editor-preview table { border-collapse: collapse; margin: 0.5em 0; }
.informe-editor-preview th, .informe-editor-preview td { border: 1px solid var(--border); padding: 4px 8px; }

/* Footer (word count + save status) */
.informe-editor-footer {
  font-variant-numeric: tabular-nums;
}

/* Macro palette (slash command) */
.macro-palette {
  font-family: var(--font);
}

.macro-palette-row {
  border-bottom: 1px solid transparent;
}

.macro-palette-row:hover,
.macro-palette-row.selected {
  background: var(--accent-light, #e0f0ff) !important;
}

.macro-palette-row strong {
  font-weight: 600;
}

/* Informe new-modal card */
.informe-new-card h3 {
  margin-top: 0;
  font-size: 1.1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

/* Dark-mode lifts */
:root[data-theme="dark"] .macro-palette {
  background: var(--surface, #1f2937);
}

:root[data-theme="dark"] .macro-palette-row.selected,
:root[data-theme="dark"] .macro-palette-row:hover {
  background: rgba(96, 165, 250, 0.2) !important;
}

:root[data-theme="dark"] .informe-editor-preview code,
:root[data-theme="dark"] .informe-editor-preview pre {
  background: rgba(255, 255, 255, 0.05);
}
