/* Sources and Evidence. Header colours and controls follow AI Prompt Builder and AI Skill Designer. */
:root {
  --sae-bg: #f5f7fa;
  --sae-panel: #ffffff;
  --sae-soft: #eef2f7;
  --sae-ink: #0f172a;
  --sae-muted: #4f5f73;
  --sae-line: #d5dde8;
  --sae-accent: #2563eb;
  --sae-accent-ink: #ffffff;
  --sae-danger: #b42318;
  --sae-warn: #8a4b00;
  --sae-warn-bg: #fff7e6;
  --sae-header-bg: #16233a;
  --sae-header-text: #dbe7f5;
}

body { background: var(--sae-bg); color: var(--sae-ink); font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; }
.tab-bar { background: var(--sae-header-bg); }
.tab-bar .title { color: var(--sae-header-text); }
.sae-app-view { height: calc(100vh - 45px); overflow: auto; padding: 12px; }

.sae-page { max-width: 1400px; margin: 0 auto; }
.sae-page h2 { font-size: 1.35rem; margin: 0; }
.sae-page h3 { font-size: 1.05rem; margin: 0; }
.sae-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.sae-heading > * { min-width: 0; overflow-wrap: anywhere; }
.sae-intro, .sae-hint { color: var(--sae-muted); font-size: 0.85rem; margin: 4px 0 10px; }
.sae-section-title { margin-top: 22px !important; margin-bottom: 4px !important; }
[hidden] { display: none !important; }
.sae-visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Buttons: Foundation's defaults force white text, so every state is set here. */
.sae-button { display: inline-block; margin: 0; padding: 6px 12px; min-height: 34px; border: 1px solid var(--sae-line); border-radius: 6px; background: var(--sae-panel); color: var(--sae-ink); font-size: 0.875rem; line-height: 1.3; cursor: pointer; }
.sae-button:hover, .sae-button:focus { background: var(--sae-soft); color: var(--sae-ink); }
.sae-button:disabled, .sae-button:disabled:hover, .sae-button.sae-primary:disabled { opacity: 0.5; cursor: default; background: var(--sae-panel); border-color: var(--sae-line); color: var(--sae-muted); }
.sae-button.sae-primary { background: var(--sae-accent); border-color: var(--sae-accent); color: var(--sae-accent-ink); }
.sae-button.sae-primary:hover, .sae-button.sae-primary:focus { background: #1d4ed8; color: var(--sae-accent-ink); }
.sae-button.sae-danger { background: var(--sae-danger); border-color: var(--sae-danger); color: #fff; }
.sae-button.sae-danger:hover, .sae-button.sae-danger:focus { background: #912018; color: #fff; }
.sae-button.sae-small { padding: 3px 8px; min-height: 28px; font-size: 0.8rem; }
.sae-page :focus-visible, .sae-prov :focus-visible { outline: 2px solid var(--sae-accent); outline-offset: 2px; }

.sae-page input, .sae-page select, .sae-page textarea { margin: 0; border-radius: 6px; border-color: var(--sae-line); box-shadow: none; font-size: 0.9rem; }
.sae-page select { height: 34px; padding: 4px 8px; width: auto; max-width: 100%; }
.sae-page label { font-weight: 600; font-size: 0.875rem; color: var(--sae-ink); margin: 14px 0 6px; }
.sae-page textarea { font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; }

.sae-status { min-height: 1.4em; margin: 4px 0 8px; font-size: 0.85rem; color: var(--sae-muted); }
.sae-error { color: var(--sae-danger) !important; }
.sae-notice { background: var(--sae-warn-bg); border: 1px solid #f5d38a; border-radius: 6px; padding: 8px 12px; font-size: 0.875rem; }
.sae-meta { color: var(--sae-muted); font-size: 0.78rem; margin: 0; }
.sae-empty { color: var(--sae-muted); list-style: none; }
.sae-card-list > .sae-empty, .sae-technique-list > .sae-empty { grid-column: 1 / -1; }
.sae-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
.sae-confirm { font-size: 0.85rem; color: var(--sae-danger); width: 100%; }
.sae-confirm-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; background: var(--sae-warn-bg); border: 1px solid #f5d38a; border-radius: 8px; padding: 8px 12px; margin-bottom: 10px; font-size: 0.875rem; }

/* Lists of cards */
.sae-search { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
.sae-search input[type=search] { flex: 1 1 240px; min-width: 0; height: 34px; }
.sae-card-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr)); gap: 12px; }
.sae-card { background: var(--sae-panel); border: 1px solid var(--sae-line); border-radius: 10px; padding: 14px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.sae-card h3 { overflow-wrap: anywhere; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sae-description { font-size: 0.875rem; margin: 0; flex: 1; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.sae-tags { margin: 0; display: flex; flex-wrap: wrap; gap: 4px; }
.sae-tag { background: var(--sae-soft); border-radius: 999px; padding: 1px 8px; font-size: 0.75rem; color: #334155; }
.sae-badge { background: #e0e7ff; color: #3730a3; border-radius: 999px; padding: 1px 8px; font-size: 0.72rem; font-weight: 600; }
.sae-template { background: #fbfcfe; }

/* Provenance info button and popup */
.sae-info, .sae-info-sample { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; min-width: 22px; margin: 0 2px; padding: 0; border: 1px solid #93a8c6; border-radius: 50%; background: #eef4ff; color: #1e40af; font: italic 700 13px/1 Georgia, "Times New Roman", serif; cursor: pointer; vertical-align: middle; }
.sae-info:hover, .sae-info:focus, .sae-info[aria-expanded=true] { background: var(--sae-accent); border-color: var(--sae-accent); color: #fff; }
.sae-info:disabled { opacity: 0.4; cursor: default; }
.sae-info-sample { cursor: default; }
.sae-prov { position: absolute; z-index: 10000; width: min(440px, calc(100vw - 16px)); max-height: min(70vh, 560px); overflow: auto; background: var(--sae-panel); color: var(--sae-ink); border: 1px solid #9fb0c8; border-radius: 10px; box-shadow: 0 12px 32px rgba(15, 23, 42, 0.22); padding: 12px 14px; font-size: 0.85rem; }
.sae-prov.sae-prov-sheet { position: fixed; left: 8px !important; right: 8px; bottom: 8px; top: auto !important; width: auto; max-height: 75vh; }
.sae-prov-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.sae-prov-head h3 { font-size: 0.95rem; margin: 0; outline: none; }
.sae-prov-close { margin: 0; padding: 0 6px; border: 0; background: transparent; color: var(--sae-muted); font-size: 1.3rem; line-height: 1; cursor: pointer; }
.sae-prov-close:hover, .sae-prov-close:focus { background: transparent; color: var(--sae-ink); }
.sae-prov-intro { margin: 6px 0; color: var(--sae-muted); font-size: 0.8rem; }
.sae-prov-list { margin: 0 0 0 1.2em; padding: 0; }
.sae-prov-citation { margin: 0 0 12px; padding-top: 8px; border-top: 1px solid var(--sae-line); }
.sae-prov-citation:first-child { border-top: 0; padding-top: 0; }
.sae-prov-line, .sae-prov-meta, .sae-prov-where, .sae-prov-note, .sae-prov-stale { margin: 2px 0; font-size: 0.82rem; line-height: 1.4; }
.sae-prov-title { font-weight: 600; color: #1d4ed8; text-decoration: underline; }
.sae-prov-meta { color: var(--sae-muted); }
.sae-prov-quote { margin: 6px 0; padding: 4px 0 4px 10px; border-left: 3px solid #93a8c6; color: #1e293b; font-size: 0.82rem; font-style: italic; line-height: 1.45; }
.sae-prov-note { color: #334155; background: var(--sae-soft); border-radius: 4px; padding: 3px 6px; }
.sae-prov-stale { color: var(--sae-warn); }

/* Badges for type, visibility, licence and classification */
.sae-badges { display: flex; flex-wrap: wrap; gap: 4px; margin: 0; }
.sae-badge.sae-public { background: #dcfce7; color: #166534; }
.sae-badge.sae-private { background: #f1f5f9; color: #334155; }
.sae-badge.sae-group { background: #fef3c7; color: #92400e; }
.sae-badge.sae-link-only { background: #fee2e2; color: #991b1b; }
.sae-badge.sae-due { background: var(--sae-warn-bg); color: var(--sae-warn); }
.sae-class { font-size: 0.72rem; font-weight: 600; border-radius: 4px; padding: 1px 6px; background: #e0e7ff; color: #3730a3; white-space: nowrap; }
.sae-class.sae-direct-requirement { background: #fee2e2; color: #991b1b; }
.sae-class.sae-interpretation { background: #fef3c7; color: #92400e; }
.sae-class.sae-recommendation { background: #dcfce7; color: #166534; }
.sae-class.sae-company-policy { background: #f3e8ff; color: #6b21a8; }

/* Source detail */
.sae-panel { background: var(--sae-panel); border: 1px solid var(--sae-line); border-radius: 10px; padding: 12px 16px; margin: 10px 0; min-width: 0; }
.sae-panel > h3 { margin-bottom: 6px !important; }
.sae-fields { display: grid; grid-template-columns: minmax(120px, max-content) minmax(0, 1fr); gap: 4px 14px; margin: 0; font-size: 0.875rem; }
.sae-fields dt { font-weight: 600; color: #334155; }
.sae-fields dd { margin: 0; overflow-wrap: anywhere; }
.sae-form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); gap: 0 14px; }
.sae-form-grid .sae-wide { grid-column: 1 / -1; }
.sae-page .sae-form-grid input, .sae-page .sae-form-grid select { width: 100%; height: 34px; }
.sae-page .sae-field-hint { display: block; font-weight: 400; color: var(--sae-muted); font-size: 0.78rem; margin-top: 2px; }
.sae-problems { color: var(--sae-danger); font-size: 0.85rem; margin: 6px 0; }
.sae-list { list-style: none; margin: 0; padding: 0; }
.sae-item { border-top: 1px solid var(--sae-line); padding: 8px 0; min-width: 0; overflow-wrap: anywhere; }
.sae-item:first-child { border-top: 0; }
.sae-item-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-weight: 600; font-size: 0.9rem; }
.sae-item p { margin: 2px 0; font-size: 0.85rem; }
.sae-quote { margin: 6px 0; padding: 4px 0 4px 10px; border-left: 3px solid #93a8c6; color: #1e293b; font-size: 0.85rem; font-style: italic; }
.sae-record { white-space: pre-wrap; overflow-wrap: anywhere; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--sae-soft); border-radius: 6px; padding: 8px; margin: 6px 0; }
.sae-hash { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.78rem; }
.sae-result-present { color: #166534; }
.sae-result-missing { color: var(--sae-danger); }

/* Passage editor preview: the same box the popup shows, drawn in place. */
.sae-preview-box { position: static; width: auto; max-height: none; box-shadow: none; margin: 6px 0; }
.sae-two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; align-items: start; }
.sae-count { font-weight: 400; color: var(--sae-muted); font-size: 0.78rem; }

/* Evidence */
.sae-part { margin: 10px 0; }
.sae-part h4 { font-size: 0.92rem; margin: 0 0 4px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; overflow-wrap: anywhere; }
.sae-table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
.sae-table th, .sae-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--sae-line); vertical-align: top; overflow-wrap: anywhere; }
.sae-table-wrap { overflow-x: auto; }

@media (max-width: 760px) {
  .sae-two { grid-template-columns: 1fr; }
  .sae-fields { grid-template-columns: 1fr; }
  .sae-fields dd { margin-bottom: 6px; }
}
@media (max-width: 640px) {
  .sae-app-view { padding: 8px; }
}
