/* TEI Editor — shell layout (S8). Visual structure only; behaviour lands later. */
:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --fg: #1c1c1c;
  --muted: #6b7280;
  --border: #d8dce2;
  --surface: #f7f8fa;
  --accent: #2563eb;
  --ok: #15803d;
  --err: #b91c1c;
  --toolbar-h: 3rem;
  --gap: 0.75rem;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

/* --- toolbar --- */
.toolbar {
  height: var(--toolbar-h);
  display: flex;
  align-items: center;
  gap: var(--gap);
  padding: 0 var(--gap);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.toolbar__title { font-size: 1rem; margin: 0; white-space: nowrap; }
.toolbar__actions { display: flex; align-items: center; gap: 0.5rem; flex: 1; }
.toolbar__spacer { flex: 1; }

button {
  font: inherit;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* --- main two-pane layout --- */
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
  padding: var(--gap);
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; overflow: auto; }
}

.editor, .sidebar { min-height: 0; display: flex; flex-direction: column; }

.editor__surface {
  flex: 1;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 1rem;
  background: var(--bg);
  line-height: 1.5;
}
.editor__surface:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.editor__surface:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  font-style: italic;
}
.editor__surface > * { margin: 0 0 0.6rem; }
.editor__surface h1, .editor__surface h2, .editor__surface h3,
.editor__surface h4, .editor__surface h5, .editor__surface h6 {
  line-height: 1.25;
}
/* Tagged inline entities (spans get real behaviour in S13). */
.editor__surface .ent {
  border-radius: 0.2rem;
  padding: 0 0.1rem;
  background: rgba(37, 99, 235, 0.12);
  box-shadow: inset 0 -1px 0 var(--accent);
}

/* --- import affordance + block bar (S10/S12) --- */
.import { margin-bottom: var(--gap); }
.import summary { cursor: pointer; font-weight: 600; }
.editor__bar { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.5rem; }
.editor__hint { font-size: 0.78rem; color: var(--muted); }

/* --- tagging (S13) --- */
.tag-bar { display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.5rem; flex-wrap: wrap; }
.tag-bar__label { font-size: 0.8rem; font-weight: 600; }
.tag-hint { font-size: 0.78rem; color: var(--err); }
.editor__surface .ent--active {
  background: rgba(245, 158, 11, 0.3);
  box-shadow: inset 0 -2px 0 #b45309;
}

/* --- entity register cards (S13) --- */
.entity-card {
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.5rem;
  margin-bottom: 0.6rem;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.entity-card__top { display: flex; align-items: center; justify-content: space-between; }
.entity-card__id {
  font-family: ui-monospace, monospace;
  font-size: 0.75rem;
  padding: 0.1rem 0.4rem;
  border-radius: 0.25rem;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
}
.entity-card__id:hover { border-color: var(--accent); }
.entity-card input { font: inherit; padding: 0.3rem 0.45rem; border: 1px solid var(--border); border-radius: 0.375rem; background: var(--bg); color: var(--fg); }
.entity-card__name { font-weight: 600; }
.entity-add { margin-top: 0.25rem; }

.sidebar { gap: var(--gap); }

/* --- tabs --- */
.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border); flex: 0 0 auto; }
.tabs [role="tab"] {
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 0.375rem 0.375rem 0 0;
  background: transparent;
}
.tabs [role="tab"][aria-selected="true"] {
  background: var(--surface);
  border-color: var(--border);
  font-weight: 600;
}
.tabs [role="tab"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* A short single line the importer flagged as a possible heading (A2). */
.editor__surface .suggested-head {
  text-decoration: underline dashed var(--muted);
  text-underline-offset: 3px;
}
/* Metadata panels and the preview each take a shrinkable, scrollable share of
   the sidebar column (min-height:0 defeats the flex min-content floor, so a
   tall Header form can no longer push the preview off-screen). */
.tabs__panels { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; }
.tab-panel {
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 0.5rem 0.5rem;
  padding: 1rem;
  background: var(--surface);
}

/* --- preview --- */
.preview { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; }
.preview__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  margin-bottom: 0.5rem;
}
.preview__switch { display: flex; gap: 0.25rem; }
.preview__xml, .preview__tree {
  flex: 1;
  overflow: auto;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.75rem;
  background: var(--surface);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
}

/* --- XML pane: line-numbered + scroll-to-line (S14) --- */
.preview__xml { counter-reset: ln; }
.xml-line {
  display: block;
  min-height: 1.2em;
  white-space: pre-wrap;
  word-break: break-word;
}
.xml-line::before {
  content: counter(ln);
  counter-increment: ln;
  display: inline-block;
  width: 2.5em;
  margin-right: 0.75em;
  color: var(--muted);
  text-align: right;
  user-select: none;
}
.xml-line--flash { background: rgba(245, 158, 11, 0.35); }

/* --- located error list (S14) --- */
.error-list {
  list-style: none;
  margin: 0 0 0.5rem;
  padding: 0;
  max-height: 9rem;
  overflow: auto;
  border: 1px solid var(--err);
  border-radius: 0.5rem;
}
.error-list__item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  font-size: 0.8rem;
  padding: 0.35rem 0.5rem;
  cursor: pointer;
}
.error-list__item:hover { background: var(--surface); }
.error-list__loc { font-family: ui-monospace, monospace; color: var(--err); font-weight: 600; }

/* --- element tree (S14) --- */
.preview__tree { font-family: ui-monospace, monospace; font-size: 0.82rem; }
.preview__tree details { margin-left: 0.9rem; }
.preview__tree summary { cursor: pointer; }
.tree-leaf { margin-left: 0.9rem; }
.tree-tag { color: var(--accent); }
.tree-text { color: var(--fg); }

/* --- validation badge --- */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.8rem;
  border: 1px solid var(--border);
}
.badge--idle { color: var(--muted); }
.badge--ok { color: var(--ok); border-color: var(--ok); }
.badge--err { color: var(--err); border-color: var(--err); }

/* --- import widget (S10) --- */
.import__label { display: block; font-weight: 600; margin-bottom: 0.4rem; }
.import__text {
  width: 100%;
  min-height: 9rem;
  resize: vertical;
  font: inherit;
  padding: 0.6rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--bg);
  color: var(--fg);
}
.import__actions { margin: 0.5rem 0 1rem; }

/* --- metadata forms (S11) --- */
/* The visible panel (hidden ones are display:none) fills .tabs__panels and
   scrolls internally rather than stretching the column. */
.tab-panel { flex: 1; min-height: 0; overflow: auto; }
.form-section { margin-bottom: 1.25rem; }
.form-section h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--border);
}
.field { margin-bottom: 0.6rem; display: flex; flex-direction: column; gap: 0.2rem; }
.field > label { font-size: 0.85rem; font-weight: 600; }
.field input, .field select, .row input {
  font: inherit;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  background: var(--bg);
  color: var(--fg);
}
.row { display: flex; gap: 0.4rem; margin-bottom: 0.4rem; align-items: center; }
.row input { flex: 1; min-width: 0; }
.row__ident { flex: 0 0 6rem; }
.row__remove {
  flex: 0 0 auto;
  padding: 0.2rem 0.55rem;
  line-height: 1;
  color: var(--err);
}
.help { margin: 0.15rem 0 0; font-size: 0.78rem; color: var(--muted); }

.placeholder { color: var(--muted); font-style: italic; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
