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

:root {
    --bg: #07111f;
    --surface: rgba(255, 255, 255, 0.78);
    --surface-solid: #ffffff;
    --surface-soft: #f8fafc;
    --border: rgba(15, 23, 42, 0.08);
    --text: #0f172a;
    --muted: #64748b;
    --primary: #0f766e;
    --primary-dark: #115e59;
    --accent: #2563eb;
    --user: linear-gradient(135deg, #0f766e 0%, #2563eb 100%);
    --shadow: 0 24px 70px rgba(15, 23, 42, 0.18);
    --soft-shadow: 0 12px 35px rgba(15, 23, 42, 0.08);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    height: 100vh;
    overflow: hidden;
    background:
        radial-gradient(circle at top left, rgba(37, 99, 235, 0.35), transparent 35%),
        radial-gradient(circle at bottom right, rgba(15, 118, 110, 0.35), transparent 35%),
        linear-gradient(135deg, #020617 0%, #0f172a 100%);
    color: var(--text);
}

.app-container {
    display: flex;
    height: calc(100vh - 28px);
    margin: 14px;
    border-radius: 28px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(24px);
    box-shadow: var(--shadow);
    border: 1px solid rgba(255, 255, 255, 0.35);
}

/* Sidebar */
.sidebar {
    width: 310px;
    background: rgba(248, 250, 252, 0.86);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: all 0.28s ease;
    flex-shrink: 0;
}

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

.sidebar-header {
    padding: 22px;
    border-bottom: 1px solid var(--border);
}

.new-chat-btn {
    width: 100%;
    padding: 13px 16px;
    border: none;
    border-radius: 16px;
    background: linear-gradient(135deg, #0f766e 0%, #2563eb 100%);
    color: white;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-shadow: 0 12px 28px rgba(37, 99, 235, 0.26);
    transition: all 0.2s ease;
}

.new-chat-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 18px 36px rgba(37, 99, 235, 0.34);
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
}

.chat-item {
    padding: 14px 15px;
    margin-bottom: 8px;
    border-radius: 16px;
    cursor: pointer;
    color: var(--text);
    border: 1px solid transparent;
    transition: all 0.2s ease;
}

.chat-item:hover {
    background: rgba(37, 99, 235, 0.07);
    border-color: rgba(37, 99, 235, 0.12);
}

.chat-item.active {
    background: #ffffff;
    border-color: rgba(15, 118, 110, 0.18);
    box-shadow: var(--soft-shadow);
}

.chat-item-title {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-preview {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Main */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, rgba(255,255,255,0.96), rgba(248,250,252,0.92));
}

.chat-header {
    height: 78px;
    padding: 0 28px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
    background: rgba(255, 255, 255, 0.72);
    backdrop-filter: blur(18px);
}

.sidebar-toggle {
    width: 42px;
    height: 42px;
    border: 1px solid var(--border);
    background: #ffffff;
    border-radius: 14px;
    font-size: 17px;
    color: var(--muted);
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.05);
}

.sidebar-toggle:hover {
    color: var(--primary);
    transform: translateY(-1px);
}

.chat-header h1 {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.04em;
    color: var(--text);
}

.chat-header h1::after {
    content: "AI Maritime Operations Copilot";
    display: block;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0;
    color: var(--muted);
    margin-top: 2px;
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    position: relative;
}

.welcome-message {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100%;
    text-align: center;
    padding: 40px;
}

.welcome-content {
    max-width: 620px;
    padding: 42px;
    border-radius: 30px;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid var(--border);
    box-shadow: var(--soft-shadow);
}

.welcome-content h2 {
    font-size: 36px;
    font-weight: 850;
    letter-spacing: -0.06em;
    margin-bottom: 14px;
    background: linear-gradient(135deg, #0f766e, #2563eb);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.welcome-content p {
    font-size: 16px;
    color: var(--muted);
}

/* Messages */
.messages-container {
    padding: 28px;
    max-width: 1180px;
    margin: 0 auto;
    width: 100%;
}

.message {
    margin-bottom: 26px;
    display: flex;
    gap: 14px;
    animation: fadeUp 0.22s ease;
}

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

.message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 42px;
    height: 42px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    flex-shrink: 0;
    box-shadow: var(--soft-shadow);
}

.message.user .message-avatar {
    background: var(--user);
    color: white;
}

.message.assistant .message-avatar {
    background: #ffffff;
    color: var(--primary);
    border: 1px solid rgba(15, 118, 110, 0.15);
}

.message-content {
    flex: 1;
    max-width: 86%;
}

.message-bubble {
    padding: 18px 22px;
    border-radius: 22px;
    font-size: 15px;
    line-height: 1.65;
    box-shadow: var(--soft-shadow);
}

.message.user .message-bubble {
    background: var(--user);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 8px;
}

.message.assistant .message-bubble {
    background: #ffffff;
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 8px;
}

/* Markdown */
.message-bubble h1,
.message-bubble h2,
.message-bubble h3,
.message-bubble h4 {
    margin: 18px 0 10px;
    color: var(--text);
    letter-spacing: -0.03em;
}

.message-bubble h1 { font-size: 1.55em; }
.message-bubble h2 { font-size: 1.35em; }
.message-bubble h3 { font-size: 1.15em; }

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

.message-bubble ul,
.message-bubble ol {
    margin: 10px 0;
    padding-left: 22px;
}

.message-bubble li {
    margin: 5px 0;
}

.message-bubble blockquote {
    border-left: 4px solid var(--primary);
    margin: 16px 0;
    padding: 10px 16px;
    background: rgba(15, 118, 110, 0.06);
    border-radius: 12px;
}

.message-bubble code {
    background: rgba(37, 99, 235, 0.08);
    color: #1d4ed8;
    padding: 3px 7px;
    border-radius: 8px;
    font-size: 0.9em;
}

.message-bubble pre {
    background: #0f172a;
    color: #e5e7eb;
    padding: 18px;
    border-radius: 16px;
    overflow-x: auto;
    margin: 16px 0;
}

.message-bubble pre code {
    background: none;
    color: inherit;
    padding: 0;
}

.message-bubble a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

.message-status {
    margin-top: 10px;
}

.status-indicator {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 11px;
    background: rgba(15, 118, 110, 0.08);
    border: 1px solid rgba(15, 118, 110, 0.12);
    border-radius: 999px;
    font-size: 12px;
    color: var(--primary-dark);
    font-weight: 700;
}

.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 8px 0;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
    animation: typing 1.4s infinite ease-in-out;
}

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

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

/* Tables */
.renderable-table {
    margin: 18px 0;
    border-radius: 18px;
    overflow: hidden;
    border: 1px solid var(--border);
    background: #ffffff;
    box-shadow: var(--soft-shadow);
}

.table-title {
    padding: 14px 18px;
    background: #f8fafc;
    font-weight: 800;
    color: var(--text);
    border-bottom: 1px solid var(--border);
}

.table-container {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 13px 16px;
    text-align: left;
    border-bottom: 1px solid #eef2f7;
}

.data-table th {
    background: #f8fafc;
    color: var(--primary-dark);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.data-table td {
    font-size: 14px;
    color: #334155;
}

.data-table tr:hover {
    background: rgba(37, 99, 235, 0.04);
}

/* Input */
.input-container {
    padding: 18px 28px 24px;
    border-top: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.78);
    backdrop-filter: blur(18px);
}

.input-wrapper {
    max-width: 1180px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 12px;
    padding: 12px 14px 12px 18px;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 22px;
    box-shadow: 0 14px 40px rgba(15, 23, 42, 0.1);
    transition: all 0.2s ease;
}

.input-wrapper:focus-within {
    border-color: rgba(37, 99, 235, 0.45);
    box-shadow: 0 18px 50px rgba(37, 99, 235, 0.14);
}

#messageInput {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    background: transparent;
    font-size: 15px;
    line-height: 1.55;
    max-height: 140px;
    color: var(--text);
    padding: 9px 0;
}

#messageInput::placeholder {
    color: #94a3b8;
}

.send-btn {
    width: 46px;
    height: 46px;
    border: none;
    border-radius: 16px;
    background: linear-gradient(135deg, #0f766e, #2563eb);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 12px 28px rgba(37, 99, 235, 0.26);
    transition: all 0.2s ease;
}

.send-btn:hover:not(:disabled) {
    transform: translateY(-2px) scale(1.02);
}

.send-btn:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
    box-shadow: none;
}

/* Export buttons already injected by JS */
.export-buttons button {
    border-radius: 12px !important;
}


/* HTML export popup */
.html-export-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(2, 6, 23, 0.64);
    backdrop-filter: blur(8px);
}

.html-export-modal {
    position: relative;
    width: min(620px, 100%);
    padding: 30px;
    border: 1px solid rgba(255, 255, 255, 0.45);
    border-radius: 22px;
    background: #ffffff;
    box-shadow: 0 28px 80px rgba(2, 6, 23, 0.34);
    animation: fadeUp 0.2s ease;
}

.html-export-modal h3 {
    margin: 0 0 8px;
    color: var(--text);
    font-size: 22px;
    letter-spacing: -0.03em;
}

.html-export-modal p {
    margin: 0 0 18px;
    color: var(--muted);
    line-height: 1.55;
}

.html-export-modal-close {
    position: absolute;
    top: 14px;
    right: 16px;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 10px;
    background: #f1f5f9;
    color: #475569;
    font-size: 25px;
    line-height: 1;
    cursor: pointer;
}

.html-export-modal-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    margin-bottom: 16px;
    border-radius: 14px;
    font-size: 20px;
}

.html-export-modal-icon.success {
    color: #047857;
    background: #d1fae5;
}

.html-export-modal-icon.error {
    color: #b91c1c;
    background: #fee2e2;
}

.html-export-file-name {
    margin-bottom: 16px;
    padding: 10px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #f8fafc;
    color: #334155;
    font-size: 12px;
    overflow-wrap: anywhere;
}

.html-export-link-label {
    display: block;
    margin-bottom: 7px;
    color: #334155;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.html-export-link-row {
    display: flex;
    gap: 10px;
}

.html-export-link-row input {
    min-width: 0;
    flex: 1;
    padding: 12px 13px;
    border: 1px solid #cbd5e1;
    border-radius: 11px;
    background: #f8fafc;
    color: #0f172a;
    font-size: 13px;
}

.html-export-copy-btn,
.html-export-open-btn,
.html-export-secondary-btn {
    border: 0;
    border-radius: 11px;
    padding: 11px 15px;
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    font-weight: 750;
    cursor: pointer;
}

.html-export-copy-btn,
.html-export-open-btn {
    color: #ffffff;
    background: linear-gradient(135deg, #2563eb, #0f766e);
}

.html-export-secondary-btn {
    color: #334155;
    background: #e2e8f0;
}

.html-export-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

.html-export-error-message {
    padding: 12px 14px;
    border: 1px solid #fecaca;
    border-radius: 11px;
    background: #fff1f2;
    color: #9f1239;
    font-size: 13px;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.export-btn:disabled {
    opacity: 0.65;
    cursor: wait !important;
    transform: none !important;
}

@media (max-width: 640px) {
    .export-buttons {
        flex-wrap: wrap;
    }

    .html-export-modal {
        padding: 24px 18px;
    }

    .html-export-link-row,
    .html-export-modal-actions {
        flex-direction: column;
    }

    .html-export-copy-btn,
    .html-export-open-btn,
    .html-export-secondary-btn {
        width: 100%;
    }
}

/* Loading */
.loading-overlay {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    background: rgba(2, 6, 23, 0.55);
    backdrop-filter: blur(8px);
}

.loading-overlay.show {
    display: flex;
}

.loading-spinner {
    width: 42px;
    height: 42px;
    border: 4px solid rgba(255, 255, 255, 0.35);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Errors */
.error-message {
    background: #fff1f2;
    color: #9f1239;
    border: 1px solid #fecdd3;
    padding: 13px 16px;
    border-radius: 16px;
    margin: 14px 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(100, 116, 139, 0.35);
    border-radius: 999px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(100, 116, 139, 0.55);
}

/* Responsive */
@media (max-width: 768px) {
    .app-container {
        margin: 0;
        height: 100vh;
        border-radius: 0;
    }

    .sidebar {
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        z-index: 100;
        box-shadow: 12px 0 40px rgba(15, 23, 42, 0.18);
    }

    .sidebar.collapsed {
        transform: translateX(-100%);
        width: 310px;
    }

    .chat-header {
        padding: 0 18px;
    }

    .messages-container {
        padding: 18px;
    }

    .message-content {
        max-width: 90%;
    }

    .input-container {
        padding: 14px;
    }

    .welcome-content {
        padding: 28px;
    }

    .welcome-content h2 {
        font-size: 28px;
    }
}