/* «Досрок» — компоненты. Классы используются всеми страницами;
   страничные стили лежат в css/pages/*.css и только дополняют эти. */

/* ---- Кнопки ------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 38px;
  padding: 0 16px;
  border: 1px solid var(--stamp);
  border-radius: var(--r-m);
  background: var(--stamp);
  color: #fff;
  font-size: 0.94rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--stamp-deep); border-color: var(--stamp-deep); text-decoration: none; }
.btn svg { width: 18px; height: 18px; }

.btn-quiet {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--ink);
}
.btn-quiet:hover { background: var(--surface-dim); border-color: var(--ink-faint); }

.btn-danger {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--red);
}
.btn-danger:hover { background: var(--red-wash); border-color: var(--red); }

.btn-small { height: 32px; padding: 0 12px; font-size: 0.88rem; border-radius: var(--r-s); }

.btn-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: none;
  padding: 0;
  color: var(--stamp);
  font-size: inherit;
  font-weight: 500;
  cursor: pointer;
}
.btn-link:hover { text-decoration: underline; text-underline-offset: 3px; }

/* Подпись последствий под кнопкой (сеть безопасности) */
.btn-caption {
  margin-top: 5px;
  font-size: 0.78rem;
  color: var(--ink-faint);
  text-align: center;
  max-width: 200px;
}

/* ---- Карточки и блоки --------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  box-shadow: var(--shadow-card);
}
.card-pad { padding: 18px 20px; }

.banner {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 16px;
  border-radius: var(--r-m);
  font-size: 0.9rem;
}
.banner svg { width: 19px; height: 19px; flex: none; margin-top: 2px; }
.banner-info { background: var(--stamp-wash); color: var(--stamp-deep); }
.banner-warn { background: var(--amber-wash); color: var(--amber); }
.banner-ok { background: var(--green-wash); color: var(--green); }

.empty {
  padding: 26px 20px;
  color: var(--ink-soft);
  font-size: 0.94rem;
}
.empty strong { color: var(--ink); }

/* ---- Таблица-реестр («как ваш реестр в Excel») -------------------------- */

.ledger-wrap { overflow-x: auto; }

.ledger {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  font-size: 0.92rem;
}
.ledger th {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-strong);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-soft);
  text-align: left;
  white-space: nowrap;
}
.ledger td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.ledger tbody tr:hover { background: var(--surface-dim); }
.ledger tbody tr:last-child td { border-bottom: 0; }
.ledger .cell-main { font-weight: 500; color: var(--ink); }
.ledger .cell-sub { font-size: 0.82rem; color: var(--ink-faint); margin-top: 2px; }

/* Групповая строка («Просрочено», «На этой неделе»…) */
.ledger .row-group td {
  padding: 8px 14px;
  background: var(--surface-dim);
  border-bottom: 1px solid var(--line);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.ledger .row-group.is-danger td { color: var(--red); }

/* ---- Статусы ------------------------------------------------------------ */

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 99px;
  font-size: 0.82rem;
  font-weight: 500;
  white-space: nowrap;
}
.status::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.status-waiting { background: var(--amber-wash); color: var(--amber); }
.status-confirmed { background: var(--green-wash); color: var(--green); }
.status-done { background: var(--surface-dim); color: var(--ink-faint); }
.status-overdue { background: var(--red-wash); color: var(--red); }
.status-neutral { background: var(--surface-dim); color: var(--ink-soft); }

/* ---- Счётчик дней -------------------------------------------------------- */

.days {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.days b { font-size: 1.25rem; font-weight: 600; line-height: 1; }
.days span { font-size: 0.8rem; color: var(--ink-faint); }
.days-danger b { color: var(--red); }
.days-soon b { color: var(--amber); }
.days-ok b { color: var(--ink); }

/* ---- Чип-основание и карточка нормы -------------------------------------- */

.chip-norm {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 8px 2px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 0.84rem;
  cursor: pointer;
  white-space: nowrap;
}
.chip-norm::before { content: '§'; color: var(--seal); font-family: var(--font-doc); }
.chip-norm:hover { border-color: var(--seal); color: var(--ink); background: var(--surface-dim); }
.chip-norm.chip-manual::before { content: '✎'; }

/* Всплывающая карточка нормы */
.norm-pop {
  position: absolute;
  z-index: 130; /* выше модальных окон и боковых карточек: чип-основание живёт и там */
  width: 400px;
  max-width: calc(100vw - 40px);
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-l);
  box-shadow: var(--shadow-pop);
}
.norm-pop h4 {
  margin: 0 0 6px;
  font-family: var(--font-doc);
  font-size: 1.02rem;
}
.norm-pop .norm-formula { font-size: 0.88rem; color: var(--ink); margin: 0 0 10px; }
.norm-pop .norm-text {
  font-family: var(--font-doc);
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--ink-soft);
  border-left: 3px solid var(--line-strong);
  padding-left: 12px;
  margin: 0 0 12px;
}

/* ---- Оттиск «редакция правил» (фирменный знак доверия) ------------------- */

.stamp-seal {
  display: inline-block;
  padding: 5px 14px;
  border: 2px solid var(--seal);
  border-radius: 999px;
  box-shadow: inset 0 0 0 1.5px var(--surface), inset 0 0 0 2.5px var(--seal);
  color: var(--seal);
  font-family: var(--font-doc);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  transform: rotate(-3deg);
  opacity: 0.9;
  white-space: nowrap;
}

/* ---- Карточка расчёта (фирменный артефакт) -------------------------------- */

.calc-card {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  box-shadow: var(--shadow-card);
  padding: 22px 26px;
  font-family: var(--font-doc);
  position: relative;
}
.calc-card::before {
  content: '';
  position: absolute;
  inset: 6px;
  border: 1px solid var(--line);
  border-radius: 2px;
  pointer-events: none;
}
.calc-card h3 {
  margin: 0 0 2px;
  font-size: 1.1rem;
  font-weight: 700;
}
.calc-card .calc-case { font-size: 0.86rem; color: var(--ink-soft); margin: 0 0 14px; }
.calc-row { display: flex; gap: 14px; padding: 9px 0; border-top: 1px dotted var(--line-strong); }
.calc-row:last-of-type { border-bottom: 1px dotted var(--line-strong); }
.calc-row .calc-label { width: 130px; flex: none; font-size: 0.82rem; color: var(--ink-faint); padding-top: 2px; }
.calc-row .calc-value { font-size: 0.95rem; }
.calc-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; }

/* ---- Вкладки -------------------------------------------------------------- */

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.tab {
  padding: 9px 14px 11px;
  border: 0;
  background: none;
  color: var(--ink-soft);
  font-size: 0.94rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--stamp); border-bottom-color: var(--stamp); }
.tab .count { color: var(--ink-faint); font-weight: 400; margin-left: 4px; }
.tab-panel[hidden] { display: none; }

/* ---- Формы ---------------------------------------------------------------- */

.field { margin-bottom: 16px; }
.field > label { display: block; font-size: 0.88rem; font-weight: 500; margin-bottom: 6px; }
.field .hint { font-size: 0.8rem; color: var(--ink-faint); margin-top: 5px; }

.input, .select, textarea.input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-m);
  background: var(--surface);
  font-size: 0.94rem;
}
textarea.input { height: auto; padding: 10px 12px; resize: vertical; }
.input:focus, .select:focus, textarea.input:focus {
  outline: 2px solid var(--stamp);
  outline-offset: 0;
  border-color: transparent;
}
.select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23565b63' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* Радио-карточка (мастер, онбординговые развилки) */
.radio-card {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 13px 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-m);
  background: var(--surface);
  cursor: pointer;
}
.radio-card:hover { border-color: var(--ink-faint); background: var(--surface-dim); }
.radio-card input { margin-top: 3px; accent-color: var(--stamp); width: 17px; height: 17px; flex: none; }
.radio-card.is-checked { border-color: var(--stamp); box-shadow: inset 0 0 0 1px var(--stamp); }
.radio-card .rc-title { font-weight: 500; }
.radio-card .rc-sub { font-size: 0.84rem; color: var(--ink-soft); margin-top: 2px; }
.radio-card .rc-aside { margin-left: auto; flex: none; font-size: 0.82rem; color: var(--ink-faint); white-space: nowrap; }

.check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  cursor: pointer;
  font-size: 0.94rem;
}
.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--stamp); flex: none; }

/* Переключатель-тумблер (настройки) */
.toggle { position: relative; display: inline-block; width: 44px; height: 25px; flex: none; }
.toggle input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.toggle .knob {
  position: absolute; inset: 0;
  background: var(--line-strong);
  border-radius: 99px;
  transition: background 0.15s;
  pointer-events: none;
}
.toggle .knob::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 19px; height: 19px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(36,39,45,0.25);
  transition: translate 0.15s;
}
.toggle input:checked + .knob { background: var(--stamp); }
.toggle input:checked + .knob::after { translate: 19px 0; }
.toggle input:focus-visible + .knob { outline: 2px solid var(--stamp); outline-offset: 2px; }

/* ---- Выпадающее меню ------------------------------------------------------- */

.menu-wrap { position: relative; }
.menu {
  position: absolute;
  z-index: 70;
  top: calc(100% + 6px);
  right: 0;
  min-width: 230px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-l);
  box-shadow: var(--shadow-pop);
}
.menu[hidden] { display: none; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-radius: var(--r-s);
  background: none;
  text-align: left;
  font-size: 0.94rem;
  color: var(--ink);
  cursor: pointer;
}
.menu-item svg { width: 18px; height: 18px; color: var(--ink-faint); }
.menu-item:hover { background: var(--surface-dim); text-decoration: none; }
.menu-item .mi-sub { display: block; font-size: 0.78rem; color: var(--ink-faint); }
.menu-sep { height: 1px; margin: 6px 4px; background: var(--line); }

/* ---- Боковая карточка (drawer) ---------------------------------------------- */

.drawer-veil, .modal-veil {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(36, 39, 45, 0.38);
}
.drawer {
  position: fixed;
  z-index: 81;
  top: 0; right: 0; bottom: 0;
  width: 440px;
  max-width: 94vw;
  background: var(--surface);
  border-left: 1px solid var(--line-strong);
  box-shadow: var(--shadow-pop);
  display: flex;
  flex-direction: column;
  animation: drawer-in 0.18s ease-out;
}
@keyframes drawer-in { from { translate: 30px 0; opacity: 0.4; } to { translate: 0 0; opacity: 1; } }
.drawer-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--line);
}
.drawer-head h3 { margin: 0; font-family: var(--font-doc); font-size: 1.15rem; line-height: 1.3; }
.drawer-body { padding: 16px 20px 24px; overflow-y: auto; }
.drawer-foot { margin-top: auto; padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  border: 0;
  border-radius: var(--r-s);
  background: none;
  color: var(--ink-faint);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-dim); color: var(--ink); }
.icon-btn svg { width: 19px; height: 19px; }

/* ---- Модальное окно ----------------------------------------------------------- */

.modal-veil { display: grid; place-items: center; padding: 24px; overflow-y: auto; }
.modal[hidden] { display: none; }
.modal {
  width: 640px;
  max-width: 100%;
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--r-l);
  box-shadow: var(--shadow-pop);
  animation: modal-in 0.16s ease-out;
}
.modal-wide { width: 760px; }
@keyframes modal-in { from { scale: 0.98; opacity: 0.5; } to { scale: 1; opacity: 1; } }
.modal-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 20px 24px 0;
}
.modal-head h3 { margin: 0; font-family: var(--font-doc); font-size: 1.3rem; }
.modal-head .icon-btn { margin-left: auto; }
.modal-body { padding: 14px 24px 20px; overflow-y: auto; }
.modal-foot {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 24px 20px;
  border-top: 1px solid var(--line);
}
.modal-foot .spacer { flex: 1; }

/* ---- Тост с «Отменить» ----------------------------------------------------------- */

.toast-zone {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: 26px;
  translate: -50% 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}
.toast {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 320px;
  max-width: 560px;
  padding: 12px 16px;
  border-radius: var(--r-m);
  background: var(--ink);
  color: #fff;
  font-size: 0.92rem;
  box-shadow: var(--shadow-pop);
  position: relative;
  overflow: hidden;
  animation: toast-in 0.2s ease-out;
}
@keyframes toast-in { from { translate: 0 12px; opacity: 0; } to { translate: 0 0; opacity: 1; } }
.toast .toast-undo {
  border: 0;
  background: none;
  color: #ffd884;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  white-space: nowrap;
}
.toast .toast-undo:hover { text-decoration: underline; }
.toast .toast-bar {
  position: absolute;
  left: 0; bottom: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.35);
  animation: toast-bar linear forwards;
}
@keyframes toast-bar { from { width: 100%; } to { width: 0; } }

/* ---- Хронология (лента событий дела) ---------------------------------------------- */

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  position: relative;
  padding: 0 0 18px 26px;
}
.timeline li::before {
  content: '';
  position: absolute;
  left: 5px; top: 7px;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--stamp);
}
.timeline li.tl-manual::before { border-color: var(--ink-faint); }
.timeline li::after {
  content: '';
  position: absolute;
  left: 9px; top: 20px; bottom: -2px;
  width: 1px;
  background: var(--line);
}
.timeline li:last-child::after { display: none; }
.timeline .tl-date { font-size: 0.82rem; color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.timeline .tl-text { font-size: 0.94rem; }
.timeline .tl-src { font-size: 0.78rem; color: var(--ink-faint); }

/* ---- Пары «ключ — значение» --------------------------------------------------------- */

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 7px 16px; font-size: 0.92rem; }
.kv dt { color: var(--ink-faint); }
.kv dd { margin: 0; }

/* ---- Слои календаря (постоянные цвета) ------------------------------------------------ */

.layer-hearing { --layer: var(--stamp); --layer-wash: var(--stamp-wash); }
.layer-deadline { --layer: var(--red); --layer-wash: var(--red-wash); }
.layer-task { --layer: var(--green); --layer-wash: var(--green-wash); }
.layer-meeting { --layer: var(--violet); --layer-wash: var(--violet-wash); }

.layer-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 99px;
  background: var(--surface);
  font-size: 0.88rem;
  cursor: pointer;
  user-select: none;
}
.layer-chip::before {
  content: '';
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--layer);
}
.layer-chip.is-off { color: var(--ink-faint); background: var(--surface-dim); }
.layer-chip.is-off::before { background: var(--line-strong); }

/* ---- Результаты поиска в шапке ---------------------------------------------------------- */

.search-pop {
  position: absolute;
  z-index: 75;
  top: calc(100% + 6px);
  left: 0;
  width: 460px;
  max-width: 84vw;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-l);
  box-shadow: var(--shadow-pop);
  max-height: 60vh;
  overflow-y: auto;
}
.search-pop[hidden] { display: none; }
.search-pop .sp-group {
  padding: 8px 12px 4px;
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.search-pop .sp-item {
  display: block;
  padding: 8px 12px;
  border-radius: var(--r-s);
  color: var(--ink);
}
.search-pop .sp-item:hover { background: var(--surface-dim); text-decoration: none; }
.search-pop .sp-item .sp-sub { font-size: 0.8rem; color: var(--ink-faint); }
