/* ── SIDEBAR ── */

:root{
    --surface:#262626;
    --border:#2e2e2e;
    --hover:#1e1e1e;
    --input-bg:#1e1e1e;
    --sidebar-w:260px;
}

#app{
    display:flex;
    height:100vh;
    width:100%;
    position:relative
}

#app textarea {
    scrollbar-color: var(--text-dim) transparent;
    scrollbar-width: thin;
}

.sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--bg);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    overflow: hidden;
    transition: width 0.3s ease, min-width 0.3s ease;
}

.sidebar.hidden {
    width: 0;
    min-width: 0;
}

.sidebar-backdrop {
    display: none;
}

.sidebar-open-btn {
    display: none;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: white;
    cursor: pointer;
    width: 32px;
    height: 32px;
    font-size: 16px;
}

.sidebar-open-btn:hover {
    background: var(--hover);
}

.sidebar-open-btn.visible {
    display: flex;
}

@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        width: var(--sidebar-w);
        min-width: var(--sidebar-w);
    }

    .sidebar.hidden {
        width: var(--sidebar-w);
        min-width: var(--sidebar-w);
        transform: translateX(-100%);
    }

    .sidebar.floating-open {
        transform: translateX(0);
    }

    .sidebar-backdrop {
        display: block;
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 99;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }

    .sidebar-backdrop.visible {
        opacity: 1;
        pointer-events: auto;
    }
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 10px;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 15px
}

.sidebar-logo .logo-circle {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
}

.sidebar-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: white;
    cursor: pointer;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.sidebar-toggle:hover {
    background: var(--hover)
}

.sidebar-nav {
    padding: 4px 10px;
    display: flex;
    flex-direction: column;
    gap: 1px
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 14px;
    color: white;
    cursor: pointer;
    text-decoration: none;

    transition: background-color, color 0.3s ease-in-out;
}

.nav-item:hover {
    background: var(--bg-raised);
    color: var(--text);

    transition: background-color, color 0.3s ease-in-out;
}

.nav-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0
}

.sidebar-section {
    padding: 6px 16px 2px;
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.sidebar-section-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: .5px
}

.chat-history-item {
    position: relative;
    display: flex;
    align-items: center;
    padding: 8px 12px;
    font-size: 13px;
    color: var(--text-dim);
    cursor: pointer;
    transition: background-color, color 0.1s ease-in-out;
}

.chat-history-item:hover {
    font-size: 13px;
    color: var(--text);
    background: var(--bg-raised);
    border-radius: 8px;
}

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

.chat-history-menu-btn {
    display: none;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 16px;
    width: 16px;
    height: 16px;
    border-radius: 4px;
    flex-shrink: 0;
}

.chat-history-item:hover .chat-history-menu-btn {
    display: flex;
}

.chat-history-menu-btn:hover {
    background: var(--surface);
    color: var(--text);
}

.chat-history-menu {
    display: none;
    position: absolute;
    right: 8px;
    top: 100%;
    background: var(--bg-popup);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px;
    z-index: 10;
    min-width: 80px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.chat-history-menu.open {
    display: block;
}

.chat-history-menu-delete {
    width: 100%;
    background: none;
    border: none;
    color: #ff5858;
    font-size: 13px;
    font-family: inherit;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    text-align: left;
}

.chat-history-menu-delete:hover {
    background: rgba(255, 88, 88, 0.1);
}

.model-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    margin: 2px 10px;
    border-radius: 8px;
    font-size: 13px;
    color: white;
    cursor: pointer;
}

.model-item:hover {
    background: var(--hover)
}

.model-icon {
    width: 24px;
    height: 16px;
    border-radius: 50%;
    border: 1.5px solid var(--text-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
}

.chat-date {
    font-size: 11px;
    color: var(--text-dim);
    padding: 8px 16px 4px;
    font-weight: 500
}

.chat-item {
    width: auto;

    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: end;
    justify-content: center;

    gap: 8px;
    padding: 12px 15px;
    margin: 1px 10px;
    font-size: 13px;

    color: white;
    background: var(--bg-popup);

    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;

}

.chat-item:hover {
    background: var(--bg-raised);
    color: var(--text);

    transition: background-color, color 0.3s ease-in-out;
}

.chat-item.active {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    color: var(--text);
}

.chat-item .emoji {
    font-size: 15px;
    flex-shrink: 0
}

.sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden
}

.sidebar-scroll::-webkit-scrollbar {
    width: 4px
}

.sidebar-scroll::-webkit-scrollbar-thumb {
    background: var(--text-dim);
    border-radius: 4px
}

.sidebar-footer {
    font-size: 11px;
    text-align: center;
    padding: 10px 12px;
}

/* ── MAIN ── */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden
}

/* Top bar */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 18px;
    min-height: 50px;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 8px
}

.topbar-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.topbar-title .chevron {
    font-size: 10px;
    color: var(--text-dim)
}

.topbar-title .plus {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 1.5px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    color: var(--text-dim);
    margin-left: 2px;
    cursor: pointer;
}

.topbar-title .plus:hover {
    border-color: white;
    color: var(--text)
}


.set-default:hover {
    color: white
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px
}

.topbar-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

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

.topbar-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    cursor: pointer;
}

/* Center content */
.main-center {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 0 20px 40px;
}

.center-logo {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 8px
}

.center-logo .logo-circle {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2.5px solid var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
}

.center-logo .model-name {
    font-size: 22px;
    font-weight: 300;
    letter-spacing: -.3px
}

/* Input */
.chat-input-wrap {
    width: 100%;
    max-width: 640px;
    background: var(--bg-popup);
    border-radius: 16px;
    padding: 14px 18px 10px;
}

.chat-input {
    width: 100%;
    background: none;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 15px;
    resize: none;
    font-family: inherit;
    overflow: hidden;
    max-height: 12em;
}

.chat-input::placeholder {
    color: var(--text-dim)
}

.input-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 8px;
}

.input-actions-left {
    display: flex;
    gap: 6px
}

.input-actions-right {
    display: flex;
    gap: 6px
}

.action-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: none;
    color: var(--text-dim);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

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

/* Suggestions */
.suggestions {
    width: 100%;
    max-width: 640px;
    margin-top: 8px
}

.suggestions-label {
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.suggestions-label .sparkle {
    font-size: 13px
}

.suggestion {
    padding: 10px 2px;
    cursor: pointer;
    border-bottom: 1px solid transparent;
}

.suggestion:hover .s-title {
    color: var(--text)
}

.s-title {
    font-size: 13.5px;
    font-weight: 600;
    color: white;
    transition: color .15s
}

.s-desc {
    font-size: 12.5px;
    color: var(--text-dim);
    margin-top: 1px
}

/* Toast */
.toast {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: #1e3a5f;
    color: #93c5fd;
    font-size: 12.5px;
    padding: 10px 18px;
    border-radius: 10px;
    display: flex;
    gap: 8px;
    align-items: center;
    border: 1px solid #2563eb33;
}

.toast a {
    color: #60a5fa;
    text-decoration: underline
}

.toast .close {
    background: none;
    border: none;
    color: #93c5fd;
    cursor: pointer;
    font-size: 16px;
    margin-left: 4px;
}

#sendBtn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: white;
    color: var(--text-dim);
}

#sendBtn[disabled] {
    background: darkgray;
    transition: background-color 0.3s ease-in-out;
}

/* Content */
.content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Chat Layout ── */

.chat-messages {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 16px 20px;
    overflow-y: auto;
    scrollbar-color: var(--text-dim) transparent;
    scrollbar-width: thin;
}

.chat-input-bottom {
    padding: 12px 20px 16px;
    border-top: 1px solid var(--border);
}

.chat-input-bottom .chat-input-wrap {
    max-width: 720px;
    margin: 0 auto;
}

/* ── Messages ── */

.msg {
    display: flex;
    max-width: 720px;
    width: 100%;
    margin: 0 auto;
}

.msg-user {
    justify-content: flex-end;
}

.msg-user .msg-bubble {
    background: var(--bg-popup);
    color: var(--text);
    padding: 10px 16px;
    border-radius: 16px 16px 4px 16px;
    max-width: 80%;
    font-size: 14px;
    line-height: 1.6;
    word-break: keep-all;
}

.msg-assistant {
    flex-direction: column;
    gap: 8px;
}

/* ── msg-text ── */

.msg-text {
    font-size: 14px;
    line-height: 1.7;
    color: var(--text);
    padding: 2px 0;
    word-break: keep-all;
}

.msg-text h1 {
    font-weight: 600;
    margin: 0.67em 0;
}

.msg-text h2 {
    font-weight: 600;
    margin: 0.45em 0;
}

.msg-text h3 {
    font-weight: 600;
    margin: 1em 0 0.5em 0;
}

.msg-text hr {
    margin: 2em 0 1em 0;
}

.msg-text strong {
    color: var(--accent);
    font-weight: 600;
}

.msg-text em {
    font-style: italic;
    padding: 0 2px;
}

.msg-text code {
    background: var(--bg-raised);
    color: var(--text);
    padding: 2px 4px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 13px;
}

.msg-text pre {
    margin: 1em 0;
    background: var(--bg-raised);
    color: var(--text);
    padding: 10px;
    border-radius: 8px;
}

.msg-text pre code {
    background: none;
    padding: 0;
    border-radius: 0;
    font-size: 13px;
}

.msg-text a {
    color: var(--accent);
    text-decoration: underline;
}

.msg-text .mention {
    color: var(--accent);
    font-weight: 600;
    padding: 0 2px;
}

.msg-text ol, ul {
    padding: 0.3em 2em;
}

.msg-text table {
    width: 100%;
    border-collapse: collapse;
    margin: 1em 0;
    font-weight: 600;
    border: 1px solid var(--border);
}

.msg-text table th {
    background: var(--bg-raised);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 0.5em 1em;
}

.msg-text table td {
    padding: 0.5em 1em;
    border: 1px solid var(--border);
}

/* ── msg-image ── */

.msg-image {
    max-width: 100%;
}

.msg-image img {
    max-width: 100%;
    border-radius: var(--radius);
    cursor: pointer;
    transition: opacity var(--transition);
}

.msg-image img:hover {
    opacity: 0.85;
}

/* ── msg-reasoning ── */

.msg-reasoning {
    border-left: 2px solid var(--text-faint);
    padding-left: 12px;
    margin: 4px 0;
}

.reasoning-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-dim);
    user-select: none;
    padding: 4px 0;
}

.reasoning-toggle:hover {
    color: var(--text);
}

.reasoning-icon {
    font-size: 10px;
    color: var(--accent-dim);
}

.reasoning-chevron {
    font-size: 10px;
    transition: transform 0.2s ease;
}

.msg-reasoning.expanded .reasoning-chevron {
    transform: rotate(90deg);
}

.reasoning-content {
    max-height: 0;
    overflow: hidden;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-dim);
    transition: max-height 0.3s ease, padding 0.3s ease;
    padding: 0;
}

.msg-reasoning.expanded .reasoning-content {
    max-height: 500px;
    padding: 6px 0 4px;
}

/* ── msg-tool-call ── */

.msg-tool-call {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin: 4px 0;
}

.tool-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    user-select: none;
}

.tool-header:hover {
    background: var(--bg-popup);
}

.tool-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid var(--text-faint);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

.tool-spinner.done {
    border: 2px solid var(--accent);
    animation: none;
    background: var(--accent);
}

.tool-spinner.error {
    border: 2px solid var(--mic-on);
    animation: none;
    background: var(--mic-on);
}

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

.tool-name {
    font-family: monospace;
    color: var(--accent);
    font-weight: 500;
}

.tool-status {
    color: var(--text-dim);
    font-size: 12px;
    margin-left: auto;
}

.msg-tool-call.done .tool-status {
    color: var(--accent-dim);
}

.msg-tool-call.error .tool-status {
    color: var(--mic-on);
}

.tool-chevron {
    font-size: 10px;
    color: var(--text-faint);
    transition: transform 0.2s ease;
}

.msg-tool-call.expanded .tool-chevron {
    transform: rotate(90deg);
}

.tool-args {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
    border-top: 1px solid transparent;
}

.msg-tool-call.expanded .tool-args {
    max-height: 300px;
    padding: 8px 12px;
    border-top-color: var(--border);
}

.tool-args pre {
    font-size: 12px;
    color: var(--text-dim);
    white-space: pre-wrap;
    word-break: break-all;
    margin: 0;
    font-family: monospace;
}

/* ── msg-tool-result (hidden by default) ── */

.msg-tool-result {
    display: none;
}

/* ── msg-error ── */

.msg-error {
    background: rgba(255, 88, 88, 0.1);
    border: 1px solid rgba(255, 88, 88, 0.2);
    color: var(--mic-on);
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
}

/* ── Voice Mode ── */

.voice-mode {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2rem;
}

.voice-status-area {
    text-align: center;
}

.voice-status-text {
    font-size: 1.1rem;
    color: var(--text-dim);
    transition: color var(--transition);
}
.voice-mode[data-state="listening"] .voice-status-text { color: var(--accent); }
.voice-mode[data-state="speaking"] .voice-status-text { color: var(--text); }

.voice-visual {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

/* Orb: empty ↔ filled transition */
.voice-orb {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: transparent;
    border: 2px solid var(--text-faint);
    box-shadow: none;
    transition: background 0.5s ease, border-color 0.5s ease,
                box-shadow 0.5s ease, transform 0.15s ease;
}

/* idle / connecting: 빈 원, 미세한 pulse */
.voice-mode[data-state="idle"] .voice-orb,
.voice-mode[data-state="connecting"] .voice-orb {
    animation: voice-idle-pulse 3s ease-in-out infinite;
}

/* listening: 빈 원 + accent 테두리 + glow */
.voice-mode[data-state="listening"] .voice-orb {
    background: transparent;
    border-color: var(--accent);
    box-shadow: 0 0 40px rgba(57, 230, 224, 0.15);
    animation: voice-listen-pulse 2s ease-in-out infinite;
}

/* speaking: 채워진 원 + 강한 glow */
.voice-mode[data-state="speaking"] .voice-orb {
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 0 60px rgba(57, 230, 224, 0.3);
    animation: voice-speak-pulse 1.2s ease-in-out infinite;
}

.voice-waveform {
    display: flex;
    align-items: center;
    gap: 2px;
    height: 48px;
    opacity: 0;
    transition: opacity 0.3s;
}
.voice-mode[data-state="listening"] .voice-waveform { opacity: 1; }

.voice-waveform .wave-bar {
    width: 3px;
    min-height: 6px;
    border-radius: 2px;
    background: var(--accent);
    transition: height 0.05s ease;
}

.voice-footer {
    margin-top: 1rem;
}

.voice-end-btn {
    padding: 0.6rem 1.5rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    font-family: inherit;
    font-size: 14px;
    transition: all var(--transition);
}
.voice-end-btn:hover {
    border-color: var(--mic-on);
    color: var(--mic-on);
}

@keyframes voice-idle-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.03); }
}
@keyframes voice-listen-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.06); }
}
@keyframes voice-speak-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

