/* ================================================================
   Дизайн-система портала ГК «Сфера»
   Корпоративные цвета: красный (C92127), белый, тёмно-серый
   ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* --- CSS-переменные (светлая тема) --- */
:root {
    --primary: #C92127;
    --primary-hover: #A81B20;
    --primary-light: #fde8e8;
    --secondary: #8B1A1E;
    --accent: #1a1a2e;
    --success: #2e7d32;
    --success-light: #e8f5e9;
    --warning: #e65100;
    --warning-light: #fff3e0;
    --danger: #c62828;
    --danger-light: #ffebee;
    --info: #1565c0;
    --info-light: #e3f2fd;
    --light: #fafafa;
    --dark: #1a1a1a;
    --gray: #757575;
    --gray-light: #e0e0e0;
    --border: #e0e0e0;
    --bg: #ffffff;
    --bg-secondary: #f5f5f5;
    --text: #212121;
    --text-secondary: #616161;
    --shadow: 0 2px 4px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
    --radius: 6px;
    --radius-sm: 4px;
    --radius-lg: 10px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --transition: 0.2s ease;
}

/* --- Сброс --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--primary);
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}

/* --- Кнопки --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    line-height: 1.4;
}
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}
.btn-success {
    background: var(--success);
    color: #fff;
}
.btn-danger {
    background: var(--danger);
    color: #fff;
}
.btn-warning {
    background: var(--warning);
    color: #fff;
}
.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}
.btn-outline:hover:not(:disabled) {
    background: var(--bg-secondary);
}
.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
}
.btn-lg {
    padding: 12px 24px;
    font-size: 16px;
}
.btn-icon {
    padding: 8px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
}
.btn-icon:hover {
    background: var(--bg-secondary);
    color: var(--text);
}

/* --- Карточки --- */
.card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 20px;
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}
.card-header h2, .card-header h3 {
    font-size: 16px;
    font-weight: 600;
}
.card-body {
    /* content */
}
.card-footer {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

/* --- Формы --- */
.form-group {
    margin-bottom: 16px;
}
.form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
}
.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 8px 12px;
    font-size: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    transition: border-color var(--transition);
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.form-textarea {
    min-height: 80px;
    resize: vertical;
}

/* --- Таблицы --- */
.table {
    width: 100%;
    border-collapse: collapse;
}
.table th,
.table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.table th {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.table tr:hover td {
    background: var(--bg-secondary);
}
.table-wrap {
    overflow-x: auto;
}

/* --- Бейджи статусов --- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    font-size: 12px;
    font-weight: 500;
    border-radius: 9999px;
}
.badge-success {
    background: var(--success-light);
    color: #065f46;
}
.badge-warning {
    background: var(--warning-light);
    color: #92400e;
}
.badge-danger {
    background: var(--danger-light);
    color: #991b1b;
}
.badge-info {
    background: var(--info-light);
    color: #1e40af;
}
.badge-neutral {
    background: var(--bg-secondary);
    color: var(--text-secondary);
}

/* --- Спиннер --- */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
.spinner-sm {
    width: 14px;
    height: 14px;
    border-width: 2px;
}
.spinner-lg {
    width: 32px;
    height: 32px;
    border-width: 3px;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- Модальное окно --- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0,0,0,0.5);
    align-items: center;
    justify-content: center;
}
.modal-overlay.active {
    display: flex;
}
.modal-window {
    background: var(--bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 90vw;
    max-height: 85vh;
    overflow-y: auto;
    animation: modalIn 0.2s ease-out;
}
.modal-window.sm { width: 400px; }
.modal-window.md { width: 600px; }
.modal-window.lg { width: 800px; }
.modal-window.xl { width: 1000px; }
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-body { padding: 20px; }
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid var(--border);
}
@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95) translateY(-10px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* --- Хедер --- */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}
.header-logo {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
}
.header-nav {
    display: flex;
    align-items: center;
    gap: 16px;
}
.header-nav a {
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    padding: 6px 10px;
    border-radius: var(--radius);
}
.header-nav a:hover,
.header-nav a.active {
    color: var(--primary);
    background: var(--primary-light);
    text-decoration: none;
}

/* --- Поиск в хедере --- */
.search-box {
    position: relative;
    width: 300px;
}
.search-box input {
    width: 100%;
    padding: 8px 12px 8px 36px;
    border: 1px solid var(--border);
    border-radius: 9999px;
    background: var(--bg-secondary);
    font-size: 13px;
}
.search-box input:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--bg);
}
.search-box .search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}
.search-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 4px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 200;
    max-height: 400px;
    overflow-y: auto;
}
.search-dropdown.active { display: block; }
.search-group { padding: 8px 12px; }
.search-group-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 4px 0;
}
.search-item {
    display: block;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text);
}
.search-item:hover {
    background: var(--bg-secondary);
    text-decoration: none;
}

/* --- Тостеры (контейнер) --- */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}
.toast {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    min-width: 300px;
    max-width: 420px;
    padding: 12px 16px;
    border-radius: var(--radius);
    background: var(--bg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    animation: toastSlideIn 0.3s ease-out;
    transition: all 0.3s ease;
}
.toast.removing {
    animation: toastSlideOut 0.3s ease-in forwards;
}
.toast-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    font-size: 16px;
    text-align: center;
}
.toast-content {
    flex: 1;
}
.toast-title {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 2px;
}
.toast-message {
    font-size: 12px;
    color: var(--text-secondary);
}
.toast-close {
    flex-shrink: 0;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 16px;
    padding: 0 2px;
}
.toast-close:hover { color: var(--text); }

.toast-success { border-left: 4px solid var(--success); }
.toast-error   { border-left: 4px solid var(--danger); }
.toast-warning { border-left: 4px solid var(--warning); }
.toast-info    { border-left: 4px solid var(--info); }

.toast-success .toast-icon { color: var(--success); }
.toast-error   .toast-icon { color: var(--danger); }
.toast-warning .toast-icon { color: var(--warning); }
.toast-info    .toast-icon { color: var(--info); }

@keyframes toastSlideIn {
    from { opacity: 0; transform: translateX(100px); }
    to   { opacity: 1; transform: translateX(0); }
}
@keyframes toastSlideOut {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(100px); }
}

/* --- AI-виджет (чат) --- */
.ai-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 380px;
    height: 520px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
    overflow: hidden;
}
.ai-widget.minimized {
    width: auto;
    height: auto;
}
.ai-widget.minimized .ai-widget-body,
.ai-widget.minimized .ai-chat-form { display: none; }

.ai-widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--primary);
    color: #fff;
    cursor: pointer;
    flex-shrink: 0;
    gap: 8px;
}
.ai-widget-header h4 {
    font-size: 13px;
    font-weight: 600;
    flex: 1;
}
.ai-widget-header .ai-header-actions {
    display: flex;
    gap: 4px;
}
.ai-widget-header .ai-header-actions button {
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.ai-widget-header .ai-header-actions button:hover { background: rgba(255,255,255,0.3); }
.ai-widget-header .ai-header-actions button.active { background: rgba(255,255,255,0.35); }
.ai-widget-header .ai-header-actions button.ai-toggle-note.active { background: #fff3e0; color: #e65100; }
.ai-widget-header .ai-header-actions button.ai-toggle-note { font-size: 12px; gap: 4px; }

.ai-widget-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

/* Сообщения */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--bg-secondary);
}
.ai-chat-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.6;
}
.ai-chat-empty i { font-size: 32px; display: block; margin-bottom: 12px; opacity: 0.4; }

/* Сообщение */
.ai-chat-msg {
    display: flex;
    gap: 8px;
    max-width: 100%;
}
.ai-msg-avatar {
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    background: var(--bg);
    color: var(--text-secondary);
    margin-top: 2px;
}
.ai-msg-content {
    flex: 1;
    min-width: 0;
    background: var(--bg);
    border-radius: 8px;
    padding: 8px 12px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.ai-msg-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    font-size: 11px;
}
.ai-msg-header strong { font-size: 12px; }
.ai-msg-time { color: var(--text-secondary); margin-left: auto; font-size: 10px; }
.ai-msg-tag {
    font-size: 9px;
    padding: 1px 6px;
    border-radius: 4px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.ai-msg-tag.note { background: var(--warning-light); color: var(--warning); }
.ai-msg-text { font-size: 13px; line-height: 1.5; word-break: break-word; }
.ai-msg-quote {
    font-size: 11px;
    color: var(--text-secondary);
    font-style: italic;
    margin-top: 6px;
    padding: 4px 8px;
    background: var(--bg-secondary);
    border-radius: 4px;
    border-left: 2px solid var(--border);
}

/* AI-ответ */
.ai-msg-response .ai-msg-avatar { background: var(--primary-light); color: var(--primary); }
.ai-msg-user .ai-msg-avatar { background: var(--info-light); color: var(--info); }
.ai-badge-cat {
    display: inline-block;
    padding: 1px 8px;
    font-size: 11px;
    font-weight: 600;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 4px;
    margin-bottom: 4px;
}
.ai-msg-confidence {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    font-size: 10px;
    color: var(--text-secondary);
}
.ai-conf-bar {
    flex: 1;
    height: 3px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}
.ai-conf-fill {
    height: 100%;
    border-radius: 2px;
    background: var(--success);
    transition: width 0.5s;
}

/* Форма ввода */
.ai-chat-form {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 8px 12px;
    border-top: 1px solid var(--border);
    background: var(--bg);
    flex-shrink: 0;
}
.ai-chat-input {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 7px 10px;
    font-size: 13px;
    font-family: inherit;
    resize: none;
    min-height: 34px;
    max-height: 80px;
    background: var(--bg-secondary);
    transition: border-color 0.2s;
}
.ai-chat-input:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--bg);
}
.ai-chat-send {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border: none;
    background: var(--primary);
    color: #fff;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: background 0.2s;
}
.ai-chat-send:hover:not(:disabled) { background: var(--primary-hover); }
.ai-chat-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* --- Утилиты --- */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.p-4 { padding: 16px; }
.text-center { text-align: center; }
.text-sm { font-size: 12px; }
.text-lg { font-size: 16px; }
.text-muted { color: var(--text-secondary); }
.font-medium { font-weight: 500; }
.font-bold { font-weight: 700; }
.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.w-full { width: 100%; }
.hidden { display: none; }

/* --- Адаптив --- */
@media (max-width: 768px) {
    .header { padding: 10px 16px; flex-wrap: wrap; gap: 8px; }
    .search-box { width: 100%; order: 3; }
    .toast-container { left: 8px; right: 8px; }
    .toast { min-width: unset; max-width: unset; }
    .ai-widget { left: 8px; right: 8px; bottom: 8px; width: auto; }
    .modal-window { max-width: 98vw; }
}

/* --- Печать --- */
@media print {
    .header, .toast-container, .ai-widget, .search-box { display: none !important; }
}
