:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #1b1f24;
  --muted: #6b7480;
  --line: #dfe3e8;
  --accent: #2d7ff9;
  --accent-dark: #1b5fc4;
  --ok: #1f9d55;
  --warn: #d97706;
  --danger: #dc2626;
  --cell-w: 46px;
  --row-h: 44px;
  --side-w: 220px;
  --radius: 8px;
}

* { box-sizing: border-box; }

/* Правила ниже задают display для .field и .row, а они специфичнее
   встроенного в браузер скрытия [hidden]. Без этого элементы с атрибутом
   hidden остаются видимыми. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 14px/1.45 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

button, input, select, textarea { font: inherit; color: inherit; }

/* --- Шапка --------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  height: 52px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 30;
}

.brand { font-weight: 700; letter-spacing: -0.01em; }

.nav { display: flex; gap: 4px; flex: 1; }

.nav a {
  padding: 6px 12px;
  border-radius: 6px;
  text-decoration: none;
  color: var(--muted);
}

.nav a:hover { background: #eef1f5; color: var(--ink); }
.nav a.active { background: #e8f0fe; color: var(--accent-dark); font-weight: 600; }

.user { display: flex; align-items: center; gap: 12px; color: var(--muted); }

.link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
}

.page { padding: 20px; }

/* --- Общие элементы ------------------------------------------------------ */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.toolbar .spacer { flex: 1; }

.btn {
  padding: 7px 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 6px;
  cursor: pointer;
}

.btn:hover { border-color: #c3cad3; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { color: var(--danger); border-color: #f2c4c4; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input[type=text], input[type=date], input[type=number], input[type=email],
input[type=password], select, textarea {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  width: 100%;
}

label.field { display: block; margin-bottom: 10px; }
label.field span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }

.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.muted { color: var(--muted); }
.tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 100px;
  font-size: 12px;
  background: #eef1f5;
  color: var(--muted);
}

/* --- Шахматка ------------------------------------------------------------ */

.grid-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: auto;
  max-height: calc(100vh - 170px);
}

.grid { min-width: max-content; position: relative; }

.grid-head {
  display: flex;
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.grid-head .side, .grid-row .side {
  width: var(--side-w);
  min-width: var(--side-w);
  position: sticky;
  left: 0;
  z-index: 5;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.grid-head .side { z-index: 25; font-size: 12px; color: var(--muted); }

.day-head {
  width: var(--cell-w);
  min-width: var(--cell-w);
  text-align: center;
  padding: 5px 0;
  border-right: 1px solid #eef1f5;
  font-size: 12px;
  line-height: 1.25;
}

.day-head.weekend { background: #fafbfc; }
.day-head.today { background: #e8f0fe; color: var(--accent-dark); font-weight: 700; }
.day-head .dow { color: var(--muted); font-size: 11px; }

.grid-row {
  display: flex;
  height: var(--row-h);
  border-bottom: 1px solid var(--line);
  position: relative;
}

.grid-row .unit-title { font-weight: 600; font-size: 13px; }
.grid-row .unit-sub { color: var(--muted); font-size: 11px; }

.cells { display: flex; position: relative; }

.cell {
  width: var(--cell-w);
  min-width: var(--cell-w);
  border-right: 1px solid #eef1f5;
  cursor: pointer;
  position: relative;
}

.cell:hover { background: #f0f6ff; }
.cell.weekend { background: #fafbfc; }
.cell.weekend:hover { background: #f0f6ff; }
.cell.closed { background: repeating-linear-gradient(45deg, #f6e5e5, #f6e5e5 4px, #fff 4px, #fff 8px); }
.cell .price {
  position: absolute;
  bottom: 1px;
  right: 3px;
  font-size: 10px;
  color: #9aa3ae;
  font-variant-numeric: tabular-nums;
}

/* Полоса брони. Смещение на полклетки с обеих сторон — так видно,
   что выезд и заезд в один день не конфликтуют. */
.bar {
  position: absolute;
  top: 5px;
  height: calc(var(--row-h) - 14px);
  border-radius: 4px;
  padding: 0 7px;
  font-size: 12px;
  line-height: calc(var(--row-h) - 14px);
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  z-index: 2;
  box-shadow: 0 1px 2px rgba(0,0,0,.15);
}

.bar:hover { filter: brightness(1.08); }
.bar.status-hold { background: var(--warn); }
.bar.status-confirmed { background: var(--accent); }
.bar.status-checked_in { background: var(--ok); }
.bar.status-checked_out { background: #6b7480; }
.bar.kind-block { background: #4b5563; background-image: repeating-linear-gradient(45deg, rgba(255,255,255,.12), rgba(255,255,255,.12) 5px, transparent 5px, transparent 10px); }
.bar.debt::after { content: " ₽"; }
.bar.conflict { outline: 2px solid var(--danger); outline-offset: -2px; }

/* --- Модальное окно ------------------------------------------------------ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 30, .45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 60px 16px;
  z-index: 50;
}

.modal {
  background: var(--panel);
  border-radius: 10px;
  width: 100%;
  max-width: 520px;
  padding: 20px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
  max-height: 85vh;
  overflow: auto;
}

.modal h2 { margin: 0 0 14px; font-size: 17px; }
.modal .actions { display: flex; gap: 8px; margin-top: 16px; }
.modal .actions .spacer { flex: 1; }

.quote-box {
  background: #f7f9fc;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  margin: 10px 0;
  font-size: 13px;
}

.quote-box .warn { color: var(--warn); }
.quote-box .err { color: var(--danger); }

/* --- Вход ---------------------------------------------------------------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px;
  width: 380px;
}

.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card p.sub { margin: 0 0 18px; color: var(--muted); }
.tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.tabs button { flex: 1; padding: 7px; border: 1px solid var(--line); background: #fff; border-radius: 6px; cursor: pointer; }
.tabs button.active { background: #e8f0fe; border-color: #bcd4fb; color: var(--accent-dark); font-weight: 600; }

/* --- Уведомление --------------------------------------------------------- */

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #1b1f24;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  z-index: 100;
  max-width: 640px;
}

.toast.error { background: var(--danger); }

/* --- Метрики ------------------------------------------------------------- */

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }

/* --- Телефон ------------------------------------------------------------- */
/* Формы заполняют с телефона не реже, чем с компьютера: три поля в строке
   на узком экране превращаются в нечитаемые огрызки. */

@media (max-width: 700px) {
  .page { padding: 12px; }

  .row { flex-direction: column; gap: 0; }

  .modal-backdrop { padding: 10px; }
  .modal { padding: 16px; max-height: 94vh; }
  .modal .actions { flex-wrap: wrap; }
  .modal .actions .btn { flex: 1; }

  .toolbar { gap: 8px; }
  .toolbar h2 { width: 100%; }
  .toolbar .btn { flex: 1; }

  th, td { padding: 7px 6px; }
  th { font-size: 11px; }

  /* Широкие таблицы прокручиваются внутри себя, а не тянут всю страницу. */
  .panel > table { display: block; overflow-x: auto; white-space: nowrap; }

  .topbar { gap: 10px; padding: 0 12px; overflow-x: auto; }
  .nav { gap: 2px; }
  .nav a { padding: 6px 9px; white-space: nowrap; }
  .user span { display: none; }
}
