/* Редакторът на лист от скицника (views/schede/_schizzo-editor.ejs, public/js/schizzo-*.js): на цял
   екран — горе заглавието, лентите, лентата за стойност и подсказката, после листът (бял като хартия и в
   тъмната тема). Лентите и менютата — schizzo-barre.css. */

/* `hidden` печели и над елементите със собствен `display`. */
.schizzo-editor [hidden] {
  display: none;
}

/* На цял екран; височината и горният ръб следват видимата част, когато екранната клавиатура е отворена
   (на iPad тя може и да превърти видимото надолу). Два пръста в рамката около листа не мащабират
   страницата (на листа мащабът е на редактора) — иначе редакторът остава уголемен и излиза от екрана. */
.schizzo-editor {
  top: var(--vvt, 0px);
  width: 100%;
  max-width: none;
  height: var(--vvh, 100%);
  touch-action: pan-x pan-y;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--bg);
  color: var(--fg);
  overscroll-behavior: contain;
}

.schizzo-editor[open] {
  display: flex;
  flex-direction: column;
}

.schizzo-editor::backdrop {
  background: var(--bg);
}

.schizzo-editor__testa {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 6px var(--gutter);
  border-bottom: 1px solid var(--line);
}

.schizzo-editor__titolo {
  margin: 0;
  font-size: 1.05rem;
}

.schizzo-editor__corpo {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.schizzo-editor__barre {
  display: grid;
  gap: 6px;
  padding: 6px var(--gutter);
  border-bottom: 1px solid var(--line);
}

.schizzo-editor__riga {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.schizzo-editor__gruppo {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
}

.schizzo-editor__storia {
  display: inline-flex;
  gap: 6px;
  margin-left: auto;
}

/* Лентата за стойност — над листа, никога под клавиатурата. */
.schizzo-editor__valore {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.schizzo-editor__valore .input {
  flex: 1 1 8em;
  min-width: 0;
}

.schizzo-editor__valore-nome {
  font-weight: 600;
}

.schizzo-editor__valore [aria-pressed='true'] {
  background: var(--mark-bg);
  color: var(--mark-fg);
}

.schizzo-editor__suggerimento {
  min-height: 1.3em;
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.schizzo-editor__aggancio {
  color: var(--fg);
  font-weight: 600;
}

.schizzo-editor__avviso {
  margin: 0;
  color: var(--danger);
  font-weight: 600;
}

.schizzo-editor__avviso:empty {
  display: none;
}

.schizzo-editor__area {
  display: grid;
  flex: 1;
  place-items: center;
  min-height: 0;
  padding: 8px;
  background: var(--wash);
}

.schizzo-editor__tela {
  display: block;
  background: #ffffff;
  box-shadow: 0 0 0 1px var(--line-strong);
  cursor: crosshair;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.schizzo-editor__tela:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
}

.schizzo-editor__tela[data-strumento='seleziona'] {
  cursor: default;
}

.schizzo-editor__tela[data-strumento='gomma'] {
  cursor: cell;
}

.schizzo-editor__tela[data-strumento='testo'] {
  cursor: text;
}

.schizzo-editor__ruota {
  display: none;
  margin: 0;
  padding: 6px var(--gutter);
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

@media (orientation: portrait) and (max-width: 640px) {
  .schizzo-editor__ruota {
    display: block;
  }
}

/* Нисък хоризонтален екран (телефон легнал): лентите — в колона вляво, листът взима височината. */
@media (orientation: landscape) and (max-height: 560px) {
  .schizzo-editor__testa {
    padding-block: 2px;
  }

  .schizzo-editor__corpo {
    flex-direction: row;
  }

  /* Редовете — колкото съдържанието: в колона с превъртане „auto“ пада до min-height (подсказката). */
  .schizzo-editor__barre {
    align-content: start;
    grid-auto-rows: max-content;
    width: 40%;
    max-width: 260px;
    overflow-y: auto;
    border-right: 1px solid var(--line);
    border-bottom: 0;
  }

  .schizzo-editor__storia {
    margin-left: 0;
  }

  /* Лентата за стойност (и подсказката ѝ) — първа в колоната: никога под края на екрана. Над отворената
     клавиатура остава горният ред: в него — полето и OK; името — само за екранния четец. */
  .schizzo-editor__valore .input {
    order: -2;
  }

  .schizzo-editor__valore [data-schizzo-valore-ok] {
    order: -1;
  }

  .schizzo-editor__valore-nome {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  /* Първа в колоната. */
  .schizzo-editor__valore,
  .schizzo-editor__barre:has(> .schizzo-editor__valore:not([hidden]))
    > .schizzo-editor__suggerimento {
    order: -1;
  }
}
