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

:root {
    --gold: #CBAA60;
    --gold-hover: #b8963f;
    --gold-light: rgba(203, 170, 96, 0.1);
    --gold-border: rgba(203, 170, 96, 0.3);
    --black: #000000;
    --dark: #1a1a1a;
    --dark-secondary: #231F20;
    --dark-card: #111111;
    --white: #ffffff;
    --gray-50: #fafafa;
    --gray-100: #f5f5f5;
    --gray-200: #e5e5e5;
    --gray-300: #d4d4d4;
    --gray-400: #a3a3a3;
    --gray-500: #737373;
    --gray-600: #525252;
    --gray-700: #363635;
    --gray-800: #262626;
    --gray-900: #171717;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --user-msg-bg: #CBAA60;
    --user-msg-text: #000000;
    --assistant-msg-bg: #ffffff;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 6px 6px 9px rgba(0, 0, 0, 0.2);
    --shadow-lg: 12px 12px 50px rgba(0, 0, 0, 0.4);
    --radius: 8px;
    --radius-sm: 6px;
}

html, body {
    height: 100%;
    font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--gray-100);
    color: var(--dark);
    line-height: 1.5;
}

.app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ========== LOGIN OVERLAY ========== */
.login-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--black);
}

.login-overlay {
    flex-direction: column;
    gap: 32px;
}

.login-logo {
    text-align: center;
}

.login-logo img {
    height: 48px;
    width: auto;
}

.login-form {
    background: var(--white);
    border-radius: 4px;
    padding: 48px 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.login-form h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--dark);
    margin-bottom: 4px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.login-form p {
    font-size: 13px;
    color: var(--gray-500);
    margin-bottom: 28px;
}

.login-form form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.login-form input {
    padding: 12px 14px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    background: var(--gray-50);
}

.login-form input:focus {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px var(--gold-light);
    background: var(--white);
}

.login-error {
    color: var(--danger);
    font-size: 13px;
    min-height: 18px;
}

.login-form .btn-primary {
    margin-top: 4px;
    padding: 12px;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

/* ========== USER INFO ========== */
.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

.user-display-name {
    font-size: 12px;
    font-weight: 500;
    color: var(--gray-500);
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.btn-logout {
    background: transparent;
    color: var(--gray-400);
    border: 1px solid var(--gray-300);
    padding: 5px 12px;
    font-size: 11px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
    font-weight: 500;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.btn-logout:hover {
    background: var(--danger);
    color: var(--white);
    border-color: var(--danger);
}

/* ========== SIDEBAR ========== */
.sidebar {
    width: 280px;
    background: var(--black);
    color: var(--gray-300);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform 0.3s ease;
    z-index: 10;
}

.sidebar.hidden {
    transform: translateX(-100%);
    position: absolute;
    height: 100%;
}

.sidebar-header {
    padding: 20px 16px 16px;
    border-bottom: 1px solid var(--gray-800);
}

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

.sidebar-logo img {
    height: 28px;
    width: auto;
    opacity: 0.9;
}

.sidebar-header h2 {
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--gray-400);
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

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

.conv-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    margin-bottom: 2px;
    transition: background 0.15s;
}

.conv-item:hover {
    background: var(--dark-secondary);
}

.conv-item.active {
    background: var(--gold);
    color: var(--black);
}

.conv-item.active .conv-item-date {
    color: var(--dark-secondary);
}

.conv-item-title {
    flex: 1;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 8px;
}

.conv-item-date {
    font-size: 11px;
    color: var(--gray-500);
    white-space: nowrap;
    margin-right: 8px;
}

.conv-delete-btn {
    background: none;
    border: none;
    color: var(--gray-500);
    cursor: pointer;
    font-size: 14px;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.15s;
    flex-shrink: 0;
}

.conv-delete-btn:hover {
    color: var(--danger);
    background: rgba(220, 38, 38, 0.15);
}

/* ========== MAIN CHAT ========== */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--gray-100);
}

.chat-header {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    gap: 12px;
}

.chat-header h1 {
    font-size: 16px;
    font-weight: 600;
    color: var(--dark);
    letter-spacing: 0.3px;
}

/* ========== MESSAGES ========== */
.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: var(--radius);
    line-height: 1.6;
    word-wrap: break-word;
    animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    align-self: flex-end;
    background: var(--gold);
    color: var(--black);
    border-bottom-right-radius: 2px;
    font-weight: 450;
}

.message.assistant {
    align-self: flex-start;
    background: var(--white);
    color: var(--dark);
    border-bottom-left-radius: 2px;
    box-shadow: var(--shadow);
    border: 1px solid var(--gray-200);
}

.message.status {
    align-self: center;
    background: var(--white);
    color: var(--gray-500);
    font-size: 13px;
    padding: 8px 16px;
    border-radius: 20px;
    border: 1px solid var(--gray-200);
}

/* ========== MARKDOWN TABLES ========== */
.message.assistant table {
    border-collapse: collapse;
    width: 100%;
    margin: 8px 0;
    font-size: 13px;
}

.message.assistant th,
.message.assistant td {
    border: 1px solid var(--gray-200);
    padding: 6px 10px;
    text-align: left;
}

.message.assistant th {
    background: var(--gray-50);
    font-weight: 600;
    color: var(--dark);
    border-bottom: 2px solid var(--gold);
}

.message.assistant tr:nth-child(even) {
    background: var(--gray-50);
}

.message.assistant code {
    background: var(--gray-100);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}

.message.assistant strong {
    font-weight: 600;
}

.message.assistant ul,
.message.assistant ol {
    padding-left: 20px;
    margin: 4px 0;
}

.message.assistant p {
    margin: 4px 0;
}

/* ========== CSV DOWNLOAD BUTTON ========== */
.btn-csv-download {
    display: inline-block;
    margin: 6px 0 4px;
    padding: 5px 14px;
    font-size: 11px;
    font-family: inherit;
    font-weight: 600;
    color: var(--gold);
    background: transparent;
    border: 1px solid var(--gold-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.btn-csv-download:hover {
    background: var(--gold);
    color: var(--black);
    border-color: var(--gold);
}

/* ========== LOADING ========== */
.loading-dots {
    display: inline-flex;
    gap: 4px;
    align-items: center;
}

.loading-dots span {
    width: 6px;
    height: 6px;
    background: var(--gold);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

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

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

/* ========== WELCOME ========== */
.welcome-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
}

.welcome-content {
    text-align: center;
    max-width: 500px;
    padding: 40px 20px;
}

.welcome-logo {
    margin-bottom: 24px;
}

.welcome-logo img {
    height: 40px;
    width: auto;
}

.welcome-content h2 {
    font-size: 20px;
    margin-bottom: 8px;
    color: var(--dark);
    font-weight: 600;
}

.welcome-content p {
    color: var(--gray-500);
    margin-bottom: 28px;
    font-size: 14px;
}

.example-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.example-btn {
    background: var(--white);
    border: 1px solid var(--gray-300);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--gray-700);
}

.example-btn:hover {
    background: var(--gold);
    color: var(--black);
    border-color: var(--gold);
}

/* ========== INPUT AREA ========== */
.input-area {
    padding: 16px 20px;
    background: var(--white);
    border-top: 1px solid var(--gray-200);
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 800px;
    margin: 0 auto;
}

.input-wrapper textarea {
    flex: 1;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    padding: 10px 14px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 120px;
    line-height: 1.5;
    transition: border-color 0.2s;
    background: var(--gray-50);
}

.input-wrapper textarea:focus {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px var(--gold-light);
    background: var(--white);
}

/* ========== BUTTONS ========== */
.btn {
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    border-radius: var(--radius-sm);
    padding: 8px 16px;
    transition: all 0.2s;
    font-weight: 500;
}

.btn-primary {
    background: var(--gold);
    color: var(--black);
    width: 100%;
    font-weight: 600;
}

.btn-primary:hover {
    background: var(--gold-hover);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-danger {
    background: transparent;
    color: var(--gray-400);
    border: 1px solid var(--gray-300);
    padding: 6px 12px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.btn-danger:hover {
    background: var(--danger);
    color: var(--white);
    border-color: var(--danger);
}

.btn-send {
    background: var(--gold);
    color: var(--black);
    padding: 10px 20px;
    border-radius: var(--radius);
    font-weight: 600;
}

.btn-send:hover {
    background: var(--gold-hover);
}

.btn-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-icon {
    background: transparent;
    font-size: 20px;
    padding: 4px 8px;
    color: var(--gray-500);
}

.btn-icon:hover {
    color: var(--dark);
}

/* ========== SCROLLBAR ========== */
.messages-area::-webkit-scrollbar,
.conversation-list::-webkit-scrollbar {
    width: 5px;
}

.messages-area::-webkit-scrollbar-thumb,
.conversation-list::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: 3px;
}

.conversation-list::-webkit-scrollbar-thumb {
    background: var(--gray-700);
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        height: 100%;
    }

    .sidebar.hidden {
        transform: translateX(-100%);
    }

    .message {
        max-width: 90%;
    }

    .chat-header h1 {
        font-size: 14px;
    }

    .user-display-name {
        display: none;
    }

    .login-form {
        margin: 0 16px;
    }
}
