/* Πίνακας — στυλ. Μόνο γραμματοσειρές συστήματος, τίποτα εξωτερικό. */

:root {
  --desk: #d3d7dd;
  --bar: #f7f8fa;
  --fg: #1d2026;
  --muted: #6b7280;
  --line: rgba(0, 0, 0, .12);
  --hover: rgba(0, 0, 0, .06);
  --accent: #2563eb;
  --accent-bg: #dbe6ff;
  --warn: #e8890c;
  --bad: #d32f2f;
  --shadow: 0 8px 30px rgba(0, 0, 0, .18), 0 1px 3px rgba(0, 0, 0, .12);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --desk: #0d0f12;
  --bar: #1b1f24;
  --fg: #e8eaed;
  --muted: #9aa3ad;
  --line: rgba(255, 255, 255, .12);
  --hover: rgba(255, 255, 255, .07);
  --accent: #7aa2ff;
  --accent-bg: #27334d;
  --warn: #ffb347;
  --bad: #ff6b6b;
  --shadow: 0 8px 30px rgba(0, 0, 0, .55), 0 1px 3px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

/* Δύο μεγέθη μπάρας: μικρά κουμπιά (προεπιλογή) και μεγάλα για άνετη αφή σε πίνακα. */
#app { --tap: 42px; --tap-h: 46px; --icon: 22px; --dot: 22px; }
#app[data-size="large"] { --tap: 56px; --tap-h: 60px; --icon: 28px; --dot: 32px; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--desk);
  color: var(--fg);
  font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
  /* Πίνακας αφής: καμία κύλιση/ανανέωση με τράβηγμα, καμία επιλογή κειμένου ή μεγεθυντικός φακός. */
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; }

/* ---------- διάταξη: μπάρα κάτω / πάνω / αριστερά / δεξιά ---------- */

#app {
  position: fixed;
  inset: 0;
  display: grid;
}
#app[data-bar="bottom"] { grid-template: "stage" 1fr "bar" auto / 1fr; }
#app[data-bar="top"]    { grid-template: "bar" auto "stage" 1fr / 1fr; }
#app[data-bar="left"]   { grid-template: "bar stage" 1fr / auto 1fr; }
#app[data-bar="right"]  { grid-template: "stage bar" 1fr / 1fr auto; }

#stage {
  grid-area: stage;
  position: relative;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
  touch-action: none;      /* όλες οι χειρονομίες στον καμβά τις χειριζόμαστε εμείς */
  background: var(--desk);
}
.layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;     /* τα γεγονότα τα παίρνει το #stage */
}

#bar {
  grid-area: bar;
  background: var(--bar);
  display: flex;
  align-items: center;
  justify-content: safe center;
  gap: 2px;
  padding: 3px max(6px, env(safe-area-inset-right)) max(3px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  touch-action: pan-x;
}
#app[data-bar="bottom"] #bar { border-top: 1px solid var(--line); }
#app[data-bar="top"] #bar { border-bottom: 1px solid var(--line); padding-top: max(3px, env(safe-area-inset-top)); padding-bottom: 3px; }

/* Πλάγια μπάρα: δύο στήλες, ώστε να χωράει σε ύψος χωρίς κύλιση. */
#app[data-bar="left"] #bar,
#app[data-bar="right"] #bar {
  display: grid;
  grid-template-columns: repeat(2, var(--tap));
  grid-auto-rows: min-content;
  align-content: safe center;
  justify-content: center;
  overflow-x: hidden;
  overflow-y: auto;
  touch-action: pan-y;
  padding: max(6px, env(safe-area-inset-top)) 4px max(6px, env(safe-area-inset-bottom));
}
#app[data-bar="left"] #bar { border-right: 1px solid var(--line); padding-left: max(4px, env(safe-area-inset-left)); }
#app[data-bar="right"] #bar { border-left: 1px solid var(--line); padding-right: max(4px, env(safe-area-inset-right)); }

#app.bar-hidden #bar { display: none; }

.sep {
  flex: none;
  width: 1px;
  height: calc(var(--tap-h) * .6);
  margin: 0 4px;
  background: var(--line);
}
#app[data-bar="left"] .sep, #app[data-bar="right"] .sep {
  grid-column: 1 / -1;
  width: auto;
  height: 1px;
  margin: 4px 4px;
}

/* ---------- κουμπιά ---------- */

.tb {
  position: relative;
  flex: none;
  width: var(--tap);
  height: var(--tap-h);
  padding: 3px 0 2px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  cursor: pointer;
  touch-action: manipulation;
}
.tb .ic { width: var(--icon); height: var(--icon); display: grid; place-items: center; }
.tb .ic svg { width: var(--icon); height: var(--icon); }

/* Το πλήκτρο της συντόμευσης, με μικρά γράμματα κάτω από το κουμπί. */
.kb {
  font-size: 9.5px;
  line-height: 1;
  min-height: 9.5px;
  color: var(--muted);
  white-space: nowrap;
  letter-spacing: .02em;
  font-variant-numeric: tabular-nums;
}
#app[data-size="large"] .kb { font-size: 11px; min-height: 11px; }

.tb:hover { background: var(--hover); }
.tb.on { background: var(--accent-bg); color: var(--accent); }
.tb.on .kb { color: var(--accent); }
.tb:disabled { opacity: .32; cursor: default; background: transparent; }
.tb:focus-visible, .swatch:focus-visible, .segb:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }

.size-ic .size-dot { display: block; border-radius: 50%; }

.pagenum {
  flex: none;
  min-width: 3.2em;
  text-align: center;
  font-weight: 600;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
}
#app[data-bar="left"] .pagenum, #app[data-bar="right"] .pagenum { grid-column: 1 / -1; padding: 2px 0; }

/* Κατάσταση αποθήκευσης στον φάκελο, ως κουκκίδα πάνω στο κουμπί «Αποθήκευση». */
.tb .badge {
  position: absolute;
  top: 5px;
  right: 6px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: none;
  box-shadow: 0 0 0 2px var(--bar);
}
.tb[data-state="pending"] .badge { display: block; background: var(--warn); }
.tb[data-state="perm"] .badge { display: block; background: var(--bad); }

.swatches { display: flex; flex: none; }
#app[data-bar="left"] .swatches, #app[data-bar="right"] .swatches {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(2, var(--tap));
}
.swatch {
  width: calc(var(--dot) + 12px);
  height: var(--tap-h);
  border: 0;
  padding: 3px 0 2px;
  background: transparent;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  touch-action: manipulation;
}
#app[data-bar="left"] .swatch, #app[data-bar="right"] .swatch { width: var(--tap); }
.swatch:hover { background: var(--hover); }
.swatch .dot {
  width: var(--dot);
  height: var(--dot);
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px var(--line);
  transition: transform .12s;
}
.swatch.on .dot { box-shadow: 0 0 0 2px var(--bar), 0 0 0 4px var(--accent); }
.swatch.on .kb { color: var(--accent); font-weight: 700; }

.floating {
  position: absolute;
  z-index: 5;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bar);
  box-shadow: var(--shadow);
  opacity: .85;
  display: none;
  place-items: center;
  cursor: pointer;
}
.floating svg { width: 28px; height: 28px; }
#app.bar-hidden #showBar { display: grid; }
#app[data-bar="bottom"] #showBar { right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); }
#app[data-bar="top"] #showBar { right: 16px; top: max(16px, env(safe-area-inset-top)); transform: rotate(180deg); }
#app[data-bar="left"] #showBar { left: 16px; bottom: 16px; transform: rotate(90deg); }
#app[data-bar="right"] #showBar { right: 16px; bottom: 16px; transform: rotate(-90deg); }

/* ---------- αναδυόμενα πάνελ ---------- */

.popover {
  position: fixed;
  z-index: 20;
  max-width: min(94vw, 580px);
  max-height: 86vh;
  overflow: auto;
  background: var(--bar);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
  touch-action: pan-y;
}
.panel h3 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .02em;
}
.seg + .seg { margin-top: 14px; }
.seg-row { display: flex; flex-wrap: wrap; gap: 6px; }
.segb {
  min-height: 48px;
  min-width: 64px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
}
.segb:hover { background: var(--hover); }
.segb.on { background: var(--accent-bg); color: var(--accent); border-color: transparent; font-weight: 600; }
.segb.primary { background: var(--accent); color: #fff; border-color: transparent; font-weight: 600; }
:root[data-theme="dark"] .segb.primary { color: #0d1526; }
.segb.wide { width: 100%; }
.hint { margin: 8px 0 0; color: var(--muted); font-size: 13px; max-width: 46ch; }
.status { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-size: 14px; max-width: 52ch; }
.status svg { flex: none; width: 20px; height: 20px; color: var(--muted); }
.eraser-panel { width: 360px; max-width: 100%; }

.toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  cursor: pointer;
}
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle .track {
  flex: none;
  width: 52px;
  height: 30px;
  border-radius: 15px;
  background: var(--line);
  position: relative;
  transition: background .15s;
}
.toggle .track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  transition: transform .15s;
}
.toggle input:checked + .track { background: var(--accent); }
.toggle input:checked + .track::after { transform: translateX(22px); }
.toggle input:focus-visible + .track { outline: 3px solid var(--accent); outline-offset: 2px; }

.size-panel { width: 312px; max-width: 100%; }
.size-preview { display: block; width: 280px; height: 90px; border-radius: 10px; background: var(--hover); }
.size-row { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.size-val { min-width: 3em; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

input[type="range"] {
  flex: 1;
  height: 48px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  touch-action: none;
}
input[type="range"]::-webkit-slider-runnable-track { height: 8px; border-radius: 4px; background: var(--line); }
input[type="range"]::-moz-range-track { height: 8px; border-radius: 4px; background: var(--line); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 32px; height: 32px; margin-top: -12px;
  border-radius: 50%; border: 0;
  background: var(--accent);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
}
input[type="range"]::-moz-range-thumb {
  width: 32px; height: 32px;
  border-radius: 50%; border: 0;
  background: var(--accent);
}

/* ---------- διάλογοι ---------- */

.dialog-back {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, .35);
}
.dialog {
  width: min(560px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: var(--bar);
  color: var(--fg);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 22px 24px 18px;
}
.dialog h2 { margin: 0 0 10px; font-size: 20px; }
.dialog p { margin: 0 0 10px; line-height: 1.5; user-select: text; -webkit-user-select: text; }
.dialog-buttons { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---------- μηνύματα ---------- */

.toast {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: 84px;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  max-width: min(92vw, 680px);
  padding: 12px 16px;
  border-radius: 12px;
  background: #22262c;
  color: #f2f3f5;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 16px;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button {
  flex: none;
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  background: #3b82f6;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

/* ---------- συμπαγές μενού ρυθμίσεων ----------
   Μικρότερα κουμπιά και δύο στήλες, ώστε να χωρούν κι άλλες ρυθμίσεις χωρίς κύλιση.
   (Οι διάλογοι κρατούν τα μεγάλα κουμπιά.) */
.popover { padding: 10px 12px; }
.popover .panel h3 { margin-bottom: 5px; font-size: 12px; }
.popover .seg + .seg { margin-top: 0; }
.popover .seg-row { gap: 4px; }
.popover .segb {
  min-height: 34px;
  min-width: 0;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 13.5px;
}
.popover .toggle { min-height: 34px; gap: 10px; font-size: 13.5px; }
.popover .toggle .track { width: 38px; height: 22px; border-radius: 11px; }
.popover .toggle .track::after { top: 3px; left: 3px; width: 16px; height: 16px; }
.popover .toggle input:checked + .track::after { transform: translateX(16px); }
.popover .hint { margin-top: 4px; font-size: 12.5px; }
.popover .status { font-size: 13.5px; margin-bottom: 6px; }
.popover input[type="range"] { height: 36px; }
.popover .size-row { margin-top: 4px; }

.panel.menu {
  display: grid;
  grid-template-columns: repeat(2, max-content);
  gap: 12px 22px;
  align-items: start;
}
.panel.menu .seg.wide { grid-column: 1 / -1; }
@media (max-width: 760px) { .panel.menu { grid-template-columns: 1fr; } .panel.menu .seg-row { flex-wrap: wrap; } }
.panel.menu .seg-row { flex-wrap: nowrap; }
.popover:has(.panel.menu) { max-width: min(96vw, 760px); }

/* ---------- μικρή μπάρα δίπλα στην επιλογή ---------- */

.selbar[hidden] { display: none; }
.selbar {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 4;
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: var(--bar);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.selbar button {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
  font-size: 14px;
}
.selbar button:hover { background: var(--hover); }
.selbar svg { width: 20px; height: 20px; }

/* ---------- κάθετη μπάρα κύλισης του χαρτιού ---------- */

.vscroll {
  position: absolute;
  z-index: 3;
  top: 6px;
  bottom: 6px;
  right: 1px;
  width: 12px;
  touch-action: none;
}
.vscroll[hidden] { display: none; }
.vthumb {
  width: 100%;
  border-radius: 6px;
  background: rgba(0, 0, 0, .22);
  cursor: grab;
  touch-action: none;
}
:root[data-theme="dark"] .vthumb { background: rgba(255, 255, 255, .25); }
.vthumb:hover, .vthumb.drag { background: var(--accent); }
@media (pointer: coarse) { .vscroll { width: 14px; } }

/* ---------- επιλογέας μεγέθους πίνακα ---------- */

.table-panel { width: 300px; max-width: 100%; }
.tp-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 3px;
  touch-action: none;
}
.tp-cell {
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
}
.tp-cell.on { background: var(--accent-bg); border-color: var(--accent); }
.tp-label { margin-top: 8px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- μικρογραφίες σελίδων ---------- */

.tb.pagenum { width: auto; min-width: var(--tap); padding-inline: 6px; }
.pagenum-txt { font-weight: 600; font-size: 13px; line-height: var(--icon); font-variant-numeric: tabular-nums; }
.pages-panel { width: min(720px, calc(96vw - 32px)); }
.thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  max-height: min(60vh, 560px);
  overflow-y: auto;
  padding: 2px;
}
.thumb { display: flex; flex-direction: column; gap: 4px; }
.thumb-img {
  display: grid;
  place-items: center;
  height: 120px;
  padding: 4px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--desk);
  cursor: pointer;
  overflow: hidden;
}
.thumb-img canvas { max-width: 100%; max-height: 100%; width: auto !important; height: auto !important; border-radius: 3px; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.thumb-img:hover { border-color: var(--accent); }
.thumb.current .thumb-img { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.thumb.marked .thumb-img { opacity: .45; border-color: var(--bad); }
.thumb-foot { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; min-height: 28px; }
.thumb-foot input { width: 18px; height: 18px; accent-color: var(--bad); }
.thumb.current .thumb-foot span { font-weight: 700; color: var(--accent); }
.pages-actions { margin-top: 10px; justify-content: space-between; }
.segb:disabled { opacity: .4; cursor: default; }
.popover:has(.pages-panel) { max-width: min(96vw, 760px); }
