@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;700&display=swap');

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

:root {
    --blue: #29a7ff;
    --blue-dark: #1e8fd4;
    --green: #a9e03b;
    --orange: #ff7324;
    --bg: #ffffff;
    --bg-gray: #f3f4f6;
    --text: #111827;
    --text-body: #4b5563;
    --text-muted: #9ca3af;
    --border: #e5e7eb;
    --user-bubble: #29a7ff;
    --assistant-bubble: #f3f4f6;
    --sidebar-width: 280px;
}

/* Dev-mode blue override */
body.dev-mode {
    --blue: #2563eb;
    --blue-dark: #1d4ed8;
    --green: #2563eb;
    --orange: #2563eb;
    --user-bubble: #2563eb;
}
body.dev-mode .sidebar-header,
body.dev-mode #chat-header {
    border-bottom: 2px solid #2563eb;
}
body.dev-mode .dev-badge {
    display: inline-block;
    background: #2563eb;
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 8px;
    vertical-align: middle;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

html, body {
    height: 100%;
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

.screen { display: flex; height: 100%; width: 100%; }
.hidden { display: none !important; }

/* tiroir-glow animated brand text */
.tiroir-glow {
    text-transform: lowercase;
    background-image: linear-gradient(
        115deg,
        #a9e03b 0%, #29a7ff 18%, #ff7324 36%,
        #a9e03b 54%, #29a7ff 72%, #ff7324 90%, #a9e03b 108%
    );
    color: transparent;
    -webkit-text-fill-color: transparent;
    background-repeat: repeat;
    background-size: 250% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    font-weight: 700;
    animation: 12s linear infinite drawerFlow;
}
@keyframes drawerFlow {
    0% { background-position: 0%; }
    50% { background-position: 100%; }
    100% { background-position: 0%; }
}

/* Auth Screen */
#auth-screen {
    justify-content: center;
    align-items: center;
    flex-direction: column;
    background: var(--bg);
}
.auth-container {
    text-align: center;
    width: 100%;
    max-width: 400px;
    padding: 2rem;
}
.auth-logo {
    width: 80px;
    height: 80px;
    margin: 0 auto 1rem;
}
.logo {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}
.tagline {
    color: var(--text-muted);
    margin-bottom: 2rem;
    font-size: 1rem;
}

.auth-error {
    color: var(--orange);
    font-size: 0.875rem;
    margin-top: 1rem;
}

.app-version {
    color: var(--text-muted);
    font-size: 0.7rem;
    margin-top: 2rem;
    opacity: 0.5;
}

/* Hanko Elements Styling */
hanko-auth {
    --color: var(--text);
    --color-shade-1: var(--text-body);
    --brand-color: var(--blue);
    --brand-color-shade-1: var(--blue-dark);
    --background-color: var(--bg);
    --border-radius: 12px;
}

/* Sidebar */
#sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100%;
}
.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}
.sidebar-logo-icon {
    height: 24px;
    width: 24px;
    flex-shrink: 0;
}
.search-container {
    flex: 1;
    position: relative;
    min-width: 0;
}
#search-input {
    width: 100%;
    padding: 0.4rem 0.7rem;
    background: var(--bg-gray);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.85rem;
    font-family: inherit;
    color: var(--text);
    outline: none;
    transition: border-color 0.2s;
}
#search-input:focus { border-color: var(--blue); }
#search-input::placeholder { color: var(--text-muted); }
#search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
    max-height: 280px;
    overflow-y: auto;
    z-index: 20;
}
.search-result-item {
    padding: 0.6rem 0.8rem;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-body);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.1s;
}
.search-result-item:first-child { border-radius: 10px 10px 0 0; }
.search-result-item:last-child { border-radius: 0 0 10px 10px; }
.search-result-item:only-child { border-radius: 10px; }
.search-result-item:hover, .search-result-item.active {
    background: var(--bg-gray);
    color: var(--text);
}
.search-result-item.search-action {
    color: var(--blue);
    font-style: italic;
    border-top: 1px solid var(--border);
}
.search-result-item mark {
    background: rgba(41, 167, 255, 0.15);
    color: inherit;
    border-radius: 2px;
    padding: 0 1px;
}
#new-chat-btn {
    background: linear-gradient(90deg, var(--blue), var(--blue-dark));
    color: white;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
}
#new-chat-btn:hover { transform: scale(1.05); }

#conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}
.conv-item {
    padding: 0.75rem 1rem;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2px;
    font-size: 0.9rem;
    color: var(--text-body);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.15s;
}
.conv-item:hover { background: var(--bg-gray); }
.conv-item.active {
    background: var(--bg-gray);
    color: var(--text);
    font-weight: 500;
}
.conv-item .conv-title {
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}
.conv-item .conv-delete {
    display: none;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 4px;
    font-size: 1rem;
}
.conv-item:hover .conv-delete { display: block; }

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--border);
}
#logout-btn {
    width: 100%;
    padding: 0.5rem;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.85rem;
    font-family: inherit;
    transition: all 0.2s;
}
#logout-btn:hover { border-color: var(--blue); color: var(--blue); }

/* Chat Area */
#chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg);
    position: relative;
}
#chat-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 500;
    color: var(--text);
    background: var(--bg);
}
#menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text);
    font-size: 1.3rem;
    cursor: pointer;
}

#messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

#empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--text-muted);
    font-size: 1.1rem;
    pointer-events: none;
    text-align: center;
}
#empty-state img {
    width: 48px;
    height: 48px;
    margin: 0 auto 0.75rem;
    opacity: 0.5;
}
#chat-area:has(.message) #empty-state { display: none; }

.message {
    max-width: 75%;
    padding: 0.75rem 1rem;
    border-radius: 16px;
    line-height: 1.6;
    word-wrap: break-word;
    font-size: 0.95rem;
}
.message.user { white-space: pre-wrap; }

/* Photo attachment in messages */
.msg-photo {
    max-width: 240px;
    max-height: 240px;
    border-radius: 12px;
    cursor: pointer;
    display: block;
    margin-bottom: 4px;
    transition: opacity 0.2s;
}
.msg-photo:hover { opacity: 0.85; }
.msg-audio {
    width: 100%;
    max-width: 280px;
    height: 36px;
    border-radius: 8px;
    display: block;
    margin-bottom: 4px;
}
.msg-doc-icon { display: block; font-size: 0.9rem; margin-bottom: 4px; }

/* Fullscreen image overlay */
.fullscreen-image {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    cursor: pointer;
}
.fullscreen-image img {
    max-width: 95vw;
    max-height: 95vh;
    border-radius: 8px;
}
.fullscreen-image .close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
}

/* Markdown in assistant messages */
.message.assistant p { margin: 0.4em 0; }
.message.assistant p:first-child { margin-top: 0; }
.message.assistant p:last-child { margin-bottom: 0; }
.message.assistant ul, .message.assistant ol { margin: 0.4em 0; padding-left: 1.5em; }
.message.assistant code {
    background: rgba(0,0,0,0.06);
    padding: 0.15em 0.4em;
    border-radius: 4px;
    font-size: 0.88em;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
}
.message.assistant pre {
    background: #1a1a2e;
    color: #eee;
    padding: 0.75em 1em;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.5em 0;
}
.message.assistant pre code {
    background: none;
    padding: 0;
    color: inherit;
}
.message.assistant strong { font-weight: 600; }
.message.assistant a { color: var(--blue); }
.message.assistant h1, .message.assistant h2, .message.assistant h3 {
    margin: 0.6em 0 0.3em;
    font-weight: 600;
}
.message.assistant h1 { font-size: 1.1em; }
.message.assistant h2 { font-size: 1.05em; }
.message.assistant h3 { font-size: 1em; }
.message.assistant blockquote {
    border-left: 3px solid var(--blue);
    padding-left: 0.75em;
    margin: 0.4em 0;
    color: var(--text-body);
}
.message.assistant table { border-collapse: collapse; margin: 0.5em 0; font-size: 0.9em; }
.message.assistant th, .message.assistant td { border: 1px solid var(--border); padding: 0.4em 0.6em; }
.message.assistant th { background: var(--bg-gray); font-weight: 600; }

.message.user {
    align-self: flex-end;
    background: var(--user-bubble);
    color: white;
    border-bottom-right-radius: 4px;
}
.message.assistant {
    align-self: flex-start;
    background: var(--assistant-bubble);
    color: var(--text);
    border-bottom-left-radius: 4px;
}
/* System messages (login, status, etc.) */
.message.system {
    align-self: center;
    max-width: 90%;
    background: transparent;
    color: var(--text-body);
    font-size: 0.88rem;
    text-align: center;
    padding: 0.5rem 1rem;
}
.message.system a {
    color: var(--blue);
    word-break: break-all;
}
.message.system.success { color: var(--green); font-weight: 500; }
.message.system.error { color: var(--orange); font-weight: 500; }

/* Thinking: tiroir text with fast gradient + status */
.thinking-logo {
    display: flex;
    align-items: center;
    gap: 10px;
}
.thinking-logo .thinking-text {
    font-weight: 700;
    font-size: 1.1rem;
    text-transform: lowercase;
    background-image: linear-gradient(115deg,
        #a9e03b 0%, #29a7ff 18%, #ff7324 36%,
        #a9e03b 54%, #29a7ff 72%, #ff7324 90%, #a9e03b 108%);
    background-size: 250% 100%;
    color: transparent;
    -webkit-text-fill-color: transparent;
    -webkit-background-clip: text;
    background-clip: text;
    animation: drawerFlow 1.5s linear infinite;
}
.thinking-logo .thinking-status {
    color: var(--text-muted);
    font-size: 0.85rem;
    animation: pulse 1.5s infinite;
}
@keyframes pulse { 50% { opacity: 0.4; } }

/* File preview */
#file-preview {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-gray);
    border-top: 1px solid var(--border);
}
#file-preview-content {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-body);
    overflow: hidden;
}
#file-preview-content img {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 8px;
}
#file-preview-content .file-icon {
    font-size: 1.5rem;
}
#file-preview-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 50%;
    transition: all 0.2s;
}
#file-preview-remove:hover {
    background: var(--border);
    color: var(--text);
}

/* Recording indicator */
#recording-indicator {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: #fef2f2;
    border-top: 1px solid #fecaca;
}
.recording-dot {
    width: 12px;
    height: 12px;
    background: #ef4444;
    border-radius: 50%;
    animation: recordPulse 1s ease-in-out infinite;
}
@keyframes recordPulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.8); }
}
#recording-time {
    font-size: 0.9rem;
    font-weight: 500;
    color: #ef4444;
    font-variant-numeric: tabular-nums;
}
#recording-cancel {
    margin-left: auto;
    background: none;
    border: 1px solid #fecaca;
    color: #ef4444;
    padding: 0.25rem 0.75rem;
    border-radius: 8px;
    font-size: 0.8rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
}
#recording-cancel:hover {
    background: #fecaca;
}

/* Upload progress */
.upload-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--border);
}
.upload-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--blue), var(--green));
    transition: width 0.3s ease;
    border-radius: 0 0 16px 16px;
}

/* Input */
#chat-form {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
    background: var(--bg);
}
.input-row {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}
#attach-btn, #mic-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 0.4rem;
    border-radius: 50%;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
#attach-btn:hover, #mic-btn:hover {
    background: var(--bg-gray);
    color: var(--blue);
}
#mic-btn.recording {
    color: #ef4444;
    background: #fef2f2;
}
#message-input {
    flex: 1;
    background: var(--bg-gray);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    padding: 0.75rem 1rem;
    font-size: 1rem;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    outline: none;
    transition: border-color 0.2s;
}
#message-input:focus { border-color: var(--blue); }
#send-btn {
    background: linear-gradient(90deg, var(--blue), var(--blue-dark));
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.1rem;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s;
}
#send-btn:hover { transform: scale(1.05); }
#send-btn:disabled { opacity: 0.4; cursor: default; transform: none; }

/* Sidebar overlay (mobile) */
#sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 9;
}

/* Mobile */
@media (max-width: 768px) {
    #sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        bottom: 0;
        z-index: 10;
        transition: left 0.2s ease;
        box-shadow: 2px 0 12px rgba(0,0,0,0.1);
    }
    #sidebar.open { left: 0; }
    #menu-btn { display: block; }
    .message { max-width: 90%; }
}
