/* =========================================================
   График дежурств — Петербургская неотложка
   v3 — 4 типа смен, отказ месяца, время мероприятия
   ========================================================= */

:root {
  /* Brand — СИНИЙ */
  --brand: #2563eb;
  --brand-dark: #1e40af;
  --brand-light: #dbeafe;

  /* Shifts */
  /* Короткая — жёлто-оранжевый */
  --short: #f59e0b;
  --short-bg: #fef3c7;
  --short-fg: #78350f;

  /* Суточная — зелёный */
  --full: #0b7a3e;
  --full-bg: #d4edda;
  --full-fg: #ffffff;

  /* Мероприятие — фиолетовый */
  --event: #7c3aed;
  --event-bg: #ede9fe;
  --event-fg: #4c1d95;

  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --success: #0b7a3e;
  --success-bg: #d4edda;

  /* Neutrals */
  --bg: #f7f8fa;
  --card: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #0f172a;
  --muted: #64748b;
  --off-bg: #f1f5f9;
  --weekend-tint: #fef7f0;

  /* Elevation */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.12);
  --shadow-lg: 0 20px 48px rgba(15, 23, 42, 0.2);

  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 14px 32px;
}

/* =============== Header =============== */
.app__head { margin-bottom: 18px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand__mark {
  width: 48px; height: 48px;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
  display: grid; place-items: center;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}
.brand__title { font-weight: 700; font-size: 17px; color: var(--brand); letter-spacing: -0.2px; }
.brand__subtitle { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* =============== Who =============== */
.who {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.who__row { display: flex; gap: 8px; padding: 3px 0; font-size: 14px; }
.who__label { color: var(--muted); min-width: 120px; }
.who__value { font-weight: 600; color: var(--text); }

/* =============== Unavailable checkbox =============== */
.unavailable {
  background: var(--danger-bg);
  border: 1px solid #fca5a5;
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.unavailable__label {
  display: flex; align-items: center; gap: 12px;
  cursor: pointer;
  user-select: none;
}
.unavailable__label input[type="checkbox"] {
  position: absolute; opacity: 0; pointer-events: none;
}
.unavailable__box {
  width: 24px; height: 24px;
  border: 2px solid var(--border-strong);
  border-radius: 6px;
  display: grid; place-items: center;
  transition: all 0.15s;
  flex-shrink: 0;
}
.unavailable__label input:checked + .unavailable__box {
  background: var(--danger);
  border-color: var(--danger);
}
.unavailable__label input:checked + .unavailable__box::after {
  content: "";
  width: 14px; height: 8px;
  border-left: 2.5px solid #fff;
  border-bottom: 2.5px solid #fff;
  transform: rotate(-45deg) translate(1px, -2px);
}
.unavailable__text {
  font-weight: 600;
  color: var(--text);
  flex: 1;
}
.unavailable__label input:checked ~ .unavailable__text {
  color: var(--danger);
}
.unavailable__reason {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}
.unavailable__reason label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}
.unavailable__reason textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  min-height: 60px;
}
.unavailable__reason textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-light);
}

/* =============== Calendar =============== */
.calendar {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
  transition: opacity 0.2s;
}
.calendar--disabled {
  opacity: 0.4;
  pointer-events: none;
  display: none;
}

.calendar__legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}
.legend__item { display: flex; align-items: center; gap: 6px; }
.legend__dot {
  width: 12px; height: 12px;
  border-radius: 3px;
  display: inline-block;
}
.legend__dot--short { background: var(--short); }
.legend__dot--full { background: var(--full); }
.legend__dot--event { background: var(--event); }

.calendar__weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 8px;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.calendar__weekdays .wk { color: #b91c1c; }

.calendar__grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
  width: 100%;
}

.day {
  width: 100%;
  min-width: 0;
  justify-self: stretch;
  aspect-ratio: 1;
  border: 1.5px solid var(--border);
  background: var(--card);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s, background 0.15s, border-color 0.15s;
  padding: 4px;
  position: relative;
  min-height: 52px;
  box-sizing: border-box;
  font-family: inherit;
}
.day:hover { border-color: var(--brand); box-shadow: 0 2px 6px rgba(11, 122, 62, 0.12); transform: translateY(-1px); }
.day:active { transform: translateY(0); }
.day--empty {
  border: none;
  background: transparent;
  cursor: default;
  visibility: hidden;
  /* Принудительно сохраняем ширину/высоту клетки */
}
.day--empty:hover { border: none; box-shadow: none; transform: none; }
.day--weekend { background: var(--weekend-tint); }
.day--today { border-color: var(--brand); border-width: 2px; }
.day--past { opacity: 0.4; cursor: not-allowed; }
.day--past:hover { border-color: var(--border); box-shadow: none; transform: none; }

.day__num { font-size: 16px; line-height: 1; }
.day__tag {
  font-size: 8px;
  font-weight: 600;
  padding: 1px 2px;
  border-radius: 3px;
  line-height: 1.15;
  letter-spacing: -0.2px;
  max-width: 100%;
  white-space: nowrap;
  overflow: visible;
}

.day--short { background: var(--short-bg); border-color: var(--short); }
.day--short .day__tag { background: var(--short); color: #fff; }

.day--full { background: var(--full); color: #fff; border-color: var(--full); }
.day--full .day__num { color: #fff; }
.day--full .day__tag { background: rgba(255,255,255,0.25); color: #fff; }

.day--event { background: var(--event-bg); border-color: var(--event); }
.day--event .day__tag { background: var(--event); color: #fff; }

.day--selected { box-shadow: 0 0 0 3px rgba(11, 122, 62, 0.2); }

.calendar__hint {
  margin-top: 12px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

/* =============== Comment =============== */
.comment {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.comment label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}
.comment textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  min-height: 60px;
}
.comment textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-light);
}

/* =============== Summary =============== */
.summary {
  background: var(--brand-light);
  border: 1px solid var(--brand);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 14px;
}
.summary__title {
  font-weight: 600;
  color: var(--brand-dark);
  margin-bottom: 6px;
}
.summary__breakdown {
  font-size: 13px;
  color: var(--brand-dark);
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
}

/* Легенда подсчёта — цвета как у типов смен */
.stat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 13px;
}
.stat b { font-weight: 700; }
.stat__dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.stat--short { background: var(--short-bg); color: var(--short-fg); }
.stat--short .stat__dot { background: var(--short); }
.stat--full { background: var(--full-bg); color: #0b532e; }
.stat--full .stat__dot { background: var(--full); }
.stat--event { background: var(--event-bg); color: var(--event-fg); }
.stat--event .stat__dot { background: var(--event); }

/* =============== Actions =============== */
.actions { margin-bottom: 20px; }

.btn {
  width: 100%;
  padding: 14px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s, background 0.15s;
  font-family: inherit;
}
.btn--primary { background: var(--brand); color: #fff; }
.btn--primary:hover { background: var(--brand-dark); }
.btn--primary:active { transform: translateY(1px); }
.btn--primary:disabled {
  background: var(--muted);
  cursor: not-allowed;
  opacity: 0.7;
}
.btn--small {
  width: auto;
  padding: 8px 14px;
  font-size: 13px;
}

.actions__status {
  margin-top: 12px;
  font-size: 13px;
  text-align: center;
  min-height: 20px;
}
.actions__status--ok { color: var(--brand); font-weight: 600; }
.actions__status--err { color: var(--danger); font-weight: 600; }

/* =============== Footer =============== */
.app__foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 0;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--border);
}
.app__foot a { color: var(--brand); text-decoration: none; font-weight: 600; }
.app__foot .dot { opacity: 0.6; }

/* =============== Popover =============== */
/* Контейнер во всю ширину, карточка — ограниченной ширины, центрирована */
.popover {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  pointer-events: none;
}
.popover[hidden] { display: none; }

.popover > * {
  pointer-events: auto;
}

.popover__card {
  width: 100%;
  max-width: 560px;
  box-sizing: border-box;
  background: var(--card);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 20px 18px 24px;
  animation: slideUp 0.2s ease-out;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
  z-index: 2;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* Overlay */
.popover::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  z-index: 1;
  animation: fadeIn 0.2s;
  pointer-events: auto;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.popover__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 16px;
  color: var(--brand-dark);
}
.popover__close {
  background: transparent;
  border: none;
  font-size: 20px;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}

.popover__options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.opt {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 14px;
  border: 1.5px solid var(--border);
  background: var(--card);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
  width: 100%;
}
.opt:hover { border-color: var(--brand); background: var(--brand-light); }
.opt__dot {
  width: 20px; height: 20px;
  border-radius: 6px;
  flex-shrink: 0;
}
.opt--short .opt__dot { background: var(--short); }
.opt--full .opt__dot { background: var(--full); }
.opt--event .opt__dot { background: var(--event); }
.opt__label { flex: 1; }
.opt__meta { font-weight: 400; color: var(--muted); font-size: 13px; }

.opt--selected { border-color: var(--brand); background: var(--brand-light); }
.opt--selected::after {
  content: "✓";
  color: var(--brand);
  font-weight: 700;
  font-size: 18px;
}

.opt--clear {
  background: var(--danger-bg);
  border-color: #fca5a5;
  color: var(--danger);
  justify-content: center;
  margin-top: 6px;
  font-weight: 600;
}
.opt--clear:hover { background: #fecaca; border-color: var(--danger); }

/* Event time subform */
.event-time[hidden] { display: none !important; }
.event-time {
  margin: 4px 0;
  padding: 14px;
  background: var(--event-bg);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--event);
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: slideDown 0.15s ease-out;
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
.event-time__title {
  font-weight: 600;
  font-size: 13px;
  color: var(--event-fg);
  margin-bottom: 2px;
}
.event-time__row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
}
.event-time__row input[type="time"] {
  padding: 6px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
}
.event-time__row input[type="time"]:disabled { opacity: 0.4; }
.event-time button { align-self: flex-end; }

/* =============== Thanks screen =============== */
.thanks {
  position: fixed;
  inset: 0;
  background: linear-gradient(180deg, var(--brand-light) 0%, #ffffff 60%);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.3s ease-out;
}
.thanks[hidden] { display: none; }
.thanks__card {
  background: var(--card);
  border-radius: 16px;
  padding: 32px 24px;
  max-width: 400px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes popIn {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.thanks__icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--success-bg);
  color: var(--success);
  display: grid;
  place-items: center;
  margin: 0 auto 20px;
}
.thanks__title {
  font-size: 22px;
  font-weight: 700;
  color: var(--brand);
  margin-bottom: 10px;
}
.thanks__text {
  font-size: 15px;
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 16px;
}
.thanks__meta {
  font-size: 13px;
  color: var(--muted);
  padding-top: 16px;
  border-top: 1px solid var(--border);
  line-height: 1.6;
}
.thanks__meta strong { color: var(--text); }

/* Красная рамка — предупреждение о правках / телефон диспетчера */
.thanks__warn {
  margin-top: 20px;
  padding: 14px 16px;
  border: 2px solid var(--danger, #dc2626);
  border-radius: 12px;
  background: rgba(220, 38, 38, 0.06);
  color: var(--danger, #dc2626);
  font-size: 14px;
  line-height: 1.5;
  text-align: center;
}
.thanks__warn[hidden] { display: none; }
.thanks__warn strong { display: inline-block; margin-bottom: 4px; }
.thanks__warn a {
  color: var(--danger, #dc2626);
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  border-bottom: 1px dashed currentColor;
}
.thanks__warn a:hover { border-bottom-style: solid; }

/* Вариант иконки — информационная (синяя) */
.thanks__icon--info {
  background: rgba(37, 99, 235, 0.1);
  color: #2563eb;
}

/* =============== Small screens =============== */
@media (max-width: 380px) {
  .day { min-height: 44px; font-size: 13px; }
  .day__num { font-size: 14px; }
  .day__tag { font-size: 7px; padding: 1px 2px; letter-spacing: -0.3px; }
  .brand__title { font-size: 15px; }
  .brand__subtitle { font-size: 12px; }
}

/* =============== Tap targets on touch =============== */
@media (hover: none) {
  .day:hover { transform: none; box-shadow: none; border-color: var(--border); }
  .day--today:hover { border-color: var(--brand); }
}
