:root {
    --bg: #ffffff;
    --fg: #0d0d0d;
    --gray-900: #1a1a1a;
    --gray-700: #404040;
    --gray-500: #737373;
    --gray-400: #a3a3a3;
    --gray-300: #d4d4d4;
    --gray-200: #e5e5e5;
    --gray-100: #f4f4f4;
    --gray-50:  #fafafa;
    --border: #ececec;
    --radius: 14px;
    --sidebar-w: 268px;
    --col: 760px;
    --font: 'Hanken Grotesk', sans-serif;
    --mono: 'JetBrains Mono', monospace;
}

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

html, body { height: 100%; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--fg);
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

.app { display: flex; height: 100vh; overflow: hidden; }

[data-lucide] { width: 18px; height: 18px; stroke-width: 1.75; }

/* ---------- SIDEBAR ---------- */
.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 14px 12px;
    gap: 6px;
    transition: margin-left .25s ease;
}
.sidebar.collapsed { margin-left: calc(-1 * var(--sidebar-w)); }

.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px 10px;
}
.brand {
    display: flex; align-items: center; gap: 9px;
    font-weight: 700; font-size: 17px; letter-spacing: -.02em;
}
.brand-icon { width: 20px; height: 20px; }

.new-chat {
    display: flex; align-items: center; gap: 10px;
    width: 100%; padding: 10px 12px;
    background: none; color: var(--gray-700);
    border: 1px solid var(--gray-200); border-radius: 11px;
    font-family: var(--font); font-size: 14px; font-weight: 500;
    cursor: pointer; transition: background .15s, border-color .15s;
}
.new-chat:hover { background: var(--gray-100); border-color: var(--gray-300); }
.new-chat [data-lucide] { width: 16px; height: 16px; color: var(--gray-500); }

.chat-list {
    flex: 1; overflow-y: auto; margin-top: 8px;
    display: flex; flex-direction: column; gap: 2px;
}
.chat-item {
    display: flex; align-items: center;
    padding: 9px 11px; border-radius: 9px;
    color: var(--gray-700); font-size: 14px;
    cursor: pointer; border: none; background: none;
    width: 100%; text-align: left;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    font-family: var(--font);
}
.chat-item:hover { background: var(--gray-100); }
.chat-item.active { background: var(--gray-100); color: var(--fg); font-weight: 500; }
.chat-item span { overflow: hidden; text-overflow: ellipsis; }

.account {
    display: flex; align-items: center; gap: 10px;
    padding: 10px; border-top: 1px solid var(--border); margin-top: 6px;
}
.account-avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--gray-100);
    display: grid; place-items: center; flex-shrink: 0;
}
.account-avatar [data-lucide] { width: 17px; height: 17px; color: var(--gray-700); }
.account-info { display: flex; flex-direction: column; min-width: 0; }
.account-email {
    font-size: 13px; font-weight: 500;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.account-credits { font-size: 12px; color: var(--gray-500); display: flex; align-items: center; gap: 5px; }
.account-credits [data-lucide] { width: 13px; height: 13px; }
.account-credits b { color: var(--gray-700); font-weight: 600; }

/* ---------- MAIN ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }

.topbar {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 20px; border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.chat-title { font-size: 15px; font-weight: 600; letter-spacing: -.01em; }

.icon-btn {
    display: grid; place-items: center;
    width: 34px; height: 34px; border-radius: 9px;
    background: none; border: none; cursor: pointer; color: var(--gray-700);
    transition: background .15s;
}
.icon-btn:hover { background: var(--gray-100); }
#openSidebarBtn { display: none; }
.sidebar.collapsed + .main #openSidebarBtn { display: grid; }

/* ---------- MESSAGES ---------- */
.messages { flex: 1; overflow-y: auto; scroll-behavior: smooth; }

.message { width: 100%; padding: 22px 24px; }
.message-inner {
    max-width: var(--col); margin: 0 auto;
    display: flex; gap: 14px;
}
.msg-avatar {
    width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
    display: grid; place-items: center;
}
.msg-avatar.user { background: var(--gray-100); }
.msg-avatar.user [data-lucide] { color: var(--gray-700); }
.msg-avatar.ai { background: var(--fg); }
.msg-avatar.ai [data-lucide] { color: var(--bg); }
.msg-avatar [data-lucide] { width: 16px; height: 16px; }

.msg-body { min-width: 0; flex: 1; padding-top: 3px; }
.msg-role {
    font-size: 12px; font-weight: 600; text-transform: uppercase;
    letter-spacing: .05em; color: var(--gray-400); margin-bottom: 5px;
}
.msg-content { color: var(--gray-900); overflow-wrap: break-word; }

/* Сообщение пользователя — справа, с лёгкой подложкой */
.message.user .message-inner { flex-direction: row-reverse; }
.message.user .msg-body { display: flex; flex-direction: column; align-items: flex-end; }
.message.user .msg-role { text-align: right; }
.message.user .msg-content {
    background: var(--gray-100); padding: 11px 15px;
    border-radius: 16px; border-top-right-radius: 5px;
    max-width: 100%; width: fit-content;
}

/* Подвал сообщения: время и копирование */
.msg-footer {
    display: flex; align-items: center; gap: 10px;
    margin-top: 8px; opacity: 0; transition: opacity .15s;
}
.message:hover .msg-footer { opacity: 1; }
.message.user .msg-footer { justify-content: flex-end; }
.msg-time { font-size: 12px; color: var(--gray-400); }
.copy-btn {
    display: inline-flex; align-items: center; gap: 5px;
    background: none; border: none; cursor: pointer;
    color: var(--gray-400); font-family: var(--font); font-size: 12px;
    padding: 2px 4px; border-radius: 6px; transition: color .15s, background .15s;
}
.copy-btn:hover { color: var(--gray-700); background: var(--gray-100); }
.copy-btn [data-lucide] { width: 13px; height: 13px; }
.msg-content > *:first-child { margin-top: 0; }
.msg-content > *:last-child { margin-bottom: 0; }
.msg-content p { margin: 0 0 12px; }
.msg-content ul, .msg-content ol { margin: 0 0 12px; padding-left: 22px; }
.msg-content li { margin-bottom: 4px; }
.msg-content h1, .msg-content h2, .msg-content h3 { margin: 18px 0 10px; letter-spacing: -.01em; }
.msg-content code {
    font-family: var(--mono); font-size: .88em;
    background: var(--gray-100); padding: 2px 6px; border-radius: 5px;
}
.msg-content pre {
    background: var(--gray-50); border: 1px solid var(--border);
    border-radius: 10px; padding: 14px 16px; overflow-x: auto; margin: 0 0 12px;
}
.msg-content pre code { background: none; padding: 0; font-size: 13px; line-height: 1.55; }
.msg-content img { max-width: 100%; border-radius: 12px; border: 1px solid var(--border); margin-top: 4px; }
.msg-content a { color: var(--fg); text-decoration: underline; text-underline-offset: 2px; }

.msg-content img.gen-image {
    max-width: 220px; border-radius: 12px; border: 1px solid var(--border);
    display: block; cursor: zoom-in; transition: opacity .15s;
}
.msg-content img.gen-image:hover { opacity: .9; }

/* Лайтбокс (увеличение фото) — без рамок */
.lightbox {
    position: fixed; inset: 0; z-index: 1000;
    background: rgba(0, 0, 0, .82);
    display: flex; align-items: center; justify-content: center;
    padding: 32px; cursor: zoom-out;
    animation: fadeIn .15s ease;
}
.lightbox img {
    max-width: 100%; max-height: 100%;
    border-radius: 8px; box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Прогресс генерации фото */
.gen-progress { display: flex; align-items: center; gap: 12px; padding-top: 4px; }
.gen-progress-bar {
    width: 160px; height: 5px; border-radius: 3px;
    background: var(--gray-200); overflow: hidden;
}
.gen-progress-fill {
    height: 100%; background: var(--gray-700); width: 0%;
    transition: width .3s ease; border-radius: 3px;
}
.gen-progress-text { font-size: 13px; color: var(--gray-500); font-variant-numeric: tabular-nums; }

/* печатает… */
.typing { display: inline-flex; gap: 4px; padding-top: 6px; }
.typing span {
    width: 6px; height: 6px; border-radius: 50%; background: var(--gray-400);
    animation: blink 1.4s infinite both;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }

/* ---------- EMPTY STATE ---------- */
.empty-state {
    height: 100%; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 8px;
    color: var(--gray-500); padding: 40px; text-align: center;
}
.empty-icon { width: 34px !important; height: 34px !important; color: var(--gray-300); margin-bottom: 6px; }
.empty-state h2 { font-size: 24px; font-weight: 600; color: var(--gray-900); letter-spacing: -.02em; }
.empty-state p { font-size: 14px; max-width: 360px; }

/* ---------- COMPOSER ---------- */
.composer-wrap { padding: 0 24px 16px; flex-shrink: 0; }
.composer {
    max-width: var(--col); margin: 0 auto;
    border: 1px solid var(--gray-300); border-radius: var(--radius);
    padding: 10px 12px 8px; background: var(--bg);
    transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within { border-color: var(--gray-500); box-shadow: 0 0 0 4px var(--gray-100); }

.attach-preview { position: relative; width: fit-content; margin-bottom: 8px; }
.attach-preview img { height: 60px; border-radius: 9px; border: 1px solid var(--border); display: block; }
.attach-remove {
    position: absolute; top: -7px; right: -7px;
    width: 20px; height: 20px; border-radius: 50%;
    background: var(--fg); color: var(--bg); border: 2px solid var(--bg);
    display: grid; place-items: center; cursor: pointer;
}
.attach-remove [data-lucide] { width: 11px; height: 11px; }

#input {
    width: 100%; border: none; outline: none; resize: none;
    font-family: var(--font); font-size: 15px; line-height: 1.5;
    color: var(--fg); background: none; max-height: 200px; padding: 4px 6px;
}
#input::placeholder { color: var(--gray-400); }

.composer-row { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }
.composer-left { display: flex; align-items: center; gap: 6px; }

.model-select { position: relative; }
.model-btn {
    display: flex; align-items: center; gap: 7px;
    padding: 7px 10px; border-radius: 9px;
    background: none; border: none; cursor: pointer;
    font-family: var(--font); font-size: 13px; font-weight: 500; color: var(--gray-700);
    transition: background .15s;
}
.model-btn:hover { background: var(--gray-100); }
.model-btn [data-lucide] { width: 15px; height: 15px; }
.model-btn .chev { width: 13px; height: 13px; color: var(--gray-400); }

.model-menu {
    position: absolute; bottom: calc(100% + 8px); left: 0;
    min-width: 240px; background: var(--bg);
    border: 1px solid var(--gray-200); border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0,0,0,.10); padding: 6px; z-index: 50;
}
.model-option {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 9px 10px; border-radius: 8px; cursor: pointer;
    background: none; border: none; width: 100%; text-align: left;
    font-family: var(--font);
}
.model-option:hover { background: var(--gray-100); }
.model-option [data-lucide] { width: 17px; height: 17px; color: var(--gray-700); margin-top: 1px; }
.model-option .mo-name { font-size: 14px; font-weight: 500; color: var(--fg); }
.model-option .mo-desc { font-size: 12px; color: var(--gray-500); }
.model-option .mo-text { display: flex; flex-direction: column; }
.model-option.selected { background: var(--gray-100); }

.send-btn {
    display: grid; place-items: center;
    width: 36px; height: 36px; border-radius: 10px;
    background: var(--fg); color: var(--bg); border: none; cursor: pointer;
    transition: opacity .15s, transform .1s;
}
.send-btn:hover { opacity: .85; }
.send-btn:active { transform: scale(.94); }
.send-btn:disabled { background: var(--gray-200); color: var(--gray-400); cursor: not-allowed; }
.send-btn [data-lucide] { width: 18px; height: 18px; }

.disclaimer { text-align: center; font-size: 12px; color: var(--gray-400); margin-top: 10px; }

.hidden { display: none !important; }

/* ---------- RESPONSIVE ---------- */
@media (max-width: 760px) {
    .sidebar {
        position: absolute; z-index: 100; height: 100%;
        background: var(--bg); box-shadow: 0 0 40px rgba(0,0,0,.12);
    }
    .sidebar.collapsed { margin-left: calc(-1 * var(--sidebar-w)); box-shadow: none; }
    #openSidebarBtn { display: grid; }
    .composer-wrap, .message { padding-left: 14px; padding-right: 14px; }
}

::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-thumb { background: var(--gray-200); border-radius: 6px; border: 3px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--gray-300); }
