/* =====================================================================
   MGBot AI — Компоненты интерфейса
   ===================================================================== */

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    padding: 10px 18px;
    min-height: 42px;          /* крупная цель нажатия — работают и школьники */
    border: 1px solid transparent;
    border-radius: var(--r-md);
    background: var(--surface-2);
    color: var(--text);
    font-family: inherit;
    font-size: var(--fs-md);
    font-weight: 550;
    line-height: 1;
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
    transition: background var(--t-fast), border-color var(--t-fast),
                color var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
}

.btn:hover { background: var(--surface-hover); }
.btn:active { transform: translateY(1px); }

.btn:disabled,
.btn[aria-disabled="true"] {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: var(--accent);
    color: var(--on-accent);
    font-weight: 650;
    border-color: transparent;
}
.btn-primary:hover { background: var(--accent-hover); box-shadow: var(--ring); }

.btn-outline {
    background: transparent;
    border-color: var(--border-strong);
    color: var(--text);
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger {
    background: transparent;
    border-color: var(--danger-line);
    color: var(--danger);
}
.btn-danger:hover { background: var(--danger-dim); border-color: var(--danger); }

.btn-sm { padding: 6px 12px; min-height: 32px; font-size: var(--fs-sm); }
.btn-lg { padding: 14px 26px; min-height: 52px; font-size: var(--fs-lg); }
.btn-icon { padding: 0; width: 40px; min-height: 40px; }
.btn-icon.btn-sm { width: 32px; min-height: 32px; }
.btn-block { width: 100%; }

.btn-group {
    display: inline-flex;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 3px;
    gap: 2px;
}
.btn-group .btn {
    background: transparent;
    border: none;
    min-height: 32px;
    padding: 6px 14px;
    font-size: var(--fs-sm);
    border-radius: var(--r-sm);
    color: var(--text-muted);
}
.btn-group .btn.active {
    background: var(--accent-dim);
    color: var(--accent);
    font-weight: 650;
}

/* ========================= Карточки и панели ========================= */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: var(--sp-5);
}

.card-tight { padding: var(--sp-4); }

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    margin-bottom: var(--sp-4);
}

.card-title {
    font-size: var(--fs-lg);
    font-weight: 650;
    margin: 0;
}

.card-sub {
    font-size: var(--fs-sm);
    color: var(--text-muted);
    margin-top: 2px;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    overflow: hidden;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}

.panel-body { padding: var(--sp-4); }

.divider {
    height: 1px;
    background: var(--border);
    border: none;
    margin: var(--sp-4) 0;
}

/* ========================= Формы ========================= */

.field { display: flex; flex-direction: column; gap: 6px; }

.label {
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--text);
}

.hint {
    font-size: var(--fs-xs);
    color: var(--text-muted);
    line-height: 1.45;
}

.input,
.select,
.textarea {
    width: 100%;
    padding: 10px 14px;
    min-height: 42px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    color: var(--text);
    font-family: inherit;
    font-size: var(--fs-md);
    transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

.input::placeholder, .textarea::placeholder { color: var(--text-faint); }

.input:focus,
.select:focus,
.textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--ring);
}

.textarea { min-height: 96px; resize: vertical; line-height: 1.5; }

.select {
    appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                      linear-gradient(135deg, currentColor 50%, transparent 50%);
    background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    padding-right: 38px;
    cursor: pointer;
}

.input-error { border-color: var(--danger) !important; }

/* Ползунок */
.range {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: var(--surface-2);
    border-radius: var(--r-pill);
    outline: none;
    cursor: pointer;
}
.range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px; height: 20px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid var(--surface);
    box-shadow: var(--shadow-sm);
}
.range::-moz-range-thumb {
    width: 20px; height: 20px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid var(--surface);
}

/* Переключатель */
.switch {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 26px;
    flex: none;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
    position: absolute;
    inset: 0;
    background: var(--border-strong);
    border-radius: var(--r-pill);
    cursor: pointer;
    transition: background var(--t-mid);
}
.switch .track::before {
    content: "";
    position: absolute;
    width: 20px; height: 20px;
    left: 3px; top: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform var(--t-mid);
    box-shadow: var(--shadow-sm);
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::before { transform: translateX(20px); }
.switch input:focus-visible + .track { box-shadow: var(--ring); }

/* Чекбокс */
.check {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    cursor: pointer;
    user-select: none;
    font-size: var(--fs-sm);
}
.check input {
    appearance: none;
    width: 20px; height: 20px;
    flex: none;
    border: 2px solid var(--border-strong);
    border-radius: var(--r-sm);
    background: var(--bg-elevated);
    cursor: pointer;
    position: relative;
    transition: background var(--t-fast), border-color var(--t-fast);
}
.check input:checked {
    background: var(--accent);
    border-color: var(--accent);
}
.check input:checked::after {
    content: "";
    position: absolute;
    left: 5px; top: 1px;
    width: 5px; height: 10px;
    border: solid var(--on-accent);
    border-width: 0 2.5px 2.5px 0;
    transform: rotate(45deg);
}

/* ========================= Чипы и бейджи ========================= */

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: var(--r-pill);
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
}
.chip-accent { background: var(--accent-dim); border-color: var(--accent-line); color: var(--accent); }
.chip-danger { background: var(--danger-dim); border-color: var(--danger-line); color: var(--danger); }
.chip-warn   { background: var(--warn-dim); color: var(--warn); border-color: transparent; }
.chip-info   { background: var(--info-dim); color: var(--info); border-color: transparent; }

.dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--text-faint);
    flex: none;
}
.dot-live { background: var(--accent); animation: pulse 1.8s ease-in-out infinite; }
.dot-rec  { background: var(--danger); animation: pulse 1.1s ease-in-out infinite; }
.dot-off  { background: var(--text-faint); }

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%      { opacity: 0.35; transform: scale(0.82); }
}

kbd {
    display: inline-block;
    padding: 2px 7px;
    min-width: 22px;
    text-align: center;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-bottom-width: 2px;
    border-radius: var(--r-sm);
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--text);
    line-height: 1.5;
}

/* ========================= Шаги ========================= */

.steps {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    flex-wrap: wrap;
}

.step {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    padding: 8px 16px;
    border-radius: var(--r-pill);
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: var(--fs-sm);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--t-fast);
}
.step:hover { border-color: var(--border-strong); color: var(--text); }

.step .step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px; height: 22px;
    border-radius: 50%;
    background: var(--border);
    color: var(--text);
    font-size: var(--fs-xs);
    font-weight: 700;
    flex: none;
}

.step.active {
    background: var(--accent-dim);
    border-color: var(--accent-line);
    color: var(--accent);
}
.step.active .step-num { background: var(--accent); color: var(--on-accent); }

.step.done .step-num { background: var(--accent); color: var(--on-accent); }
.step.done { color: var(--text); }

.step-arrow { color: var(--text-faint); font-size: var(--fs-sm); }

/* ========================= Прогресс ========================= */

.progress {
    width: 100%;
    height: 10px;
    background: var(--surface-2);
    border-radius: var(--r-pill);
    overflow: hidden;
}
.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-hover));
    border-radius: var(--r-pill);
    transition: width 0.4s ease;
}
.progress-bar.indeterminate {
    width: 35% !important;
    animation: slide 1.4s ease-in-out infinite;
}
@keyframes slide {
    0%   { margin-left: -35%; }
    100% { margin-left: 100%; }
}

/* ========================= Таблица ========================= */

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

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--fs-sm);
}
.table th {
    text-align: left;
    padding: 10px 14px;
    font-weight: 600;
    color: var(--text-muted);
    font-size: var(--fs-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
}
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: none; }

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

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.62);
    backdrop-filter: blur(3px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--sp-5);
    z-index: 900;
    animation: fade var(--t-mid);
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-lg);
    width: min(560px, 100%);
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    animation: rise var(--t-mid);
}
@keyframes rise {
    from { opacity: 0; transform: translateY(14px) scale(0.98); }
    to   { opacity: 1; transform: none; }
}

.modal-wide { width: min(1080px, 100%); }

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    padding: var(--sp-4) var(--sp-5);
    border-bottom: 1px solid var(--border);
}
.modal-body { padding: var(--sp-5); overflow-y: auto; }
.modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: var(--sp-2);
    padding: var(--sp-4) var(--sp-5);
    border-top: 1px solid var(--border);
}

/* ========================= Тосты ========================= */

.toast-stack {
    position: fixed;
    right: var(--sp-5);
    bottom: var(--sp-5);
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    z-index: 1000;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: 13px 18px;
    min-width: 260px;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-md);
    font-size: var(--fs-sm);
    color: var(--text);
    pointer-events: auto;
    animation: toast-in var(--t-mid);
}
.toast.err  { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
.toast.info { border-left-color: var(--info); }
.toast.out  { animation: toast-out var(--t-mid) forwards; }

@keyframes toast-in {
    from { opacity: 0; transform: translateX(24px); }
    to   { opacity: 1; transform: none; }
}
@keyframes toast-out {
    to { opacity: 0; transform: translateX(24px); }
}

/* ========================= Пустые состояния ========================= */

.empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--sp-3);
    padding: var(--sp-7) var(--sp-5);
    text-align: center;
    color: var(--text-muted);
}
.empty-icon {
    font-size: 44px;
    line-height: 1;
    opacity: 0.55;
}
.empty-title {
    font-size: var(--fs-lg);
    font-weight: 650;
    color: var(--text);
}
.empty-text { font-size: var(--fs-sm); max-width: 420px; }

/* ========================= Скелетоны ========================= */

.skeleton {
    background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-hover) 50%, var(--surface-2) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
    border-radius: var(--r-sm);
}
@keyframes shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ========================= Подсказка при наведении ========================= */

.tip { position: relative; }
.tip::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    padding: 6px 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-sm);
    font-size: var(--fs-xs);
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--t-fast);
    box-shadow: var(--shadow-md);
    z-index: 50;
}
.tip:hover::after { opacity: 1; }

/* ===== Справка «?»: маленький кружок с пояснением при наведении/тапе ===== */

.help {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    margin-left: 6px;
    border-radius: 50%;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 700;
    cursor: help;
    vertical-align: middle;
    flex: none;
    user-select: none;
}
.help:hover { background: var(--accent-dim); border-color: var(--accent-line); color: var(--accent); }

.help::after {
    content: attr(data-help);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    width: max-content;
    max-width: 260px;
    padding: 9px 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-md);
    font-size: var(--fs-xs);
    font-weight: 500;
    line-height: 1.5;
    color: var(--text);
    text-align: left;
    white-space: normal;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--t-fast);
    box-shadow: var(--shadow-md);
    z-index: 60;
}
.help:hover::after, .help:focus::after { opacity: 1; }

/* У правого края экрана подсказка прижимается влево, чтобы не обрезалась */
.help.help-left::after { left: auto; right: 0; transform: none; }

/* ========================= Информационная плашка ========================= */

.note {
    display: flex;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    background: var(--info-dim);
    border-radius: var(--r-md);
    font-size: var(--fs-sm);
    color: var(--text);
    line-height: 1.5;
}
.note-icon { flex: none; font-size: var(--fs-lg); line-height: 1.3; }
.note-warn { background: var(--warn-dim); }
.note-danger { background: var(--danger-dim); }
.note-accent { background: var(--accent-dim); }
