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

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

body {
    background: #111;
    color: #e0e0e0;
    font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ── Loading screen ── */
#loading-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: #555;
    font-size: 13px;
}

#loading-spinner {
    width: 28px;
    height: 28px;
    border: 2px solid #2a2a2a;
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

/* ── Auth screen ── */
#auth-screen {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

#auth-card {
    background: #1e1e1e;
    border: 1px solid #2a2a2a;
    border-radius: 16px;
    padding: 40px;
    max-width: 360px;
    width: 100%;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

#auth-card h1 { font-size: 26px; font-weight: 700; }
#auth-card p  { color: #888; font-size: 13px; }

#auth-btn {
    padding: 11px 24px;
    background: #2563eb;
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
#auth-btn:hover        { background: #1d4ed8; }
#auth-btn:focus-visible { outline: 2px solid #60a5fa; outline-offset: 2px; }
#auth-btn:disabled     { opacity: 0.45; cursor: not-allowed; }
#auth-status { font-size: 11px; color: #666; min-height: 14px; }

/* ── Chat screen ── */
#chat-screen {
    display: none;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    width: 100%;
    max-width: 760px;
    position: relative;
}

/* ── Top bar ── */
#top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 44px;
    padding: 0 8px;
    background: #1a1a1a;
    border-bottom: 1px solid #2a2a2a;
    flex-shrink: 0;
    z-index: 10;
}

#conv-title {
    flex: 1;
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    color: #ccc;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 8px;
}

#hamburger-btn,
#new-chat-btn {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color 0.15s, background 0.15s;
}
#hamburger-btn:hover,
#new-chat-btn:hover { color: #e0e0e0; background: #2a2a2a; }

/* ── Status bar ── */
#status {
    padding: 7px 16px;
    background: #1a1a2e;
    border-bottom: 1px solid #2a2a4a;
    color: #93c5fd;
    font-size: 12px;
    text-align: center;
    flex-shrink: 0;
}

/* ── Main content area ── */
#main-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

/* ── Chat view ── */
#chat-view {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

#messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ── Message bubbles ── */
.msg {
    max-width: 78%;
    padding: 10px 14px;
    border-radius: 14px;
    line-height: 1.55;
    word-break: break-word;
    overflow-wrap: break-word;
}

.msg.user {
    align-self: flex-end;
    background: #2563eb;
    color: #fff;
    border-bottom-right-radius: 4px;
    white-space: pre-wrap;
}

.msg.assistant {
    align-self: flex-start;
    background: #1e1e1e;
    border: 1px solid #2a2a2a;
    border-bottom-left-radius: 4px;
}

.msg.tool {
    align-self: flex-start;
    background: transparent;
    border: 1px solid #1e3a2a;
    color: #4ade80;
    font-size: 11px;
    font-family: monospace;
    padding: 5px 10px;
    border-radius: 8px;
    white-space: pre-wrap;
}

.msg.error {
    align-self: flex-start;
    background: transparent;
    border: 1px solid #3a1a1a;
    color: #f87171;
    font-size: 12px;
    border-radius: 8px;
    white-space: pre-wrap;
}

/* ── Markdown inside assistant bubbles ── */
.msg.assistant h1,
.msg.assistant h2,
.msg.assistant h3 {
    font-size: 14px;
    font-weight: 700;
    margin: 10px 0 4px;
    color: #e0e0e0;
}
.msg.assistant h1:first-child,
.msg.assistant h2:first-child,
.msg.assistant h3:first-child { margin-top: 0; }

.msg.assistant p            { margin: 0 0 7px; }
.msg.assistant p:last-child { margin-bottom: 0; }

.msg.assistant ul,
.msg.assistant ol  { margin: 0 0 7px 18px; }
.msg.assistant li  { margin-bottom: 3px; }

.msg.assistant strong { color: #fff; }

.msg.assistant code {
    background: #0d0d0d;
    border: 1px solid #2a2a2a;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 12px;
    font-family: monospace;
}

.msg.assistant pre {
    background: #0d0d0d;
    border: 1px solid #2a2a2a;
    padding: 10px 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 6px 0;
}
.msg.assistant pre code { background: none; border: none; padding: 0; }

/* ── Warning banner ── */
#warning-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0 16px 4px;
    padding: 7px 12px;
    background: #291a00;
    border: 1px solid #7c4a00;
    border-radius: 8px;
    color: #fbbf24;
    font-size: 12px;
    flex-shrink: 0;
}
#warning-dismiss {
    background: none;
    border: none;
    color: #fbbf24;
    font-size: 16px;
    cursor: pointer;
    line-height: 1;
    padding: 0 2px;
    opacity: 0.7;
}
#warning-dismiss:hover { opacity: 1; }

/* ── Input row ── */
#input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 16px 14px;
    flex-shrink: 0;
}

#input {
    flex: 1;
    padding: 10px 14px;
    background: #1e1e1e;
    border: 1px solid #2a2a2a;
    border-radius: 10px;
    color: #e0e0e0;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    resize: none;
    overflow-y: hidden;
    min-height: 44px;
    max-height: 160px;
    line-height: 1.5;
    transition: border-color 0.15s;
}
#input::placeholder { color: #555; }
#input:focus        { border-color: #2563eb; outline: none; }

#send {
    height: 44px;
    padding: 0 12px;
    background: #1e1e1e;
    border: 1px solid #2a2a2a;
    border-radius: 10px;
    color: #9ca3af;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.25s ease, border-color 0.25s ease, color 0.25s ease;
}
#send:hover         { background: #2563eb; border-color: #2563eb; color: white; }
#send:focus-visible { outline: 2px solid #60a5fa; outline-offset: 2px; }
#send:disabled      { opacity: 0.45; cursor: not-allowed; }

/* ── Usage view ── */
#usage-view {
    flex: 1;
    overflow-y: auto;
    padding: 32px 24px;
}

#usage-content h2 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 20px;
    color: #e0e0e0;
}

#usage-details {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.usage-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: #1e1e1e;
    border: 1px solid #2a2a2a;
    border-radius: 8px;
    font-size: 13px;
}

.usage-label { color: #888; }

/* ── Overlay panel backdrop ── */
#panel-backdrop {
    position: fixed;
    inset: 44px 0 0 0; /* start below top bar */
    background: rgba(0, 0, 0, 0.5);
    z-index: 20;
}

/* ── Overlay panel ── */
#overlay-panel {
    position: fixed;
    top: 44px; /* below top bar */
    left: 0;
    bottom: 0;
    width: 260px;
    background: #1a1a1a;
    border-right: 1px solid #2a2a2a;
    z-index: 30;
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
}

#overlay-panel.open {
    transform: translateX(0);
}

#panel-top {
    flex: 1;
    overflow-y: auto;
    padding: 12px 0;
}

.panel-new-chat {
    display: block;
    width: calc(100% - 24px);
    margin: 0 12px 12px;
    padding: 10px 14px;
    background: #2563eb;
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s;
}
.panel-new-chat:hover { background: #1d4ed8; }

/* ── Conversation list ── */
#conv-list {
    padding: 0 6px;
}

.conv-empty {
    padding: 12px 10px;
    color: #555;
    font-size: 12px;
}

.conv-item {
    position: relative;
    display: flex;
    align-items: center;
    padding: 9px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.1s;
    gap: 6px;
}
.conv-item:hover { background: #242424; }
.conv-item.active { background: #1e2a3a; }

.conv-item-body {
    flex: 1;
    min-width: 0;
}

.conv-item-title {
    font-size: 13px;
    color: #ccc;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.conv-item.active .conv-item-title { color: #60a5fa; }

.conv-item-title-input {
    font-size: 13px;
    font-family: inherit;
    background: #0d0d0d;
    border: 1px solid #2563eb;
    border-radius: 4px;
    color: #e0e0e0;
    padding: 2px 6px;
    width: 100%;
    outline: none;
}

.conv-item-time {
    font-size: 11px;
    color: #555;
    margin-top: 2px;
}

.conv-item-actions {
    display: none;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}
.conv-item:hover .conv-item-actions,
.conv-item:focus-within .conv-item-actions { display: flex; }

@media (hover: none), (pointer: coarse) {
    .conv-item-actions { display: flex; }
}

.conv-action-btn {
    background: none;
    border: none;
    color: #555;
    cursor: pointer;
    padding: 3px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    transition: color 0.15s, background 0.15s;
}
.conv-action-btn:hover { color: #e0e0e0; background: #333; }
.conv-action-btn.delete:hover { color: #f87171; }

/* ── Panel footer ── */
#panel-footer {
    border-top: 1px solid #2a2a2a;
    padding: 8px 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.panel-footer-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 10px;
    background: none;
    border: none;
    border-radius: 6px;
    color: #888;
    font-size: 13px;
    cursor: pointer;
    text-align: left;
    transition: color 0.15s, background 0.15s;
}
.panel-footer-btn:hover { color: #e0e0e0; background: #242424; }
.panel-logout-btn:hover { color: #f87171; }

/* ── Modals ── */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-card {
    background: #1e1e1e;
    border: 1px solid #2a2a2a;
    border-radius: 12px;
    width: 100%;
    max-width: 340px;
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid #2a2a2a;
    font-size: 14px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: #888;
    font-size: 20px;
    cursor: pointer;
    padding: 0 2px;
    line-height: 1;
}
.modal-close:hover { color: #e0e0e0; }

.modal-body {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    font-size: 13px;
}

.modal-body a { color: #60a5fa; }
.modal-body p { color: #888; }

.modal-hint {
    font-size: 11px;
    color: #555;
}

.danger-btn {
    padding: 9px 14px;
    background: #3a1a1a;
    border: 1px solid #7c2d12;
    border-radius: 7px;
    color: #f87171;
    font-size: 13px;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s;
}
.danger-btn:hover { background: #4a1a1a; }
