/* ─── Переменные ─────────────────────────────────────────────────── */
:root {
    --bg: #f7f8fa;
    --bg-card: #ffffff;
    --bg-sidebar: #1e2433;
    --bg-sidebar-hover: #2a3040;
    --bg-input: #f0f2f5;
    --text: #1a1d26;
    --text-muted: #6b7280;
    --text-inverse: #e8eaed;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-light: #dbeafe;
    --border: #e5e7eb;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #f59e0b;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.08);
    --transition: 0.15s ease;
    --font: 'Segoe UI', -apple-system, system-ui, sans-serif;
}

/* ─── Reset ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Формы и кнопки ─────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font);
    white-space: nowrap;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.btn-secondary { background: var(--bg-input); color: var(--text); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.9; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-full { width: 100%; }

.input {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: var(--font);
    background: var(--bg-card);
    transition: border-color var(--transition);
    outline: none;
}
.input:focus { border-color: var(--accent); }

.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 5px;
}

/* ─── Auth ────────────────────────────────────────────────────────── */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, #1e2433 0%, #2a3553 100%);
}

.auth-card {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.auth-logo {
    text-align: center;
    margin-bottom: 28px;
}

.auth-logo h1 {
    font-size: 26px;
    font-weight: 700;
    color: var(--accent);
}

.auth-logo p {
    color: var(--text-muted);
    font-size: 14px;
    margin-top: 4px;
}

.auth-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 24px;
    background: var(--bg-input);
    border-radius: var(--radius);
    padding: 3px;
}

.auth-tab {
    flex: 1;
    padding: 8px;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    border-radius: 8px;
    cursor: pointer;
    transition: all var(--transition);
    border: none;
    background: none;
    font-family: var(--font);
}
.auth-tab.active {
    background: var(--bg-card);
    color: var(--text);
    box-shadow: var(--shadow);
}

.auth-form { display: none; }
.auth-form.active { display: block; }

.auth-error {
    background: #fef2f2;
    color: var(--danger);
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 16px;
    border: 1px solid #fecaca;
}

/* ─── Чат layout ──────────────────────────────────────────────────── */
.chat-layout {
    display: flex;
    height: 100vh;
}

.sidebar {
    width: 280px;
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-header h2 {
    color: #fff;
    font-size: 18px;
    font-weight: 600;
}

.sidebar-header p {
    color: rgba(255,255,255,0.45);
    font-size: 12px;
    margin-top: 2px;
}

.sidebar-actions { padding: 12px 16px; }

.btn-new-chat {
    width: 100%;
    padding: 10px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font);
}
.btn-new-chat:hover { background: var(--accent-hover); }

.conv-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.conv-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background var(--transition);
    color: var(--text-inverse);
    font-size: 13px;
    margin-bottom: 2px;
}
.conv-item:hover { background: var(--bg-sidebar-hover); }
.conv-item.active { background: var(--accent); }

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

.conv-item-delete {
    opacity: 0;
    background: none;
    border: none;
    color: rgba(255,255,255,0.5);
    cursor: pointer;
    font-size: 16px;
    padding: 2px;
    transition: opacity var(--transition);
}
.conv-item:hover .conv-item-delete { opacity: 1; }

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid rgba(255,255,255,0.08);
}

.sidebar-footer a {
    display: block;
    color: rgba(255,255,255,0.5);
    font-size: 13px;
    padding: 6px 8px;
    border-radius: 6px;
    transition: all var(--transition);
}
.sidebar-footer a:hover {
    color: rgba(255,255,255,0.8);
    background: var(--bg-sidebar-hover);
    text-decoration: none;
}

/* ─── Чат main ────────────────────────────────────────────────────── */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-card);
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-header h3 {
    font-size: 16px;
    font-weight: 600;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.provider-badge {
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 20px;
    background: var(--accent-light);
    color: var(--accent);
    font-weight: 500;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.chat-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: var(--text-muted);
    text-align: center;
}

.chat-empty h3 {
    font-size: 22px;
    color: var(--text);
    margin-bottom: 8px;
}

.chat-empty p { font-size: 14px; max-width: 400px; }

.message {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    max-width: 800px;
}

.message-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
}

.message-user .message-avatar { background: var(--accent-light); color: var(--accent); }
.message-assistant .message-avatar { background: #f0fdf4; color: var(--success); }

.message-content {
    flex: 1;
    font-size: 14px;
    line-height: 1.7;
    min-width: 0;
}

.message-content p { margin-bottom: 8px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content strong { font-weight: 600; }
.message-content ul, .message-content ol { margin: 8px 0; padding-left: 20px; }
.message-content li { margin-bottom: 4px; }

.message-role {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.chat-input-area {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    background: var(--bg-card);
}

.chat-input-wrapper {
    display: flex;
    gap: 10px;
    max-width: 800px;
}

.chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: var(--font);
    resize: none;
    outline: none;
    min-height: 46px;
    max-height: 150px;
    transition: border-color var(--transition);
    background: var(--bg);
}
.chat-input:focus { border-color: var(--accent); }

.chat-send {
    align-self: flex-end;
    width: 46px;
    height: 46px;
    border-radius: var(--radius);
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    flex-shrink: 0;
}
.chat-send:hover { background: var(--accent-hover); }
.chat-send:disabled { background: var(--border); cursor: not-allowed; }

.typing-indicator {
    display: none;
    gap: 4px;
    padding: 8px 0;
}
.typing-indicator.active { display: flex; }
.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    animation: typing 1s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing { 0%,100% { opacity: 0.3; } 50% { opacity: 1; } }

/* ─── Admin ───────────────────────────────────────────────────────── */
.admin-wrapper {
    max-width: 960px;
    margin: 0 auto;
    padding: 32px 24px;
}

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

.admin-header h1 { font-size: 24px; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

.stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--accent);
}

.stat-card .stat-label {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}

.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 24px;
}

.card h2 {
    font-size: 18px;
    margin-bottom: 16px;
}

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

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

th, td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}
.badge-green { background: #dcfce7; color: #166534; }
.badge-red { background: #fef2f2; color: #991b1b; }
.badge-gray { background: #f3f4f6; color: #4b5563; }

.add-form {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.add-form .form-group { margin-bottom: 0; flex: 1; min-width: 140px; }

/* ─── About page ──────────────────────────────────────────────────── */
.about-wrapper {
    max-width: 760px;
    margin: 0 auto;
    padding: 48px 24px;
}

.about-wrapper h1 {
    font-size: 32px;
    margin-bottom: 8px;
}

.about-wrapper h2 {
    font-size: 20px;
    margin: 32px 0 12px;
    color: var(--text);
}

.about-wrapper p {
    color: var(--text-muted);
    font-size: 15px;
    margin-bottom: 12px;
}

.about-features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin: 24px 0;
}

.about-feature {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

.about-feature h3 {
    font-size: 15px;
    margin-bottom: 4px;
}

.about-feature p {
    font-size: 13px;
    margin: 0;
}

/* ─── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .chat-messages { padding: 16px; }
    .chat-input-area { padding: 12px 16px; }
    .auth-card { padding: 28px 20px; }
    .add-form { flex-direction: column; }
}
