/* ============================================================
   Дизайн-система (токены). Тёмная тема — по умолчанию,
   светлая — переопределение переменных на body.light-theme.
   ============================================================ */
:root {
    --bg: #1f1f23;
    --bg-sidebar: #17171a;
    --surface: #26262b;
    --surface-2: #2f2f36;
    --surface-3: #383840;
    --border: rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.18);

    --text: #ececf1;
    --text-muted: rgba(236, 236, 241, 0.66);
    --text-faint: rgba(236, 236, 241, 0.42);

    --accent: #10a37f;
    --accent-hover: #0e9072;
    --accent-soft: rgba(16, 163, 127, 0.14);
    --danger: #ff6b6b;

    --radius: 14px;
    --radius-sm: 9px;
    --radius-pill: 999px;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.25);
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
    --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.40);

    --ease: 0.22s cubic-bezier(0.4, 0, 0.2, 1);

    --grad: linear-gradient(120deg, #10a37f 0%, #6366f1 100%);
}

body.light-theme {
    --bg: #ffffff;
    --bg-sidebar: #f7f7f8;
    --surface: #ffffff;
    --surface-2: #f1f1f3;
    --surface-3: #e8e8ec;
    --border: rgba(0, 0, 0, 0.10);
    --border-strong: rgba(0, 0, 0, 0.16);

    --text: #1f2330;
    --text-muted: rgba(31, 35, 48, 0.66);
    --text-faint: rgba(31, 35, 48, 0.45);

    --accent-soft: rgba(16, 163, 127, 0.12);

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.10);
    --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.14);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Roboto', 'Helvetica Neue', sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    transition: background-color var(--ease), color var(--ease);
}

a { color: var(--accent); }

::selection { background: var(--accent-soft); }

/* ============================================================
   Кнопки
   ============================================================ */
.btn {
    padding: 0.75rem 1.75rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: transform var(--ease), background-color var(--ease), box-shadow var(--ease);
}

.btn:active { transform: translateY(1px); }

.btn-primary {
    background-color: var(--accent);
    color: #fff;
    box-shadow: 0 6px 18px rgba(16, 163, 127, 0.30);
}

.btn-primary:hover {
    background-color: var(--accent-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: rgba(255, 255, 255, 0.08);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.22);
}

body.light-theme .btn-secondary {
    background-color: rgba(0, 0, 0, 0.05);
    color: var(--text);
    border-color: var(--border-strong);
}

.btn-secondary:hover { background-color: rgba(255, 255, 255, 0.16); }
body.light-theme .btn-secondary:hover { background-color: rgba(0, 0, 0, 0.09); }

.btn-block { width: 100%; }

.btn-large {
    padding: 1rem 2.5rem;
    font-size: 1.05rem;
}

/* ============================================================
   Главная страница
   ============================================================ */
.home-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 5rem 1.5rem 3rem;
    gap: 4.5rem;
    background:
        radial-gradient(900px 500px at 50% -10%, rgba(99, 102, 241, 0.25), transparent 60%),
        linear-gradient(135deg, #0f0c29 0%, #241f47 50%, #1c1c2e 100%);
}

body.light-theme .home-container {
    background:
        radial-gradient(900px 500px at 50% -10%, rgba(99, 102, 241, 0.18), transparent 60%),
        linear-gradient(135deg, #eef1fb 0%, #f3eefc 50%, #eaf0f7 100%);
}

.home-hero {
    text-align: center;
    max-width: 820px;
}

.hero-badge {
    display: inline-block;
    background: rgba(16, 163, 127, 0.16);
    border: 1px solid rgba(16, 163, 127, 0.40);
    color: #1ed3a6;
    padding: 0.45rem 1.1rem;
    border-radius: var(--radius-pill);
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 1.75rem;
    backdrop-filter: blur(8px);
}

.home-hero h1 {
    font-size: clamp(2.2rem, 5vw, 3.6rem);
    line-height: 1.15;
    margin-bottom: 1.5rem;
    color: #fff;
    font-weight: 800;
    letter-spacing: -0.02em;
}

body.light-theme .home-hero h1 { color: #1a1d2b; }

.gradient-text {
    background: linear-gradient(90deg, #10a37f, #818cf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    font-size: 1.15rem;
    color: rgba(255, 255, 255, 0.72);
    margin-bottom: 2.5rem;
    max-width: 620px;
    margin-left: auto;
    margin-right: auto;
}

body.light-theme .subtitle { color: rgba(26, 29, 43, 0.7); }

.home-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.home-gallery {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: 175px 175px;
    gap: 0.9rem;
    width: 100%;
    max-width: 920px;
}

.gallery-item {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s var(--ease);
}

.gallery-item:hover img { transform: scale(1.07); }
.gallery-item-tall { grid-row: span 2; }
.gallery-item-wide { grid-column: span 2; }

.gallery-overlay {
    position: absolute;
    inset: auto 0 0 0;
    padding: 1.5rem 0.9rem 0.8rem;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.78));
    color: #fff;
    font-size: 0.85rem;
    font-weight: 600;
    opacity: 0;
    transition: opacity var(--ease);
}

.gallery-item:hover .gallery-overlay { opacity: 1; }

.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 1.25rem;
    max-width: 920px;
    width: 100%;
}

.feature {
    text-align: center;
    padding: 1.75rem 1.25rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: var(--radius);
    backdrop-filter: blur(10px);
    transition: transform var(--ease), background var(--ease);
}

body.light-theme .feature {
    background: rgba(255, 255, 255, 0.7);
    border-color: rgba(0, 0, 0, 0.06);
}

.feature:hover {
    transform: translateY(-5px);
    background: rgba(255, 255, 255, 0.09);
}

body.light-theme .feature:hover { background: #fff; }

.feature-icon {
    font-size: 2.1rem;
    margin-bottom: 0.85rem;
}

.feature h3 {
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
    color: #fff;
}

body.light-theme .feature h3 { color: #1a1d2b; }

.feature p {
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.9rem;
}

body.light-theme .feature p { color: rgba(26, 29, 43, 0.65); }

.home-cta {
    text-align: center;
    padding: 1rem;
}

.home-cta h2 {
    font-size: clamp(1.5rem, 3vw, 2rem);
    margin-bottom: 1.5rem;
    color: #fff;
}

body.light-theme .home-cta h2 { color: #1a1d2b; }

.home-footer {
    text-align: center;
    max-width: 760px;
    color: rgba(255, 255, 255, 0.42);
    font-size: 0.82rem;
    line-height: 1.6;
    border-top: 1px solid rgba(255, 255, 255, 0.10);
    padding-top: 2rem;
}

body.light-theme .home-footer {
    color: rgba(26, 29, 43, 0.55);
    border-top-color: rgba(0, 0, 0, 0.10);
}

.home-footer-author {
    margin-top: 0.5rem;
    color: rgba(255, 255, 255, 0.78);
    font-weight: 700;
}

body.light-theme .home-footer-author { color: rgba(26, 29, 43, 0.85); }

/* ============================================================
   Аутентификация
   ============================================================ */
.auth-container {
    position: relative;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background:
        radial-gradient(700px 400px at 50% 0%, rgba(99, 102, 241, 0.35), transparent 60%),
        linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
}

body.light-theme .auth-container {
    background:
        radial-gradient(700px 400px at 50% 0%, rgba(99, 102, 241, 0.20), transparent 60%),
        linear-gradient(135deg, #e9eefc 0%, #ede7f6 100%);
}

.auth-box {
    background: rgba(255, 255, 255, 0.10);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    padding: 2.75rem;
    border-radius: 18px;
    width: 100%;
    max-width: 410px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    box-shadow: var(--shadow-lg);
}

body.light-theme .auth-box {
    background: rgba(255, 255, 255, 0.88);
    border-color: rgba(0, 0, 0, 0.06);
}

.auth-box h2 {
    text-align: center;
    margin-bottom: 1.75rem;
    color: #fff;
    font-size: 1.6rem;
    font-weight: 700;
}

body.light-theme .auth-box h2 { color: var(--text); }

.form-group { margin-bottom: 1.35rem; }

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.9rem;
    font-weight: 500;
}

body.light-theme .form-group label { color: var(--text-muted); }

.form-group input {
    width: 100%;
    padding: 0.8rem 1rem;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.10);
    color: #fff;
    font-size: 1rem;
    transition: border-color var(--ease), background var(--ease);
}

body.light-theme .form-group input {
    background: #fff;
    border-color: var(--border-strong);
    color: var(--text);
}

.form-group input::placeholder { color: rgba(255, 255, 255, 0.45); }

.form-group input:focus {
    outline: none;
    border-color: var(--accent);
    background: rgba(255, 255, 255, 0.16);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

body.light-theme .form-group input:focus { background: #fff; }

.error-message {
    background: rgba(255, 80, 80, 0.18);
    color: #ff8a8a;
    padding: 0.85rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.25rem;
    border: 1px solid rgba(255, 80, 80, 0.35);
    font-size: 0.9rem;
}

.auth-links {
    text-align: center;
    margin-top: 1.5rem;
    font-size: 0.92rem;
}

.auth-links p { margin: 0.5rem 0; color: rgba(255, 255, 255, 0.8); }
body.light-theme .auth-links p { color: var(--text-muted); }

.auth-links a {
    color: #fff;
    font-weight: 600;
    text-decoration: none;
}

body.light-theme .auth-links a { color: var(--accent-hover); }
.auth-links a:hover { text-decoration: underline; }

.auth-footer {
    position: absolute;
    bottom: 1.25rem;
    left: 0;
    right: 0;
    text-align: center;
    color: rgba(255, 255, 255, 0.78);
    font-size: 0.85rem;
    font-weight: 500;
}

body.light-theme .auth-footer { color: rgba(26, 29, 43, 0.6); }

/* ============================================================
   Чат — общий каркас
   ============================================================ */
.chat-container {
    display: flex;
    height: 100vh;
    background-color: var(--bg);
}

.sidebar {
    width: 270px;
    background-color: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
}

.sidebar-header {
    padding: 0.9rem;
}

.btn-new-chat {
    width: 100%;
    padding: 0.8rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text);
    cursor: pointer;
    font-size: 0.92rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: background var(--ease), border-color var(--ease);
}

.btn-new-chat span { font-size: 1.15rem; line-height: 1; }
.btn-new-chat:hover { background: var(--surface-2); border-color: var(--accent); }

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 0.4rem 0.5rem;
}

.chats-list {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.chat-item {
    padding: 0.65rem 0.7rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--ease);
}

.chat-item:hover { background: rgba(255, 255, 255, 0.06); }
body.light-theme .chat-item:hover { background: rgba(0, 0, 0, 0.05); }

.chat-item.active { background: var(--surface-2); }

.chat-item-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.chat-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.chat-item.active .chat-title { color: var(--text); }

.chat-actions {
    display: none;
    gap: 0.15rem;
}

.chat-item:hover .chat-actions { display: flex; }

.chat-edit,
.chat-archive,
.chat-delete {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0.2rem 0.3rem;
    border-radius: 5px;
    opacity: 0.7;
    transition: opacity var(--ease), background var(--ease);
}

.chat-edit:hover,
.chat-archive:hover,
.chat-delete:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.10);
}

body.light-theme .chat-edit:hover,
body.light-theme .chat-archive:hover,
body.light-theme .chat-delete:hover {
    background: rgba(0, 0, 0, 0.07);
}

.sidebar-footer {
    padding: 0.75rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

.btn-settings {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0.45rem;
    border-radius: var(--radius-sm);
    text-decoration: none;
    transition: background var(--ease), color var(--ease);
}

.btn-settings:hover {
    background: rgba(255, 255, 255, 0.10);
    color: var(--text);
}

body.light-theme .btn-settings:hover { background: rgba(0, 0, 0, 0.06); }

.btn-logout {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.88rem;
    padding: 0.45rem 0.6rem;
    border-radius: var(--radius-sm);
    transition: background var(--ease), color var(--ease);
}

.btn-logout:hover {
    background: rgba(255, 255, 255, 0.10);
    color: var(--text);
}

body.light-theme .btn-logout:hover { background: rgba(0, 0, 0, 0.06); }

.username {
    font-size: 0.82rem;
    color: var(--text-faint);
    margin-left: auto;
    max-width: 90px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--bg);
    min-width: 0;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 2rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.welcome-message {
    text-align: center;
    margin: auto;
    color: var(--text-muted);
    max-width: 640px;
    padding: 1rem;
}

.welcome-message h2 {
    font-size: 1.8rem;
    color: var(--text);
    margin-bottom: 0.5rem;
}

/* ============================================================
   Чат — сообщения
   ============================================================ */
.message {
    display: flex;
    gap: 1rem;
    padding: 1.25rem;
    border-radius: var(--radius);
    max-width: 860px;
    width: 100%;
    margin: 0 auto;
    animation: fadeInUp 0.3s var(--ease);
}

.message.user { background-color: var(--surface); }
.message.assistant { background-color: transparent; }

.message-avatar {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-weight: 700;
    font-size: 0.8rem;
    color: #fff;
}

.message.user .message-avatar { background: #5b6470; }
.message.assistant .message-avatar { background: var(--grad); }

.message-content { flex: 1; min-width: 0; }

.message-text {
    margin-bottom: 0.5rem;
    line-height: 1.65;
    word-wrap: break-word;
}

.revised-prompt {
    margin-top: 0.6rem;
    padding: 0.65rem 0.85rem;
    background: var(--accent-soft);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.message-image-container {
    position: relative;
    display: inline-block;
    margin-top: 0.6rem;
    max-width: 100%;
}

.message-image {
    max-width: min(512px, 100%);
    max-height: 512px;
    width: auto;
    height: auto;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: block;
    cursor: zoom-in;
    transition: transform var(--ease);
}

.message-image:hover { transform: scale(1.01); }

.image-btn-row {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.7rem;
    flex-wrap: wrap;
}

/* Единый стиль кнопок под изображением */
.btn-download,
.btn-open {
    padding: 0.5rem 0.95rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--text);
    transition: background var(--ease), transform var(--ease);
}

.btn-download {
    background: var(--accent);
    color: #fff;
    border-color: transparent;
}

.btn-download:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-open:hover { background: var(--surface-3); transform: translateY(-1px); }

.btn-mini {
    margin-top: 0.5rem;
    padding: 0.3rem 0.7rem;
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-pill);
    cursor: pointer;
    font-size: 0.78rem;
    transition: background var(--ease), color var(--ease);
}

.btn-mini:hover { background: var(--surface-2); color: var(--text); }

/* Загрузочная анимация */
.loading-message .message-content {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.loading-dots {
    display: flex;
    gap: 6px;
    align-items: center;
}

.loading-dots span {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background-color: var(--accent);
    animation: bounce 1.2s infinite ease-in-out;
}

.loading-dots span:nth-child(2) { animation-delay: 0.18s; }
.loading-dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0.65); opacity: 0.5; }
    40% { transform: scale(1.15); opacity: 1; }
}

.loading-text {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-style: italic;
}

/* Примеры промптов */
.examples-title {
    margin-top: 1.75rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.example-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.7rem;
    margin-top: 0.85rem;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.example-btn {
    padding: 0.8rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.85rem;
    text-align: left;
    transition: background var(--ease), border-color var(--ease), transform var(--ease);
}

.example-btn:hover {
    background: var(--surface-2);
    border-color: var(--accent);
    color: var(--text);
    transform: translateY(-2px);
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   Чат — поле ввода
   ============================================================ */
.chat-input-container {
    padding: 1rem 1rem 1.25rem;
    border-top: 1px solid var(--border);
    background-color: var(--bg);
}

.gen-options {
    max-width: 820px;
    margin: 0 auto 0.7rem;
    display: flex;
    gap: 1.25rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    flex-wrap: wrap;
}

.gen-options label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.gen-options select {
    background-color: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 0.35rem 0.55rem;
    font-size: 0.8rem;
    cursor: pointer;
}

.chat-input-form {
    max-width: 820px;
    margin: 0 auto;
    display: flex;
    gap: 0.6rem;
    align-items: flex-end;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 16px;
    padding: 0.5rem 0.5rem 0.5rem 1rem;
    transition: border-color var(--ease), box-shadow var(--ease);
}

.chat-input-form:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

#messageInput {
    flex: 1;
    padding: 0.55rem 0;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 1rem;
    resize: none;
    min-height: 24px;
    max-height: 200px;
    font-family: inherit;
    line-height: 1.5;
}

#messageInput:focus { outline: none; }
#messageInput::placeholder { color: var(--text-faint); }

.btn-send {
    padding: 0.6rem 1.4rem;
    background-color: var(--accent);
    color: #fff;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    transition: background var(--ease), transform var(--ease);
}

.btn-send:hover:not(:disabled) { background-color: var(--accent-hover); transform: translateY(-1px); }
.btn-send:disabled { opacity: 0.45; cursor: not-allowed; }

/* ============================================================
   Модальные окна (настройки, архив)
   ============================================================ */
.settings-modal {
    display: none;
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(3px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.settings-modal.active { display: flex; animation: fadeInUp 0.2s var(--ease); }

.settings-content {
    background-color: var(--surface);
    padding: 1.75rem;
    border-radius: 18px;
    max-width: 420px;
    width: 100%;
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.settings-header h2 { margin: 0; font-size: 1.3rem; }

.btn-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.6rem;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    line-height: 1;
    transition: background var(--ease);
}

.btn-close:hover { background: var(--surface-2); }

.settings-item { margin-bottom: 1.25rem; }
.settings-item label { display: block; margin-bottom: 0.6rem; color: var(--text-muted); }

.theme-toggle { display: flex; gap: 0.75rem; }

.theme-option {
    flex: 1;
    padding: 0.75rem;
    border: 2px solid var(--border-strong);
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-align: center;
    font-weight: 600;
    transition: all var(--ease);
}

.theme-option.active {
    border-color: var(--accent);
    background-color: var(--accent-soft);
    color: var(--accent);
}

.settings-author,
.page-author {
    margin-top: 1.5rem;
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-faint);
}

.archive-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 55vh;
    overflow-y: auto;
}

.archive-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.7rem 0.9rem;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
}

.archive-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.9rem;
}

/* ============================================================
   Галерея «Мои изображения»
   ============================================================ */
.gallery-page {
    min-height: 100vh;
    background-color: var(--bg);
    padding: 2rem clamp(1rem, 4vw, 3rem);
    max-width: 1240px;
    margin: 0 auto;
}

.gallery-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 2rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
}

.gallery-header h1 { font-size: 1.7rem; }

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1.5rem;
}

.gallery-card {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: transform var(--ease), box-shadow var(--ease);
}

.gallery-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow);
}

.gallery-card img {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    display: block;
}

.gallery-card-body {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    flex: 1;
}

.gallery-card-prompt {
    font-size: 0.9rem;
    line-height: 1.45;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.gallery-card-meta {
    font-size: 0.75rem;
    color: var(--text-faint);
    margin-top: auto;
}

.gallery-card .btn-download {
    text-decoration: none;
    text-align: center;
}

.gallery-empty {
    text-align: center;
    padding: 5rem 1rem;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

/* ============================================================
   Панель администратора
   ============================================================ */
.admin-container {
    min-height: 100vh;
    background-color: var(--bg);
    padding: 2rem clamp(1rem, 4vw, 3rem);
    max-width: 1240px;
    margin: 0 auto;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 2rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
}

.admin-header h1 { font-size: 1.8rem; margin: 0; }
.admin-actions { display: flex; gap: 1rem; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 1.25rem;
    margin-bottom: 3rem;
}

.stat-card {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: transform var(--ease), box-shadow var(--ease);
}

.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }

.stat-icon { font-size: 2.6rem; flex-shrink: 0; }
.stat-content { flex: 1; }

.stat-content h3 {
    font-size: 0.88rem;
    color: var(--text-muted);
    margin: 0 0 0.35rem 0;
    font-weight: 500;
}

.stat-number {
    font-size: 2rem;
    font-weight: 800;
    margin: 0;
    color: var(--accent);
}

.stat-label {
    font-size: 0.82rem;
    color: var(--text-faint);
    margin: 0.2rem 0 0 0;
}

.stats-section { margin-bottom: 3rem; }

.stats-section h2 {
    font-size: 1.4rem;
    margin-bottom: 1rem;
    color: var(--text);
}

.section-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.user-count-badge {
    background: var(--accent-soft);
    border: 1px solid rgba(16, 163, 127, 0.4);
    color: var(--accent);
    padding: 0.25rem 0.8rem;
    border-radius: var(--radius-pill);
    font-size: 0.82rem;
    font-weight: 600;
}

.table-container {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
}

.stats-table thead { background-color: var(--surface-2); }

.stats-table th {
    padding: 0.9rem 1rem;
    text-align: left;
    font-weight: 700;
    color: var(--text);
    font-size: 0.88rem;
    border-bottom: 1px solid var(--border);
}

.stats-table td {
    padding: 0.9rem 1rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
}

.stats-table tbody tr:last-child td { border-bottom: none; }
.stats-table tbody tr:hover { background-color: var(--surface-2); }

.btn-delete-user {
    background: rgba(255, 80, 80, 0.14);
    color: #ff7b7b;
    border: 1px solid rgba(255, 80, 80, 0.3);
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    transition: background var(--ease);
}

.btn-delete-user:hover { background: rgba(255, 80, 80, 0.28); }

.empty-message {
    text-align: center;
    color: var(--text-faint);
    font-style: italic;
}

/* ============================================================
   Глобальный переключатель темы
   ============================================================ */
.global-theme-toggle {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    z-index: 1200;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: rgba(0, 0, 0, 0.4);
    color: #fff;
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
    box-shadow: var(--shadow);
    transition: transform var(--ease), background var(--ease);
}

.global-theme-toggle:hover { transform: scale(1.1) rotate(-10deg); }

body.light-theme .global-theme-toggle {
    background: rgba(255, 255, 255, 0.85);
    color: #1f2330;
    border-color: rgba(0, 0, 0, 0.12);
}

/* ============================================================
   Гамбургер и оверлей (мобильные)
   ============================================================ */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 1100;
    background-color: var(--surface);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    width: 42px;
    height: 42px;
    font-size: 1.2rem;
    cursor: pointer;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1050;
}

.sidebar-overlay.active { display: block; }

/* ============================================================
   Скроллбар
   ============================================================ */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.16);
    border-radius: var(--radius-pill);
}
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.28); }

body.light-theme ::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.18); }
body.light-theme ::-webkit-scrollbar-thumb:hover { background: rgba(0, 0, 0, 0.28); }

/* ============================================================
   Адаптив
   ============================================================ */
@media (max-width: 768px) {
    .sidebar-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        width: 270px;
        z-index: 1060;
        transform: translateX(-100%);
        transition: transform var(--ease);
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }

    .chat-messages { padding: 3.5rem 0.75rem 1rem; }
    .message { padding: 1rem 0.5rem; }
    .example-grid { grid-template-columns: 1fr; }
    .home-container { padding-top: 4rem; gap: 3rem; }
    .home-gallery { grid-template-rows: 140px 140px; }
    .global-theme-toggle { bottom: 1rem; right: 1rem; }
}

@media (max-width: 480px) {
    .auth-box { padding: 2rem 1.5rem; }
    .gen-options { gap: 0.6rem; font-size: 0.75rem; }
    .home-gallery {
        grid-template-columns: repeat(2, 1fr);
        grid-template-rows: repeat(3, 130px);
    }
    .gallery-item-wide { grid-column: span 2; }
}
