/* --- General & Theming --- */
:root {
    --bg-color: #1c1c1e; --surface-color: #2c2c2e; --inspector-bg: #222224;
    --primary-color: #0a84ff; --primary-hover: #359aff; --text-color: #f2f2f7;
    --text-muted: #8e8e93; --border-color: #3a3a3c;
    --font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: var(--font-family); background-color: var(--bg-color); color: var(--text-color); overflow: hidden; }
#app-container { display: flex; flex-direction: column; height: 100%; }

/* --- Header & Buttons --- */
#main-header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; padding: 0.5rem 1rem; gap: 1rem; background-color: var(--surface-color); border-bottom: 1px solid var(--border-color); box-shadow: 0 2px 8px rgba(0,0,0,0.2); z-index: 10; flex-shrink: 0; }
.control-group { display: flex; align-items: center; gap: 0.5rem; }
button { display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 1rem; font-size: 0.9rem; font-weight: 500; border: none; border-radius: 8px; cursor: pointer; transition: all 0.2s ease; background-color: var(--primary-color); color: white; }
button.btn-secondary { background-color: #3a3a3c; }
button:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,0.2); }
button.btn-secondary:hover:not(:disabled) { background-color: #4a4a4c; }
button:disabled { background-color: #2c2c2e; color: var(--text-muted); cursor: not-allowed; opacity: 0.6; }
button svg { width: 1.2em; height: 1.2em; fill: currentColor; flex-shrink: 0; }
button span { display: none; }
#gesture-label-input { padding: 0.5rem 0.75rem; font-size: 0.9rem; background-color: var(--bg-color); border: 1px solid var(--border-color); border-radius: 8px; color: var(--text-color); width: 180px; transition: border-color 0.2s; }
#gesture-label-input:focus { outline: none; border-color: var(--primary-color); }

/* --- Main Content & Views --- */
#main-content { position: relative; flex-grow: 1; overflow: hidden; }
.view { position: absolute; inset: 0; display: flex; opacity: 0; visibility: hidden; transition: opacity 0.3s, visibility 0.3s; }
.view.active-view { opacity: 1; visibility: visible; }
#capture-view { flex-direction: column; }
#touch-area { flex-grow: 1; position: relative; background-color: #111; touch-action: none; }
#trail-canvas, #touch-visuals { position: absolute; inset: 0; pointer-events: none; }
#status-message { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; font-size: clamp(1rem, 4vw, 1.5rem); color: var(--text-muted); }

/* --- Collapsible Inspector (Mobile First) --- */
#inspector-panel {
    position: fixed; top: 0; right: 0; width: 320px; height: 100%;
    background-color: var(--inspector-bg); z-index: 1001;
    transform: translateX(100%); transition: transform 0.3s ease-out;
    display: flex; flex-direction: column; gap: 1.5rem; padding: 1rem;
    border-left: 1px solid var(--border-color);
}
#inspector-close-btn { position: absolute; top: 0.5rem; right: 0.5rem; background: none; border: none; font-size: 1.5rem; color: var(--text-muted); cursor: pointer; display: block; padding: 0.25rem 0.5rem; }
#resizer-handle { display: none; }
#inspector-backdrop { position: fixed; inset: 0; background-color: rgba(0,0,0,0.5); z-index: 1000; opacity: 0; pointer-events: none; transition: opacity 0.3s; }
body.inspector-open #inspector-panel { transform: translateX(0); }
body.inspector-open #inspector-backdrop { opacity: 1; pointer-events: auto; }

/* --- Inspector Content --- */
.inspector-section h3 { font-size: 1rem; margin-bottom: 0.75rem; color: var(--primary-color); border-bottom: 1px solid var(--border-color); padding-bottom: 0.5rem;}
.table-section { flex-grow: 1; min-height: 0; display: flex; flex-direction: column; }
.stats-grid { display: grid; grid-template-columns: auto 1fr; gap: 0.25rem 1rem; font-size: 0.9rem; align-items: center;}
.table-container { flex-grow: 1; overflow-y: auto; border: 1px solid var(--border-color); border-radius: 4px; }
.settings-content { display: flex; flex-direction: column; gap: 0.75rem; font-size: 0.9rem; }
.settings-content button { width: 100%; }
details summary { cursor: pointer; font-weight: 500; }
.input-group { display: flex; align-items: center; gap: 0.5rem; background-color: var(--surface-color); padding: 0.5rem; border-radius: 6px; }
.input-group label { flex-shrink: 0; }
.input-group input[type="number"] { flex-grow: 1; background: var(--bg-color); border: 1px solid var(--border-color); color: var(--text-color); border-radius: 4px; padding: 0.25rem 0.5rem; width: 60px; text-align: right; }
.input-group span { font-size: 0.8rem; color: var(--text-muted); }

/* --- Analysis View --- */
#analysis-view { flex-direction: column; padding: 1rem; gap: 1rem; background-color: var(--bg-color); }
.analysis-header { display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; padding-bottom: 1rem; }
.analysis-plots { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; flex-grow: 1; min-height: 0; }
.plot-container { position: relative; border: 1px solid var(--border-color); border-radius: 8px; overflow: hidden; box-shadow: inset 0 0 10px rgba(0,0,0,0.3); }
.plot-container.loading::before { content: 'Generating Plot...'; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: var(--text-muted); font-size: 1.2rem; }

/* --- Desktop Adaptive Layout --- */
@media (min-width: 901px) {
    #capture-view { flex-direction: row; }
    #inspector-panel {
        position: relative; flex-basis: 350px; min-width: 280px; max-width: 600px;
        height: auto; transform: none; z-index: 1; box-shadow: none;
        transition: flex-basis 0.3s, min-width 0.3s, padding 0.3s, border 0.3s;
    }
    body:not(.inspector-open) #inspector-panel { flex-basis: 0 !important; min-width: 0 !important; overflow: hidden; padding: 0; border: none; }
    #inspector-close-btn { display: none; }
    #resizer-handle {
        display: block; position: absolute; top: 0; left: 0; bottom: 0;
        width: 5px; cursor: col-resize; z-index: 2; transition: background-color 0.2s;
    }
    #resizer-handle:hover { background-color: var(--primary-color); }
    #inspector-backdrop { display: none; }
}
@media (min-width: 769px) { button span { display: block; } }
@media (max-width: 1200px) { .analysis-plots { grid-template-columns: 1fr; } }
.touch-point { position: absolute; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.9); transform: translate(-50%, -50%); backdrop-filter: blur(2px); }