:root{
  --page-w: 148;         /* A5 ברירת מחדל: 148mm */
  --page-h: 210;         /* A5 ברירת מחדל: 210mm */
  --margins-mm: 15;
  --columns: 1;

  --font-size: 16px;
  --line-height: 1.6;
  --heading-scale: 1.25;

  --bg: #0f172a;
  --panel: #111827;
  --card: #0b1220;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --border: rgba(255, 255, 255, 0.08);
}

*{ box-sizing: border-box; }

body{
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, "Noto Sans Hebrew", sans-serif;
}

.topbar{
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
}

.topbar__title{
  font-weight: 700;
  margin-bottom: 10px;
}

.topbar__actions{
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.status{
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.file{
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
}

.file input{
  display: none;
}

.btn{
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
}

.btn:disabled{
  opacity: 0.5;
  cursor: not-allowed;
}

.layout{
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 12px;
  padding: 12px;
}

.panel{
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  height: calc(100vh - 140px);
  overflow: auto;
}

.panel__title{
  margin: 0 0 10px 0;
  font-size: 16px;
}

.field{
  margin-bottom: 12px;
}

.field label{
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

.field select,
.field input[type="range"]{
  width: 100%;
}

.hint{
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.sep{
  border: none;
  border-top: 1px solid var(--border);
  margin: 14px 0;
}

.toc{
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  border-radius: 12px;
  padding: 10px;
}

.toc a{
  display: block;
  color: var(--text);
  text-decoration: none;
  padding: 4px 6px;
  border-radius: 8px;
}

.toc a:hover{
  background: rgba(255, 255, 255, 0.06);
}

.toc .lvl-1{ margin-right: 0; font-weight: 700; }
.toc .lvl-2{ margin-right: 12px; }
.toc .lvl-3{ margin-right: 24px; }

.preview{
  min-height: calc(100vh - 140px);
  overflow: auto;
}

.page{
  margin: 0 auto;
  width: calc(var(--page-w) * 1mm);
  min-height: calc(var(--page-h) * 1mm);
  background: #ffffff;
  color: #0b1220;
  border-radius: 14px;
  border: 1px solid rgba(0,0,0,0.08);
  box-shadow: 0 12px 40px rgba(0,0,0,0.35);
  padding: calc(var(--margins-mm) * 1mm);
}

.doc{
  direction: rtl;
  unicode-bidi: plaintext;
  font-size: var(--font-size);
  line-height: var(--line-height);
}

.doc.columns-2{
  column-count: var(--columns);
  column-gap: 12mm;
}

.doc h1,
.doc h2,
.doc h3{
  break-after: avoid;
  page-break-after: avoid;
  margin: 0 0 8px 0;
}

.doc h1{ font-size: calc(var(--font-size) * var(--heading-scale) * 1.35); }
.doc h2{ font-size: calc(var(--font-size) * var(--heading-scale) * 1.15); }
.doc h3{ font-size: calc(var(--font-size) * var(--heading-scale) * 1.02); }

.doc p{
  margin: 0 0 10px 0;
}

.doc img{
  max-width: 100%;
  height: auto;
}

.doc table{
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
}

.doc td, .doc th{
  border: 1px solid rgba(0,0,0,0.18);
  padding: 6px;
  vertical-align: top;
}

@media print{
  body{
    background: #fff;
  }

  .topbar, .panel{
    display: none !important;
  }

  .layout{
    display: block;
    padding: 0;
  }

  .page{
    width: auto;
    min-height: auto;
    border: none;
    box-shadow: none;
    border-radius: 0;
    padding: calc(var(--margins-mm) * 1mm);
  }
}
