/* ===================================================
   TruInsights MCP — Dark Theme Stylesheet
   =================================================== */

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fb;
    --bg-card: #ffffff;
    --bg-hover: #f0f1f5;
    --text-primary: #1a1d2e;
    --text-secondary: #5f6577;
    --text-muted: #9ca3b0;
    --accent: #6c63ff;
    --accent-hover: #5a52d5;
    --accent-glow: rgba(108, 99, 255, 0.15);
    --success: #059669;
    --error: #dc2626;
    --warning: #d97706;
    --border: #e2e5eb;
    --border-light: #d0d4dc;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --transition: 0.2s ease;
}

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

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* ===== Header ===== */
.app-header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 1.5rem 2rem;
}

.header-logo {
    height: 36px;
    vertical-align: middle;
    margin-right: 0.3rem;
}

.header-content h1 {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 0.3rem;
}

/* ===== Tab Navigation ===== */
.tab-nav {
    display: flex;
    gap: 0;
    background: var(--bg-secondary);
    border-bottom: 2px solid var(--border);
    padding: 0 1.5rem;
    overflow-x: auto;
}

.tab-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 0.9rem 1.4rem;
    font-family: var(--font);
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all var(--transition);
    white-space: nowrap;
}

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

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* ===== Tab Content ===== */
.tab-content {
    padding: 1.5rem 2rem;
    max-width: 1400px;
    margin: 0 auto;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
    animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== Cards ===== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}

.card h3 {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 0.8rem;
}

.card {
    overflow: hidden;
}

.card h4 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.4rem;
}

.card-subtitle {
    color: var(--text-secondary);
    font-size: 0.87rem;
    margin-bottom: 1rem;
}

/* ===== Chat UI ===== */
.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 230px);
    min-height: 500px;
}

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

.message {
    display: flex;
    gap: 0.8rem;
    max-width: 85%;
}

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

.message-bubble {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.9rem 1.2rem;
    font-size: 0.92rem;
    line-height: 1.55;
    word-break: break-word;
}

.message.user .message-bubble {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.message.assistant .message-bubble {
    background: var(--bg-secondary);
}

.message-sql {
    background: #f5f6fa;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.8rem 1rem;
    margin-top: 0.7rem;
    font-family: 'Cascadia Code', 'Fira Code', monospace;
    font-size: 0.82rem;
    color: #16653a;
    overflow-x: auto;
    white-space: pre-wrap;
    cursor: pointer;
}

.message-sql summary {
    cursor: pointer;
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 0.85rem;
    margin-bottom: 0.4rem;
}

.message-chart {
    margin-top: 0.7rem;
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.chat-input-area {
    display: flex;
    gap: 0.7rem;
    padding: 1rem 0 0;
    border-top: 1px solid var(--border);
}

#chatInput {
    flex: 1;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.9rem 1.2rem;
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.92rem;
    outline: none;
    transition: border-color var(--transition);
}

#chatInput:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.btn-send {
    background: var(--accent);
    border: none;
    border-radius: var(--radius);
    width: 48px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
}

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

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

.send-icon {
    color: #fff;
    font-size: 1.2rem;
}

/* ===== Dashboard Grid ===== */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.chart-area {
    width: 100%;
    height: 400px;
    position: relative;
}

.chart-area .loading-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* ===== SQL Playground ===== */
.sql-editor {
    width: 100%;
    background: #f5f6fa;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1rem;
    color: #16653a;
    font-family: 'Cascadia Code', 'Fira Code', monospace;
    font-size: 0.88rem;
    resize: vertical;
    outline: none;
    margin-bottom: 1rem;
    transition: border-color var(--transition);
}

.sql-editor:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.btn-primary {
    background: var(--accent);
    border: none;
    color: #fff;
    padding: 0.7rem 1.5rem;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition);
}

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

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

.sql-result {
    margin-top: 1rem;
}

/* ===== Data Table ===== */
.table-wrapper {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.data-table th {
    background: var(--bg-primary);
    color: var(--text-secondary);
    text-align: left;
    padding: 0.65rem 1rem;
    border-bottom: 2px solid var(--border);
    font-weight: 600;
    white-space: nowrap;
}

.data-table td {
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}

.data-table tr:hover td {
    background: var(--bg-hover);
}

/* ===== Examples ===== */
.examples-section {
    margin-bottom: 1.8rem;
}

.examples-section h4 {
    font-size: 1.05rem;
    margin-bottom: 0.3rem;
}

.tool-label {
    color: var(--text-muted);
    font-size: 0.82rem;
    margin-bottom: 0.7rem;
}

.example-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.example-q {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 0.5rem 1rem;
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.83rem;
    cursor: pointer;
    transition: all var(--transition);
}

.example-q:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(108, 99, 255, 0.08);
}

.info-box {
    background: rgba(108, 99, 255, 0.1);
    border: 1px solid rgba(108, 99, 255, 0.25);
    border-radius: var(--radius-sm);
    padding: 0.9rem 1.2rem;
    font-size: 0.88rem;
    color: var(--text-secondary);
    margin-top: 1rem;
}

/* ===== About — Architecture ===== */
.arch-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.arch-card {
    text-align: center;
}

.arch-card h4 {
    margin-bottom: 0.5rem;
}

.arch-card p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-align: left;
}

.access-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.access-item {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1rem;
}

.access-item h4 {
    margin-bottom: 0.4rem;
}

.access-item code {
    font-size: 0.8rem;
    color: var(--success);
}

/* ===== Objection Item ===== */
.objection-item {
    background: rgba(245, 158, 11, 0.08);
    border: 1px solid rgba(245, 158, 11, 0.2);
    border-radius: var(--radius-sm);
    padding: 0.8rem 1rem;
    margin-bottom: 0.6rem;
    font-size: 0.9rem;
}

.objection-item .freq {
    color: var(--warning);
    font-weight: 600;
}

/* ===== Alerts ===== */
.alert {
    border-radius: var(--radius-sm);
    padding: 0.8rem 1.2rem;
    font-size: 0.9rem;
    margin-bottom: 0.8rem;
}

.alert-success {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: var(--success);
}

.alert-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: var(--error);
}

.alert-info {
    background: rgba(108, 99, 255, 0.1);
    border: 1px solid rgba(108, 99, 255, 0.25);
    color: var(--text-secondary);
}

/* ===== Loading Spinner ===== */
.loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 2rem auto;
}

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

/* ===== Typing dots ===== */
.typing-dots {
    display: inline-flex;
    gap: 4px;
    padding: 0.6rem 0;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.4s infinite;
}

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

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

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: translateY(0);
    }

    40% {
        transform: translateY(-8px);
    }
}

/* ===== Code styling ===== */
code {
    background: var(--bg-primary);
    color: var(--success);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.85em;
    font-family: 'Cascadia Code', 'Fira Code', monospace;
}

/* ===== Footer ===== */
.app-footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-muted);
    font-size: 0.82rem;
    border-top: 1px solid var(--border);
    margin-top: 2rem;
}

.app-footer a {
    color: var(--accent);
    text-decoration: none;
}

.app-footer a:hover {
    text-decoration: underline;
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .arch-grid {
        grid-template-columns: 1fr;
    }

    .access-grid {
        grid-template-columns: 1fr;
    }

    .tab-content {
        padding: 1rem;
    }
}

@media (max-width: 600px) {
    .app-header {
        padding: 1rem;
    }

    .header-content h1 {
        font-size: 1.3rem;
    }

    .tab-btn {
        padding: 0.7rem 0.9rem;
        font-size: 0.8rem;
    }

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

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-light);
}