:root {
    --bg-color: #0F172A;
    --card-bg: rgba(30, 41, 59, 0.7);
    --border-color: rgba(255, 255, 255, 0.1);
    --accent-color: #F28C3D;
    --accent-hover: #d6752d;
    --text-primary: #F8FAFC;
    --text-secondary: #94A3B8;
    --input-bg: rgba(15, 23, 42, 0.6);
    --font-family: 'Inter', sans-serif;
    --success-color: #22c55e;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-family);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 20px;
}

.app-container {
    width: 100%;
    max-width: 1200px;
}

/* Header */
.app-header {
    text-align: center;
    margin-bottom: 40px;
    padding-top: 20px;
}

.logo {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -1px;
    color: white;
}

.logo .highlight {
    color: var(--accent-color);
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 5px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

/* Main Grid */
.main-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    align-items: stretch; /* Ensure columns match height */
}

.left-column, .right-column {
    display: flex;
    flex-direction: column;
    height: 100%; /* Fill the grid cell */
}

/* Make sure the glass card expands to fill remaining space */
.input-panel, .results-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Ensure content inside panels can scroll/flex if needed, or just standard */
.results-panel {
    justify-content: flex-start;
}

@media (max-width: 900px) {
    .main-grid {
        grid-template-columns: 1fr;
    }
}

/* Glass Card */
.glass-card {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 30px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
}

/* Tabs */
.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 25px;
    background: var(--input-bg);
    padding: 5px;
    border-radius: 12px;
    overflow-x: auto;
}

.tab-btn {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.tab-btn:hover {
    color: white;
}

.tab-btn.active {
    background: var(--accent-color);
    color: white;
    color: white;
    box-shadow: 0 2px 10px rgba(242, 140, 61, 0.3);
}

/* Docs Icon in Header */
.subtitle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    position: relative;
}

.docs-icon-btn-header {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(242, 140, 61, 0.2); 
    border: 1px solid var(--accent-color);
    color: var(--accent-color);
    font-weight: 700;
    font-size: 0.8rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.docs-icon-btn-header:hover {
    background: var(--accent-color);
    color: white;
}

.docs-icon-btn-header.active {
    background: var(--accent-color);
    color: white;
    box-shadow: 0 0 10px rgba(242, 140, 61, 0.5);
}

/* Buy Button (Small) */
.btn-buy-small {
    align-self: flex-start; /* Prevent stretching in flex column */
    display: inline-block;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    text-decoration: none;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 6px 12px;
    border-radius: 6px;
    margin-bottom: 10px;
    box-shadow: 0 4px 10px rgba(16, 185, 129, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.2s ease;
    letter-spacing: 0.5px;
}

.btn-buy-small:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 15px rgba(16, 185, 129, 0.4);
    background: linear-gradient(135deg, #34d399 0%, #059669 100%);
    color: white;
}

/* Inputs */
.input-group {
    display: none;
    animation: fadeIn 0.3s ease;
}

.input-group.active {
    display: block;
}

.input-row {
    display: flex;
    gap: 15px;
    margin-bottom: 15px;
}

.field {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin-bottom: 15px;
}

.field label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    font-weight: 600;
}

.field input, .field select, .field textarea {
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px 15px;
    color: white;
    font-family: var(--font-family);
    font-size: 1rem;
    transition: border-color 0.2s;
    width: 100%;
}

.field input:focus, .field select:focus, .field textarea:focus {
    outline: none;
    border-color: var(--accent-color);
}

/* Dataset UI */
.dataset-ui textarea#csv-input {
    height: 200px;
    font-family: monospace;
    font-size: 0.85rem;
    line-height: 1.4;
    resize: vertical;
}

.action-btn {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    margin-top: 10px;
    transition: background 0.2s;
}

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

.secondary-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    flex: 1;
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: white;
}

.btn-group {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

/* Mapping Interface */
#mapping-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 20px;
}

.map-row {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.03);
    padding: 10px;
    border-radius: 8px;
}

.map-label {
    flex: 1;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.map-select {
    flex: 2;
}

/* Settings Drawer */
.settings-drawer {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.field.small input {
    padding: 8px 10px;
    font-size: 0.9rem;
}

/* Results Panel */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
}

.results-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
}

.tools {
    display: flex;
    gap: 8px;
}

.icon-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: 8px;
    width: 36px;
    height: 36px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

/* Primary Metric (Single Mode) */
.primary-metric {
    text-align: center;
    margin-bottom: 30px;
    padding: 20px;
    background: rgba(242, 140, 61, 0.1);
    border: 1px solid rgba(242, 140, 61, 0.2);
    border-radius: 12px;
}

.primary-metric .label {
    color: var(--accent-color);
    font-size: 0.9rem;
    font-size: 0.9rem;
    font-weight: 700;
    margin-bottom: 5px;
}

.primary-metric .value {
    font-size: 3rem;
    font-weight: 700;
    line-height: 1.1;
}

.primary-metric .ci {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-top: 5px;
}

/* Metrics Grid (Single Mode) */
.metrics-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 30px;
}

.metric-card {
    background: rgba(255, 255, 255, 0.03);
    padding: 15px;
    border-radius: 10px;
    text-align: center;
}

.metric-card .label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    color: var(--text-secondary);
    margin-bottom: 5px;
}

.metric-card .value {
    font-size: 1.1rem;
    font-weight: 600;
}

/* Text Report (Single Mode) */
.text-report h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 10px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

textarea#report-text {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    color: var(--text-secondary);
    font-family: monospace;
    font-size: 0.85rem;
    resize: none;
    height: 150px;
    line-height: 1.5;
}

/* Batch Results Table */
.status-msg {
    text-align: center;
    color: var(--text-secondary);
    margin-top: 50px;
    font-style: italic;
}

.table-container {
    max-height: 400px;
    overflow: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    text-align: left;
}

th, td {
    padding: 10px 15px;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

th {
    background: var(--input-bg);
    position: sticky;
    top: 0;
    font-weight: 600;
    color: var(--text-secondary);
    z-index: 10;
}

td {
    color: var(--text-primary);
}

tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}


/* Contextual Tooltips */
.field label {
    display: flex;
    align-items: center;
    gap: 6px;
}

.info-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
    font-size: 10px;
    font-weight: bold;
    cursor: help;
    transition: all 0.2s;
    position: relative;
}

.info-icon:hover {
    background: var(--accent-color);
    color: white;
}

/* Tooltip Popup */
.info-icon::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 150%;
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    color: white;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-size: 0.75rem;
    font-size: 0.75rem;
    width: 300px;
    white-space: normal;
    text-align: center;
    line-height: 1.4;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 100;
    font-weight: normal;
    text-transform: none;
    visibility: hidden;
}

.info-icon:hover::after {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(-5px);
}

/* Tooltip Arrow */
.info-icon::before {
    content: '';
    position: absolute;
    bottom: 110%; /* Adjust to touch popup */
    left: 50%;
    transform: translateX(-50%);
    border-width: 5px;
    border-style: solid;
    border-color: #1e293b transparent transparent transparent;
    opacity: 0;
    transition: opacity 0.2s;
    visibility: hidden;
     z-index: 100;
}

.info-icon:hover::before {
    opacity: 1;
    visibility: visible;
}

/* Rich Tooltip (HTML Content) */
.tooltip-container {
    position: relative;
    /* Ensure label doesn't clip content if overflow hidden elsewhere */
}

.rich-tooltip-content {
    visibility: hidden;
    opacity: 0;
    position: absolute;
    bottom: 150%;
    left: 50%; /* Center relative to parent label? No, label is block usually. */
    left: 140px; /* Offset to not block label text */
    transform: translateY(10px);
    width: 320px;
    background: #1e293b;
    border: 1px solid var(--border-color);
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    z-index: 200;
    transition: all 0.2s ease;
    pointer-events: none; /* Allow hovering label, but maybe we want to select text in tooltip? */
    text-transform: none;
    font-weight: normal;
    color: var(--text-primary);
    text-align: left;
}

.tooltip-container:hover .rich-tooltip-content,
.rich-tooltip-trigger:hover + .rich-tooltip-content {
    visibility: visible;
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.rich-tooltip-content p {
    font-size: 0.8rem;
    margin-bottom: 10px;
    line-height: 1.4;
    color: var(--text-secondary);
}

.rich-tooltip-content strong {
    color: var(--accent-color);
}

.example-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    font-family: monospace;
    font-size: 0.75rem;
    background: rgba(0,0,0,0.2);
    padding: 8px;
    border-radius: 4px;
}

.example-grid span {
    color: var(--text-secondary);
}

/* Footer */
.app-footer {
    text-align: center;
    margin-top: 40px;
    padding-bottom: 20px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    opacity: 0.7;
}

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

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

/* CLES Narrative Box */
.cles-box {
    margin-top: 20px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
}

.cles-box h4 {
    margin: 0 0 10px 0;
    font-size: 0.9rem;
    color: var(--accent-color);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.cles-box p {
    font-size: 0.9rem;
    line-height: 1.5;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.cles-box p:last-child {
    margin-bottom: 0;
}

.cles-box strong {
    color: var(--text-primary);
    font-weight: 600;
}

/* Modal Overlay */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(5px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    display: flex;
    opacity: 1;
}

/* Modal Content */
.modal-content {
    background: var(--bg-color); /* Fallback */
    background: rgba(30, 41, 59, 0.9);
    border: 1px solid var(--border-color);
    padding: 30px;
    border-radius: 12px;
    width: 90%;
    max-width: 650px;
    position: relative;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    text-align: center;
}

.modal-overlay.active .modal-content {
    transform: scale(1);
}

.modal-content h3 {
    margin-bottom: 20px;
    color: var(--text-primary);
}

.close-modal {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
}

.close-modal:hover {
    color: var(--text-primary);
}

/* Visualizer Canvas */
#viz-canvas {
    width: 100%;
    height: auto;
    border-radius: 6px;
    background: rgba(15, 23, 42, 0.5); /* Inner dark bg for contrast */
}

/* Legend */
.viz-legend {
    margin-top: 15px;
    display: flex;
    justify-content: center;
    gap: 20px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.dot.control {
    background: var(--text-secondary);
    opacity: 0.5;
}

@media (max-width: 600px) {
    /* 1. Maximize Screen Real Estate */
    body {
        padding: 10px; /* Reduce outer spacing */
    }
    .glass-card {
        padding: 20px; /* Recover 20px of width (10px per side) */
    }
    .app-header {
        margin-bottom: 25px;
    }
    
    /* 2. Stop iOS Auto-Zoom */
    .field input, .field select, .field textarea {
        font-size: 16px !important; /* Must be 16px to prevent zoom on focus */
    }

    /* 3. Touch Friendly Tabs */
    .tab-btn {
        padding: 12px 15px; /* Larger tap target */
    }
    
    /* Tighter Spacing for small screens */
    .input-row {
        gap: 10px;
    }
    .main-grid {
        gap: 20px;
    }
}


/* Visualizer Controls */
.viz-controls {
    margin-top: 25px;
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.viz-controls label {
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: 500;
}

#viz-val {
    color: var(--accent-color);
    font-weight: bold;
    min-width: 40px;
    display: inline-block;
}

#viz-slider {
    width: 80%;
    max-width: 400px;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
}

#viz-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: var(--accent-color);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 10px rgba(245, 158, 11, 0.5);
    transition: transform 0.1s;
}

#viz-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

/* Audio Toggle Pulse */
#audio-toggle.playing {
    animation: pulse-audio 1.5s infinite;
    color: var(--accent-color);
    border-color: var(--accent-color);
}

@keyframes pulse-audio {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(242, 140, 61, 0.7); }
    70% { transform: scale(1.1); box-shadow: 0 0 0 10px rgba(242, 140, 61, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(242, 140, 61, 0); }
}

