:root {
  --bg: #f4f2ee;
  --panel: #fff;
  --line: #d6d1c8;
  --text: #22201c;
  --muted: #6f6a60;
  --accent: #1f5f8b;
  --expected: #fde9b8;
  --expected-b: #d9a521;
  --seated: #cfeacb;
  --seated-b: #3f9a3a;
  --gone: #e6e3dd;
  --danger: #b3261e;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
/* Без случайно увеличение с два пръста — иначе екранът се „отрязва" и се появява хоризонтален скрол. */
html { touch-action: pan-x pan-y; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, select { font: inherit; color: inherit; }
button {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.small { min-height: 36px; padding: 0 10px; font-size: 14px; margin-top: 6px; }
input, select {
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
h2 { margin: 0 0 8px; font-size: 15px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
ul { list-style: none; margin: 0; padding: 0; }

header {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.datenav { display: flex; gap: 6px; align-items: center; }
#dayname { margin-left: 6px; font-weight: 600; white-space: nowrap; }
#search { flex: 1; min-width: 180px; }

.bar {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.bar.warn { background: var(--danger); }
.bar button { color: var(--text); }
[hidden] { display: none !important; }

main { flex: 1; min-height: 0; display: flex; }
aside {
  width: 300px;
  flex: none;
  overflow-y: auto;
  padding: 12px;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.count { color: var(--text); }
.empty { color: var(--muted); font-size: 14px; }

.res {
  padding: 8px 10px;
  margin-bottom: 6px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--expected-b);
  border-radius: 8px;
  background: var(--panel);
  cursor: pointer;
}
.res.seated { border-left-color: var(--seated-b); }
.res.left, .res.noshow, .res.cancelled { border-left-color: #aaa; color: var(--muted); }
.res.noshow .name, .res.cancelled .name, .res.left .name { text-decoration: line-through; }
.res .line { display: flex; gap: 6px; align-items: baseline; }
.res .name { flex: 1; overflow-wrap: anywhere; }
.res .badge { font-size: 12px; color: var(--muted); white-space: nowrap; }
.res .meta, .res .note { font-size: 13px; color: var(--muted); }
.res .note { font-style: italic; }

#planwrap { flex: 1; min-width: 0; overflow: auto; padding: 12px; }
#plan {
  position: relative;
  container-type: inline-size;
  aspect-ratio: 1200 / 1000;
  width: min(100%, calc((100vh - 110px) * 1.2));
  min-width: 620px;
  margin: 0 auto;
}
.zone { position: absolute; border: 2px solid #8d877b; border-radius: 6px; background: #fbfaf7; }
.zlabel { position: absolute; top: 6px; left: 10px; font-size: max(11px, 1.3cqw); font-weight: 700; color: var(--muted); letter-spacing: .05em; }
.table {
  position: absolute;
  min-height: 0;
  padding: 2px 4px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 1px;
  overflow: hidden;
  text-align: left;
  border: 2px solid #8d877b;
  border-radius: 6px;
  font-size: max(10px, 1.25cqw);
  line-height: 1.2;
}
.table b { font-size: 1.15em; }
.table.expected { background: var(--expected); border-color: var(--expected-b); }
.table.seated { background: var(--seated); border-color: var(--seated-b); }
.assigning .table { outline: 3px dashed var(--accent); outline-offset: 1px; }
.chip { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-radius: 3px; padding: 0 2px; }
.chip.expected { background: #fff8; }
.chip.seated { background: #fff8; font-weight: 600; }
.chip.left { color: var(--muted); text-decoration: line-through; }

dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  padding: 18px;
  border: 0;
  border-radius: 12px;
  box-shadow: 0 10px 40px #0005;
  color: var(--text);
}
dialog::backdrop { background: #0006; }
dialog h2 { font-size: 18px; text-transform: none; letter-spacing: 0; color: var(--text); margin-bottom: 14px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
label, .field > span { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label input, label select { width: 100%; color: var(--text); font-size: 16px; }
.wide { grid-column: 1 / -1; }
.field { margin-top: 12px; }
.pick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.pick + .zname, .zname { margin-top: 6px; font-size: 12px; color: var(--muted); }
.pick button { min-width: 48px; padding: 0 10px; }
.pick button.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.err { color: var(--danger); margin: 12px 0 0; }
.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* Вертикален екран (таблет в портрет, телефон): схемата отгоре на цялата ширина, списъците отдолу. */
@media (orientation: portrait), (max-width: 760px) {
  main { flex-direction: column; overflow-y: auto; }
  #planwrap { order: -1; flex: none; overflow-x: auto; }
  #plan { width: 100%; }
  aside {
    width: auto;
    border-right: 0;
    border-top: 1px solid var(--line);
    overflow: visible;
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
  #resultsBox { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  aside { grid-template-columns: 1fr; }
  header { gap: 8px; padding: 8px; }
  .datenav { width: 100%; flex-wrap: wrap; }
  #date { flex: 1; min-width: 0; }
  #dayname { flex-basis: 100%; margin: 0; order: -1; white-space: normal; }
  #search { flex: 1 1 100%; min-width: 0; }
  #new { flex: 1; }
  #planwrap { padding: 8px; }
  aside { padding: 8px; }
  .grid { grid-template-columns: 1fr; }
  dialog { padding: 14px; }
  .dlghead { top: -14px; margin: -14px -14px 12px; padding-left: 14px; }
  .actions button { flex: 1; }
}

.loginpage { align-items: center; justify-content: center; }
.loginpage form {
  width: min(340px, calc(100vw - 32px));
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.loginpage h1 { margin: 0; font-size: 22px; }
.loginpage input { font-size: 22px; letter-spacing: .2em; text-align: center; }
.loginpage .err { margin: 0; }

.link { position: absolute; height: 0; border-top: 4px solid var(--expected-b); transform-origin: 0 0; margin-top: -2px; }
.link.seated { border-color: var(--seated-b); }
.plus {
  position: absolute;
  z-index: 1;
  transform: translate(-50%, -50%);
  width: 1.7em;
  height: 1.7em;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--expected-b);
  color: #fff;
  font-weight: 700;
  font-size: max(12px, 1.4cqw);
  pointer-events: none;
}
.plus.seated { background: var(--seated-b); }

.dlghead {
  position: sticky;
  top: -18px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: -18px -18px 14px;
  padding: 10px 10px 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
dialog .dlghead h2 { margin: 0; }
.x { min-width: 44px; padding: 0; border: 0; font-size: 28px; line-height: 1; color: var(--muted); }
