/* ── Общие сбросы и базовые стили ── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    font-size: 13px;
    color: #333;
    background: #f5f5f5;
    /* Без внешних отступов — работаем в iframe Б24 */
    margin: 0;
    padding: 0;
}

/* ── Контейнер страницы ── */
.page-container {
    padding: 16px;
    max-width: 100%;
}

/* ── Заголовки блоков ── */
.section-title {
    font-size: 15px;
    font-weight: 600;
    color: #1e3a5f;
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 2px solid #d4e3f5;
}

/* ── Кнопки в стиле Битрикс24 ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 14px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.15s, opacity 0.15s;
    white-space: nowrap;
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: #2067b0;
    color: #fff;
}
.btn-primary:hover:not(:disabled) {
    background: #1a56a0;
}

.btn-secondary {
    background: #e5e9ef;
    color: #333;
    border: 1px solid #c5cdd8;
}
.btn-secondary:hover:not(:disabled) {
    background: #d8dde6;
}

.btn-danger {
    background: #fff;
    color: #d9534f;
    border: 1px solid #d9534f;
}
.btn-danger:hover:not(:disabled) {
    background: #fdf2f2;
}

.btn-success {
    background: #3dbb62;
    color: #fff;
}
.btn-success:hover:not(:disabled) {
    background: #30a854;
}

.btn-sm {
    padding: 3px 9px;
    font-size: 12px;
}

/* ── Таблицы ── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.data-table thead tr {
    background: #e8edf4;
}

.data-table thead th {
    padding: 9px 12px;
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    color: #546e8a;
    border-bottom: 1px solid #cdd5df;
    white-space: nowrap;
}

.data-table tbody tr {
    border-bottom: 1px solid #eef0f4;
    transition: background 0.1s;
}

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

.data-table tbody tr:hover {
    background: #f0f5fb;
}

.data-table tbody tr:nth-child(even) {
    background: #fafbfd;
}

.data-table tbody tr:nth-child(even):hover {
    background: #f0f5fb;
}

.data-table td {
    padding: 8px 12px;
    vertical-align: middle;
}

/* Строка итогов */
.data-table tfoot tr {
    background: #eaf0f9;
    font-weight: 600;
}

.data-table tfoot td {
    padding: 9px 12px;
    border-top: 2px solid #cdd5df;
}

/* Колонка действий */
.td-actions {
    width: 80px;
    text-align: right;
    white-space: nowrap;
}
.td-actions .btn {
    margin-left: 3px;
}

/* ── Мастера ── */
.masters-section {
    margin-top: 20px;
}

.masters-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}

.master-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    background: #e8f0fb;
    border: 1px solid #b8d0f0;
    border-radius: 14px;
    font-size: 12px;
    color: #1e5aa8;
}

.master-chip.primary {
    background: #d0eaff;
    border-color: #2067b0;
    font-weight: 600;
}

.master-chip .remove-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #8aa5c8;
    font-size: 14px;
    line-height: 1;
    padding: 0 0 0 2px;
}
.master-chip .remove-btn:hover {
    color: #d9534f;
}

/* ── Модальное окно ── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    width: 460px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.modal-header {
    padding: 16px 20px 12px;
    border-bottom: 1px solid #e0e5ee;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title {
    font-size: 15px;
    font-weight: 600;
    color: #1e3a5f;
}

.modal-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 20px;
    color: #999;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 4px;
}
.modal-close:hover {
    background: #f0f0f0;
    color: #555;
}

.modal-body {
    padding: 16px 20px;
    flex: 1;
}

.modal-footer {
    padding: 12px 20px;
    border-top: 1px solid #e0e5ee;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* ── Форма ── */
.form-group {
    margin-bottom: 14px;
}

.form-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #546e8a;
    margin-bottom: 4px;
}

.form-control {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid #c5cdd8;
    border-radius: 4px;
    font-size: 13px;
    color: #333;
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
}

.form-control:focus {
    border-color: #2067b0;
    box-shadow: 0 0 0 3px rgba(32,103,176,0.12);
}

.form-control.error {
    border-color: #d9534f;
}

/* Поиск в выпадашке */
.select-search-wrapper {
    position: relative;
}

.select-search-input {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid #c5cdd8;
    border-radius: 4px 4px 0 0;
    font-size: 13px;
    outline: none;
}
.select-search-input:focus {
    border-color: #2067b0;
    box-shadow: 0 0 0 3px rgba(32,103,176,0.12);
}

.select-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #c5cdd8;
    border-top: none;
    border-radius: 0 0 4px 4px;
    max-height: 180px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    display: none;
}

.select-dropdown.open {
    display: block;
}

.select-option {
    padding: 7px 10px;
    cursor: pointer;
    font-size: 13px;
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.1s;
}
.select-option:last-child {
    border-bottom: none;
}
.select-option:hover,
.select-option.focused {
    background: #e8f0fb;
    color: #1a56a0;
}

.selected-service-display {
    font-size: 12px;
    color: #546e8a;
    margin-top: 4px;
    min-height: 16px;
}

/* ── Уведомления ── */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 10px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    max-width: 320px;
    animation: slideIn 0.2s ease;
}

.toast.success {
    background: #3dbb62;
    color: #fff;
}

.toast.error {
    background: #d9534f;
    color: #fff;
}

.toast.info {
    background: #2067b0;
    color: #fff;
}

@keyframes slideIn {
    from { transform: translateX(60px); opacity: 0; }
    to   { transform: translateX(0);    opacity: 1; }
}

/* ── Загрузка ── */
.loading-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #c5cdd8;
    border-top-color: #2067b0;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    color: #888;
    padding: 20px;
    text-align: center;
}

/* ── Тулбар над таблицей ── */
.table-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    flex-wrap: wrap;
    gap: 8px;
}

/* ── Пустое состояние ── */
.empty-state {
    text-align: center;
    padding: 30px 20px;
    color: #999;
    font-size: 13px;
}

/* ── Бейджи/теги ── */
.badge {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}

.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-green  { background: #dcfce7; color: #166534; }
.badge-gray   { background: #f0f0f0; color: #555;    }
.badge-orange { background: #fff3cd; color: #856404; }

/* ── Разделитель ── */
.divider {
    height: 1px;
    background: #e0e5ee;
    margin: 16px 0;
}

/* ── Адаптация для маленьких iframe ── */
@media (max-width: 600px) {
    .data-table thead th:nth-child(n+4),
    .data-table tbody td:nth-child(n+4) {
        display: none;
    }
    .modal {
        width: 100%;
        border-radius: 0;
    }
}
