/* Use Telegram theme variables for a native look */
:root {
    --tg-theme-bg-color: #ffffff;
    --tg-theme-text-color: #000000;
    --tg-theme-hint-color: #999999;
    --tg-theme-link-color: #2481cc;
    --tg-theme-button-color: #2481cc;
    --tg-theme-button-text-color: #ffffff;
    --tg-theme-secondary-bg-color: #f1f2f3;
    --twa-viewport-max-width: 100%;
    --twa-vh: 100dvh;
    color-scheme: light;
}

html {
    height: 100%;
    width: 100vw !important;
    max-width: none !important;
    overflow-x: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 0;
    width: 100vw !important;
    max-width: none !important;
    min-width: 100vw !important;
    min-height: 100%;
    min-height: var(--twa-vh, 100dvh);
    display: block;
    background-color: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-text-color);
    overflow-x: hidden;
}

#app-shell {
    box-sizing: border-box;
    width: 100vw !important;
    max-width: none !important;
    min-width: 100vw !important;
}

/* careAdminBoot toggles this on #gate / #app-shell; without it both stay in the flex row */
.hidden {
    display: none !important;
}

.twa-viewport {
    box-sizing: border-box;
    width: 100vw !important;
    max-width: none !important;
    min-width: 100vw !important;
    height: var(--twa-vh, 100dvh);
    max-height: var(--twa-vh, 100dvh);
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    background-color: var(--tg-theme-bg-color);
    padding-top: max(0.75rem, env(safe-area-inset-top, 0px));
    padding-right: max(0.75rem, env(safe-area-inset-right, 0px));
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom, 0px));
    padding-left: max(0.75rem, env(safe-area-inset-left, 0px));
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.container {
    padding: 0;
    padding-bottom: 0.5rem;
}

h1, h2, h3 {
    color: var(--tg-theme-text-color);
    margin-top: 1.5rem;
    margin-bottom: 1rem;
    font-family: "Manrope", system-ui, sans-serif;
    font-weight: 600;
    letter-spacing: -0.03em;
}
.container > h1:first-child { margin-top: 0; }
h1 {
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1.25;
}
h2 {
    font-size: 1.0625rem;
    font-weight: 600;
    line-height: 1.3;
    text-align: center;
}
h3 {
    font-size: 1rem;
    font-weight: 600;
}

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.kurator-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.kurator-list--sorting {
    user-select: none;
    -webkit-user-select: none;
}

.kurator-card {
    position: relative;
    z-index: 0;
    background-color: var(--tg-theme-secondary-bg-color);
    border-radius: 8px;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    overflow: visible;
}

.kurator-card--dragging {
    opacity: 0.75;
}

.kurator-card-main {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

/* ФИО и почта — одна колонка, один левый край (как у ФИО); статус — в .action-cell */
.kurator-text-col {
    flex: 1;
    min-width: 0;
    text-align: left;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.2rem;
}

.kurator-name-row {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    width: 100%;
    min-width: 0;
    font-weight: 500;
    overflow: visible;
}

/* ❗ верификация (текст из kurator_shift_automation §8.1) */
.verification-warning {
    position: relative;
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    overflow: visible;
}

.verification-warning-trigger {
    background: none;
    border: none;
    padding: 2px 4px;
    margin: -2px -4px;
    cursor: help;
    border-radius: 6px;
    font: inherit;
    line-height: 1;
    color: #dc3545;
    opacity: 0.95;
}

.verification-warning-trigger:hover,
.verification-warning-trigger:focus-visible {
    opacity: 1;
}

.verification-warning-trigger:focus-visible {
    outline: 2px solid var(--tg-theme-link-color);
    outline-offset: 2px;
}

.verification-warning-bubble {
    position: absolute;
    z-index: 80;
    left: 50%;
    bottom: calc(100% + 10px);
    transform: translateX(-50%);
    box-sizing: border-box;
    width: max-content;
    max-width: min(17.5rem, calc(100vw - 2.5rem));
    padding: 0.65rem 0.75rem;
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1.45;
    color: var(--tg-theme-text-color);
    text-align: left;
    background: var(--tg-theme-bg-color);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 10px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease, visibility 0.15s ease;
}

.verification-warning-bubble::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -6px;
    border: 6px solid transparent;
    border-top-color: var(--tg-theme-bg-color);
    filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.06));
}

.verification-warning:hover .verification-warning-bubble,
.verification-warning:focus-within .verification-warning-bubble,
.verification-warning.is-open .verification-warning-bubble {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.kurator-name {
    white-space: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    min-width: 0;
}
.kurator-name::-webkit-scrollbar {
    display: none;
}

.kurator-email {
    width: 100%;
    font-size: 0.9em;
    color: var(--tg-theme-hint-color);
    white-space: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.kurator-email::-webkit-scrollbar {
    display: none;
}

.action-cell-tools {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    justify-content: flex-end;
    flex-wrap: wrap;
}

/* Бейдж под строкой доля+иконки, выровнен вправо */
.action-cell .kurator-statuses {
    margin-top: 0;
    width: 100%;
    display: flex;
    justify-content: flex-end;
}

.status-badge {
    padding: 0.2em 0.5em;
    border-radius: 4px;
    font-size: 0.85em;
    font-weight: 600;
}

button.status-badge {
    font: inherit;
    font-size: 0.85em;
    font-weight: 600;
    font-family: inherit;
    border: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

button.status-badge:focus-visible {
    outline: 2px solid var(--tg-theme-link-color);
    outline-offset: 2px;
}

.status-badge.status-active {
    color: #fff;
    background-color: #28a745;
}

.status-badge.status-inactive {
    color: var(--tg-theme-text-color);
    background-color: #e9ecef;
}

/* Kurators Guide — свёрнута по умолчанию (<details>) */
.kurators-guide {
    background-color: var(--tg-theme-secondary-bg-color);
    border-radius: 10px;
    margin-bottom: 0.75rem;
    margin-top: -0.25rem;
    border: 1px solid color-mix(in srgb, var(--tg-theme-hint-color) 22%, transparent);
    overflow: hidden;
}

.kurators-guide > summary {
    list-style: none;
}

.kurators-guide > summary::-webkit-details-marker {
    display: none;
}

.kurators-guide-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.625rem;
    padding: 0.5625rem 0.875rem;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.kurators-guide-summary-text {
    font-family: "Manrope", system-ui, sans-serif;
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.3;
    color: var(--tg-theme-text-color);
}

.kurators-guide-chevron {
    flex-shrink: 0;
    width: 0.35rem;
    height: 0.35rem;
    margin-top: 0.05rem;
    border-right: 2px solid var(--tg-theme-hint-color);
    border-bottom: 2px solid var(--tg-theme-hint-color);
    transform: rotate(-45deg);
    transition: transform 0.2s ease;
    opacity: 0.8;
}

.kurators-guide[open] .kurators-guide-chevron {
    transform: rotate(45deg);
}

.kurators-guide[open] > .kurators-guide-summary {
    border-bottom: 1px solid color-mix(in srgb, var(--tg-theme-hint-color) 18%, transparent);
}

.kurators-guide-panel {
    padding: 0.625rem 0.875rem 0.75rem;
}

.kurators-guide-blocks {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.guide-block {
    display: grid;
    grid-template-columns: 2.875rem minmax(0, 1fr);
    column-gap: 0.875rem;
    row-gap: 0;
    align-items: start;
}

.guide-block-icon {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    width: 100%;
    padding-top: 0.2rem;
    box-sizing: border-box;
}

.guide-lightning {
    font-size: 1.125rem;
    line-height: 1;
    display: block;
}

.guide-mini-badge {
    display: inline-block;
    padding: 0.15em 0.4em 0.12em;
    border-radius: 4px;
    font-family: "Manrope", system-ui, sans-serif;
    font-size: 0.5625rem;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: 0.02em;
    color: #fff;
    background-color: #28a745;
    white-space: nowrap;
}

.guide-pct {
    font-size: 1.125rem;
    font-weight: 700;
    font-family: "Manrope", system-ui, sans-serif;
    line-height: 1;
    display: block;
    color: var(--tg-theme-text-color);
}

.guide-icon-cal,
.guide-icon-moon {
    font-size: 1.125rem;
    line-height: 1;
    display: block;
}

.guide-block-body {
    min-width: 0;
}

.guide-block-title {
    margin: 0 0 0.35rem;
    font-family: "Manrope", system-ui, sans-serif;
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.35;
    color: var(--tg-theme-text-color);
}

.guide-block-text {
    margin: 0;
    font-size: 0.8125rem;
    font-weight: 400;
    line-height: 1.45;
    letter-spacing: -0.01em;
    color: color-mix(in srgb, var(--tg-theme-text-color) 78%, var(--tg-theme-hint-color));
}

.kurators-guide-foot {
    margin: 0.75rem 0 0;
    padding-top: 0.5rem;
    border-top: 1px solid color-mix(in srgb, var(--tg-theme-hint-color) 18%, transparent);
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1.4;
    letter-spacing: -0.01em;
    color: var(--tg-theme-hint-color);
}

.icon-button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    opacity: 0.6;
    transition: opacity 0.2s;
    color: var(--tg-theme-text-color);
}
.icon-button:hover { opacity: 1; }
.icon-button.inactive { opacity: 0.32; }
.icon-button:disabled {
    opacity: 0.28;
    cursor: not-allowed;
    pointer-events: none;
}
.icon-button svg {
    width: 18px;
    height: 18px;
    stroke-width: 2;
    stroke: currentColor;
}

.text-danger { color: #dc3545; }
.text-muted {
    color: var(--tg-theme-hint-color);
    font-size: 0.9em;
}

.action-cell {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    align-items: flex-end;
    gap: 0.35rem;
    align-self: flex-start;
}

.drag-handle {
    cursor: grab;
    color: #adb5bd;
    font-weight: bold;
    padding-right: 0.4rem;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

.add-button {
    background: none;
    border: 1px dashed var(--tg-theme-secondary-bg-color);
    border-radius: 6px;
    padding: 0.75rem;
    cursor: pointer;
    color: var(--tg-theme-hint-color);
    margin-top: 1rem;
    width: 100%;
    transition: all 0.2s;
}
.add-button:hover {
    background: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-text-color);
}

.share-input-group {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    color: var(--tg-theme-hint-color);
    position: relative;
}

/* Ошибка суммы долей активных (как подсказка у ❗) */
.share-input-group--invalid {
    z-index: 4;
}

.share-input-group--invalid .kurator-share-input {
    border-color: #dc3545 !important;
    color: #c82333;
    box-shadow: 0 0 0 1px rgba(220, 53, 69, 0.35);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.share-input-group--invalid .kurator-share-input:focus {
    outline: none;
    border-color: #dc3545 !important;
    box-shadow: 0 0 0 2px rgba(220, 53, 69, 0.35);
}

.share-input-group--invalid .modal-input {
    border-color: #dc3545 !important;
    color: #c82333;
    box-shadow: 0 0 0 1px rgba(220, 53, 69, 0.35);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.share-input-group--invalid .modal-input:focus {
    outline: none;
    border-color: #dc3545 !important;
    box-shadow: 0 0 0 2px rgba(220, 53, 69, 0.35);
}

.kurator-edit-email-wrap {
    width: 100%;
}

.kurator-edit-email-wrap .modal-input {
    flex: 1 1 auto;
    min-width: 0;
}

.modal-field:has(.kurator-edit-email-wrap.share-input-group--invalid) {
    position: relative;
    z-index: 6;
}

.kurator-card:has(.share-input-group--invalid) {
    z-index: 4;
}

.share-sum-hint-bubble {
    position: absolute;
    z-index: 80;
    right: 0;
    bottom: calc(100% + 8px);
    left: auto;
    transform: none;
    box-sizing: border-box;
    width: min(14rem, calc(100vw - 2rem));
    max-width: calc(100vw - 2rem);
    margin: 0;
    padding: 0.55rem 0.65rem;
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1.35;
    color: var(--tg-theme-text-color);
    text-align: center;
    background: var(--tg-theme-bg-color);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 10px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease, visibility 0.15s ease;
    overflow-wrap: break-word;
    word-wrap: break-word;
}

.share-sum-hint-bubble::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -6px;
    border: 6px solid transparent;
    border-top-color: var(--tg-theme-bg-color);
    filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.06));
}

.share-input-group--invalid:hover .share-sum-hint-bubble,
.share-input-group--invalid:focus-within .share-sum-hint-bubble,
.share-input-group--invalid .share-sum-hint-bubble:hover {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.share-select {
    border: 1px solid var(--tg-theme-secondary-bg-color);
    border-radius: 4px;
    background-color: var(--tg-theme-bg-color);
    color: var(--tg-theme-text-color);
    -webkit-appearance: none;
    appearance: none;
    text-align: center;
    font-variant-numeric: tabular-nums;
    box-sizing: border-box;
}

/* Блок настроек: тот же кегль и линия, что у подписей слева; компактные поля */
#settings-section .setting-item {
    align-items: baseline;
}

#settings-section .setting-item label {
    font-size: 1rem;
    line-height: 1.35;
}

#settings-section .setting-item .text-muted {
    font-size: 1rem;
    line-height: 1.35;
}

#settings-section .time-range {
    align-items: baseline;
    gap: 0.35rem;
}

#settings-section .share-select {
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.35;
    font-weight: 400;
    padding: 0.15rem 0.35rem;
}

/* Время: достаточно ширины под «HH:00», без «раздутых» полей */
#settings-section .time-range .share-select,
#settings-section #nightly-run-time {
    min-width: 4rem;
    width: auto;
    max-width: none;
}

/* Окно активности: уже, значения 1…10 */
#settings-section #activity-window.share-select {
    min-width: 1.75rem;
    width: auto;
    max-width: 2.25rem;
    padding-left: 0.2rem;
    padding-right: 0.2rem;
}

.kurator-share-input {
    width: 3rem;
    min-width: 3rem;
    max-width: 3rem;
    padding: 0.5rem 0.25rem;
    border: 1px solid var(--tg-theme-secondary-bg-color);
    border-radius: 4px;
    background-color: var(--tg-theme-bg-color);
    color: var(--tg-theme-text-color);
    font: inherit;
    font-size: 0.9375rem;
    font-variant-numeric: tabular-nums;
    text-align: center;
    box-sizing: border-box;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.kurator-share-input::placeholder {
    color: var(--tg-theme-hint-color);
    opacity: 0.6;
}

.kurator-share-input:focus-visible {
    outline: 2px solid var(--tg-theme-link-color);
    outline-offset: 2px;
}

.share-input-group--invalid .kurator-share-input:focus-visible {
    outline: none;
}

.page-section {
    margin-top: 2rem;
}

.container > h1 + .page-section {
    margin-top: 1.25rem;
}

#log-section.page-section {
    margin-top: 2.5rem;
}

.calendar-toolbar, .settings-grid, .log-toolbar {
    margin-bottom: 1rem;
}
.calendar-toolbar {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.25rem;
}
#prev-month-btn,
#next-month-btn {
    min-width: 2.5rem;
    min-height: 2.5rem;
    padding: 0.25rem 0.6rem;
    font-size: 1.05rem;
}
.calendar-toolbar h3 {
    margin: 0 0.75rem;
    min-width: 0;
    flex: 1 1 auto;
    text-align: center;
    font-family: "Manrope", system-ui, sans-serif;
    font-weight: 600;
    letter-spacing: -0.03em;
    font-size: 1rem;
}

/* Календарь смен: свёртка до одной недели + зона «следующей недели» с «Раскрыть» */
.schedule-calendar-viewport {
    position: relative;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    transition: max-height 0.4s ease;
}

.schedule-calendar-viewport.is-expanded {
    overflow: visible;
}

.schedule-calendar-inner {
    width: 100%;
}

/* Под полной неделей: ряд как у шапки дат + кнопка (без перекрытия строк кураторов) */
.schedule-collapse-footer {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.35rem;
    margin-top: 0.35rem;
    padding-top: 0.45rem;
    border-top: 1px dashed color-mix(in srgb, var(--tg-theme-hint-color) 35%, transparent);
}

/* display:flex выше перебивает нативный [hidden] — после раскрытия футер с кнопкой должен пропадать */
.schedule-collapse-footer[hidden] {
    display: none !important;
}

.schedule-next-week-placeholder {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0;
    text-align: center;
    font-size: 0.85rem;
    line-height: 1.2;
    min-height: 1.15rem;
    color: color-mix(in srgb, var(--tg-theme-hint-color) 55%, transparent);
    font-weight: 600;
    opacity: 0.65;
}

.schedule-collapse-footer .schedule-expand-btn {
    align-self: center;
    margin-top: 0.15rem;
}

.schedule-expand-btn {
    pointer-events: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    margin-bottom: 0.15rem;
    padding: 0.35rem 0.85rem;
    border: none;
    border-radius: 999px;
    background: color-mix(in srgb, var(--tg-theme-secondary-bg-color) 85%, var(--tg-theme-bg-color));
    color: var(--tg-theme-link-color);
    font: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    font-family: "Manrope", system-ui, sans-serif;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.schedule-expand-btn:active {
    transform: scale(0.98);
}

.schedule-expand-label {
    line-height: 1.2;
}

.schedule-expand-chevron {
    display: inline-block;
    width: 0.45em;
    height: 0.45em;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg) translateY(-0.15em);
    opacity: 0.9;
}

/* Календарь смен: недели по 7 колонок, без горизонтального скролла */
.schedule-calendar-root {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.schedule-week-block {
    width: 100%;
    max-width: 100%;
}

.schedule-week-block--collapsed-hidden {
    display: none !important;
}

.schedule-month-week-table {
    width: 100%;
    max-width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: 0.65rem;
}

.schedule-month-week-table th,
.schedule-month-week-table td {
    padding: 0.15rem 0.1rem;
    text-align: center;
    vertical-align: middle;
    min-width: 0;
}

.sched-corner {
    width: 22%;
    max-width: 5.5rem;
}

.sched-day-head {
    width: calc((100% - 22%) / 7);
    font-weight: 600;
    line-height: 1.2;
    color: var(--tg-theme-text-color);
}

.sched-day-head--pad {
    color: var(--tg-theme-hint-color);
    opacity: 0.35;
}

.sched-day-head--today .sched-dn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.45em;
    height: 1.45em;
    border-radius: 50%;
    background: var(--tg-theme-button-color, #2481cc);
    color: var(--tg-theme-button-text-color, #fff);
    font-size: 0.78rem;
    line-height: 1;
}

.sched-cell-wrap--today {
    position: relative;
}
.sched-cell-wrap--today::before {
    content: "";
    position: absolute;
    inset: 1px;
    border-radius: 6px;
    border: 1.5px solid var(--tg-theme-button-color, #2481cc);
    opacity: 0.25;
    pointer-events: none;
}

.sched-wd {
    display: block;
    font-size: 0.58rem;
    font-weight: 600;
    color: var(--tg-theme-hint-color);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.sched-dn {
    display: block;
    font-size: 0.72rem;
    font-weight: 700;
    font-family: "Manrope", system-ui, sans-serif;
}

.sched-kurator-name {
    text-align: left;
    font-weight: 500;
    font-size: 0.68rem;
    line-height: 1.25;
    max-width: 5.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-right: 0.2rem;
}

.sched-cell-wrap {
    padding: 0.1rem;
}

.sched-cell-wrap--pad {
    background: transparent;
}

.sched-day-toggle {
    display: block;
    width: 100%;
    max-width: 100%;
    aspect-ratio: 1;
    max-height: 1.65rem;
    margin: 0 auto;
    padding: 0;
    border: none;
    border-radius: 4px;
    background-color: var(--tg-theme-secondary-bg-color);
    cursor: pointer;
    transition: background-color 0.15s, transform 0.1s;
    box-sizing: border-box;
}

.sched-day-toggle.is-on-duty {
    background-color: #28a745;
}

.sched-day-toggle:active {
    transform: scale(0.94);
}

.twa-viewport.twa-has-save-pad {
    padding-bottom: 5.5rem;
}

.global-save-bar {
    position: fixed;
    left: 0;
    right: 0;
    transform: none;
    bottom: 0;
    z-index: 1500;
    box-sizing: border-box;
    width: 100%;
    max-width: none;
    padding: 0.65rem 1rem;
    padding-bottom: max(0.65rem, env(safe-area-inset-bottom, 0px));
    background: color-mix(in srgb, var(--tg-theme-bg-color) 94%, transparent);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid color-mix(in srgb, var(--tg-theme-hint-color) 18%, transparent);
    box-shadow: 0 -6px 28px rgba(0, 0, 0, 0.07);
}

.global-save-bar[hidden] {
    display: none !important;
}

/* Скрываем HTML-кнопки когда доступны нативные кнопки Telegram */
body.tg-native-btns .global-save-bar {
    display: none !important;
}
body.tg-native-btns .twa-has-save-pad {
    padding-bottom: 0 !important;
}
body.tg-native-btns-full #kurator-edit-modal .modal-actions {
    display: none;
}
body.tg-native-btns-full #manual-run-confirm-modal .modal-actions {
    display: none;
}

.global-save-btn {
    width: 100%;
    margin: 0;
    border: none;
    border-radius: 0.875rem;
    padding: 0.8rem 1rem;
    min-height: 2.75rem;
    box-sizing: border-box;
    background-color: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
    font-weight: 600;
    font-size: 1rem;
    line-height: 1.25;
    font-family: "Manrope", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    letter-spacing: -0.02em;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.global-save-btn:hover {
    filter: brightness(1.04);
    color: var(--tg-theme-button-text-color);
}

.global-save-btn:active {
    filter: brightness(0.94);
    transform: scale(0.992);
}

.settings-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    padding: 1rem;
    border: 1px dashed var(--tg-theme-secondary-bg-color);
    border-radius: 8px;
}

.setting-item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1rem;
}
.setting-item label {
    font-weight: 500;
    flex-shrink: 0;
}
.time-range {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.log-section-heading {
    text-align: center;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
}

.log-toolbar {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.65rem 0.85rem;
}

.log-run-btn {
    flex: 0 0 auto;
    width: auto;
    min-width: 0;
}

.log-run-btn.is-busy,
.log-run-btn[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

.log-page-btn {
    font-family: "Manrope", system-ui, sans-serif;
    font-size: 0.8125rem;
    font-weight: 600;
    padding: 0.4rem 0.85rem;
    border-radius: 8px;
    border: 1px solid color-mix(in srgb, var(--tg-theme-hint-color) 35%, transparent);
    background: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-text-color);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.log-page-btn:hover:not(:disabled) {
    border-color: color-mix(in srgb, var(--tg-theme-link-color) 45%, transparent);
    color: var(--tg-theme-link-color);
}

.log-page-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.log-page-btn--edge {
    flex: 0 0 auto;
}

.log-page-num {
    font-family: "Manrope", system-ui, sans-serif;
    font-size: 0.8125rem;
    font-weight: 600;
    min-width: 2.25rem;
    padding: 0.35rem 0.5rem;
    border-radius: 8px;
    border: 1px solid color-mix(in srgb, var(--tg-theme-hint-color) 28%, transparent);
    background: var(--tg-theme-bg-color);
    color: var(--tg-theme-hint-color);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
}

.log-page-num:hover:not(.is-active) {
    border-color: color-mix(in srgb, var(--tg-theme-link-color) 40%, transparent);
    color: var(--tg-theme-link-color);
}

.log-page-num.is-active {
    border-color: var(--tg-theme-link-color);
    background: color-mix(in srgb, var(--tg-theme-link-color) 12%, transparent);
    color: var(--tg-theme-link-color);
}

.log-table-card {
    margin-top: 0.75rem;
    border-radius: 10px;
    border: 1px solid color-mix(in srgb, var(--tg-theme-hint-color) 22%, transparent);
    overflow: hidden;
    background: var(--tg-theme-bg-color);
}

.log-pagination--embedded {
    margin: 0;
    border-top: 1px solid color-mix(in srgb, var(--tg-theme-hint-color) 15%, transparent);
    background: color-mix(in srgb, var(--tg-theme-secondary-bg-color) 45%, var(--tg-theme-bg-color));
}

.log-pagination-row {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.45rem;
    padding: 0.5rem 0.4rem;
    min-width: 0;
}

.log-page-numbers-scroll {
    flex: 1 1 0;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    cursor: grab;
    scrollbar-width: none;
    -ms-overflow-style: none;
    touch-action: pan-x;
}

.log-page-numbers-scroll::-webkit-scrollbar {
    display: none;
    height: 0;
}

.log-page-numbers-scroll.log-page-numbers-scroll--dragging {
    cursor: grabbing;
    user-select: none;
}

.log-page-numbers {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-start;
    gap: 0.35rem;
    width: max-content;
    min-height: 2.25rem;
    padding: 0.05rem 0;
}

.log-page-info {
    flex: 0 0 auto;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--tg-theme-hint-color);
    white-space: nowrap;
    max-width: 38%;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (min-width: 380px) {
    .log-page-info {
        max-width: none;
    }
}

.log-table-wrap {
    margin-top: 0;
    border: none;
    border-radius: 0;
    /* Не hidden: иначе обрезается последний столбец и ломается горизонтальный скролл */
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--tg-theme-bg-color);
    cursor: grab;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.log-table-wrap::-webkit-scrollbar {
    display: none;
    height: 0;
}

.log-table-wrap.log-table-wrap--dragging {
    cursor: grabbing;
    user-select: none;
}

.log-table {
    width: 100%;
    /*
     * fixed + 100%: ячейки не расширяются под nowrap-текст, он рисуется вправо без фона/линий.
     * auto + min(min-content): таблица не уже контента — шапка и border-bottom на всю ширину скролла.
     */
    min-width: max(22rem, min-content);
    table-layout: auto;
    border-collapse: collapse;
    font-size: 0.875rem;
    line-height: 1.35;
}

/*
 * Дата / статус / две метрики; у статуса достаточно места под «СТАТУС» в шапке.
 */
.log-table col.log-col-date {
    width: 35%;
}

.log-table col.log-col-status {
    /* Достаточно ширины, чтобы «СТАТУС» помещался целиком: иначе overflow:hidden
       обрезает центрированный текст и он визуально не совпадает с кругами в tbody */
    width: 18%;
}

.log-table col.log-col-metric {
    width: 23.5%;
}

.log-table thead th {
    text-align: left;
    vertical-align: middle;
    font-weight: 600;
    font-family: "Manrope", system-ui, sans-serif;
    font-size: 0.7rem;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--tg-theme-hint-color);
    padding: 0.55rem 0.35rem;
    background: color-mix(in srgb, var(--tg-theme-secondary-bg-color) 55%, var(--tg-theme-bg-color));
    border-bottom: 1px solid color-mix(in srgb, var(--tg-theme-hint-color) 15%, transparent);
    box-sizing: border-box;
}

/* Текст шапки не рисуется поверх соседней колонки (эффект «СТАТУССТУДЕНТЫ»).
 * «Статус» не режем: обрезка ломала визуальное совпадение с иконками; колонка расширена. */
.log-table thead th:first-child,
.log-table thead th.log-th-num:not(.log-th-errs) {
    overflow: hidden;
}

.log-table thead th:first-child,
.log-table tbody td.log-td-date {
    padding-left: 0.45rem;
    padding-right: 0.35rem;
}

/*
 * Статус по центру. Не использовать display:flex на th/td — ломается border-collapse, линии между строками рвутся.
 * letter-spacing у общей шапки визуально сдвигает «СТАТУС» вправо — отключаем только здесь.
 */
.log-table thead th.log-th-status,
.log-table tbody td.log-td-status {
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
    padding-left: 0.45rem;
    padding-right: 0.45rem;
    box-sizing: border-box;
}

.log-table thead th.log-th-status {
    letter-spacing: normal;
}

/* Числа и заголовки числовых колонок — одна строка */
.log-table thead th.log-th-num {
    text-align: right;
    padding-left: 0.35rem;
    padding-right: 0.45rem;
    white-space: nowrap;
}

.log-table tbody td {
    padding: 0.55rem 0.35rem;
    vertical-align: middle;
    border-bottom: 1px solid color-mix(in srgb, var(--tg-theme-hint-color) 12%, transparent);
}

.log-table tbody td.log-td-num {
    text-align: right;
    padding-left: 0.35rem;
    padding-right: 0.45rem;
    white-space: nowrap;
}

/* «Студенты»: заголовок и числа по одной вертикальной оси — по центру колонки */
.log-table thead th.log-th-num.log-th-students,
.log-table tbody td.log-td-num.log-td-students {
    text-align: center;
    padding-left: 0.45rem;
    padding-right: 0.45rem;
}

/* «Ошибки»: без видимой линии — только доп. отступ слева как невидимый зазор от «Студенты» */
.log-table thead th.log-th-errs,
.log-table tbody td.log-td-errs {
    text-align: center;
    padding-left: 0.65rem;
    padding-right: 0.65rem;
}

/* Подпись «ОШИБКИ» чуть левее центра колонки — целиком в кадре до свайпа вправо */
.log-table thead th.log-th-errs {
    padding-left: 0.4rem;
    padding-right: 1.25rem;
}

.log-table tbody tr:last-child td {
    border-bottom: none;
}

.log-td-mono {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
}

.log-datetime {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
    min-width: 0;
    max-width: 100%;
}

.log-date-line {
    font-weight: 600;
    font-family: "Manrope", system-ui, sans-serif;
    font-size: 0.9375rem;
    color: var(--tg-theme-text-color);
    line-height: 1.3;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
}

.log-time-line {
    font-size: 0.84375rem;
    font-variant-numeric: tabular-nums;
    color: var(--tg-theme-hint-color);
    white-space: nowrap;
}

/* Иконки статуса в логах (компактно, без налезания на «Студенты») */
.log-status-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.7rem;
    height: 1.7rem;
    border-radius: 50%;
    flex-shrink: 0;
    box-sizing: border-box;
    color: #fff;
}

.log-status-badge svg {
    width: 0.92rem;
    height: 0.92rem;
    flex-shrink: 0;
}

.log-status-badge--completed {
    background-color: #28a745;
}

.log-status-badge--running {
    background-color: #6c757d;
}

.log-status-badge--failed {
    background-color: #dc3545;
}

.status-label {
    padding: 0.25em 0.6em;
    font-size: 0.8em;
    font-weight: 700;
    border-radius: 3px;
    color: #fff;
    white-space: nowrap;
}
.status-completed { background-color: #28a745; }
.status-running { background-color: #6c757d; }
.status-failed { background-color: #dc3545; }
.status-abandoned { background-color: #ffc107; color: #212529;}
.status-partially_completed { background-color: #ffc107; color: #212529;}

/* Редактирование куратора */
.modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    visibility: hidden;
    pointer-events: none;
    transition: visibility 0.2s step-end;
}

.modal.is-open {
    visibility: visible;
    pointer-events: auto;
    transition: visibility 0s step-start;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.modal.is-open .modal-backdrop {
    opacity: 1;
}

.modal-sheet {
    position: relative;
    width: 100%;
    max-width: none;
    box-sizing: border-box;
    padding: 0.5rem 1rem max(1rem, env(safe-area-inset-bottom, 0px));
    background: var(--tg-theme-bg-color);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.12);
    transform: translateY(100%);
    transition: transform 0.22s ease;
}

.modal.is-open .modal-sheet {
    transform: translateY(0);
}

.modal-handle {
    width: 36px;
    height: 4px;
    margin: 0 auto 0.75rem;
    border-radius: 2px;
    background: var(--tg-theme-secondary-bg-color);
}

.modal-title {
    font-family: "Manrope", system-ui, sans-serif;
    font-size: 1.0625rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    margin: 0 0 0.5rem;
    color: var(--tg-theme-text-color);
}

.modal-salebot-note {
    margin: 0 0 1rem;
    font-size: 0.8125rem;
    line-height: 1.45;
    color: color-mix(in srgb, var(--tg-theme-text-color) 72%, var(--tg-theme-hint-color));
}

.modal-confirm-text {
    margin: 0;
    font-size: 0.9375rem;
    line-height: 1.45;
    color: var(--tg-theme-text-color);
}

.modal-field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-bottom: 0.85rem;
}

.modal-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--tg-theme-hint-color);
}

.modal-input {
    box-sizing: border-box;
    width: 100%;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--tg-theme-secondary-bg-color);
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    color: var(--tg-theme-text-color);
    background: var(--tg-theme-bg-color);
}

.modal-input:focus {
    outline: none;
    border-color: var(--tg-theme-link-color);
}

.modal-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1.25rem;
}

.modal-btn {
    flex: 1;
    padding: 0.7rem 1rem;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: "Manrope", system-ui, sans-serif;
    cursor: pointer;
    border: none;
}

.modal-btn-secondary {
    background: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-text-color);
}

.modal-btn-primary {
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
}

/* Deno Deploy: gate + toasts + shell header */
.care-gate {
    box-sizing: border-box;
    width: 100vw !important;
    max-width: none !important;
    min-width: 100vw !important;
    min-height: 100vh;
    min-height: var(--twa-vh, 100dvh);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: var(--tg-theme-bg-color, #0f1115);
    color: var(--tg-theme-text-color, #e8eaed);
    text-align: center;
    font-family: "Manrope", system-ui, sans-serif;
}
.care-gate .lead {
    max-width: 22rem;
    margin: 0 0 0.75rem;
    line-height: 1.45;
}
.care-gate .err {
    color: #f28b82;
    margin-top: 0.5rem;
}
.care-shell-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.65rem 0 1rem;
    flex-wrap: wrap;
}
.care-shell-header h1 {
    margin: 0;
    font-size: 1.15rem;
}
.toast-root {
    position: fixed;
    top: 0.75rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 99999;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    align-items: center;
    pointer-events: none;
    max-width: min(92vw, 420px);
}
.toast {
    pointer-events: auto;
    padding: 0.55rem 0.9rem;
    border-radius: 10px;
    font-size: 0.9rem;
    font-family: "Manrope", system-ui, sans-serif;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
}
.toast.ok {
    background: #1e3a2f;
    color: #c8e6c9;
    border: 1px solid #2e7d32;
}
.toast.err {
    background: #3a1e1e;
    color: #ffcdd2;
    border: 1px solid #c62828;
}

.toast.toast-loading {
    background: color-mix(in srgb, var(--tg-theme-secondary-bg-color) 92%, #000);
    color: var(--tg-theme-text-color);
    border: 1px solid color-mix(in srgb, var(--tg-theme-hint-color) 35%, transparent);
    animation: care-toast-pulse 1.1s ease-in-out infinite;
}

.toast-err-persistent {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    padding: 0.7rem 0.9rem 0.6rem;
    max-width: min(92vw, 380px);
    width: min(92vw, 380px);
}
.toast-err-msg {
    font-weight: 600;
    line-height: 1.35;
}
.toast-err-id {
    font-size: 0.72rem;
    opacity: 0.7;
    letter-spacing: 0.02em;
    font-family: monospace;
}
.toast-err-actions {
    display: flex;
    gap: 0.4rem;
    margin-top: 0.1rem;
}
.toast-err-btn {
    flex: 1;
    padding: 0.38rem 0.5rem;
    border-radius: 7px;
    border: none;
    font-size: 0.78rem;
    font-weight: 600;
    font-family: "Manrope", system-ui, sans-serif;
    cursor: pointer;
    line-height: 1.2;
}
.toast-err-btn-retry {
    background: #c62828;
    color: #fff;
}
.toast-err-btn-copy {
    background: rgba(255,255,255,0.12);
    color: #ffcdd2;
    border: 1px solid rgba(255,255,255,0.18);
}
.toast-err-btn-copy.copied {
    color: #a5d6a7;
    border-color: #388e3c;
}

@keyframes care-toast-pulse {
    50% { opacity: 0.88; }
}

.log-status-badge--partial {
    color: #f9a825;
}

.log-phase-line {
    display: block;
    font-size: 0.68em;
    line-height: 1.1;
    margin-top: 0.2rem;
    white-space: nowrap;
    color: var(--tg-theme-hint-color, #888);
    letter-spacing: 0;
}

/* ── Boot screen ──────────────────────────────────────────── */
.boot-screen {
    position: fixed;
    inset: 0;
    z-index: 98000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    opacity: 1;
    transition: opacity 0.25s ease;
    pointer-events: all;
}
.boot-screen.hidden {
    opacity: 0;
    pointer-events: none;
}
.boot-screen-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid #e0e0e0;
    border-top-color: #2481cc;
    border-radius: 50%;
    animation: save-spin 0.75s linear infinite;
}

/* ── Save overlay ─────────────────────────────────────────── */
.save-overlay {
    position: fixed;
    inset: 0;
    z-index: 99000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    opacity: 0;
    transition: opacity 0.18s ease;
    pointer-events: none;
}
.save-overlay.visible {
    opacity: 1;
    pointer-events: all;
}
.save-overlay-card {
    background: #ffffff;
    border-radius: 20px;
    padding: 2rem 2.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.85rem;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.22), 0 4px 16px rgba(0, 0, 0, 0.12);
    transform: scale(0.92);
    transition: transform 0.18s ease;
    min-width: 180px;
}
.save-overlay.visible .save-overlay-card {
    transform: scale(1);
}
.save-overlay-spinner {
    width: 44px;
    height: 44px;
    border: 3.5px solid #e0e0e0;
    border-top-color: #2481cc;
    border-radius: 50%;
    animation: save-spin 0.75s linear infinite;
    flex-shrink: 0;
}
@keyframes save-spin {
    to { transform: rotate(360deg); }
}
.save-overlay-check {
    width: 44px;
    height: 44px;
    background: #34C759;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    animation: save-check-pop 0.22s ease;
}
@keyframes save-check-pop {
    0%   { transform: scale(0.6); opacity: 0; }
    70%  { transform: scale(1.12); }
    100% { transform: scale(1); opacity: 1; }
}
.save-overlay-check svg {
    width: 24px;
    height: 24px;
    stroke: #ffffff;
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}
.save-overlay-label {
    font-family: "Manrope", system-ui, sans-serif;
    font-size: 1rem;
    font-weight: 600;
    color: #1a1a1a;
    letter-spacing: -0.01em;
}
