/* Claude Chat — Dark Theme */
:root {
    --bg-primary: #212121;
    --bg-secondary: #1a1a1a;
    --bg-sidebar: #171717;
    --bg-input: #2f2f2f;
    --bg-hover: #2a2a2a;
    --bg-user-msg: #2f2f2f;
    --bg-tool: #1e2a1e;
    --text-primary: #ececec;
    --text-secondary: #b4b4b4;
    --text-muted: #8e8e8e;
    --border: #3a3a3a;
    --border-light: #2a2a2a;
    --accent: #2196F3;
    --accent-hover: #1976D2;
    --accent-light: rgba(33, 150, 243, 0.15);
    --danger: #e53935;
    --success: #4caf50;
    --warning: #ff9800;
    --sidebar-width: 260px;
    --header-height: 52px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --transition: 0.2s ease;
}

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

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-primary);
    overflow: hidden;
}

.hidden { display: none !important; }

.screen {
    width: 100%;
    height: 100%;
}

/* ===== LOGIN ===== */
#login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
}

.login-card {
    width: 100%;
    max-width: 380px;
    padding: 40px 32px;
    text-align: center;
}

.login-logo { margin-bottom: 16px; }

.login-title {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 4px;
}

.login-subtitle {
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 32px;
}

.form-group { margin-bottom: 16px; }

.form-group input {
    width: 100%;
    padding: 12px 16px;
    font-size: 15px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    outline: none;
    transition: border var(--transition);
}

.form-group input:focus {
    border-color: var(--accent);
}

.form-group input::placeholder { color: var(--text-muted); }

.btn-primary {
    width: 100%;
    padding: 12px;
    font-size: 15px;
    font-weight: 600;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition);
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.error-msg {
    margin-top: 12px;
    padding: 8px 12px;
    font-size: 13px;
    color: var(--danger);
    background: rgba(229, 57, 53, 0.1);
    border-radius: var(--radius-sm);
}

/* ===== CHAT LAYOUT ===== */
#chat-screen {
    display: flex;
    height: 100vh;
}

/* Sidebar */
#sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    transition: transform var(--transition);
}

.sidebar-header {
    padding: 12px;
}

.btn-new-chat {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition);
}

.btn-new-chat:hover { background: var(--bg-hover); }

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 8px;
}

.chat-list::-webkit-scrollbar { width: 4px; }
.chat-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.chat-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    margin-bottom: 2px;
    font-size: 13px;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition);
    position: relative;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.chat-item.active { background: var(--bg-input); color: var(--text-primary); }

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

.chat-owner-badge {
    flex-shrink: 0;
    font-size: 10px;
    padding: 1px 5px;
    margin-left: 4px;
    border-radius: 3px;
    background: var(--accent-light);
    color: var(--accent);
    white-space: nowrap;
    line-height: 1.4;
}

.chat-item-delete {
    display: none;
    padding: 2px 6px;
    font-size: 16px;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
}

.chat-item:hover .chat-item-delete { display: block; }
.chat-item-delete:hover { color: var(--danger); }

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}

.role-badge {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
    text-transform: uppercase;
}

.role-badge.admin { background: var(--accent-light); color: var(--accent); }
.role-badge.user { background: rgba(76,175,80,0.15); color: var(--success); }

.btn-ghost {
    padding: 6px 12px;
    font-size: 13px;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    transition: color var(--transition);
}

.btn-ghost:hover { color: var(--text-primary); }

/* Main area */
#main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-primary);
}

/* Header */
#chat-header {
    height: var(--header-height);
    min-height: var(--header-height);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    border-bottom: 1px solid var(--border-light);
}

.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    color: var(--text-secondary);
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition);
}

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

.chat-title {
    flex: 1;
    font-size: 15px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.model-select {
    padding: 6px 10px;
    font-size: 13px;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
    cursor: pointer;
}

.model-select option { background: var(--bg-secondary); }

.cost-badge {
    font-size: 12px;
    padding: 4px 8px;
    color: var(--text-muted);
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    font-family: monospace;
}

/* Messages */
.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px 0;
    scroll-behavior: smooth;
}

.messages-area::-webkit-scrollbar { width: 6px; }
.messages-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
}

.welcome-icon { margin-bottom: 16px; opacity: 0.7; }
.welcome h2 { font-size: 24px; font-weight: 600; margin-bottom: 8px; color: var(--text-secondary); }
.welcome p { font-size: 15px; }

/* Message bubbles */
.message {
    max-width: 800px;
    margin: 0 auto;
    padding: 12px 24px;
}

.message-user {
    padding: 16px 24px;
    display: flex;
    justify-content: flex-end;
}

.message-user .message-content {
    background: var(--bg-user-msg);
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    max-width: 85%;
    white-space: pre-wrap;
    word-break: break-word;
}

.message-assistant {
    padding: 16px 24px;
}

.message-assistant .message-content {
    line-height: 1.7;
    word-break: break-word;
}

/* Tool use indicator */
.tool-block {
    margin: 8px 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    font-size: 13px;
}

.tool-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-tool);
    color: var(--success);
    cursor: pointer;
    user-select: none;
}

.tool-header svg { flex-shrink: 0; }

.tool-body {
    display: none;
    padding: 8px 12px;
    background: var(--bg-secondary);
    font-family: 'SF Mono', Consolas, monospace;
    font-size: 12px;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 300px;
    overflow-y: auto;
    color: var(--text-secondary);
}

.tool-block.open .tool-body { display: block; }
.tool-block.open .tool-chevron { transform: rotate(90deg); }

/* Markdown styles */
.message-assistant .message-content h1,
.message-assistant .message-content h2,
.message-assistant .message-content h3 {
    margin: 16px 0 8px;
    font-weight: 600;
}

.message-assistant .message-content h1 { font-size: 20px; }
.message-assistant .message-content h2 { font-size: 17px; }
.message-assistant .message-content h3 { font-size: 15px; }

.message-assistant .message-content p { margin: 8px 0; }

.message-assistant .message-content ul,
.message-assistant .message-content ol {
    margin: 8px 0;
    padding-left: 24px;
}

.message-assistant .message-content li { margin: 4px 0; }

.message-assistant .message-content a {
    color: var(--accent);
    text-decoration: none;
}

.message-assistant .message-content a:hover { text-decoration: underline; }

.message-assistant .message-content blockquote {
    margin: 8px 0;
    padding: 4px 16px;
    border-left: 3px solid var(--border);
    color: var(--text-secondary);
}

.message-assistant .message-content table {
    border-collapse: collapse;
    margin: 12px 0;
    width: 100%;
    font-size: 14px;
}

.message-assistant .message-content th,
.message-assistant .message-content td {
    padding: 8px 12px;
    border: 1px solid var(--border);
    text-align: left;
}

.message-assistant .message-content th { background: var(--bg-secondary); font-weight: 600; }

/* Code blocks */
.message-assistant .message-content code {
    font-family: 'SF Mono', Consolas, 'Courier New', monospace;
    font-size: 13px;
}

.message-assistant .message-content :not(pre) > code {
    background: var(--bg-input);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}

.code-block {
    margin: 12px 0;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border);
}

.code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    background: #1a1a2e;
    font-size: 12px;
    color: var(--text-muted);
}

.code-copy {
    padding: 2px 8px;
    font-size: 11px;
    color: var(--text-muted);
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    transition: all var(--transition);
}

.code-copy:hover { color: var(--text-primary); border-color: var(--text-muted); }
.code-copy.copied { color: var(--success); border-color: var(--success); }

.code-block pre {
    margin: 0;
    padding: 12px 16px;
    overflow-x: auto;
    background: #0d1117;
}

.code-block pre code {
    font-size: 13px;
    line-height: 1.5;
}

/* Thinking indicator */
.thinking {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 24px;
    max-width: 800px;
    margin: 0 auto;
}

.thinking-dots {
    display: flex;
    gap: 4px;
}

.thinking-dots span {
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: 50%;
    animation: dot-pulse 1.4s infinite ease-in-out;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-pulse {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1); }
}

.thinking-label {
    font-size: 13px;
    color: var(--text-muted);
}

.btn-stop {
    padding: 4px 12px;
    font-size: 12px;
    color: var(--danger);
    background: none;
    border: 1px solid var(--danger);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    margin-left: auto;
}

.btn-stop:hover { background: rgba(229, 57, 53, 0.1); }

/* Input area */
.input-wrapper {
    padding: 12px 24px 20px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 8px 12px;
    transition: border var(--transition);
}

.input-area:focus-within { border-color: var(--accent); }

#message-input {
    flex: 1;
    max-height: 200px;
    padding: 6px 4px;
    font-size: 15px;
    font-family: inherit;
    line-height: 1.5;
    color: var(--text-primary);
    background: none;
    border: none;
    outline: none;
    resize: none;
    overflow-y: auto;
}

#message-input::placeholder { color: var(--text-muted); }

.btn-send {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    color: #fff;
    background: var(--accent);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    flex-shrink: 0;
    transition: all var(--transition);
}

.btn-send:hover { background: var(--accent-hover); }
.btn-send:disabled { opacity: 0.3; cursor: not-allowed; }

/* Attach button */
.btn-attach {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    color: var(--text-muted);
    background: none;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    flex-shrink: 0;
    transition: all var(--transition);
}

.btn-attach:hover { color: var(--text-primary); background: var(--bg-hover); }

/* Image preview strip */
.image-preview {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    overflow-x: auto;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.image-preview::-webkit-scrollbar { height: 4px; }
.image-preview::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.img-thumb {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: var(--radius-md);
    overflow: hidden;
    flex-shrink: 0;
    border: 1px solid var(--border);
}

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

.img-thumb-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: #fff;
    background: rgba(0,0,0,0.6);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    line-height: 1;
}

.img-thumb-remove:hover { background: var(--danger); }

/* Images in messages */
.msg-images {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.msg-images img {
    max-width: 200px;
    max-height: 200px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: opacity var(--transition);
}

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

.assistant-images {
    margin-top: 12px;
    margin-bottom: 0;
}

.assistant-images img {
    max-width: 100%;
    max-height: 400px;
}

/* Images in assistant messages (markdown + appended) */
.message-content img.chat-image,
.message-content p img {
    max-width: 100%;
    max-height: 400px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: opacity var(--transition);
    display: block;
    margin: 8px 0;
}

.message-content img.chat-image:hover,
.message-content p img:hover { opacity: 0.85; }

/* Drag overlay */
.drag-overlay {
    position: fixed;
    inset: 0;
    background: rgba(33, 150, 243, 0.1);
    border: 3px dashed var(--accent);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--accent);
    pointer-events: none;
}

/* Image modal (fullscreen view) */
.img-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.85);
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.img-modal img {
    max-width: 95vw;
    max-height: 95vh;
    object-fit: contain;
    border-radius: var(--radius-md);
}

/* Sidebar overlay (mobile) */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 90;
}

/* ===== ADMIN MODAL ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 400;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 500px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.modal-close:hover { color: var(--text-primary); }

.modal-body {
    padding: 16px 20px;
    overflow-y: auto;
}

.users-list {
    margin-bottom: 16px;
}

.user-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-light);
    margin-bottom: 8px;
    background: var(--bg-secondary);
}

.user-row-info {
    flex: 1;
    min-width: 0;
}

.user-row-name {
    font-weight: 500;
    color: var(--text-primary);
    font-size: 14px;
}

.user-row-login {
    font-size: 12px;
    color: var(--text-muted);
}

.user-row .role-badge {
    font-size: 10px;
    flex-shrink: 0;
}

.user-row-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.user-row-actions button {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    font-size: 12px;
    transition: all var(--transition);
}

.user-row-actions button:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.user-row-actions .btn-delete:hover {
    border-color: var(--danger);
    color: var(--danger);
}

.user-form {
    border-top: 1px solid var(--border);
    padding-top: 16px;
}

.user-form h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.user-form input,
.user-form select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 14px;
    margin-bottom: 8px;
    outline: none;
}

.user-form input:focus,
.user-form select:focus {
    border-color: var(--accent);
}

.user-form-buttons {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

.user-form-buttons .btn-primary {
    padding: 8px 20px;
    font-size: 13px;
}

.user-form-buttons .btn-ghost {
    padding: 8px 16px;
    font-size: 13px;
}

.sidebar-footer-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
}

#admin-btn {
    padding: 4px 8px;
    display: flex;
    align-items: center;
}

#admin-btn svg {
    opacity: 0.7;
}

#admin-btn:hover svg {
    opacity: 1;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    #sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 100;
        transform: translateX(-100%);
    }

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

    .message { padding: 8px 12px; }
    .message-user { padding: 12px; }
    .message-assistant { padding: 12px; }
    .input-wrapper { padding: 8px 12px 12px; }
    .thinking { padding: 8px 12px; }

    .message-user .message-content { max-width: 95%; }
}

@media (min-width: 769px) {
    #sidebar-toggle { display: none; }
}
