:root {
  --desk: #e9edf0;
  --surface: #f7f9fa;
  --ink: #1b2833;
  --muted: #566573;
  --line: #c6cfd6;
  --marker: #ffe14d;
  --marker-edge: #e6c400;
  --pen: #17527a;
  --ok: #17693f;
  --ok-bg: #e2f3e9;
  --err: #a32222;
  --err-bg: #fbe7e7;
  --warn-bg: #fff6d6;
  --wa: #1b7f4b;
  --wa-ink: #fff;
  --font: "Segoe UI", "Noto Sans Hebrew", "Arial Hebrew", Arial, sans-serif;
  --mono: Consolas, "Cascadia Mono", "DejaVu Sans Mono", "Courier New", monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --desk: #161d23; --surface: #1f2931; --ink: #e6ebef; --muted: #a2afba; --line: #3b4954;
    --pen: #8ec5ea; --ok: #7fd8a4; --ok-bg: #173526; --err: #ffa7a7; --err-bg: #452020; --warn-bg: #3d3515;
    --wa: #7fd8a4; --wa-ink: #0f2a1c;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--desk); color: var(--ink); font: 14px/1.5 var(--font); }
button, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--pen); outline-offset: 2px; }
[hidden] { display: none !important; }

.app { display: flex; flex-direction: column; gap: 10px; height: 100%; padding: 12px; min-width: 300px; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.top h1 { margin: 0; font-size: 16px; font-weight: 700; }
.pane { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.pane-input { flex: 0 0 auto; }
.pane-output { flex: 1 1 auto; min-height: 280px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }

.seg { display: flex; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; background: var(--surface); }
.seg legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.seg label { flex: 1; text-align: center; cursor: pointer; }
.seg label + label { border-inline-start: 1px solid var(--line); }
.seg input { position: absolute; opacity: 0; }
.seg span { display: block; padding: 6px 4px; font-size: 13px; }
.seg input:checked + span { background: var(--ink); color: var(--surface); font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--pen); outline-offset: -2px; }

.checks { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.check { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; width: fit-content; }
.check input { margin: 0; width: 15px; height: 15px; accent-color: var(--pen); cursor: pointer; }

#input { width: 100%; height: 150px; resize: vertical; padding: 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); line-height: 1.55; }
#input::placeholder { color: var(--muted); }

button { cursor: pointer; border-radius: 6px; padding: 7px 14px; border: 1px solid transparent; }
button:disabled { opacity: .45; cursor: not-allowed; }
.ghost { background: transparent; border-color: var(--line); }
.ghost:hover:not(:disabled) { border-color: var(--ink); }
.solid { background: var(--pen); color: #fff; font-weight: 600; }
@media (prefers-color-scheme: dark) { .solid { color: #10202c; } }
.marker { flex: 1; background: var(--marker); color: #1b2833; font-weight: 700; font-size: 15px; border-radius: 3px 16px 5px 13px / 11px 4px 13px 5px; border-color: var(--marker-edge); }
.marker:hover { filter: saturate(1.25) brightness(.97); }
.copy-bar .row button { flex: 1; white-space: nowrap; }
.wa { background: var(--wa); color: var(--wa-ink); font-weight: 600; }
.wa:hover:not(:disabled) { filter: brightness(1.08); }

.view-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); }
.view-tabs button { border: 0; border-radius: 0; background: none; padding: 5px 12px; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -1px; }
.view-tabs button[aria-selected="true"] { color: var(--ink); font-weight: 600; border-bottom-color: var(--marker-edge); }

.status { font-size: 13px; padding: 0 8px; border-radius: 5px; min-height: 0; display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.status:empty { display: none; }
.status.ok { background: var(--ok-bg); color: var(--ok); padding: 5px 8px; }
.status.err { background: var(--err-bg); color: var(--err); padding: 5px 8px; }
.status.info { background: var(--surface); color: var(--muted); padding: 5px 8px; }
.status button { padding: 1px 10px; background: none; border-color: currentColor; }

.warnings { background: var(--warn-bg); border-radius: 5px; padding: 5px 8px; font-size: 13px; }
.warnings summary { cursor: pointer; font-weight: 600; }
.warnings ul { margin: 6px 0 2px; padding-inline-start: 18px; max-height: 130px; overflow: auto; }
.warnings a { color: inherit; }

.stage { flex: 1 1 auto; min-height: 0; display: flex; gap: 10px; overflow: hidden; }
.stage.compare { flex-direction: column; }
.empty { flex: 1; display: grid; place-items: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 7px; padding: 24px; text-align: center; }
.compare-col { flex: 1 1 0; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.compare-col > h2 { display: none; margin: 0 0 3px; font-size: 13px; color: var(--muted); font-weight: 600; }
.stage.compare .compare-col > h2 { display: block; }
#source div { white-space: pre-wrap; overflow-wrap: anywhere; min-height: 1.5em; }
#source { flex: 1; margin: 0; padding: 12px; overflow: auto; font: 13px/1.55 var(--mono); background: var(--surface); border: 1px solid var(--line); border-radius: 7px; }

/* הגיליון נשאר לבן גם בתצוגה כהה, כי כך הוא ייראה במסמך */
.sheet { flex: 1; overflow: auto; background: #fff; color: #1b2833; border: 1px solid var(--line); border-radius: 7px; padding: 18px 16px; line-height: 1.65; font-size: 15px; }
.sheet > :first-child { margin-top: 0; }
.sheet h1, .sheet h2, .sheet h3, .sheet h4, .sheet h5, .sheet h6 { line-height: 1.3; margin: 1.1em 0 .4em; }
.sheet h1 { font-size: 1.55em; } .sheet h2 { font-size: 1.3em; } .sheet h3 { font-size: 1.13em; } .sheet h4, .sheet h5, .sheet h6 { font-size: 1em; }
.sheet p { margin: 0 0 .7em; }
.sheet hr { border: 0; border-top: 1px solid #c6cfd6; margin: 1.2em 0; }
.sheet ul { margin: .2em 0 .7em; padding-inline-start: 22px; }
/* רשימה בלי נקודות: כל פריט נראה כמו שורה רגילה, ורק רשימה פנימית מוזזת פנימה */
.sheet ul.no-dots { list-style: none; padding-inline-start: 0; }
.sheet ul.no-dots > li { margin: 0 0 .35em; }
.sheet li > ul.no-dots { padding-inline-start: 22px; }
.sheet blockquote { margin: .7em 0; padding-inline-start: 12px; border-inline-start: 3px solid #c6cfd6; color: #3d4c59; }
.sheet code { font-family: var(--mono); font-size: .9em; background: #eef1f4; padding: 1px 4px; border-radius: 3px; unicode-bidi: isolate; }
.sheet pre { direction: ltr; text-align: left; background: #f3f5f7; border: 1px solid #dde3e8; border-radius: 5px; padding: 10px; overflow: auto; font-size: 13px; line-height: 1.45; }
.sheet pre code { background: none; padding: 0; white-space: pre; }
.sheet a { color: #17527a; }
.sheet bdi { unicode-bidi: isolate; }
.plain-out { font-size: 14px; }
.plain-out div { white-space: pre-wrap; overflow-wrap: anywhere; min-height: 1.5em; }

.math { unicode-bidi: isolate; display: inline-block; direction: ltr; }
.math-block { direction: ltr; overflow-x: auto; overflow-y: hidden; text-align: center; margin: .6em 0 .9em; padding: .55em 0 .35em; }
.math-broken code { background: #fff1c9; }
.math-broken-block, .kept-wrap { margin: .7em 0; }
.kept-note { font-size: 12.5px; color: #6c5500; background: #fff6d6; padding: 3px 8px; border-radius: 4px 4px 0 0; }
.human { font-family: "Cambria Math", Cambria, serif; padding: 6px 8px; direction: ltr; text-align: left; }
.kept-wrap pre, .math-broken-block pre { margin-top: 0; border-radius: 0 0 5px 5px; }

.oli { display: flex; gap: 6px; margin: 0 0 .35em; }
.oli-m { flex: none; font-weight: 600; min-width: 1.3em; }
.oli-b { flex: 1; min-width: 0; }
.oli.option { padding-inline-start: 10px; }
.role-note { background: #fff8dc; border-inline-start: 3px solid #e0b400; padding: 5px 9px; }
.role-page { color: #667; font-size: .85em; }

.table-wrap { overflow-x: auto; margin: .7em 0; }
.sheet table { border-collapse: collapse; width: 100%; font-size: .94em; }
.sheet th, .sheet td { border: 1px solid #aeb9c2; padding: 5px 8px; vertical-align: top; }
.sheet th { background: #e9edf1; }
.sheet th[dir="rtl"], .sheet td[dir="rtl"] { text-align: right; }
.sheet th[dir="ltr"], .sheet td[dir="ltr"] { text-align: left; }
.sheet .a-center { text-align: center !important; }

.diagram { margin: .9em 0; overflow-x: auto; padding: 4px 0; position: relative; }
.tree ul { display: flex; justify-content: center; list-style: none; margin: 0; padding: 18px 0 0; position: relative; }
.tree > ul { padding-top: 0; }
.tree li { position: relative; display: flex; flex-direction: column; align-items: center; padding: 18px 6px 0; min-width: 88px; }
.tree > ul > li { padding-top: 0; }
.tree li::before, .tree li::after { content: ""; position: absolute; top: 0; width: 50%; height: 18px; border-top: 1.5px solid #5b6b7a; }
.tree li::before { inset-inline-start: 0; }
.tree li::after { inset-inline-end: 0; border-inline-start: 1.5px solid #5b6b7a; }
.tree li:first-child::before, .tree > ul > li::before, .tree > ul > li::after { display: none; }
.tree li:last-child::after { border: 0; }
.tree li:last-child::before { border-inline-end: 1.5px solid #5b6b7a; }
.tree li:only-child::before { display: none; }
.tree li:only-child::after { border: 0; border-inline-start: 1.5px solid #5b6b7a; }
.tree ul ul::before { content: ""; position: absolute; top: 0; inset-inline-start: 50%; height: 18px; border-inline-start: 1.5px solid #5b6b7a; }
.tree-node { background: #f3f6f9; border: 1.5px solid #5b6b7a; border-radius: 6px; padding: 5px 10px; text-align: center; font-size: .92em; line-height: 1.4; position: relative; z-index: 1; }
.tree-label { font-size: .78em; font-weight: 700; background: var(--marker); color: #1b2833; padding: 0 6px; border-radius: 3px; position: relative; z-index: 1; margin-bottom: 2px; }
.flow-row { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.flow-arrow { display: inline-flex; flex-direction: column; align-items: center; color: #5b6b7a; font-size: 1.1em; }
.flow-arrow small { font-size: .7em; }
.diagram-revert { display: block; margin: 6px auto 0; padding: 0 8px; font-size: 11.5px; color: #566573; background: none; border: 0; text-decoration: underline; }

.copy-bar { display: flex; flex-direction: column; gap: 6px; }
.target { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.target select { flex: 1; min-width: 0; padding: 4px 6px; border-radius: 5px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }

/* כרטיסייה רחבה: מקור מימין ותוצאה משמאל */
@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: minmax(320px, 2fr) 3fr; grid-template-rows: auto 1fr; }
  .top { grid-column: 1 / -1; }
  .pane-input { height: 100%; }
  #input { flex: 1; height: auto; resize: none; }
  .pane-output { min-height: 0; }
  .stage.compare { flex-direction: row; }
}
@media (prefers-reduced-motion: no-preference) {
  .status.ok, .status.err { animation: pop .18s ease-out; }
  @keyframes pop { from { transform: translateY(-3px); opacity: .4; } }
}

/* אפליקציה לטלפון: הכללים עם web חלים רק מחוץ לתוסף */
.top h1 small { margin-inline-start: 8px; font-size: 11px; font-weight: 400; color: var(--muted); white-space: nowrap; }
.web #copyWa { background: transparent; color: var(--wa); border-color: var(--wa); }
.web .top button { white-space: nowrap; }
@media (max-width: 600px) {
  .web .row button, .web .top button { padding-block: 10px; }
  .web .seg span { padding-block: 9px; }
  .web .check { min-height: 30px; }
  .web .check input { width: 18px; height: 18px; }
  .web .target select { padding-block: 8px; }
}
