/* ── Reset & base ── */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background: #fafafa;
    color: #1a1a1a;
    height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ── Layout ── */
.app-container {
    max-width: 860px;
    margin: 0 auto;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-left: 1px solid #eee;
    border-right: 1px solid #eee;
}

/* ── Header ── */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
    background: #fff;
}

a.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none !important;
    color: inherit;
}

a.header-left:hover,
a.header-left:visited,
a.header-left h1 {
    text-decoration: none !important;
    color: inherit;
}

header h1 {
    font-size: 1.35em;
    font-weight: 700;
    color: #1a1a1a;
    letter-spacing: -0.02em;
}

header nav {
    display: flex;
    align-items: center;
    gap: 4px;
}

header nav a {
    color: #6b6b6b;
    text-decoration: none;
    font-size: 0.87em;
    padding: 6px 12px;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
}

header nav a:hover {
    background: #f5f5f5;
    color: #1a1a1a;
}

header nav a.active {
    background: #f0f0f0;
    color: #1a1a1a;
    font-weight: 500;
}

#export-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    color: #6b6b6b;
    background: none;
    border: 1px solid #e0e0e0;
    font-size: 0.87em;
    padding: 5px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

#export-btn:hover {
    background: #f5f5f5;
    color: #1a1a1a;
}

/* ── Main / chat area ── */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px;
}

/* ── Messages ── */
.message {
    margin-bottom: 18px;
    padding: 10px 14px;
    border-radius: 10px;
    max-width: 88%;
    line-height: 1.55;
    font-size: 0.92em;
    word-wrap: break-word;
}

.message.user {
    background: #f5f5f5;
    margin-left: auto;
    color: #1a1a1a;
}

.message.assistant {
    background: transparent;
    padding-left: 0;
    padding-right: 0;
    color: #333;
}

.message.assistant.error {
    background: #fef2f2;
    border-left: 2px solid #dc4c3e;
    padding: 10px 14px;
}

/* ── SQL blocks ── */
.message .sql-block {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 12px 14px;
    border-radius: 8px;
    font-family: 'SF Mono', 'Fira Code', 'JetBrains Mono', 'Consolas', monospace;
    font-size: 0.82em;
    overflow-x: auto;
    margin: 10px 0;
    white-space: pre-wrap;
    word-break: break-all;
    line-height: 1.5;
}

/* ── Tables ── */
.message table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.87em;
    margin: 10px 0;
}

.message th,
.message td {
    padding: 8px 12px;
    text-align: left;
}

.message th {
    background: #fafafa;
    font-weight: 600;
    font-size: 0.85em;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #6b6b6b;
    border-bottom: 2px solid #eee;
}

.message td {
    border-bottom: 1px solid #f0f0f0;
    color: #333;
}

.message tbody tr:hover td {
    background: #fafafa;
}

.message .table-wrap {
    max-height: 400px;
    overflow: auto;
    border: 1px solid #eee;
    border-radius: 8px;
}

.message .table-wrap table {
    margin: 0;
    border: none;
}

.message .row-count {
    font-size: 0.8em;
    color: #999;
    margin-top: 6px;
}

/* ── Chart button ── */
.chart-btn {
    display: inline-block;
    margin-top: 10px;
    padding: 6px 14px;
    background: #fff;
    color: #dc4c3e;
    border: 1px solid #dc4c3e;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.84em;
    font-weight: 500;
    transition: background 0.15s;
}

.chart-btn:hover {
    background: #fef2f2;
}

/* ── Chart area ── */
.chart-area {
    position: relative;
    padding: 16px 20px;
    border-top: 1px solid #eee;
    max-height: 420px;
    flex-shrink: 0;
    background: #fafafa;
}

.chart-close {
    position: absolute;
    top: 10px;
    right: 14px;
    width: 28px;
    height: 28px;
    border: none;
    background: #fff;
    color: #999;
    font-size: 1.2em;
    line-height: 1;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    transition: color 0.15s;
}

.chart-close:hover {
    color: #333;
}

.chart-controls {
    display: flex;
    gap: 6px;
    margin-top: 12px;
    justify-content: center;
}

.chart-controls button {
    padding: 4px 14px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    background: #fff;
    color: #6b6b6b;
    cursor: pointer;
    font-size: 0.82em;
    transition: background 0.15s, color 0.15s;
}

.chart-controls button:hover {
    background: #f5f5f5;
    color: #1a1a1a;
}

/* ── Footer / input ── */
footer {
    padding: 14px 20px;
    border-top: 1px solid #eee;
    flex-shrink: 0;
    background: #fff;
}

footer form {
    display: flex;
    gap: 8px;
    align-items: center;
    background: #f5f5f5;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    padding: 4px 4px 4px 16px;
    transition: border-color 0.2s;
}

footer form:focus-within {
    border-color: #ccc;
    box-shadow: 0 0 0 3px rgba(0,0,0,0.03);
}

footer input {
    flex: 1;
    padding: 10px 0;
    border: none;
    background: transparent;
    font-size: 0.92em;
    color: #1a1a1a;
    outline: none;
}

footer input::placeholder {
    color: #aaa;
}

footer button[type="submit"] {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #dc4c3e;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s;
}

footer button[type="submit"]:hover {
    background: #c9372c;
}

footer button[type="submit"]:disabled {
    background: #ddd;
    cursor: not-allowed;
}

/* ── Loading animation ── */
.loading-dots::after {
    content: '';
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
    0%  { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
}

/* ── Responsive ── */
@media (max-width: 600px) {
    .message { max-width: 95%; }
    header { padding: 10px 14px; }
    footer { padding: 10px 14px; }
}
