:root {
  color-scheme: light;
  --ink: #142724;
  --muted: #65736f;
  --paper: #f4f0e7;
  --surface: #fffdf8;
  --line: #d9d4c8;
  --forest: #123c36;
  --forest-2: #1e554d;
  --teal: #2d7165;
  --gold: #c9973f;
  --danger: #9f3f37;
  --shadow: 0 16px 45px rgb(22 45 40 / 14%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

@font-face { font-family: "Noto Sans Hebrew"; src: url("/assets/fonts/NotoSansHebrew-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Noto Sans Hebrew"; src: url("/assets/fonts/NotoSansHebrew-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Noto Serif Hebrew"; src: url("/assets/fonts/NotoSerifHebrew-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Noto Serif Hebrew"; src: url("/assets/fonts/NotoSerifHebrew-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-height: 100%; }
body { margin: 0; min-width: 0; overflow: auto; background: var(--paper); color: var(--ink); }
button, input, select, textarea { font: inherit; }
button, select, input[type="checkbox"], input[type="range"], input[type="color"] { cursor: pointer; }
button { color: inherit; }

.studio-topbar {
  position: relative; z-index: 50; display: grid; grid-template-columns: 310px minmax(240px, 1fr) auto;
  min-height: 66px; align-items: center; gap: 1rem; padding: .55rem 1rem; color: white;
  border-bottom: 1px solid rgb(255 255 255 / 12%); background: #102f2b;
}
.studio-brand { display: inline-flex; align-items: center; gap: .7rem; color: white; text-decoration: none; }
.studio-logo { width: 54px; height: 42px; border-radius: 7px; object-fit: cover; object-position: left center; }
.brand-mark { display: grid; place-items: center; width: 39px; height: 39px; border: 1px solid rgb(255 255 255 / 28%); border-radius: 50%; color: #edc775; font-size: 1.3rem; }
.studio-brand strong, .studio-brand small { display: block; }
.studio-brand strong { font-family: Georgia, serif; font-size: 1.12rem; }
.studio-brand small { margin-top: .08rem; color: rgb(255 255 255 / 63%); font-size: .61rem; letter-spacing: .12em; text-transform: uppercase; }
.document-title { min-width: 0; text-align: center; }
.document-title input { width: min(420px, 100%); padding: .4rem .65rem; border: 1px solid transparent; border-radius: 7px; outline: none; background: transparent; color: white; font-weight: 700; text-align: center; }
.document-title input:hover, .document-title input:focus { border-color: rgb(255 255 255 / 22%); background: rgb(255 255 255 / 7%); }
.document-title span { display: block; margin-top: .05rem; color: rgb(255 255 255 / 55%); font-size: .65rem; }
.top-actions { display: flex; align-items: center; gap: .45rem; }

.button, .icon-action, .mini-button, .page-actions button, .layer-actions button, .element-toolbar button {
  border: 1px solid var(--line); border-radius: 9px; background: var(--surface); font-weight: 750;
}
.button { min-height: 38px; padding: .55rem .85rem; }
.button.primary { border-color: #e3bd6a; background: #d9a84e; color: #102f2b; }
.button.quiet { border-color: rgb(255 255 255 / 20%); background: rgb(255 255 255 / 8%); color: white; }
.icon-action { width: 36px; height: 36px; border-color: rgb(255 255 255 / 18%); background: rgb(255 255 255 / 7%); color: white; font-size: 1.15rem; }
.button:hover:not(:disabled), .icon-action:hover:not(:disabled), .mini-button:hover:not(:disabled), .element-toolbar button:hover:not(:disabled) { filter: brightness(1.06); transform: translateY(-1px); }
button:disabled { cursor: not-allowed; opacity: .42; }

.studio-shell { display: grid; grid-template-columns: 286px minmax(520px, 1fr) 315px; min-height: calc(100vh - 66px); align-items: start; }
.left-panel, .right-panel { min-width: 0; overflow: visible; background: var(--surface); }
.left-panel { border-right: 1px solid var(--line); }
.right-panel { border-left: 1px solid var(--line); }
.panel-section { padding: 1rem; border-bottom: 1px solid var(--line); }
.section-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem; }
.eyebrow { color: var(--teal); font-size: .61rem; font-weight: 850; letter-spacing: .14em; text-transform: uppercase; }
h1, h2 { margin: .22rem 0 .75rem; font-family: Georgia, serif; font-weight: 600; }
h1 { font-size: 1.3rem; }
h2 { font-size: 1.12rem; }
.mini-button { padding: .35rem .55rem; color: var(--forest); font-size: .67rem; }

#setup-form label, #inspector label, .day-dialog label { display: block; margin-bottom: .72rem; }
#setup-form label > span, #inspector label > span, .day-dialog label > span { display: block; margin-bottom: .3rem; color: #4d5b57; font-size: .67rem; font-weight: 780; letter-spacing: .025em; }
input[type="text"], input[type="number"], select, textarea { width: 100%; min-height: 36px; padding: .48rem .55rem; border: 1px solid var(--line); border-radius: 8px; outline: none; background: white; color: var(--ink); font-size: .76rem; }
textarea { resize: vertical; line-height: 1.4; }
input:focus, select:focus, textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgb(45 113 101 / 11%); }
.two-fields, .three-fields { display: grid; gap: .55rem; }
.two-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.three-fields { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.content-options { margin: .3rem 0 .8rem; border: 1px solid var(--line); border-radius: 9px; }
.content-options summary { padding: .62rem; color: var(--forest); font-size: .72rem; font-weight: 800; }
.check-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .42rem; padding: 0 .65rem .7rem; }
.check-grid label { display: flex !important; align-items: center; gap: .3rem; margin: 0 !important; font-size: .66rem; }
.rebuild { width: 100%; border-color: var(--forest) !important; background: var(--forest) !important; color: white; }
.setup-section.collapsed #setup-form { display: none; }

.pages-section { min-height: 300px; }
.page-list { display: grid; gap: .45rem; max-height: 45vh; overflow: auto; padding-right: .2rem; }
.page-item { display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; align-items: center; gap: .55rem; padding: .48rem; border: 1px solid var(--line); border-radius: 9px; background: #faf8f2; cursor: pointer; }
.page-item:hover { border-color: #a9b7b2; }
.page-item.selected { border-color: var(--teal); background: #edf5f2; box-shadow: inset 3px 0 var(--teal); }
.page-thumb { display: grid; place-items: center; width: 34px; height: 43px; border: 1px solid #cfc8b8; border-radius: 3px; background: white; color: var(--forest); font-family: Georgia, serif; font-size: .58rem; box-shadow: 0 2px 5px rgb(0 0 0 / 8%); }
.page-thumb.landscape { width: 43px; height: 31px; }
.page-item strong { display: block; overflow: hidden; font-size: .7rem; text-overflow: ellipsis; white-space: nowrap; }
.page-item small { color: var(--muted); font-size: .6rem; }
.page-index { color: #8b918d; font-size: .62rem; }
.page-actions, .layer-actions { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .7rem; }
.page-actions button, .layer-actions button { flex: 1 1 auto; min-height: 30px; padding: .35rem .48rem; font-size: .65rem; }
.danger { border-color: #e3c4c0 !important; color: var(--danger) !important; }

.design-stage { position: sticky; top: 0; display: grid; grid-template-rows: 49px minmax(620px, calc(100vh - 115px)); min-width: 0; background: #e6e3dc; }
.element-toolbar { display: flex; align-items: center; gap: .45rem; padding: .5rem .75rem; border-bottom: 1px solid #cbc7bc; background: #f8f6f0; }
.element-toolbar button { min-height: 32px; padding: .35rem .62rem; color: var(--forest); font-size: .68rem; }
.element-toolbar .compact-tool { min-width: 34px; padding-inline: .45rem; font-size: 1rem; }
.element-toolbar button span { margin-right: .25rem; font-family: Georgia, serif; font-size: .9rem; }
.toolbar-divider { width: 1px; height: 25px; margin: 0 .35rem; background: var(--line); }
.zoom-control, .guide-toggle { display: flex; align-items: center; gap: .45rem; margin-left: auto; color: var(--muted); font-size: .66rem; font-weight: 700; }
.guide-toggle { margin-left: .4rem; }
.zoom-control input { width: 110px; }
.zoom-control output { min-width: 30px; }
.canvas-viewport { position: relative; overflow: auto; padding: 36px; }
.canvas-empty { position: absolute; inset: 0; display: grid; place-content: center; gap: .5rem; color: #6b7672; text-align: center; }
.canvas-empty strong { font-family: Georgia, serif; font-size: 1.4rem; }
.canvas-empty span { font-size: .78rem; }
.sheet-frame { width: max-content; margin: 0 auto 60px; }
.sheet { position: relative; width: var(--sheet-width, 640px); height: var(--sheet-height, 905px); overflow: hidden; background: white; box-shadow: 0 18px 60px rgb(25 39 36 / 23%); user-select: none; touch-action: none; }
.sheet-caption { margin-top: .7rem; color: #5d6864; font-size: .68rem; font-weight: 700; text-align: center; }
.safe-guide, .binding-guide { position: absolute; z-index: 500; pointer-events: none; }
.safe-guide { border: 1px dashed rgb(31 131 112 / 75%); }
.binding-guide { background: repeating-linear-gradient(45deg, rgb(201 151 63 / 8%), rgb(201 151 63 / 8%) 5px, rgb(201 151 63 / 15%) 5px, rgb(201 151 63 / 15%) 10px); border-bottom: 1px dashed rgb(201 151 63 / 80%); }
.sheet.hide-guides .safe-guide, .sheet.hide-guides .binding-guide { display: none; }

.design-element { position: absolute; z-index: 2; min-width: 2px; min-height: 2px; overflow: hidden; cursor: move; transform-origin: center; }
.design-element.locked { cursor: default; }
.design-element.selected { outline: 2px solid #1c89da; outline-offset: 2px; overflow: visible; }
.design-element.hidden-element { display: none; }
.element-text { display: flex; white-space: pre-wrap; overflow: hidden; line-height: var(--line-height, 1.15); unicode-bidi: plaintext; }
.element-text.align-left { justify-content: flex-start; text-align: left; }
.element-text.align-center { justify-content: center; text-align: center; }
.element-text.align-right { justify-content: flex-end; text-align: right; }
.element-text .text-content { width: 100%; unicode-bidi: plaintext; }
.element-image img { width: 100%; height: 100%; display: block; }
.element-image.fit-cover img { object-fit: cover; }
.element-image.fit-contain img { object-fit: contain; }
.element-image.fit-stretch img { object-fit: fill; }
.element-shape { border-style: solid; }
.resize-handle { position: absolute; right: -7px; bottom: -7px; z-index: 20; width: 13px; height: 13px; border: 2px solid white; border-radius: 50%; background: #1c89da; box-shadow: 0 1px 4px rgb(0 0 0 / 30%); cursor: nwse-resize; }
.resize-handle.top-left { inset: -7px auto auto -7px; cursor: nwse-resize; }
.resize-handle.top-right { inset: -7px -7px auto auto; cursor: nesw-resize; }
.resize-handle.bottom-left { inset: auto auto -7px -7px; cursor: nesw-resize; }
.resize-handle.bottom-right { inset: auto -7px -7px auto; }

.preview-calendar { display: grid; grid-template-columns: repeat(7, 1fr); grid-template-rows: auto repeat(var(--weeks), 1fr); width: 100%; height: 100%; overflow: hidden; border-top: 1px solid var(--grid); border-left: 1px solid var(--grid); background: #fffdf8; font-size: clamp(6px, .72vw, 12px); }
.preview-weekday { display: grid; place-items: center; min-width: 0; padding: .22em; border-right: 1px solid var(--grid); border-bottom: 1px solid var(--grid); background: var(--weekday); color: white; font-weight: 800; unicode-bidi: plaintext; }
.preview-day, .preview-empty { position: relative; min-width: 0; overflow: hidden; padding: .38em; border-right: 1px solid var(--grid); border-bottom: 1px solid var(--grid); }
.preview-empty { background: rgb(246 242 233 / 50%); }
.preview-day.shabbat { background: var(--shabbat); }
.preview-day.holiday { background: var(--holiday); }
.preview-day.override { box-shadow: inset 0 0 0 2px rgb(45 113 101 / 40%); }
.preview-date-row { display: flex; justify-content: space-between; gap: .2em; margin-bottom: .35em; }
.preview-gregorian { font-family: Georgia, serif; font-size: 1.38em; font-weight: 800; }
.preview-hebrew { color: var(--teal); font-family: "Noto Sans Hebrew", sans-serif; font-size: .9em; direction: rtl; unicode-bidi: plaintext; }
.preview-event { display: block; overflow: hidden; margin: .14em 0; color: var(--ink); font-size: .82em; line-height: 1.12; overflow-wrap: anywhere; white-space: normal; unicode-bidi: plaintext; }
.preview-event.hebrew { font-family: "Noto Sans Hebrew", sans-serif; direction: rtl; text-align: right; }
.preview-event.major { color: #8a5a0b; font-weight: 800; }
.preview-note { color: var(--teal); font-size: .76em; font-weight: 750; unicode-bidi: plaintext; }
.preview-note.hebrew { font-family: "Noto Sans Hebrew", sans-serif; direction: rtl; text-align: right; }

.inspector-section { min-height: 330px; }
.inspector-group { margin-bottom: 1rem; padding-bottom: .65rem; border-bottom: 1px solid #ebe7dd; }
.inspector-group h3 { margin: 0 0 .6rem; color: var(--forest); font-size: .72rem; }
.inspector-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; }
.inspector-grid label { margin-bottom: .35rem !important; }
.color-row { display: grid; grid-template-columns: 42px minmax(0, 1fr); align-items: center; gap: .45rem; }
input[type="color"] { width: 42px; height: 34px; padding: 2px; border: 1px solid var(--line); border-radius: 7px; background: white; }
.inspector-check { display: flex !important; align-items: center; gap: .45rem; font-size: .7rem; }
.inspector-check span { margin: 0 !important; }
.inline-action { width: 100%; min-height: 34px; margin-bottom: .55rem; border: 1px solid var(--line); border-radius: 8px; background: #f5f2e9; color: var(--forest); font-size: .68rem; font-weight: 800; }
.hint { margin: .2rem 0 .7rem; color: var(--muted); font-size: .66rem; line-height: 1.45; }

.layer-list { display: grid; gap: .3rem; max-height: 260px; overflow: auto; }
.layer-item { display: flex; align-items: center; gap: .4rem; min-width: 0; padding: .42rem .5rem; border: 1px solid transparent; border-radius: 7px; background: #f7f4ed; cursor: pointer; }
.layer-item.selected { border-color: var(--teal); background: #e9f2ef; }
.layer-icon { width: 20px; color: var(--teal); font-family: Georgia, serif; text-align: center; }
.layer-name { overflow: hidden; flex: 1; font-size: .67rem; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.layer-state { color: #8b948f; font-size: .58rem; }

dialog { width: min(720px, calc(100vw - 2rem)); max-height: calc(100vh - 3rem); overflow: auto; padding: 0; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--ink); box-shadow: 0 30px 90px rgb(0 0 0 / 32%); }
dialog::backdrop { background: rgb(10 25 22 / 58%); backdrop-filter: blur(3px); }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; padding: 1.15rem 1.25rem .7rem; border-bottom: 1px solid var(--line); }
.dialog-heading h2 { margin-bottom: .2rem; }
.dialog-heading button { border: 0; background: transparent; color: var(--muted); font-size: 1.5rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .6rem; padding: 1rem 1.25rem 1.25rem; }
.dialog-actions .button.quiet { border-color: var(--line); background: white; color: var(--ink); }
.dialog-actions.stacked { flex-direction: column; }
.download-link { display: grid; place-items: center; text-decoration: none; }
.report-dialog #preflight-report { padding: 1rem 1.25rem; }
.report-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; margin-bottom: 1rem; }
.report-summary article { padding: .7rem; border: 1px solid var(--line); border-radius: 10px; background: #f8f5ee; }
.report-summary span, .report-summary strong { display: block; }
.report-summary span { color: var(--muted); font-size: .61rem; }
.report-summary strong { margin-top: .2rem; font-family: Georgia, serif; font-size: 1.05rem; }
.report-status { margin-bottom: 1rem; padding: .75rem; border-radius: 9px; font-size: .76rem; font-weight: 800; }
.report-status.ready { background: #e3f1eb; color: #195d4b; }
.report-status.blocked { background: #fae8e5; color: #8b3029; }
.day-events { margin: .75rem 0; padding: .65rem .75rem; border: 1px solid var(--line); border-radius: 9px; }
.day-events legend { padding: 0 .25rem; color: var(--forest); font-size: .72rem; font-weight: 800; }
.day-events .inspector-check { margin: .4rem 0 !important; }
.day-event-editor { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: .45rem .6rem; padding: .65rem 0; border-bottom: 1px solid var(--line); }
.day-event-editor > input[type="checkbox"] { margin-top: 1.6rem; }
.day-event-fields { display: grid; grid-template-columns: 1fr 1fr 96px; gap: .4rem; }
.day-event-fields label { margin: 0 !important; }
.hebrew-input, .day-event-fields .event-hebrew { direction: rtl; unicode-bidi: plaintext; font-family: "Noto Sans Hebrew", sans-serif; font-size: .9rem; text-align: right; }
.gallery-dialog { width: min(920px, calc(100vw - 2rem)); }
.gallery-dialog > .hint, .gallery-actions, .gallery-grid { margin-inline: 1.25rem; }
.gallery-actions { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-block: 1rem; }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .8rem; padding-bottom: 1.25rem; }
.gallery-empty { grid-column: 1 / -1; padding: 2rem; border: 1px dashed var(--line); border-radius: 12px; color: var(--muted); text-align: center; }
.gallery-card { overflow: hidden; border: 1px solid var(--line); border-radius: 11px; background: white; }
.gallery-card img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: #eee; }
.gallery-card strong { display: block; overflow: hidden; padding: .5rem .55rem .15rem; font-size: .68rem; text-overflow: ellipsis; white-space: nowrap; }
.gallery-card small { display: block; padding: 0 .55rem .5rem; color: var(--muted); font-size: .58rem; }
.gallery-card-actions { display: grid; grid-template-columns: 1fr auto; border-top: 1px solid var(--line); }
.gallery-card-actions button { min-height: 32px; border: 0; background: #f7f4ed; font-size: .63rem; font-weight: 800; }
.gallery-card-actions .gallery-delete { border-left: 1px solid var(--line); color: var(--danger); }
.report-list { margin: .6rem 0 1rem; padding: 0; list-style: none; }
.report-list li { padding: .55rem .65rem; border-bottom: 1px solid #ebe7dd; font-size: .7rem; line-height: 1.4; }
.report-list strong { margin-right: .35rem; }
.day-dialog, .small-dialog { width: min(510px, calc(100vw - 2rem)); }
.day-dialog form, .small-dialog > p { padding: 1rem 1.25rem 0; }

.busy-overlay { position: fixed; z-index: 1000; inset: 0; display: grid; place-content: center; gap: .8rem; background: rgb(16 47 43 / 80%); color: white; text-align: center; backdrop-filter: blur(3px); }
.spinner { width: 44px; height: 44px; margin: 0 auto; border: 4px solid rgb(255 255 255 / 22%); border-top-color: #e9c36f; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; z-index: 1100; right: 1rem; bottom: 1rem; max-width: 390px; padding: .75rem .95rem; border-radius: 10px; background: #173f39; color: white; font-size: .74rem; box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .18s ease; }
.toast.visible { opacity: 1; transform: translateY(0); }
.toast.error { background: #823d36; }

@media (max-width: 1280px) {
  .studio-shell { grid-template-columns: 255px minmax(470px, 1fr) 285px; }
  .studio-topbar { grid-template-columns: 265px minmax(180px, 1fr) auto; }
  .button { padding-inline: .58rem; font-size: .68rem; }
}

@media (max-width: 980px) {
  .studio-topbar { grid-template-columns: 1fr auto; }
  .document-title { grid-column: 1 / -1; grid-row: 2; }
  .top-actions { justify-content: flex-end; flex-wrap: wrap; }
  .studio-shell { grid-template-columns: minmax(250px, 1fr) minmax(0, 1.8fr); }
  .right-panel { grid-column: 1 / -1; border-top: 1px solid var(--line); border-left: 0; }
  .design-stage { top: 0; }
}

@media (max-width: 700px) {
  .studio-topbar { display: flex; flex-wrap: wrap; gap: .55rem; padding: .65rem; }
  .studio-brand { flex: 1 1 200px; }
  .document-title { width: 100%; order: 3; }
  .top-actions { flex: 1 1 auto; }
  .studio-shell { display: block; }
  .left-panel, .right-panel { border: 0; }
  .setup-section { max-height: 48vh; overflow: auto; }
  .pages-section { padding-block: .75rem; }
  .page-list { display: flex; max-height: none; overflow-x: auto; }
  .page-item { min-width: 210px; }
  .design-stage { position: relative; min-height: 70vh; margin: 0; }
  .element-toolbar { flex-wrap: wrap; height: auto; }
  .zoom-control { margin-left: 0; }
  .canvas-viewport { min-height: 64vh; padding: 12px; overflow: auto; }
  .two-fields, .three-fields { grid-template-columns: 1fr; }
  .check-grid { grid-template-columns: 1fr; }
  .report-summary { grid-template-columns: repeat(2, 1fr); }
  .day-event-fields { grid-template-columns: 1fr; }
  .gallery-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
