@import url("https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,400;0,14..32,500;0,14..32,600;0,14..32,700;1,14..32,400&display=swap");

:root {
    --bg: #000;
    --sidebar: #171717;
    --hover: #212121;
    --composer: #2f2f2f;
    --text: #ececec;
    --muted: #b4b4b4;
    --border: #2a2a2a;
    --user: #2f2f2f;
    --danger: #7f1d1d;
    --danger-border: #991b1b;
    --font: "Inter", ui-sans-serif, system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
}

button, input, textarea, select {
    font-family: inherit;
}

/* Auth */
.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1rem;
}

.auth-card {
    width: min(420px, 100%);
    background: var(--sidebar);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.5rem;
}

.auth-card.wide { width: min(560px, 100%); }
.auth-card h1 { margin: 0 0 .25rem; font-size: 1.5rem; }
.subtitle { color: var(--muted); margin-top: 0; }

label { display: block; margin: .75rem 0 .25rem; color: var(--muted); font-size: .9rem; }

.input {
    width: 100%;
    padding: .7rem .85rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--composer);
    color: var(--text);
}

.btn-primary, .btn-secondary {
    border: 0;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
}

.btn-primary {
    background: var(--text);
    color: #111;
    padding: .7rem 1rem;
    margin-top: 1rem;
    width: 100%;
}

.btn-secondary {
    background: var(--hover);
    color: var(--text);
    border: 1px solid var(--border);
    padding: .5rem .75rem;
}

.alert {
    background: var(--danger);
    border: 1px solid var(--danger-border);
    padding: .75rem;
    border-radius: 10px;
    margin: 1rem 0;
}

.company-list { list-style: none; padding: 0; margin: 1rem 0 0; }
.company-list li { margin-bottom: .5rem; }
.company-list button { width: 100%; text-align: left; }

/* Shell */
.app-shell {
    display: flex;
    height: 100vh;
    width: 100%;
    overflow: hidden;
}

.sidebar {
    width: 260px;
    flex: 0 0 260px;
    background: var(--sidebar);
    display: flex;
    flex-direction: column;
    padding: 12px;
    min-height: 0;
}

.app-shell.sidebar-collapsed .sidebar {
    display: none;
}

.brand-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 4px 12px;
    gap: 8px;
}

.brand-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

.brand-name {
    font-weight: 600;
    font-size: 15px;
}

.thread-search-panel {
    margin: 0 0 10px;
}

.thread-search-field {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--hover);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 10px;
    color: var(--muted);
}

.thread-search-field input {
    flex: 1;
    min-width: 0;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text);
    font-size: 13px;
}

.thread-search-field input::placeholder {
    color: var(--muted);
}

.thread-list-empty {
    color: var(--muted);
    font-size: 13px;
    padding: 12px 10px;
}

.icon-btn {
    border: 0;
    background: transparent;
    color: var(--muted);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: inline-grid;
    place-items: center;
    cursor: pointer;
}

.icon-btn:hover {
    background: var(--hover);
    color: var(--text);
}

.btn-new-chat {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    border: 0;
    background: var(--hover);
    color: var(--text);
    border-radius: 999px;
    padding: 11px 14px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    margin-bottom: 12px;
}

.btn-new-chat:hover { background: #2a2a2a; }

.sidebar-section {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.section-label {
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    padding: 10px 10px 6px;
}

.section-label-spaced {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}

.thread-list {
    list-style: none;
    padding: 0;
    margin: 0;
    overflow-y: auto;
}

.thread-item {
    position: relative;
    display: flex;
    align-items: center;
    margin: 0;
    border-radius: 10px;
}

.thread-item:hover,
.thread-item.menu-open,
.thread-item.active {
    background: var(--hover);
}

.thread-item.active {
    background: #2a2a2a;
}

.thread-open {
    flex: 1;
    min-width: 0;
    text-align: left;
    background: transparent;
    border: 0;
    color: var(--text);
    padding: 9px 10px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.thread-item-team .thread-open {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    white-space: normal;
}

.thread-title-text {
    display: block;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.thread-owner {
    display: block;
    font-size: 11px;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.thread-more {
    flex: 0 0 28px;
    width: 28px;
    height: 28px;
    margin-right: 4px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    display: none;
    place-items: center;
    cursor: pointer;
}

.thread-item:hover .thread-more,
.thread-item.menu-open .thread-more,
.thread-item.active .thread-more {
    display: inline-grid;
}

.thread-more:hover {
    background: #333;
    color: var(--text);
}

.thread-menu {
    display: none;
    position: fixed;
    z-index: 1000;
    min-width: 160px;
    padding: 6px;
    border-radius: 12px;
    background: #2f2f2f;
    border: 1px solid var(--border);
    box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
    overflow: visible;
}

.thread-menu.open { display: grid; gap: 2px; }

.thread-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    border: 0;
    background: transparent;
    color: var(--text);
    border-radius: 8px;
    padding: 9px 10px;
    font-size: 13px;
    cursor: pointer;
    text-align: left;
}

.thread-menu-item:hover { background: #3a3a3a; }

.thread-menu-item.danger {
    color: #f87171;
}

.thread-menu-item.danger:hover {
    background: rgba(248, 113, 113, .12);
}

.thread-item.renaming {
    background: #2a2a2a;
    padding: 4px;
}

.thread-rename-input {
    width: 100%;
    border: 1px solid #5b5b5b;
    background: #1f1f1f;
    color: var(--text);
    border-radius: 8px;
    padding: 7px 9px;
    font-size: 14px;
    outline: none;
}

.thread-rename-input:focus {
    border-color: #8b8b8b;
}

.sidebar-footer {
    border-top: 1px solid var(--border);
    padding-top: 8px;
    margin-top: 8px;
}

.btn-logout {
    width: 100%;
    border: 0;
    background: transparent;
    color: var(--muted);
    text-align: left;
    padding: 10px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 14px;
}

.btn-logout:hover {
    background: var(--hover);
    color: var(--text);
}

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

.chat-topbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    min-height: 52px;
    flex: 0 0 auto;
}

.chat-model-title {
    margin: 0;
    font-size: 17px;
    font-weight: 600;
}

.mobile-only { display: none; }
.app-shell.sidebar-collapsed .mobile-only { display: inline-grid; }

.chat-body {
    flex: 1;
    min-height: 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

.empty-state {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.empty-state.hidden { display: none; }

.empty-greeting {
    margin: 0;
    font-size: 32px;
    font-weight: 600;
    text-align: center;
}

.messages {
    flex: 1;
    min-height: 0;
    min-width: 0;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 16px 0 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.messages.hidden { display: none; }

.message {
    width: min(768px, calc(100% - 32px));
    max-width: 100%;
    min-width: 0;
    margin: 0 auto;
    line-height: 1.65;
    font-size: 16px;
}

.message.user {
    background: var(--user);
    border-radius: 22px;
    padding: 12px 18px;
    width: fit-content;
    max-width: min(768px, calc(100% - 32px));
    margin-left: auto;
    margin-right: max(16px, calc((100% - 768px) / 2));
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.message-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.message-attachment-img {
    max-width: min(280px, 70vw);
    max-height: 220px;
    border-radius: 12px;
    object-fit: contain;
    background: #111;
    border: 1px solid #333;
    cursor: zoom-in;
}

.message-attachment-img:hover {
    border-color: #666;
}

.image-lightbox {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0, 0, 0, .88);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px 24px 24px;
    cursor: zoom-out;
}

.image-lightbox.hidden { display: none; }

body.lightbox-open { overflow: hidden; }

.image-lightbox-img {
    max-width: min(96vw, 1400px);
    max-height: calc(100vh - 72px);
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, .5);
    cursor: default;
}

.image-lightbox-close {
    position: absolute;
    top: 12px;
    right: 16px;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, .12);
    color: #fff;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    display: grid;
    place-items: center;
    padding: 0;
}

.image-lightbox-close:hover {
    background: rgba(255, 255, 255, .22);
}

.message.user .message-text {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.message.assistant {
    background: transparent;
    padding: 0 4px;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.message.assistant > *:first-child { margin-top: 0; }
.message.assistant > *:last-child { margin-bottom: 0; }

.message.assistant pre {
    background: #0d0d0d;
    border: 1px solid #2a2a2a;
    padding: 14px 16px;
    border-radius: 12px;
    overflow-x: auto;
    max-width: 100%;
}

.message.assistant code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: .88em;
}

.message.assistant :not(pre) > code {
    background: #2a2a2a;
    padding: .1rem .35rem;
    border-radius: 6px;
}

.message.assistant a { color: #7dd3fc; }

.message.assistant .table-scroll {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    margin: 12px 0;
    border: 1px solid #2a2a2a;
    border-radius: 12px;
    background: #111;
    -webkit-overflow-scrolling: touch;
}

.message.assistant table {
    border-collapse: collapse;
    width: max-content;
    min-width: 100%;
    margin: 0;
    font-size: 13px;
    line-height: 1.4;
}

.message.assistant th,
.message.assistant td {
    border-bottom: 1px solid #2a2a2a;
    border-right: 1px solid #222;
    padding: 8px 10px;
    text-align: left;
    vertical-align: top;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
    max-width: 220px;
}

.message.assistant th:last-child,
.message.assistant td:last-child {
    border-right: 0;
}

.message.assistant thead th {
    position: sticky;
    top: 0;
    background: #1a1a1a;
    color: #d4d4d4;
    font-weight: 600;
    white-space: nowrap;
    max-width: none;
}

.message.assistant tbody tr:last-child td {
    border-bottom: 0;
}

.client-reply-box {
    position: relative;
    margin: 14px 0 4px;
    padding: 18px 44px 18px 18px;
    background: #2a2a2a;
    border: 1px solid #3a3a3a;
    border-radius: 14px;
    color: var(--text);
    white-space: normal;
    line-height: 1.65;
}

.client-reply-body {
    overflow-wrap: anywhere;
    word-break: break-word;
}

.client-reply-body > *:first-child { margin-top: 0; }
.client-reply-body > *:last-child { margin-bottom: 0; }

.client-reply-body h1,
.client-reply-body h2,
.client-reply-body h3,
.client-reply-body h4 {
    margin: 1em 0 .45em;
    font-weight: 600;
    line-height: 1.3;
}

.client-reply-body h3 { font-size: 1.05em; }

.client-reply-body p { margin: .55em 0; }

.client-reply-body ul,
.client-reply-body ol {
    margin: .45em 0;
    padding-left: 1.35em;
}

.client-reply-body li { margin: .2em 0; }

.client-reply-body hr {
    border: 0;
    border-top: 1px solid #444;
    margin: 1em 0;
}

.client-reply-body strong { font-weight: 600; }

.client-reply-copy {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #c8c8c8;
    display: inline-grid;
    place-items: center;
    cursor: pointer;
}

.client-reply-copy:hover {
    background: #3a3a3a;
    color: #fff;
}

.client-reply-copy.copied {
    color: #86efac;
}

.composer-wrap {
    flex: 0 0 auto;
    width: min(768px, calc(100% - 32px));
    margin: 0 auto;
    padding: 0 0 18px;
}

.composer-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
    padding: 0 4px;
}

.composer-attachments.hidden { display: none; }

.composer-attachment {
    position: relative;
    width: 72px;
    height: 72px;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid #333;
    background: #1a1a1a;
}

.composer-attachment img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.composer-attachment.uploading { opacity: .65; }
.composer-attachment.error { border-color: #991b1b; }

.composer-attachment-status {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(0,0,0,.35);
    color: #fff;
    font-size: 18px;
}

.composer-attachment-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 20px;
    height: 20px;
    border: 0;
    border-radius: 50%;
    background: rgba(0,0,0,.7);
    color: #fff;
    cursor: pointer;
    line-height: 1;
    padding: 0;
}

.composer {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--composer);
    border-radius: 28px;
    padding: 10px 10px 10px 12px;
}

.btn-attach {
    flex: 0 0 34px;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--muted);
    display: grid;
    place-items: center;
    cursor: pointer;
    padding: 0;
}

.btn-attach:hover { color: var(--text); background: #3a3a3a; }
.btn-attach:disabled { opacity: .35; cursor: default; }

.composer textarea {
    flex: 1;
    resize: none;
    border: 0;
    outline: none;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 16px;
    line-height: 1.45;
    max-height: 200px;
    min-height: 28px;
    padding: 6px 0;
    width: 100%;
}

.composer textarea::placeholder { color: var(--muted); }

.btn-send {
    flex: 0 0 34px;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 50%;
    background: #fff;
    color: #0d0d0d;
    display: grid;
    place-items: center;
    cursor: pointer;
    padding: 0;
}

.btn-send:hover { opacity: .9; }
.btn-send:disabled { opacity: .35; cursor: default; }

.message.working {
    color: var(--muted);
    padding: 4px;
}

.working-title {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-size: 15px;
    color: var(--text);
    font-weight: 500;
}

.working-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid #555;
    border-top-color: #fff;
    border-radius: 50%;
    animation: working-spin .7s linear infinite;
}

@keyframes working-spin {
    to { transform: rotate(360deg); }
}

.working-steps {
    list-style: none;
    margin: 10px 0 0;
    padding: 0;
    display: grid;
    gap: 4px;
}

.working-steps li {
    font-size: 13px;
    color: #8e8e8e;
    padding-left: 24px;
    position: relative;
}

.working-steps li::before {
    content: '';
    position: absolute;
    left: 5px;
    top: 7px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #555;
}

.working-steps li.current {
    color: #cfcfcf;
}

.working-steps li.current::before {
    background: #fff;
}

.composer-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    padding: 0 4px;
    position: relative;
}

.toolbar-chip-wrap {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

.toolbar-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
    border-radius: 999px;
    padding: 7px 12px;
    font-size: 13px;
    cursor: pointer;
    max-width: min(360px, 100%);
}

.toolbar-chip:hover,
.toolbar-chip.active {
    background: var(--hover);
    color: var(--text);
}

.toolbar-chip span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.toolbar-chip-clear {
    border: 0;
    background: transparent;
    color: var(--muted);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
}

.toolbar-chip-clear:hover {
    background: var(--hover);
    color: var(--text);
}

.empresa-picker {
    position: relative;
}

.empresa-picker-panel {
    position: absolute;
    left: 0;
    bottom: calc(100% + 8px);
    width: min(360px, calc(100vw - 48px));
    max-height: 320px;
    display: flex;
    flex-direction: column;
    background: #2a2a2a;
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, .45);
    z-index: 40;
    overflow: hidden;
}

.empresa-picker-search {
    border: 0;
    border-bottom: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    padding: 12px 14px;
    font-size: 14px;
    outline: none;
}

.empresa-picker-list {
    list-style: none;
    margin: 0;
    padding: 6px;
    overflow-y: auto;
    max-height: 260px;
}

.empresa-picker-list button {
    width: 100%;
    text-align: left;
    border: 0;
    background: transparent;
    color: var(--text);
    border-radius: 10px;
    padding: 10px 12px;
    cursor: pointer;
    font-size: 13px;
    display: grid;
    gap: 2px;
}

.empresa-picker-list button:hover,
.empresa-picker-list button.active {
    background: #3a3a3a;
}

.empresa-picker-list .empresa-meta {
    color: var(--muted);
    font-size: 11px;
}

.empresa-picker-empty {
    color: var(--muted);
    font-size: 13px;
    padding: 16px;
}

.picker-panel-footer {
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 11px;
    padding: 8px 12px;
}

.empresa-picker-list label.repo-option {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    width: 100%;
    border-radius: 10px;
    padding: 10px 12px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text);
}

.empresa-picker-list label.repo-option:hover,
.empresa-picker-list label.repo-option.active {
    background: #3a3a3a;
}

.empresa-picker-list label.repo-option input {
    margin-top: 2px;
    accent-color: #fff;
}

.empresa-picker-list label.repo-option .repo-option-text {
    display: grid;
    gap: 2px;
    min-width: 0;
}

.composer-hint {
    margin: 8px 0 0;
    text-align: center;
    color: #8e8e8e;
    font-size: 12px;
}

.hidden { display: none !important; }

@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(280px, 86vw);
        z-index: 30;
        transform: translateX(-105%);
        transition: transform .2s ease;
        display: flex;
    }

    .app-shell.sidebar-open .sidebar {
        transform: translateX(0);
        box-shadow: 16px 0 40px rgba(0,0,0,.5);
    }

    .app-shell.sidebar-collapsed .sidebar { display: flex; }

    .mobile-only { display: inline-grid; }

    .empty-greeting { font-size: 26px; }
}
