:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --ink: #1d1d1f;
  --muted: #6b6b70;
  --line: #e3e1dc;
  --accent: #2f5bd3;
  --accent-ink: #ffffff;
  --warn-bg: #fff4d6;
  --warn: #b77900;
  --err: #c0362c;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17181b;
    --panel: #212226;
    --ink: #ececef;
    --muted: #a0a0a8;
    --line: #34353b;
    --accent: #6d8ff0;
    --accent-ink: #0d0e10;
    --warn-bg: #3a3014;
    --warn: #f0be4a;
    --err: #ff7a6e;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17181b;
  --panel: #212226;
  --ink: #ececef;
  --muted: #a0a0a8;
  --line: #34353b;
  --accent: #6d8ff0;
  --accent-ink: #0d0e10;
  --warn-bg: #3a3014;
  --warn: #f0be4a;
  --err: #ff7a6e;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", "Arial Hebrew", Arial, "Noto Sans Hebrew", sans-serif;
  background: var(--bg);
  color: var(--ink);
}
.top { padding: 20px 24px 8px; display: flex; align-items: flex-start; gap: 12px; }
.top > div:first-child { flex: 1; }
.account { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); }
.account [hidden] { display: none; }
.account button { padding: 4px 10px; font-size: 13px; }

.auth { display: flex; justify-content: center; padding-top: 24px; }
.auth[hidden] { display: none; }
.auth-card[hidden] { display: none; }
#signedOut { font-size: 16px; line-height: 1.5; margin: 0; }
.auth-card {
  width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 26px 24px;
}
.auth-card h2 { margin: 0 0 4px; font-size: 22px; }
.auth-card label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.auth-card label[hidden] { display: none; }
.auth-card input {
  font: inherit; font-size: 16px; padding: 9px 11px; border-radius: 7px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
}
.auth-card input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.auth-card button { padding: 10px; font-size: 16px; }
.auth-error { color: var(--err); font-size: 14px; margin: 0; min-height: 1em; }
.auth-switch { margin: 0; font-size: 14px; color: var(--muted); text-align: center; }
.auth-switch a { color: var(--accent); }
h1 { margin: 0; font-size: 26px; }
.sub { margin: 2px 0 0; color: var(--muted); }
main { padding: 12px 24px 48px; max-width: 1300px; margin: 0 auto; }

.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 56px 16px; border: 2px dashed var(--line); border-radius: 16px;
  background: var(--panel); cursor: pointer; text-align: center; transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone:focus, .dropzone.over { border-color: var(--accent); outline: none; }
.dz-icon { font-size: 34px; color: var(--accent); }
.dz-title { font-size: 20px; font-weight: 600; }
.dz-hint { color: var(--muted); font-size: 14px; }

.doc-bar { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.doc-title {
  flex: 1; min-width: 180px; font: inherit; font-size: 20px; font-weight: 600; padding: 6px 10px;
  border: 1px solid transparent; border-radius: 7px; background: transparent; color: var(--ink);
}
.doc-title:hover { border-color: var(--line); }
.doc-title:focus { outline: none; border-color: var(--accent); background: var(--panel); }
.save-state { font-size: 13px; color: var(--muted); white-space: nowrap; }
.save-state.err { color: var(--err); }

.doc-list { margin-top: 28px; }
.list-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.list-head h2 { margin: 0; flex: 1; }
.list-head button { padding: 4px 10px; font-size: 13px; }
.list-note { color: var(--muted); font-size: 14px; margin: 4px 0 12px; max-width: 70ch; line-height: 1.5; }
.writer-pick { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.writer-pick select, .dialog-input {
  font: inherit; font-size: 14px; padding: 5px 8px; border-radius: 7px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
}
.dialog-input { width: 100%; font-size: 16px; padding: 8px 10px; margin-bottom: 16px; }
.writer-name { flex: 1; margin: 0; font-size: 20px; min-width: 0; }
.writer-panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; }
.writer-panel .list-note { margin: 8px 0 0; }
.panel-title { margin: 0 0 4px; font-size: 16px; }
.train-row { display: flex; align-items: center; gap: 12px; margin-top: 10px; flex-wrap: wrap; }
.train-bar { flex: 1; min-width: 120px; max-width: 360px; height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.train-bar > div { height: 100%; width: 0; background: var(--accent); transition: width .4s; }
.example-list { display: flex; flex-direction: column; gap: 8px; }
.example {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 14px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px;
}
.example .crop { cursor: default; }
.example-text { font-size: 18px; min-width: 0; }
.example-was { font-size: 13px; color: var(--muted); margin-top: 4px; }
.example button { padding: 4px 10px; font-size: 13px; }
.doc-list h2 { font-size: 17px; margin: 0 0 10px; }
.doc-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; margin-bottom: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
.doc-item a { flex: 1; color: var(--ink); text-decoration: none; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-item a:hover { color: var(--accent); }
.doc-item .meta { font-size: 13px; color: var(--muted); white-space: nowrap; }
.doc-item button { padding: 4px 10px; font-size: 13px; }

.toolbar {
  position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; gap: 10px 16px;
  align-items: center; padding: 10px 12px; margin-bottom: 16px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
.tabs { display: flex; gap: 4px; background: var(--bg); padding: 3px; border-radius: 8px; }
.tab { border: 0; background: transparent; color: var(--ink); padding: 7px 14px; border-radius: 6px; cursor: pointer; font: inherit; }
.tab.active { background: var(--panel); box-shadow: 0 1px 3px rgba(0,0,0,.15); font-weight: 600; }
.status { color: var(--muted); font-size: 14px; flex: 1; min-width: 120px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
button {
  font: inherit; font-size: 14px; padding: 7px 12px; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
}
button.secondary { background: transparent; color: var(--ink); border-color: var(--line); }
button.danger { background: var(--err); border-color: var(--err); color: #fff; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.dialog-wrap { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; padding: 16px; }
.dialog { background: var(--panel); color: var(--ink); border-radius: 12px; padding: 20px 22px; max-width: 420px; width: 100%; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.dialog-msg { margin: 0 0 18px; font-size: 16px; line-height: 1.5; white-space: pre-line; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-start; }
button:disabled { opacity: .5; cursor: default; }
.check { font-size: 13px; color: var(--muted); display: flex; gap: 4px; align-items: center; }

.page { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 18px; overflow: hidden; }
.page-head { display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.page-head h2 { font-size: 15px; margin: 0; flex: 1; }
.page-head .state { font-size: 13px; color: var(--muted); }
.page-head .state.err { color: var(--err); }
.page-head button { padding: 4px 10px; font-size: 13px; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: -2px; margin-inline-end: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

.col-head { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 8px 14px 0; font-size: 12px; color: var(--muted); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 8px 14px; border-bottom: 1px solid var(--line); align-items: center; }
.row:last-child { border-bottom: 0; }
.row.unclear { background: var(--warn-bg); }
.draft-note { padding: 10px 14px; color: var(--muted, #666); font-size: 14px; border-bottom: 1px solid var(--line); }
.row.draft { opacity: 0.85; }
.draft-text { font-size: 18px; line-height: 1.6; padding: 8px 10px; }
.row textarea {
  width: 100%; font: inherit; font-size: 19px; padding: 8px 10px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  resize: none; overflow: hidden; line-height: 1.4; display: block;
}
.row textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
.crop { display: block; max-width: 100%; max-height: 110px; border-radius: 4px; background: #fff; cursor: zoom-in; justify-self: start; }
.flag { grid-column: 2; font-size: 12px; color: var(--warn); display: flex; gap: 8px; align-items: center; }
.flag button { padding: 1px 8px; font-size: 12px; background: transparent; color: var(--warn); border-color: var(--warn); }
.empty { padding: 18px 14px; color: var(--muted); }

.doc {
  padding: 28px 36px; font-size: 20px; line-height: 1.8; min-height: 120px; outline: none;
  white-space: pre-wrap; font-family: "David", "Frank Ruehl", "Times New Roman", "Noto Serif Hebrew", serif;
}
.doc:focus { box-shadow: inset 0 0 0 2px var(--accent); }
.doc mark { background: var(--warn-bg); color: inherit; border-bottom: 2px dotted var(--warn); }

.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.75); z-index: 20; display: flex; align-items: center; justify-content: center; padding: 20px; }
.lightbox[hidden] { display: none; }
.lb-inner { position: relative; max-width: 95vw; max-height: 92vh; overflow: auto; background: #fff; border-radius: 8px; }
.lb-stage { position: relative; }
.lb-stage img { display: block; max-width: 92vw; }
.lb-box { position: absolute; border: 3px solid #ff3b30; background: rgba(255,59,48,.08); pointer-events: none; }
.lb-close { position: sticky; top: 6px; float: inline-end; margin: 6px; z-index: 2; }

@media (max-width: 720px) {
  main, .top { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  .row, .col-head { grid-template-columns: 1fr; }
  .flag { grid-column: 1; }
  .doc { padding: 18px; }
  .doc-item { flex-wrap: wrap; }
  .example { grid-template-columns: 1fr; }
  .top { flex-wrap: wrap; }
  .top > div:first-child { flex-basis: 100%; }
  h1 { font-size: 22px; }
  .doc-item a { flex-basis: 100%; }
}
.writer-dialog { max-width: 440px; }
.pick-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.pick-new { margin-bottom: 4px; }
.pick-new .dialog-input { width: 100%; box-sizing: border-box; }
