/* Бронирование помещений Зала Царства */

:root {
  --paper: #F6F7F5;
  --surface: #FFFFFF;
  --ink: #1D2830;
  --muted: #5B6872;
  --line: #D8DDDF;
  --line-soft: #E9ECED;
  --act: #1F6F64;
  --act-ink: #FFFFFF;
  --act-soft: #E3F0EC;
  --warn: #B3402E;
  --warn-soft: #F8E6E2;
  --now: #C2452F;

  --row: 22px;          /* высота 30-минутной строки */
  --time-col: 3.4rem;
  --radius: 8px;
  --radius-sm: 5px;
  --font: 'Commissioner', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #141A1E;
    --surface: #1B2328;
    --ink: #E6EBEE;
    --muted: #9AA7B0;
    --line: #2F3A41;
    --line-soft: #232C32;
    --act: #4FB3A3;
    --act-ink: #0E1A18;
    --act-soft: #1D3632;
    --warn: #E5826F;
    --warn-soft: #3A2421;
    --now: #F07A62;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --paper: #141A1E;
  --surface: #1B2328;
  --ink: #E6EBEE;
  --muted: #9AA7B0;
  --line: #2F3A41;
  --line-soft: #232C32;
  --act: #4FB3A3;
  --act-ink: #0E1A18;
  --act-soft: #1D3632;
  --warn: #E5826F;
  --warn-soft: #3A2421;
  --now: #F07A62;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--act); outline-offset: 2px; }

.icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Шапка ---------- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem clamp(16px, 3vw, 32px) 0.4rem;
}
.brand { display: flex; align-items: baseline; gap: 0.7rem; flex-wrap: wrap; min-width: 0; }
.brand-hall { font-weight: 750; font-size: 1.05rem; letter-spacing: -0.01em; }
.brand-title { color: var(--muted); font-size: 0.95rem; }
.top-tools { display: flex; align-items: center; gap: 0.5rem; }

.lang, .btn, .btn-quiet, .btn-icon, .seg {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius-sm);
  min-height: 36px;
  padding: 0.35rem 0.75rem;
}
.lang { padding-right: 1.6rem; }
.btn-quiet { display: inline-flex; align-items: center; gap: 0.4rem; border-color: transparent; background: transparent; color: var(--muted); }
.btn-quiet:hover { color: var(--ink); background: var(--line-soft); }
.btn-icon { display: inline-grid; place-items: center; width: 36px; padding: 0; }
.btn:hover, .btn-icon:hover, .seg:hover { border-color: var(--muted); }

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  padding: 0.5rem clamp(16px, 3vw, 32px);
}
.nav { display: flex; align-items: center; gap: 0.4rem; min-width: 0; }
.range {
  margin: 0 0 0 0.6rem;
  font-size: clamp(1.15rem, 2.2vw, 1.5rem);
  font-weight: 650;
  letter-spacing: -0.015em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.views { display: inline-flex; }
.seg { border-radius: 0; margin-left: -1px; }
.seg:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); margin-left: 0; }
.seg:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.seg[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); position: relative; z-index: 1; }

.filter {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.4rem;
  padding: 0.2rem clamp(16px, 3vw, 32px) 0.8rem;
}
.filter-label { color: var(--muted); margin-right: 0.3rem; font-size: 0.9rem; }
.rchip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 0.2rem 0.75rem 0.2rem 0.55rem;
  font-size: 0.88rem;
}
.rdot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.15); }
.rchip[aria-pressed="false"] { color: var(--muted); background: transparent; border-style: dashed; }
.rchip[aria-pressed="false"] .rdot { background: transparent; box-shadow: inset 0 0 0 2px var(--c); }

/* ---------- Сетка времени (день, неделя) ---------- */

.cal { padding: 0 clamp(16px, 3vw, 32px) 1rem; }
.cal[aria-busy="true"] { opacity: 0.6; transition: opacity 0.2s 0.15s; }

.tscroll {
  overflow: auto;
  max-height: calc(100vh - 170px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.tgrid { --colmin: 150px; min-width: calc(var(--time-col) + var(--cols) * var(--colmin)); }
.tgrid-week { --colmin: 36px; }
.thead, .tbody {
  display: grid;
  grid-template-columns: var(--time-col) repeat(var(--cols), minmax(var(--colmin), 1fr));
}
.thead {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.corner { position: sticky; left: 0; background: var(--surface); z-index: 2; }

.room-head {
  border-top: 4px solid var(--c);
  padding: 0.45rem 0.6rem 0.4rem;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.4rem;
  min-width: 0;
  border-left: 1px solid var(--line-soft);
}
.room-name { font-weight: 650; font-size: 0.92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-cap { color: var(--muted); font-size: 0.78rem; }
.tgrid-week .room-head { padding: 0.25rem 0.2rem; justify-content: center; border-top-width: 3px; }
.tgrid-week .room-name { font-size: 0.72rem; font-weight: 600; }
.tgrid-week .room-head:nth-child(n) { border-left-color: var(--line-soft); }

.day-head {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.5rem 0 0.3rem;
  border-left: 1px solid var(--line);
}
.dh-wd { color: var(--muted); font-size: 0.85rem; }
.dh-num { font-weight: 700; font-size: 1.05rem; }
.day-head.is-today .dh-num {
  background: var(--act);
  color: var(--act-ink);
  border-radius: 999px;
  min-width: 1.8em;
  text-align: center;
  padding: 0 0.35em;
}

.times {
  position: sticky;
  left: 0;
  z-index: 3;
  background: var(--surface);
  display: grid;
  grid-template-rows: repeat(var(--slots), var(--row));
  border-right: 1px solid var(--line);
}
.tick { font-size: 0.72rem; color: var(--muted); text-align: right; padding-right: 0.45rem; transform: translateY(-0.55em); }
.tick:first-child { transform: none; }

.col {
  position: relative;
  height: calc(var(--slots) * var(--row));
  border-left: 1px solid var(--line-soft);
  background-image: repeating-linear-gradient(to bottom,
    transparent 0, transparent calc(var(--row) - 1px), var(--line-soft) calc(var(--row) - 1px), var(--line-soft) var(--row),
    transparent var(--row), transparent calc(2 * var(--row) - 1px), var(--line) calc(2 * var(--row) - 1px), var(--line) calc(2 * var(--row)));
  touch-action: pan-x pan-y;
  cursor: cell;
  user-select: none;
}
.col-daystart { border-left: 1px solid var(--line); }
.col:hover { background-color: color-mix(in srgb, var(--c) 5%, transparent); }
.col-past, .past-shade { background-color: color-mix(in srgb, var(--muted) 7%, transparent); }
.col-past { cursor: default; }
.past-shade { position: absolute; left: 0; right: 0; top: 0; height: calc(var(--len) / 30 * var(--row)); pointer-events: none; }
.now-line {
  position: absolute;
  left: -1px;
  right: 0;
  top: calc(var(--at) / 30 * var(--row));
  border-top: 2px solid var(--now);
  z-index: 2;
  pointer-events: none;
}
.col-daystart .now-line::before {
  content: '';
  position: absolute;
  left: -4px;
  top: -5px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--now);
}

.sel {
  position: absolute;
  left: 3px;
  right: 3px;
  top: calc(var(--top) * var(--row));
  height: calc(var(--len) * var(--row));
  background: color-mix(in srgb, var(--act) 18%, transparent);
  border: 1.5px dashed var(--act);
  border-radius: var(--radius-sm);
  pointer-events: none;
  z-index: 3;
}

.ev {
  position: absolute;
  left: 3px;
  right: 3px;
  top: calc(var(--top) * var(--row) + 1px);
  height: calc(var(--len) * var(--row) - 2px);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 1px;
  overflow: hidden;
  text-align: left;
  padding: 0.2rem 0.45rem;
  border: 0;
  border-left: 3px solid var(--c);
  border-radius: 3px var(--radius-sm) var(--radius-sm) 3px;
  background: color-mix(in srgb, var(--c) 15%, var(--surface));
  color: var(--ink);
  font-size: 0.8rem;
  line-height: 1.25;
  z-index: 1;
  cursor: pointer;
}
.ev:hover { background: color-mix(in srgb, var(--c) 24%, var(--surface)); }
.ev-time { display: flex; align-items: center; gap: 0.25rem; color: color-mix(in srgb, var(--c) 55%, var(--ink)); font-weight: 600; font-size: 0.74rem; white-space: nowrap; }
.ev-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.ev-name { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-icon { width: 11px; height: 11px; }
.ev-series { background: color-mix(in srgb, var(--c) 22%, var(--surface)); }
.ev-modified { outline: 1px dashed var(--c); outline-offset: -1px; }
.ev-short { flex-direction: row; gap: 0.4rem; align-items: center; padding-block: 0; }
.ev-short .ev-name { display: none; }
.ev-compact { left: 1px; right: 1px; padding: 0.15rem 0.2rem; border-left-width: 2px; font-size: 0.68rem; }
.ev-compact .ev-time { font-size: 0.64rem; }
.ev-compact.ev-short .ev-title { display: none; }

/* ---------- Месяц ---------- */

.mgrid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.mwd { padding: 0.45rem 0.6rem; color: var(--muted); font-size: 0.85rem; border-bottom: 1px solid var(--line); }
.mcell {
  min-height: 7.2rem;
  padding: 0.3rem 0.35rem 0.4rem;
  border-top: 1px solid var(--line-soft);
  border-left: 1px solid var(--line-soft);
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.mcell:nth-child(7n + 1) { border-left: 0; }
.mcell.weekend { background: color-mix(in srgb, var(--muted) 4%, transparent); }
.mcell.out { color: var(--muted); }
.mcell.out .chip { opacity: 0.6; }
.mday {
  align-self: flex-start;
  border: 0;
  background: none;
  font-weight: 650;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  margin-bottom: 2px;
}
.mday:hover { background: var(--line-soft); }
.mcell.is-today .mday { background: var(--act); color: var(--act-ink); }
.chip {
  display: flex;
  gap: 0.35rem;
  align-items: baseline;
  min-width: 0;
  border: 0;
  border-left: 3px solid var(--c);
  background: color-mix(in srgb, var(--c) 12%, var(--surface));
  border-radius: 2px 4px 4px 2px;
  padding: 0.05rem 0.35rem;
  font-size: 0.76rem;
  text-align: left;
}
.chip-time { color: var(--muted); flex: none; }
.chip-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.more { border: 0; background: none; color: var(--act); font-size: 0.76rem; text-align: left; padding: 0.05rem 0.35rem; }

/* ---------- Список ---------- */

.list { max-width: 900px; }
.lday { margin-bottom: 1.4rem; }
.lday-title { font-size: 1rem; font-weight: 650; margin: 0 0 0.4rem; }
.lday-title::first-letter, .dh-wd::first-letter, .mwd::first-letter, .range::first-letter { text-transform: uppercase; }
.lday.is-today .lday-title { color: var(--act); }
.lrows { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.lrows li + li { border-top: 1px solid var(--line-soft); }
.lrow {
  display: grid;
  grid-template-columns: 7.5rem minmax(6rem, 11rem) 1fr auto;
  gap: 0.8rem;
  align-items: baseline;
  width: 100%;
  border: 0;
  border-left: 4px solid var(--c);
  background: none;
  padding: 0.55rem 0.9rem;
  text-align: left;
}
.lrow:hover { background: color-mix(in srgb, var(--c) 8%, transparent); }
.lr-time { font-weight: 600; }
.lr-room { color: var(--muted); }
.lr-title { display: flex; gap: 0.35rem; align-items: center; font-weight: 600; }
.lr-name { color: var(--muted); }

.empty { color: var(--muted); padding: 2rem 0; }
.empty.error { color: var(--warn); }
.hint { color: var(--muted); font-size: 0.85rem; padding: 0 clamp(16px, 3vw, 32px) 1.5rem; margin: 0; }
.cal[data-view="month"] + .hint, .cal[data-view="list"] + .hint { display: none; }

/* ---------- Модальные окна и формы ---------- */

.modal {
  border: 0;
  padding: 0;
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100vh - 32px);
  box-shadow: 0 18px 50px rgb(10 20 25 / 0.28);
}
.modal.wide { width: min(980px, calc(100vw - 24px)); }
.modal::backdrop { background: rgb(18 28 34 / 0.45); }
.modal[open] { animation: rise 0.16s ease-out; }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

.m-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.25rem 0.4rem;
}
.m-head h2 { margin: 0; font-size: 1.2rem; font-weight: 700; letter-spacing: -0.01em; }
.m-sub { color: var(--muted); margin: 0.15rem 0 0; }
.m-close { border: 0; background: none; color: var(--muted); padding: 0.2rem; border-radius: var(--radius-sm); }
.m-close:hover { color: var(--ink); background: var(--line-soft); }
.m-body { padding: 0.6rem 1.25rem 1.1rem; overflow: auto; max-height: calc(100vh - 170px); }
.m-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
  align-items: center;
  padding: 0.85rem 1.25rem 1.1rem;
  border-top: 1px solid var(--line-soft);
}
.m-foot .spacer { flex: 1; }

.fields { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0.75rem 0.8rem; }
.field { grid-column: span 6; display: flex; flex-direction: column; gap: 0.25rem; min-width: 0; }
.field.half { grid-column: span 3; }
.field.third { grid-column: span 2; }
.field > span { font-size: 0.85rem; color: var(--muted); }
.field input, .field select, .field textarea {
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.6rem;
  min-height: 40px;
  width: 100%;
}
.field input[type="color"] { padding: 0.2rem; min-height: 40px; }
.field textarea { min-height: 5rem; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--act); outline-offset: -1px; border-color: var(--act); }
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--warn); }
.ferr { color: var(--warn); font-size: 0.82rem; }
.check { grid-column: span 6; display: flex; gap: 0.55rem; align-items: flex-start; font-size: 0.9rem; }
.check input { width: 18px; height: 18px; margin: 0.1rem 0 0; accent-color: var(--act); }
.note { grid-column: span 6; color: var(--muted); font-size: 0.85rem; margin: -0.2rem 0 0; }
.note.warn { color: var(--warn); }

.btn-primary, .btn-danger, .btn-secondary {
  border-radius: var(--radius-sm);
  min-height: 40px;
  padding: 0.45rem 1rem;
  font-weight: 600;
  border: 1px solid transparent;
}
.btn-primary { background: var(--act); color: var(--act-ink); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: 0.6; cursor: progress; }
.btn-secondary { background: var(--surface); border-color: var(--line); }
.btn-secondary:hover { border-color: var(--muted); }
.btn-danger { background: transparent; color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.btn-danger.armed { background: var(--warn); color: var(--surface); }

.conflicts { grid-column: span 6; background: var(--warn-soft); color: var(--ink); border-radius: var(--radius-sm); padding: 0.6rem 0.8rem; }
.conflicts p { margin: 0 0 0.3rem; color: var(--warn); font-weight: 600; }
.conflicts ul { margin: 0; padding-left: 1.1rem; }

.detail { display: grid; grid-template-columns: auto 1fr; gap: 0.35rem 1rem; margin: 0.3rem 0 0.6rem; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; }
.badge { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.82rem; color: var(--muted); background: var(--line-soft); border-radius: 999px; padding: 0.1rem 0.6rem; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; background: var(--c); vertical-align: -1px; margin-right: 0.35rem; }

.linkbox { display: flex; gap: 0.4rem; margin: 0.5rem 0; }
.linkbox input, .linkbox textarea { flex: 1; border: 1px solid var(--line); background: var(--paper); border-radius: var(--radius-sm); padding: 0.5rem 0.6rem; min-width: 0; }
.linkbox textarea { min-height: 9rem; resize: vertical; }

.tabs { display: flex; gap: 0.2rem; border-bottom: 1px solid var(--line); margin: 0 1.25rem; }
.tab { border: 0; background: none; padding: 0.55rem 0.8rem; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 600; }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--act); }

.choice { display: grid; gap: 0.5rem; }
.choice button { text-align: left; }

.atable { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.atable th { text-align: left; color: var(--muted); font-weight: 500; font-size: 0.82rem; padding: 0.3rem 0.35rem; }
.atable td { padding: 0.3rem 0.35rem; border-top: 1px solid var(--line-soft); vertical-align: middle; }
.atable input:not([type="checkbox"]) { width: 100%; border: 1px solid var(--line); background: var(--paper); border-radius: var(--radius-sm); padding: 0.35rem 0.45rem; min-height: 34px; }
.atable input[type="color"] { width: 44px; padding: 2px; }
.atable input[type="number"] { width: 5rem; }
.atable .acts { white-space: nowrap; text-align: right; }
.atable .acts button { min-height: 34px; padding: 0.25rem 0.7rem; }
.srow { display: flex; align-items: center; gap: 0.8rem; width: 100%; padding: 0.6rem 0.7rem; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); text-align: left; margin-bottom: 0.4rem; }
.srow:hover { border-color: var(--muted); }
.srow .s-main { flex: 1; min-width: 0; }
.srow .s-title { font-weight: 650; }
.srow .s-meta { color: var(--muted); font-size: 0.85rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translate(-50%, 1rem);
  background: var(--ink);
  color: var(--paper);
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 100;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--warn); color: #fff; }

/* ---------- Узкие экраны ---------- */

@media (max-width: 700px) {
  body { font-size: 15px; }
  .top { padding-top: 0.7rem; }
  .brand-title, .settings-label { display: none; }
  .bar { flex-direction: column; align-items: stretch; }
  .views { width: 100%; }
  .seg { flex: 1; }
  .nav { flex-wrap: wrap; }
  .range { flex-basis: 100%; margin: 0.35rem 0 0; font-size: 1.1rem; white-space: normal; }
  .filter { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 0.6rem; }
  .rchip, .filter-label { flex: none; }
  .room-name { font-size: 0.84rem; }
  .room-cap { display: none; }
  .tgrid { --colmin: 128px; }
  .tgrid-week { --colmin: 34px; }
  .tscroll { max-height: calc(100vh - 230px); }
  .mcell { min-height: 4.8rem; padding: 0.2rem; }
  .chip-time { display: none; }
  .chip { font-size: 0.68rem; padding: 0 0.2rem; }
  .lrow { grid-template-columns: 6.5rem 1fr; gap: 0.15rem 0.6rem; }
  .lr-name { grid-column: 2; }
  .lr-room { grid-column: 1; grid-row: 2; font-size: 0.82rem; }
  .field.half, .field.third { grid-column: span 6; }
  .atable thead { display: none; }
  .atable tr { display: grid; grid-template-columns: 1fr 1fr; gap: 0.3rem; padding: 0.5rem 0; border-top: 1px solid var(--line-soft); }
  .atable td { border: 0; padding: 0; }
  .atable td:first-child, .atable .acts { grid-column: span 2; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media print {
  .top-tools, .bar .views, .nav button, .filter, .hint { display: none; }
  .tscroll { max-height: none; overflow: visible; border: 0; }
  body { background: #fff; }
  .lrow { border-left-width: 6px; }
}
