/* Notatnik - notatka w powłoce (od 0.9.6; do 0.9.5 app.css): warstwa #editor na cały ekran bez pasków powłoki, pasek
   narzędzi w tokenach Hegios (grupy .ed-grp w ramce, koła koloru zostają kołami, Cofnij i Ponów, "..."), kartka na dwóch
   canvasach (#stage), notatka tekstowa (.text), linia dyktowania, pasek stron w ramce (.ed-pages), panel "..." jako okno
   .act-dlg, arkusz bloku tekstu (.sheet-wrap), paski "Cofnij" i komunikatu (.undo-bar, .msg-bar) oraz pasek przypomnienia
   (.banner). Kartka, kreski i reguły pióra są w crm/edytor.js bez zmian; tu tylko skóra. Twarde kąty, jeden jasny motyw. */

/* -- warstwa edytora -- */
.ed {
  position: fixed; inset: 0; z-index: 850; display: flex; flex-direction: column; background: var(--h-bg); color: var(--h-text);
  overscroll-behavior: none;
}
.ed-bar {
  flex: 0 0 auto; display: flex; align-items: center; gap: var(--h-sp-2); padding: 6px var(--h-sp-3);
  padding-top: calc(6px + env(safe-area-inset-top)); padding-left: calc(12px + env(safe-area-inset-left)); padding-right: calc(12px + env(safe-area-inset-right));
  background: var(--h-surface); border-bottom: 1px solid var(--h-border); box-shadow: var(--h-shadow-sm); z-index: 2;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; white-space: nowrap; overflow-x: auto;
}
.ed-bar::-webkit-scrollbar { display: none; }
.ed-bar .h-icon-btn { width: 40px; height: 40px; color: var(--h-text); flex-shrink: 0; }
.ed-back { margin-left: -8px; }
.ed-title {
  flex: 1 1 200px; min-width: 100px; border: 1px solid transparent; background: var(--h-bg); color: var(--h-text);
  padding: 8px 10px; min-height: 40px; font-size: var(--h-fs-15); font-weight: var(--h-fw-med); outline: none;
}
.ed-title:focus { border-color: var(--h-accent); background: var(--h-surface); }
/* grupa przycisków w ramce: narzędzie, kolory, cofnij i ponów; wybrany granatowy */
.ed-grp { display: inline-flex; border: 1px solid var(--h-border-strong); flex-shrink: 0; }
.ed-grp > button {
  width: 44px; height: 40px; display: inline-flex; align-items: center; justify-content: center; background: var(--h-surface);
  border: none; border-left: 1px solid var(--h-border-strong); color: var(--h-graphite); cursor: pointer; padding: 0;
  -webkit-tap-highlight-color: transparent;
}
.ed-grp > button:first-child { border-left: none; }
.ed-grp > button:hover:not(:disabled) { color: var(--h-text); background: var(--h-bg); }
.ed-grp > button[aria-pressed="true"] { background: var(--h-navy); color: #fff; }
.ed-grp > button:disabled { opacity: .4; cursor: default; }
.ed-grp > button:focus-visible { outline: 2px solid var(--h-accent); outline-offset: -2px; }
/* koło koloru: koło z natury; wybrane z obwódką wokół krążka (przycisk zostaje biały) */
.ed-grp .swatch i { display: block; width: 22px; height: 22px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }
.ed-grp .swatch[aria-pressed="true"] { background: var(--h-surface); color: var(--h-graphite); }
.ed-grp .swatch[aria-pressed="true"] i { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--h-navy); }
.ed-bar .dict[aria-pressed="true"] { background: var(--h-error-bg); color: var(--h-error); border-color: var(--h-error); }
.ed-bar .h-btn { min-height: 40px; flex-shrink: 0; }
.ed-bar .more-btn { margin-left: auto; }

/* Pasek edytora ma się mieścić bez przewijania także na połowie ekranu (507 px) i na telefonie. */
@media (max-width: 640px) {
  .ed-bar { gap: 4px; padding-left: calc(6px + env(safe-area-inset-left)); padding-right: calc(6px + env(safe-area-inset-right)); position: relative; }
  .ed-title { flex: 1 1 60px; min-width: 60px; padding: 8px; }
  /* Notatka odręczna: w trakcie pisania tytuł zajmuje cały pasek za strzałką "wróć", żeby było go widać w całości.
     (W notatce tekstowej tytuł ma dość miejsca i bez tego.) */
  .ed:not(.text-note) .ed-title:focus {
    position: absolute; z-index: 1; top: calc(6px + env(safe-area-inset-top)); left: calc(46px + env(safe-area-inset-left));
    width: calc(100% - 52px - env(safe-area-inset-left) - env(safe-area-inset-right)); padding: 8px 12px;
  }
  .ed-grp > button { width: 36px; }
  .ed-bar .h-icon-btn { width: 40px; }   /* Wróć, Wklej, "...": pole dotyku 40 px (narzędzia w grupach 36 px, żeby pasek mieścił się przy 507 px) */
  .ed-back { margin-left: -2px; }
  .ed-title { min-width: 52px; }
  .ed-grp .swatch i { width: 20px; height: 20px; }
  /* Wklej w notatce tekstowej (0.9.3): na wąskim ekranie sama ikona, żeby pasek z "Słucham..." nadal się mieścił */
  .ed-bar .paste { padding-left: 9px; padding-right: 9px; min-width: 40px; }
  .ed-bar .paste span { display: none; }
}

/* -- dyktowanie: linia pod paskiem -- */
.dict-line {
  flex: 0 0 auto; margin: 0; padding: 8px clamp(20px, 10vw, 180px);
  min-height: 37px; line-height: 20px; white-space: nowrap; overflow: hidden;
  background: #FFFEFB; color: var(--h-text-muted); font-size: var(--h-fs-13); border-bottom: 1px solid var(--h-border);
}
.dict-line.wrap { white-space: normal; }   /* podpowiedź może się zawinąć */
.dict-line:empty { border-bottom-color: transparent; }   /* pusta linia tylko trzyma miejsce */

/* -- kartka -- */
#stage {
  flex: 1 1 auto; position: relative; overflow: hidden;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  background: var(--h-bg);
}
#stage canvas { position: absolute; left: 0; top: 0; pointer-events: none; }

/* -- notatka tekstowa -- */
.text {
  flex: 1 1 auto; border: 0; resize: none; outline: none; display: block; width: 100%;
  background: #FFFEFB; color: var(--h-text);
  font: 17px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding: 24px clamp(20px, 10vw, 180px) calc(40px + env(safe-area-inset-bottom));
}
.text[hidden] { display: none; }

/* -- pasek stron w ramce z obrysem (na dole, na środku) -- */
.pagenav {
  position: absolute; z-index: 2; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  white-space: nowrap; display: inline-flex; align-items: center;
  background: var(--h-surface); border: 1px solid var(--h-border-strong); box-shadow: var(--h-shadow-md);
  -webkit-user-select: none; user-select: none;
}
.pagenav .btn {
  width: 44px; height: 40px; background: none; border: none; border-left: 1px solid var(--h-border); color: var(--h-graphite);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; padding: 0; -webkit-tap-highlight-color: transparent;
}
.pagenav .btn:first-child { border-left: none; }
.pagenav .btn:hover:not(:disabled) { color: var(--h-text); background: var(--h-bg); }
.pagenav .btn:disabled { opacity: .35; cursor: default; }
.pagenav .label { padding: 0 var(--h-sp-3); font-family: var(--h-font-mono); font-size: var(--h-fs-13); color: var(--h-graphite); font-variant-numeric: tabular-nums; border-left: 1px solid var(--h-border); line-height: 40px; }

/* -- panel "...": okno jak hForm (.act-dlg w crm.css; własne klasy, żeby nie mylić go z oknem powłoki) z polami notatki i pióra -- */
.ed-more {
  position: fixed; z-index: 1100; top: calc(58px + env(safe-area-inset-top)); right: calc(10px + env(safe-area-inset-right));
  width: min(460px, calc(100vw - 20px)); max-height: calc(100% - 70px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow-y: auto; -webkit-overflow-scrolling: touch; background: var(--h-surface); border: 1px solid var(--h-border-strong);
  box-shadow: var(--h-shadow-lg); padding: var(--h-sp-5);
}
/* nagłówek z X zostaje u góry przy przewijaniu (jak w panelu do 0.9.5) */
.ed-more-head { display: flex; align-items: center; gap: var(--h-sp-2); position: sticky; top: calc(-1 * var(--h-sp-5)); z-index: 1; margin: calc(-1 * var(--h-sp-5)) calc(-1 * var(--h-sp-5)) var(--h-sp-2); padding: var(--h-sp-5) var(--h-sp-5) var(--h-sp-2); background: var(--h-surface); }
.ed-more-head .h-icon-btn svg { pointer-events: none; }
.ed-more .ed-more-head h2 { flex: 1; font-size: var(--h-fs-16); font-weight: var(--h-fw-sem); color: var(--h-text); margin: 0; padding: 0; border: none; text-transform: none; letter-spacing: 0; }
.ed-more .h-field { margin-top: var(--h-sp-3); }
body.has-banner .ed-more { top: calc(120px + env(safe-area-inset-top)); max-height: calc(100% - 132px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
.ed-more .h-field > span { font-size: var(--h-fs-13); font-weight: var(--h-fw-med); color: var(--h-text); }
.ed-more .h-field > span b { font-weight: var(--h-fw-reg); color: var(--h-text-muted); margin-left: 4px; font-family: var(--h-font-mono); font-size: var(--h-fs-12); }
.ed-more .inline { display: flex; gap: var(--h-sp-2); align-items: center; }
.ed-more .inline .h-input { flex: 1 1 auto; min-width: 0; }
.ed-more .inline .h-btn { flex-shrink: 0; }
.ed-more .check { display: flex; align-items: center; gap: var(--h-sp-2); font-size: var(--h-fs-14); min-height: 40px; cursor: pointer; }
.ed-more .check input { width: 20px; height: 20px; margin: 0; accent-color: var(--h-accent); }
.ed-more .ed-row { display: flex; align-items: center; justify-content: space-between; gap: var(--h-sp-3); padding: var(--h-sp-2) 0; border-top: 1px solid var(--h-border); margin-top: var(--h-sp-2); font-size: var(--h-fs-14); }
.ed-more .ed-row > span { flex: 1 1 auto; }
.ed-more .ed-row input[type="checkbox"] { width: 22px; height: 22px; margin: 0; accent-color: var(--h-accent); }
.ed-more h2 { font-size: var(--h-fs-12); font-weight: var(--h-fw-sem); color: var(--h-graphite); text-transform: uppercase; letter-spacing: .4px; margin: var(--h-sp-4) 0 var(--h-sp-1); padding-top: var(--h-sp-3); border-top: 1px solid var(--h-border); }
.ed-more input[type="range"] { width: 100%; accent-color: var(--h-accent); }
.ed-more .h-input[type="date"], .ed-more .h-input[type="datetime-local"] { -webkit-appearance: none; appearance: none; min-height: 40px; }
.ed-more .hint { color: var(--h-text-muted); font-size: var(--h-fs-13); margin: var(--h-sp-3) 0 0; white-space: normal; }
.ed-more .ed-grp > button.size i { display: block; border-radius: 50%; background: currentColor; }
.pp { display: block; width: 20px; height: 20px; border: 1px solid var(--h-border-strong); background-color: #fff; }
.pp-lines { background-image: linear-gradient(to bottom, transparent 4px, #d6dcec 4px, #d6dcec 5px); background-size: 100% 5px; }
.pp-grid { background-image: linear-gradient(#d6dcec 1px, transparent 1px), linear-gradient(90deg, #d6dcec 1px, transparent 1px); background-size: 5px 5px; }
.pp-dots { background-image: radial-gradient(#b8c1d8 1px, transparent 1.2px); background-size: 5px 5px; background-position: 2px 2px; }
.ed-more .ed-grp > button[aria-pressed="true"] .pp { border-color: #fff; }

/* -- pasek "Usunięto - Cofnij" i komunikat (nad dolnym menu powłoki, nad nawigacją stron w notatce) -- */
.undo-bar {
  position: fixed; z-index: 1200; left: 50%; transform: translateX(-50%);
  bottom: calc(18px + env(safe-area-inset-bottom) + var(--crm-dol));
  max-width: calc(100vw - 20px); background: var(--h-toast-bg); color: var(--h-toast-text); padding: 8px 8px 8px 16px;
  display: flex; align-items: center; gap: 14px; white-space: nowrap; box-shadow: var(--h-shadow-lg);
  font-size: var(--h-fs-13); -webkit-user-select: none; user-select: none;
}
body.v-editor .undo-bar { bottom: calc(18px + env(safe-area-inset-bottom)); }   /* w notatce nie ma dolnego menu */
body .undo-bar.above-nav { bottom: var(--undo-bottom, calc(76px + env(safe-area-inset-bottom))); }   /* edytor liczy z nawigacji stron */
body .undo-bar.lifted { bottom: var(--undo-bottom); }
.undo-bar .h-btn { flex: 0 0 auto; background: none; border: 1px solid currentColor; color: inherit; min-height: 48px; padding: 6px 14px; font-weight: var(--h-fw-sem); }
.undo-bar.wrap { white-space: normal; width: max-content; }
.undo-bar.wrap #undo-text { min-width: 0; overflow-wrap: anywhere; }
.msg-bar { bottom: calc(var(--msg-bottom, 18px) + env(safe-area-inset-bottom)); white-space: normal; padding: 12px 16px; width: max-content; max-width: min(560px, calc(100vw - 20px)); }
.msg-bar.passive { pointer-events: none; }   /* komunikat, którego nie zamyka się dotknięciem: kartka pod nim działa dalej */

/* -- pasek przypomnienia notatki: pod paskiem u góry, na wierzchu (nad kartką zostaje, bo kartka nie może skakać) -- */
.banner {
  position: fixed; z-index: 1150; top: calc(62px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  max-width: calc(100vw - 20px); background: var(--h-toast-bg); color: var(--h-toast-text); padding: 8px 8px 8px 14px;
  display: flex; align-items: center; gap: 10px; box-shadow: var(--h-shadow-lg); font-size: var(--h-fs-13);
}
.banner svg { width: 20px; height: 20px; fill: none; stroke: #fde047; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
.banner .t { font-weight: var(--h-fw-sem); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.banner .h-btn-secondary { background: none; color: inherit; border-color: currentColor; }
body.has-banner .ed.text-note .ed-bar { margin-bottom: 64px; }   /* notatka tekstowa zostawia paskowi wolny pas */
body.has-banner .nt-head { margin-top: 56px; }

/* -- arkusz bloku tekstu (po przytrzymaniu bloku na kartce): od dołu, od 640 px na środku -- */
.sheet-wrap { position: fixed; inset: 0; z-index: 1100; display: flex; align-items: flex-end; justify-content: center; background: rgba(35,39,46,.45); }
.sheet-wrap > .sheet {
  width: 100%; max-width: 560px; max-height: calc(100% - 16px - env(safe-area-inset-top)); overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch; background: var(--h-surface); color: var(--h-text); box-shadow: var(--h-shadow-lg);
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  padding-left: calc(16px + env(safe-area-inset-left)); padding-right: calc(16px + env(safe-area-inset-right));
}
@media (min-width: 640px) { .sheet-wrap { align-items: center; padding: 16px; } .sheet-wrap > .sheet { max-height: 100%; } }
.sheet h2 { margin: 0 0 12px; font-size: var(--h-fs-16); font-weight: var(--h-fw-sem); overflow-wrap: anywhere; }
.f-row { display: flex; flex-direction: column; gap: 6px; min-width: 0; margin-bottom: 12px; }
.f-row > label { font-size: var(--h-fs-13); font-weight: var(--h-fw-med); color: var(--h-text); }
.f-input {
  width: 100%; min-width: 0; min-height: 48px; border: 1px solid var(--h-border-strong); outline: none; padding: 10px 12px;
  background: var(--h-surface); color: var(--h-text); font: inherit; font-size: 16px;
}
.f-input:focus { border-color: var(--h-accent); box-shadow: 0 0 0 3px rgba(46,100,168,.18); }
.f-mic { display: flex; gap: 8px; }
.f-mic .f-input { flex: 1 1 auto; }
.f-mic .h-btn { flex: 0 0 auto; width: 48px; min-height: 48px; padding: 0; }
.f-mic .h-btn[aria-pressed="true"] { background: var(--h-accent); color: #fff; border-color: var(--h-accent); }
.f-mic .h-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.f-dict { margin: 0; min-height: 18px; font-size: var(--h-fs-13); color: var(--h-text-muted); white-space: nowrap; overflow: hidden; }
.f-dict.wrap { white-space: normal; }
.tb-text { min-height: 120px; resize: vertical; line-height: 1.4; }
.f-mic .tb-text { flex: 1 1 auto; }
.f-mic:has(.tb-text) { align-items: flex-start; }
.f-err { margin: 0 0 12px; font-weight: var(--h-fw-sem); color: var(--h-error); }
.f-err:empty { display: none; }
.f-buttons { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 4px; }
.f-buttons .h-btn { flex: 1 1 96px; min-height: 48px; }
.ms-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.ms-btns .h-btn { flex: 0 0 auto; min-width: 48px; min-height: 48px; max-width: 100%; }

@media (hover: none) and (pointer: coarse) {
  .ed-grp > button { width: 44px; height: 44px; }
  .ed-bar .h-icon-btn { width: 44px; height: 44px; }
  .pagenav .btn { height: 44px; }
  .pagenav .label { line-height: 44px; }
}

/* w notatce nie ma pasków powłoki (warstwa zasłania je; visibility: hidden także dla czytników i testów) */
body.v-editor .layout > .topbar, body.v-editor .layout > .sidebar { visibility: hidden; }
