/**
 * SaleSimulator - Main Application Styles
 */

:root {
    --bg: #f5f7fb;
    --primary: #2563eb;
    --primary-soft: #dbeafe;
    --text: #111827;
    --muted: #6b7280;
    --border: #e5e7eb;
    --danger: #ef4444;
    --success: #16a34a;
    --warning: #f59e0b;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
}

/* ================================
   Модальное окно авторизации
   ================================ */
.auth-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

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

.auth-box {
    background: #fff;
    border-radius: 16px;
    padding: 24px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.15);
}

.auth-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 20px;
    text-align: center;
}

.auth-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.auth-tab {
    flex: 1;
    padding: 8px;
    border: none;
    background: #f3f4f6;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.15s;
}

.auth-tab.active {
    background: var(--primary);
    color: #fff;
}

/* ================================
   Формы
   ================================ */
.form-group {
    margin-bottom: 12px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--muted);
    margin-bottom: 4px;
}

.form-group input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

/* ================================
   Основное приложение
   ================================ */
.app {
    max-width: 1280px;
    margin: 0 auto;
    padding: 16px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.app-title {
    font-size: 1.25rem;
    font-weight: 600;
}

.app-subtitle {
    font-size: 0.875rem;
    color: var(--muted);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-name {
    font-size: 0.9rem;
    color: var(--muted);
}

/* ================================
   Layout
   ================================ */
.layout {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr) 280px;
    gap: 12px;
    flex: 1;
}

@media (max-width: 1024px) {
    .layout {
        grid-template-columns: minmax(0, 1fr);
    }
    .card.settings-panel,
    .card.score-panel {
        order: -1;
    }
}

/* ================================
   Карточки
   ================================ */
.card {
    background: #ffffff;
    border-radius: 12px;
    border: 1px solid var(--border);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.card-title {
    font-size: 0.95rem;
    font-weight: 600;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
    background: var(--primary-soft);
    color: var(--primary);
}

/* ================================
   Элементы форм
   ================================ */
label {
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 2px;
    display: block;
}

select, input[type="text"] {
    width: 100%;
    padding: 6px 8px;
    border-radius: 8px;
    border: 1px solid var(--border);
    font-size: 0.85rem;
}

select:focus, input[type="text"]:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.2);
}

/* ================================
   Кнопки
   ================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 7px 12px;
    border-radius: 999px;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    gap: 6px;
    transition: background 0.15s, box-shadow 0.15s;
}

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

.btn-primary {
    background: var(--primary);
    color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
    background: #1d4ed8;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.25);
}

.btn-outline {
    background: #ffffff;
    color: var(--muted);
    border: 1px solid var(--border);
}

.btn-outline:hover:not(:disabled) {
    background: #f9fafb;
}

.btn-sm {
    padding: 4px 10px;
    font-size: 0.8rem;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

/* ================================
   Панель настроек
   ================================ */
.settings-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.pill-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.pill {
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    border: 1px solid var(--border);
    cursor: pointer;
    background: #f9fafb;
    color: var(--muted);
    transition: all 0.15s;
}

.pill:hover {
    border-color: var(--primary);
}

.pill.active {
    background: var(--primary-soft);
    color: var(--primary);
    border-color: var(--primary-soft);
}

/* ================================
   Чат
   ================================ */
.chat-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 500px;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.chat-status {
    font-size: 0.75rem;
    color: var(--muted);
}

.chat-window {
    flex: 1;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: #f9fafb;
    padding: 12px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.msg {
    max-width: 85%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 0.9rem;
    line-height: 1.4;
    word-wrap: break-word;
}

.msg-manager {
    align-self: flex-end;
    background: var(--primary);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.msg-client {
    align-self: flex-start;
    background: #ffffff;
    color: var(--text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.msg-meta {
    font-size: 0.7rem;
    color: var(--muted);
    margin-top: 2px;
}

.msg-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.msg-group:has(.msg-manager) {
    align-items: flex-end;
}

/* ================================
   Индикатор набора
   ================================ */
.typing-dots {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: var(--muted);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* ================================
   Пустое состояние
   ================================ */
.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--muted);
    font-size: 0.9rem;
}

/* ================================
   Ввод сообщения
   ================================ */
.chat-input {
    margin-top: 8px;
    border-radius: 10px;
    border: 1px solid var(--border);
    padding: 8px;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chat-input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

textarea {
    flex: 1;
    resize: none;
    min-height: 60px;
    max-height: 140px;
    border-radius: 8px;
    border: 1px solid transparent;
    padding: 8px 10px;
    font-size: 0.9rem;
    line-height: 1.4;
    background: #f9fafb;
    font-family: inherit;
}

textarea:disabled {
    background: #f3f4f6;
}

.input-hint {
    font-size: 0.72rem;
    color: var(--muted);
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

/* ================================
   Панель оценки
   ================================ */
.score-main {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.score-number {
    font-size: 1.5rem;
    font-weight: 600;
}

.score-number.good { color: var(--success); }
.score-number.bad { color: var(--danger); }

.score-sub {
    font-size: 0.78rem;
    color: var(--muted);
}

.score-bars {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}

.score-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
}

.score-label {
    color: var(--muted);
    min-width: 90px;
}

.score-bar {
    flex: 1;
    height: 6px;
    background: #f3f4f6;
    border-radius: 999px;
    overflow: hidden;
}

.score-bar-fill {
    height: 100%;
    background: var(--primary);
    width: 0%;
    transition: width 0.3s ease;
}

.score-value {
    width: 24px;
    text-align: right;
    font-weight: 500;
}

.score-comment {
    margin-top: 8px;
    padding: 10px 12px;
    border-radius: 8px;
    background: #f9fafb;
    border: 1px solid var(--border);
    font-size: 0.85rem;
    line-height: 1.4;
    max-height: 120px;
    overflow-y: auto;
}

/* ================================
   История сессий
   ================================ */
.history-list {
    margin-top: 4px;
    font-size: 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 200px;
    overflow-y: auto;
}

.history-item {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
}

.history-item:hover {
    background: #f3f4f6;
}

.history-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.history-score {
    font-weight: 500;
    color: var(--primary);
}

.history-item.finished {
    opacity: 0.7;
}

.history-item.finished .history-title {
    color: var(--muted);
}

.history-item.goal-achieved .history-title {
    color: var(--success);
}

.history-item.goal-failed .history-title {
    color: var(--danger);
}

/* ================================
   Статус сессии
   ================================ */
.session-status {
    margin-top: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    background: #f9fafb;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.status-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
}

.status-label {
    color: var(--muted);
}

.status-value {
    font-weight: 500;
}

.goal-status {
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
}

.goal-status.in-progress {
    background: var(--primary-soft);
    color: var(--primary);
}

.goal-status.achieved {
    background: #dcfce7;
    color: var(--success);
}

.goal-status.not-achieved {
    background: #fee2e2;
    color: var(--danger);
}

/* ================================
   Уведомления
   ================================ */
#notifications {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.notification {
    padding: 12px 16px;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    font-size: 0.9rem;
    animation: slideIn 0.3s ease;
}

.notification-success {
    border-left: 4px solid var(--success);
}

.notification-error {
    border-left: 4px solid var(--danger);
}

.notification.fade-out {
    animation: fadeOut 0.3s ease forwards;
}

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

@keyframes fadeOut {
    to { transform: translateX(100%); opacity: 0; }
}

/* ================================
   Загрузка
   ================================ */
body.loading {
    cursor: wait;
}

body.loading .btn {
    pointer-events: none;
}

/* ================================
   Приветственный экран
   ================================ */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 24px;
    gap: 16px;
}

.welcome-icon {
    font-size: 3rem;
    line-height: 1;
}

.welcome-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text);
}

.welcome-text {
    font-size: 0.9rem;
    color: var(--muted);
    max-width: 400px;
}

.welcome-steps {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 8px 0;
}

.welcome-step {
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    font-size: 0.9rem;
}

.step-num {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.welcome-tip {
    background: #fef3c7;
    border: 1px solid #fcd34d;
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 0.85rem;
    color: #92400e;
    max-width: 400px;
    text-align: left;
    line-height: 1.4;
}

.welcome-help-btn {
    margin-top: 8px;
}

/* ================================
   Модальное окно справки
   ================================ */
.help-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

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

.help-box {
    background: #fff;
    border-radius: 16px;
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 40px rgba(0,0,0,0.15);
}

.help-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border);
}

.help-title {
    font-size: 1.15rem;
    font-weight: 600;
}

.help-close {
    width: 32px;
    height: 32px;
    border: none;
    background: #f3f4f6;
    border-radius: 8px;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.help-close:hover {
    background: #e5e7eb;
}

.help-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.help-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.help-section-title {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text);
}

.help-section p {
    margin: 0;
    font-size: 0.9rem;
    color: var(--muted);
    line-height: 1.5;
}

.help-section ol,
.help-section ul {
    margin: 0;
    padding-left: 20px;
    font-size: 0.9rem;
    color: var(--muted);
    line-height: 1.6;
}

.help-section li {
    margin-bottom: 4px;
}

.help-section-highlight {
    background: var(--primary-soft);
    border-radius: 12px;
    padding: 16px;
}

.help-section-highlight .help-section-title {
    color: var(--primary);
}

.help-section-highlight p {
    color: var(--text);
}

.help-example {
    font-style: italic;
    background: rgba(255,255,255,0.6);
    padding: 10px 12px;
    border-radius: 8px;
    margin-top: 8px;
    font-size: 0.85rem !important;
}

.help-criteria {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.help-criterion {
    background: #f9fafb;
    border-radius: 8px;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.help-criterion strong {
    font-size: 0.85rem;
    color: var(--text);
}

.help-criterion span {
    font-size: 0.8rem;
    color: var(--muted);
}

.help-footer {
    padding: 16px 24px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: center;
}

.help-footer .btn {
    min-width: 180px;
}

/* Кнопка справки в хедере */
#helpBtn {
    width: 32px;
    height: 32px;
    padding: 0;
    font-weight: 600;
    font-size: 0.9rem;
}

@media (max-width: 600px) {
    .help-criteria {
        grid-template-columns: 1fr;
    }
}
