/* ============================================================
   КОМПОНЕНТЫ: кнопки, формы, модалки, таблицы, карточки, фильтры
   ============================================================ */

/* --- Таблицы --- */
.container table,
.chart-card table,
.client-card table {
    width: 100%;
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    border-collapse: collapse;
}

.container table th,
.chart-card table th,
.client-card table th {
    background: #f9f9f9;
    padding: 12px 16px;
    text-align: left;
    font-size: 13px;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.container table td,
.chart-card table td,
.client-card table td {
    padding: 12px 16px;
    border-top: 1px solid #eee;
    font-size: 14px;
}

.container table tr:hover,
.chart-card table tr:hover,
.client-card table tr:hover {
    background: #fafafa;
}

/* --- Карточки статистики --- */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}
.stat-card {
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.stat-card .label { font-size: 13px; color: #888; margin-bottom: 8px; }
.stat-card .value { font-size: 32px; font-weight: 600; color: #4CAF50; }

/* --- Фильтры и поиск --- */
.filters, .search {
    background: white;
    padding: 16px;
    border-radius: 12px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}
.filters input, .filters select,
.search input {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
}
.search input { flex: 1; }

.filters button, .search button {
    padding: 8px 16px;
    background: #4CAF50;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
}
.filters button:hover, .search button:hover { background: #45a049; }

.filters a, .search a {
    padding: 8px 16px;
    background: #eee;
    color: #666;
    text-decoration: none;
    border-radius: 8px;
    font-size: 14px;
}

/* --- Кнопки --- */
.btn-edit        { background: #2196F3; color: white; border: none; padding: 6px 12px; border-radius: 6px; font-size: 12px; cursor: pointer; }
.btn-edit:hover  { background: #1976D2; }

.btn-move        { background: #FF9800; color: white; border: none; padding: 6px 12px; border-radius: 6px; font-size: 12px; cursor: pointer; }
.btn-move:hover  { background: #F57C00; }

.btn-history     { background: #9C27B0; color: white; border: none; padding: 6px 12px; border-radius: 6px; font-size: 12px; cursor: pointer; }
.btn-history:hover { background: #7B1FA2; }

.btn-cancel      { background: #f44336; color: white; border: none; padding: 6px 12px; border-radius: 6px; font-size: 12px; cursor: pointer; }
.btn-cancel:hover { background: #d32f2f; }

.btn-save        { flex: 1; padding: 12px; background: #4CAF50; color: white; border: none; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; }
.btn-save:hover  { background: #45a049; }

.btn-cancel-form { flex: 1; padding: 12px; background: #eee; color: #333; border: none; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; }
.btn-cancel-form:hover { background: #ddd; }

.btn-bulk        { background: #2196F3; color: white; border: none; padding: 8px 16px; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer; }
.btn-bulk:hover  { background: #1976D2; }

/* --- Модальное окно --- */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.modal-overlay.active { display: flex; }

.modal {
    background: white;
    border-radius: 12px;
    padding: 24px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid #eee;
}
.modal-header h2 { font-size: 18px; }

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #999;
    padding: 0 8px;
}
.modal-close:hover { color: #333; }

/* --- Формы --- */
.edit-form { padding: 8px 0; }
.edit-form .field { margin-bottom: 16px; }
.edit-form label {
    display: block;
    font-size: 13px;
    color: #666;
    margin-bottom: 6px;
    font-weight: 600;
}
.edit-form input, .edit-form select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
}
.edit-form input:focus, .edit-form select:focus {
    outline: none;
    border-color: #4CAF50;
}
.edit-form .checkbox-field {
    display: flex;
    align-items: center;
    gap: 8px;
}
.edit-form .checkbox-field input { width: auto; }
.edit-form textarea {
    font-family: inherit;
    font-size: 14px;
}
.edit-form .buttons {
    display: flex;
    gap: 12px;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid #eee;
}

/* --- Карточка клиента --- */
.client-card {
    background: white;
    padding: 24px;
    border-radius: 12px;
    margin-bottom: 24px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.client-card h2 { margin-bottom: 16px; }
.client-info {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}
.client-info .label { font-size: 13px; color: #888; margin-bottom: 4px; }
.client-info .value { font-size: 16px; }

/* --- Карточка графика --- */
.chart-card {
    background: white;
    padding: 24px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    margin-bottom: 24px;
}
.chart-card h2 { margin-bottom: 16px; font-size: 18px; }
canvas { max-height: 400px; }

/* --- Карточка записи (модалка дня) --- */
.appointment-item {
    background: #f9f9f9;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 12px;
    border-left: 4px solid #4CAF50;
}
.appointment-item.unpaid { border-left-color: #ff9800; }
.appointment-item.note {
    border-left-color: #9C27B0;
    background: #f3e5f5;
}
.appointment-item .time { font-weight: 600; font-size: 15px; margin-bottom: 4px; }
.appointment-item .details { font-size: 13px; color: #666; line-height: 1.6; }
.appointment-item .actions { margin-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; }
.appt-header { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.appt-checkbox { width: 18px; height: 18px; cursor: pointer; }

/* --- Массовое редактирование --- */
.bulk-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: #f0f4ff;
    border-radius: 8px;
    margin-bottom: 16px;
}
.bulk-label { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }

/* --- Логин --- */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    margin: 0;
}
.login-box {
    background: white;
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
    width: 340px;
    max-width: 92vw;
}
.login-box h1 { margin: 0 0 24px 0; font-size: 20px; }
.login-box input {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    box-sizing: border-box;
}
.login-box button {
    width: 100%;
    padding: 12px;
    background: #4CAF50;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    margin-top: 16px;
}
.login-box button:hover { background: #45a049; }

/* --- Выпадающие списки клиентов в формах --- */
.client-results {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid #ddd;
    border-radius: 8px;
    margin-top: 4px;
    background: white;
}
.client-results:empty { display: none; }
.client-result-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 14px;
    border-bottom: 1px solid #f0f0f0;
}
.client-result-item:last-child { border-bottom: none; }
.client-result-item:hover { background: #f0f4ff; }

/* --- Ключевые слова и коды категорий --- */
.cat-code {
    background: #f0f0f0;
    color: #333;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-family: monospace;
}

/* --- Примечание услуги --- */
.service-note-preview {
    font-size: 13px;
    color: #666;
    cursor: help;
}

/* --- Периоды рабочих часов (в модалке) --- */
.wh-period input {
    font-family: inherit;
    font-size: 14px;
}

/* --- Bulk-слоты (массовое создание записей) --- */
.bulk-item input {
    font-family: inherit;
    font-size: 14px;
}

/* --- VK результат поиска --- */
.vk-result {
    padding: 16px;
    background: #e8f5e9;
    border-radius: 8px;
    margin-bottom: 16px;
    border-left: 4px solid #4CAF50;
}
.vk-result .vk-name { font-size: 16px; font-weight: 700; color: #2e7d32; margin-bottom: 8px; }
.vk-result .vk-link { font-size: 13px; color: #555; margin-bottom: 4px; }
.vk-result .vk-id { font-size: 13px; color: #888; }

/* --- Неоплаченные записи (страница доходов) --- */
.unpaid-block {
    background: #fff3cd;
    padding: 16px;
    border-radius: 12px;
    margin-bottom: 16px;
    border-left: 4px solid #ff9800;
}
.unpaid-block h3 {
    margin-bottom: 12px;
    font-size: 15px;
    color: #856404;
    font-weight: 600;
}
.unpaid-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: white;
    border-radius: 8px;
    margin-bottom: 8px;
    font-size: 14px;
    gap: 12px;
    flex-wrap: wrap;
}
.unpaid-item .unpaid-info { flex: 1; min-width: 200px; }
.unpaid-item .unpaid-info b { color: #333; }
.unpaid-item .btn-paid {
    padding: 8px 16px;
    background: #4CAF50;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}
.unpaid-item .btn-paid:hover { background: #45a049; }

/* --- Графики (dashboard, reports) --- */
.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-bottom: 24px;
}
.charts-grid .chart-card {
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    min-height: 320px;
}
.charts-grid .chart-card h3 {
    font-size: 15px;
    margin-bottom: 16px;
    color: #666;
    font-weight: 600;
}
.charts-grid .chart-card canvas { max-height: 250px; }

@media (max-width: 800px) {
    .charts-grid { grid-template-columns: 1fr; }
}

/* --- Сетка мастеров --- */
.masters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 16px;
}
.master-card {
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.master-card h3 { font-size: 16px; margin-bottom: 8px; }
.master-desc { font-size: 13px; color: #888; margin-bottom: 16px; }
.master-actions { display: flex; gap: 8px; }

/* Сортируемые заголовки */
.sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
.sortable:hover {
    background: #f0f0f0;
}
.sort-arrow {
    color: #4CAF50;
    font-size: 11px;
    margin-left: 2px;
}
body.dark .sortable:hover {
    background: #3a3a3a;
}

/* Чекбоксы напоминаний */
.reactivate-cb {
    width: 18px;
    height: 18px;
    cursor: pointer;
}
.cb-head,
.cb-cell {
    width: 30px;
    text-align: center;
}

/* ============================================================
   ЧЁРНЫЙ СПИСОК
   ============================================================ */

.blacklist-card {
    background: #fff8f8;
    border: 1px solid #ffcdd2;
    border-radius: 12px;
    padding: 16px 20px;
    margin-bottom: 24px;
}

.blacklist-card h3 {
    font-size: 16px;
    color: #c62828;
}

.blacklist-entry {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: white;
    border-radius: 8px;
    margin-bottom: 8px;
    border-left: 4px solid #f44336;
    font-size: 14px;
    gap: 12px;
    flex-wrap: wrap;
}

.blacklist-entry:last-child {
    margin-bottom: 0;
}

.blacklist-label {
    font-weight: 600;
    flex: 1;
    min-width: 200px;
}

.blacklist-global {
    color: #c62828;
}

.blacklist-master {
    color: #e65100;
}

.blacklist-meta {
    font-size: 11px;
    color: #888;
    white-space: nowrap;
}

.blacklist-remove {
    padding: 4px 10px !important;
    font-size: 12px !important;
    background: #eee !important;
    color: #666 !important;
}

.blacklist-remove:hover {
    background: #f44336 !important;
    color: white !important;
}

.blacklist-empty {
    color: #888;
    font-size: 13px;
    padding: 8px 0;
}

/* Dropdown для выбора мастера */
.dropdown-wrapper {
    position: relative;
    display: inline-block;
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    z-index: 100;
    min-width: 200px;
    max-height: 300px;
    overflow-y: auto;
    margin-top: 4px;
}

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

.dropdown-item {
    padding: 10px 16px;
    cursor: pointer;
    font-size: 14px;
    border-bottom: 1px solid #f5f5f5;
}

.dropdown-item:last-child {
    border-bottom: none;
}

.dropdown-item:hover {
    background: #f0f4ff;
}

/* Тёмная тема */
body.dark .blacklist-card {
    background: #3a1a1a;
    border-color: #5a2a2a;
}
body.dark .blacklist-card h3 {
    color: #ef5350;
}
body.dark .blacklist-entry {
    background: #2a2a2a;
    color: #e0e0e0;
}
body.dark .blacklist-meta {
    color: #999;
}
body.dark .blacklist-empty {
    color: #888;
}
body.dark .dropdown-menu {
    background: #2a2a2a;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
body.dark .dropdown-item {
    color: #e0e0e0;
    border-bottom-color: #3a3a3a;
}
body.dark .dropdown-item:hover {
    background: #333;
}

/* Хлебные крошки */
.breadcrumbs {
    max-width: 1200px;
    margin: 16px auto 0;
    padding: 0 24px;
    font-size: 13px;
    color: #888;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
}
.breadcrumbs a {
    color: #4CAF50;
    text-decoration: none;
}
.breadcrumbs a:hover {
    text-decoration: underline;
}
.breadcrumbs .sep {
    color: #ccc;
}
.breadcrumbs .current {
    color: #333;
    font-weight: 600;
}
body.dark .breadcrumbs .current { color: #e0e0e0; }
body.dark .breadcrumbs .sep { color: #555; }

@media (max-width: 768px) {
    .breadcrumbs { padding: 0 12px; margin-top: 12px; }
}

/* Предпросмотр шаблонов */
.tpl-preview {
    margin-top: 8px;
    padding: 12px;
    background: #e8f5e9;
    color: #1b3a1b;
    border-radius: 8px;
    font-size: 13px;
    white-space: pre-wrap;
    line-height: 1.5;
}

body.dark .tpl-preview {
    background: #2a3a2a;
    color: #e0e0e0;
    border: 1px solid #3a4a3a;
}