:root {
    --bg-color: #0f0f13;
    --card-bg: rgba(30, 30, 40, 0.6);
    --glass-border: rgba(255, 255, 255, 0.08);
    --primary-color: #2D7FF9;
    --text-color: #ffffff;
    --text-muted: #a0a0b0;
    --green: #2ecc71;
    --purple: #9b59b6;
    --red: #e74c3c;
    --font-stack: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
    margin: 0;
    font-family: var(--font-stack);
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    background-image:
        radial-gradient(circle at 10% 20%, rgba(45, 127, 249, 0.15) 0%, transparent 20%),
        radial-gradient(circle at 90% 80%, rgba(255, 0, 150, 0.08) 0%, transparent 20%);
    box-sizing: border-box;
    overflow-x: hidden;
    padding: 10px; /* Reduced padding for mobile */
}

/* --- TABS --- */
.tab-nav {
    display: flex;
    gap: 8px; /* Smaller gap */
    background: rgba(255,255,255,0.05);
    padding: 4px;
    border-radius: 100px;
    margin: 10px 0 20px 0;
    border: 1px solid var(--glass-border);
    z-index: 10;
    max-width: 100%;
    overflow-x: auto; /* Scrollable on tiny screens */
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 8px 16px;
    border-radius: 100px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}

.tab-btn:hover { color: white; }
.tab-btn.active {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 4px 12px rgba(45, 127, 249, 0.3);
}

.tab-content {
    display: none;
    width: 100%;
    max-width: 420px; 
    padding-bottom: 40px;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease-out;
}

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

/* --- FULLSCREEN CHARTS TAB --- */
.tab-content.fullscreen-tab {
    max-width: none;
    width: 100%;
    /* Use dynamic viewport height */
    height: calc(100vh - 80px);
    padding: 0 0 20px 0;
    box-sizing: border-box;
}

.tab-content.fullscreen-tab.active {
    display: grid;
    /* Mobile: 1 column. Desktop: Auto fit */
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    grid-auto-rows: minmax(300px, 1fr);
    gap: 15px;
}

/* CHAT TAB Specific Override (Reset grid) */
#tab-chat.active {
    display: flex; /* Flex for full height chat */
    flex-direction: column;
}

.chart-card {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(12px);
    border-radius: 20px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
    position: relative;
    overflow: hidden;
}

.chart-card:hover {
    border-color: rgba(255,255,255,0.2);
    transform: translateY(-2px);
}

.chart-card h3 {
    margin: 0 0 10px 0;
    font-size: 1rem;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chart-card h3::after {
    content: '⤢';
    font-size: 1.2rem;
    opacity: 0.5;
}

.canvas-wrapper {
    flex: 1;
    position: relative;
    width: 100%;
    min-height: 0;
}

/* EXPANDED STATE */
.chart-card.expanded {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0; /* Fullscreen */
    z-index: 2000;
    border-radius: 0;
    border: none;
    padding: 20px;
    background: #0f0f13; /* Opaque bg */
    transform: none;
    cursor: default;
}

.chart-card.expanded h3::after {
    content: '✕';
    opacity: 1;
    cursor: pointer;
    padding: 10px;
}

/* --- DASHBOARD STYLES --- */
.container {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 20px;
    box-sizing: border-box;
}

header h1 {
    font-size: 1.4rem;
    font-weight: 700;
    margin: 0 0 12px 0;
    text-align: center;
}

.stats-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.02));
    border-radius: 16px;
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(10px);
}

.stat { display: flex; flex-direction: column; align-items: center; }
.stat .label { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 4px; }
.stat .value { font-size: 1.5rem; font-weight: 700; }
.stat .unit { font-size: 0.9rem; font-weight: 400; color: var(--text-muted); }
.pos { color: var(--green); }
.neg { color: var(--red); }

.glass-panel {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(12px);
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.card h2 { font-size: 1.1rem; margin: 0 0 16px 0; }
.input-group { margin-bottom: 12px; }
.input-group label { display: block; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 6px; }

input {
    width: 100%;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    color: white;
    padding: 12px;
    border-radius: 12px;
    font-size: 16px; /* Prevents zoom on iOS */
    font-family: inherit;
    box-sizing: border-box;
}
input:focus { outline: none; border-color: var(--primary-color); }

.input-row { display: flex; gap: 10px; }
.input-row .input-group { flex: 1; }

button.btn {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}
.btn.primary { background: var(--primary-color); color: white; }
.btn.secondary { background: rgba(255, 255, 255, 0.1); color: white; font-size: 0.9rem; padding: 12px; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.upload-form { flex: 1; min-width: 120px; }
.upload-form input[type="file"] { display: none; }
.upload-form label { display: block; text-align: center; width: 100%; cursor: pointer; }

/* Delete Button */
.btn-delete {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 8px; /* Larger hit area */
    transition: color 0.2s;
    line-height: 1;
}
.btn-delete:hover { color: var(--red); }

/* History */
.history h3 { margin-top: 24px; margin-bottom: 12px; font-size: 1rem; }
.table-container { padding: 0; overflow-x: auto; /* Scroll table horizontally */ }
table { width: 100%; border-collapse: collapse; min-width: 300px; }
th { text-align: left; padding: 12px; color: var(--text-muted); font-size: 0.75rem; background: rgba(0, 0, 0, 0.2); }
td { padding: 12px; border-bottom: 1px solid var(--glass-border); font-size: 0.9rem; }
.comment { color: var(--text-muted); font-size: 0.8rem; max-width: 80px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Chat Styles */
.msg { display: flex; margin-bottom: 10px; }
.msg.user { justify-content: flex-end; }
.msg.bot { justify-content: flex-start; }

.msg-content {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.95rem;
    line-height: 1.4;
    word-wrap: break-word; /* Handle long text */
}

.msg.user .msg-content {
    background: var(--primary-color);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.msg.bot .msg-content {
    background: rgba(255,255,255,0.1);
    color: var(--text-color);
    border-bottom-left-radius: 4px;
}

/* Chat Markdown Styles */
.msg-content p { margin: 0 0 8px 0; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content strong { color: var(--primary-color); font-weight: 700; }
.msg-content ul, .msg-content ol { margin: 5px 0 10px 20px; padding: 0; }
.msg-content li { margin-bottom: 4px; }
.msg-content h1, .msg-content h2, .msg-content h3 { margin: 12px 0 8px 0; font-size: 1rem; color: white; }

/* Flash Messages */
#flash-container {
    position: fixed; top: 10px; left: 50%; transform: translateX(-50%);
    width: 90%; max-width: 400px; z-index: 2100;
}
.flash-message {
    background: rgba(46, 204, 113, 0.95); color: #fff;
    padding: 12px 16px; border-radius: 12px; margin-bottom: 10px; text-align: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

@media (max-width: 600px) {
    .tab-content.fullscreen-tab.active {
        grid-template-columns: 1fr; /* Force single column */
    }
}
