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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #fff;
    color: #333;
    height: 100vh;
    overflow: hidden;
}

.hidden { display: none !important; }

/* ── KASTOR BRAND COLORS ───────────────────────────────────── */
:root {
    --kastor-dark: #1a3d3d;
    --kastor-yellow: #f4b942;
    --kastor-orange: #f5a623;
    --kastor-text: #333;
    --kastor-gray: #666;
    --kastor-light-gray: #999;
}

/* ── LOGIN ────────────────────────────────────────────────── */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: #fff;
    padding: 2rem;
}

.login-card {
    background: #fff;
    padding: 3rem;
    border-radius: 20px;
    box-shadow: 0 10px 60px rgba(0,0,0,0.08);
    width: 420px;
    max-width: 100%;
    text-align: center;
}

.login-logo {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--kastor-dark);
    margin-bottom: 1rem;
}

.portal-badge {
    display: inline-block;
    background: #f5f5f5;
    color: var(--kastor-gray);
    padding: 0.5rem 1.5rem;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-bottom: 2rem;
}

.login-card form {
    text-align: left;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--kastor-light-gray);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}

.form-group input {
    width: 100%;
    padding: 1rem;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: #fff;
}

.form-group input:focus {
    border-color: var(--kastor-yellow);
    box-shadow: 0 0 0 3px rgba(244, 185, 66, 0.1);
}

.form-group input::placeholder {
    color: #ccc;
}

.login-error {
    background: #fff0f0;
    color: #cc0000;
    padding: 0.75rem;
    border-radius: 8px;
    font-size: 0.85rem;
    margin-bottom: 1rem;
    text-align: center;
}

#login-btn {
    width: 100%;
    padding: 1rem;
    background: var(--kastor-dark);
    color: var(--kastor-yellow);
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    cursor: pointer;
    transition: background 0.2s;
    margin-top: 0.5rem;
}

#login-btn:hover {
    background: #0f2e2e;
}

.login-footer-text {
    color: var(--kastor-light-gray);
    font-size: 0.8rem;
    margin-top: 1.5rem;
}

/* ── APP CONTAINER ──────────────────────────────────────────── */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: #f5f5f5;
}

/* ── HEADER ───────────────────────────────────────────────── */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    background: var(--kastor-dark);
    color: #fff;
    flex-shrink: 0;
}

.app-header h1 { 
    font-size: 1.2rem; 
    font-weight: 600; 
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.85rem;
}

.user-email { opacity: 0.9; }

.user-role {
    background: rgba(255,255,255,0.2);
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
    font-size: 0.75rem;
    text-transform: uppercase;
}

.logout-btn {
    background: rgba(255,255,255,0.15);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.3);
    padding: 0.4rem 0.8rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: background 0.2s;
}

.logout-btn:hover { background: rgba(255,255,255,0.25); }

/* ── TABS ──────────────────────────────────────────────────── */
.tabs {
    display: flex;
    background: #fff;
    border-bottom: 1px solid #e0e0e0;
    flex-shrink: 0;
}

.tab {
    padding: 0.75rem 1.5rem;
    border: none;
    background: none;
    font-size: 0.9rem;
    cursor: pointer;
    color: #888;
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
}

.tab:hover { color: #333; }
.tab.active { color: var(--kastor-dark); border-bottom-color: var(--kastor-yellow); font-weight: 500; }

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

/* ── SIDEBAR ──────────────────────────────────────────────── */
.sidebar {
    width: 280px;
    flex-shrink: 0;
    background: #fff;
    border-right: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar.hidden { display: none; }

.new-conv-btn {
    margin: 1rem;
    padding: 0.75rem;
    background: var(--kastor-dark);
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.2s;
    flex-shrink: 0;
}

.new-conv-btn:hover { background: #0f2e2e; }

.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 0.5rem 0.5rem;
}

.conv-item {
    padding: 0.75rem;
    margin-bottom: 0.25rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    color: #444;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.15s;
}

.conv-item:hover { background: #f0f0f0; }
.conv-item.active { background: #e8f4f8; font-weight: 500; color: var(--kastor-dark); }

.conv-item-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    margin-right: 0.5rem;
}

.conv-item-delete {
    background: none;
    border: none;
    color: #bbb;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0 0.2rem;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
}

.conv-item:hover .conv-item-delete { opacity: 1; }
.conv-item-delete:hover { color: #cc0000; }

/* ── CONTENT ──────────────────────────────────────────────── */
.content {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.tab-content { display: none; flex: 1; flex-direction: column; }
.tab-content.active { display: flex; }

/* ── CHAT ─────────────────────────────────────────────────── */
#tab-chat {
    background: #f9f9f9;
}

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

.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #ccc;
}

.chat-empty-icon {
    width: 60px;
    height: 60px;
    border: 2px dashed #ddd;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: #ddd;
    margin-bottom: 1rem;
}

.chat-empty p { font-size: 0.9rem; color: #999; }

.chat-message {
    padding: 1rem 1.25rem;
    border-radius: 12px;
    max-width: 75%;
    line-height: 1.6;
    font-size: 0.95rem;
    word-wrap: break-word;
}

.chat-message.user {
    background: var(--kastor-dark);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.chat-message.assistant {
    background: #fff;
    border: 1px solid #e8e8e8;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.chat-message.assistant h1, .chat-message.assistant h2, .chat-message.assistant h3 {
    margin: 0.6rem 0 0.3rem;
    font-size: 1rem;
    font-weight: 600;
}

.chat-message.assistant p { margin-bottom: 0.5rem; }
.chat-message.assistant p:last-child { margin-bottom: 0; }
.chat-message.assistant ul, .chat-message.assistant ol { margin: 0.3rem 0 0.5rem 1.2rem; }
.chat-message.assistant li { margin-bottom: 0.2rem; }
.chat-message.assistant code {
    background: #f0f0f0;
    padding: 0.15em 0.4em;
    border-radius: 3px;
    font-family: 'SFMono-Regular', Consolas, monospace;
    font-size: 0.9em;
}
.chat-message.assistant pre {
    background: #f5f5f5;
    border: 1px solid #e8e8e8;
    padding: 0.75rem;
    border-radius: 6px;
    overflow-x: auto;
    margin: 0.5rem 0;
}
.chat-message.assistant pre code { background: none; padding: 0; font-size: 0.85em; }
.chat-message.assistant table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.5rem 0;
    font-size: 0.85rem;
}
.chat-message.assistant th, .chat-message.assistant td {
    border: 1px solid #e0e0e0;
    padding: 0.4rem 0.75rem;
    text-align: left;
}
.chat-message.assistant th { background: #f5f5f5; font-weight: 600; }
.chat-message.assistant blockquote {
    border-left: 3px solid #ddd;
    padding-left: 0.75rem;
    color: #777;
    margin: 0.4rem 0;
}
.chat-message.assistant strong { font-weight: 600; }
.chat-message.assistant em { font-style: italic; }
.chat-message.assistant a { color: var(--kastor-dark); }

.chat-message.streaming { border-left: 3px solid var(--kastor-yellow); }

/* Typing indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0.5rem 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #ccc;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

.chat-input-area {
    display: flex;
    gap: 0.75rem;
    padding: 1.25rem 1.5rem;
    background: #fff;
    border-top: 1px solid #e8e8e8;
    flex-shrink: 0;
}

.chat-input-area textarea {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    outline: none;
    resize: none;
    min-height: 44px;
    max-height: 120px;
    transition: border-color 0.2s;
}

.chat-input-area textarea:focus { border-color: var(--kastor-yellow); }
.chat-input-area textarea:disabled { background: #f5f5f5; }

#send-btn {
    background: var(--kastor-dark);
    color: #fff;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.2s;
}

#send-btn:disabled { background: #ccc; cursor: not-allowed; }
#send-btn:hover:not(:disabled) { background: #0f2e2e; }

/* ── FILES TAB ────────────────────────────────────────────── */
#tab-files {
    overflow-y: auto;
    padding: 2rem;
    background: #f9f9f9;
}

.files-header {
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.files-header h2 {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #888;
}

.files-count {
    font-size: 0.85rem;
    color: #aaa;
}

.files-actions {
    margin-bottom: 1.5rem;
}

.upload-btn {
    padding: 0.75rem 1.5rem;
    background: var(--kastor-dark);
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.2s;
}

.upload-btn:hover { background: #0f2e2e; }

.files-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.file-item {
    display: flex;
    align-items: center;
    padding: 1rem 1.25rem;
    background: #fff;
    border: 1px solid #e8e8e8;
    border-radius: 10px;
    gap: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}

.file-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

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

.file-name {
    font-size: 0.95rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #333;
}

.file-meta {
    font-size: 0.8rem;
    color: #999;
    margin-top: 0.2rem;
}

.file-delete-btn {
    background: none;
    border: 1px solid #ffcccc;
    color: #cc0000;
    padding: 0.4rem 0.9rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.15s;
}

.file-delete-btn:hover { background: #fff0f0; }

.files-empty {
    text-align: center;
    padding: 4rem;
    color: #bbb;
    font-size: 0.95rem;
}
