:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --border-color: #30363d;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --accent-blue: #58a6ff;
    --accent-green: #3fb950;
    --accent-red: #f85149;
    --accent-yellow: #d29922;
    --accent-purple: #a371f7;
    --legend-x: #f85149;
    --legend-y: #3fb950;
    --legend-z: #58a6ff;
    --font-mono: 'JetBrains Mono', monospace;
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 16px;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    overflow-x: hidden;
}

.app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding-bottom: 80px;
}

.hidden {
    display: none !important;
}

.header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 16px 20px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.logo {
    font-family: var(--font-mono);
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-primary);
}

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

.build-tag {
    font-size: 0.7rem;
    font-weight: 400;
    color: var(--text-muted);
    margin-left: 8px;
}

.status-bar {
    display: flex;
    gap: 20px;
    align-items: center;
}

.build-number {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-muted);
    background: var(--bg-secondary);
    padding: 4px 10px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.status-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    font-family: var(--font-mono);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: background 0.3s ease;
}

.status-item.active .status-dot {
    background: var(--accent-green);
    box-shadow: 0 0 8px var(--accent-green);
}

.status-item.warning .status-dot {
    background: var(--accent-yellow);
}

.status-item.error .status-dot {
    background: var(--accent-red);
}

.status-text {
    color: var(--text-secondary);
}

.main {
    flex: 1;
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.controls-section {
    margin-bottom: 24px;
}

.start-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 32px 24px;
    text-align: center;
}

.start-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 20px;
    color: var(--accent-blue);
}

.start-icon svg {
    width: 100%;
    height: 100%;
}

.start-card h2 {
    font-size: 1.5rem;
    margin: 0 0 12px;
    font-weight: 600;
}

.start-card p {
    color: var(--text-secondary);
    margin: 0 0 24px;
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
}

.start-info {
    display: flex;
    justify-content: center;
    gap: 32px;
    margin-bottom: 24px;
    padding: 16px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
}

.info-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.info-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.info-value {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: var(--text-primary);
}

.controls-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
}

.control-group {
    display: flex;
    gap: 12px;
}

.buffer-info {
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: var(--font-mono);
    font-size: 0.85rem;
}

.buffer-label {
    color: var(--text-secondary);
}

.buffer-bar {
    width: 120px;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
}

.buffer-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent-blue), var(--accent-purple));
    border-radius: 4px;
    transition: width 0.1s ease;
}

.buffer-value {
    color: var(--text-primary);
    min-width: 80px;
}

.rate-display {
    color: var(--accent-purple);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    padding: 4px 10px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    min-width: 70px;
    text-align: center;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    font-size: 0.9rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.btn-primary {
    background: var(--accent-blue);
    color: #fff;
}

.btn-primary:hover {
    background: #79b8ff;
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
}

.btn-small {
    padding: 8px 12px;
    font-size: 0.8rem;
}

.btn-danger {
    background: transparent;
    color: var(--accent-red);
    border: 1px solid var(--accent-red);
}

.btn-danger:hover {
    background: var(--accent-red);
    color: #fff;
}

.btn-start {
    padding: 16px 32px;
    font-size: 1rem;
}

.btn-start svg {
    width: 24px;
    height: 24px;
}

.charts-section {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

/* legacy context-panel styles removed — replaced by tab-content/tab-view */

.debug-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.debug-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-tertiary);
}

.debug-header h3 {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 600;
}

.debug-content {
    padding: 12px 16px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
}

.debug-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.8rem;
}

.debug-label {
    color: var(--text-muted);
}

.debug-value {
    color: var(--accent-green);
    font-weight: 500;
}

@media (min-width: 900px) {
    .charts-section {
        grid-template-columns: 1fr 1fr;
    }
}

.chart-container {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.chart-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chart-header h3 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

.chart-legend {
    display: flex;
    gap: 16px;
}

.legend-item {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 500;
    padding: 4px 10px;
    border-radius: 4px;
    background: var(--bg-tertiary);
}

.legend-x { color: var(--legend-x); }
.legend-y { color: var(--legend-y); }
.legend-z { color: var(--legend-z); }

.chart-info {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--accent-purple);
}

.chart-wrapper {
    padding: 16px;
    height: 280px;
    position: relative;
}

.data-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.data-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.data-header h3 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

.data-count {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    padding: 4px 10px;
    border-radius: 4px;
}

.data-actions {
    padding: 12px 20px;
    display: flex;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-tertiary);
}

.data-list {
    max-height: 300px;
    overflow-y: auto;
}

.empty-state {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-muted);
}

.data-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.15s ease;
    position: relative;
    user-select: none;
}

.data-item:last-child {
    border-bottom: none;
}

.data-item:hover {
    background: var(--bg-tertiary);
}

/* Selection mode */
.data-item.selected {
    background: rgba(88, 166, 255, 0.1);
}

.data-item.selected::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--accent-blue);
}

.data-checkbox {
    display: none;
    width: 22px;
    height: 22px;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    margin-right: 14px;
    flex-shrink: 0;
    position: relative;
    cursor: pointer;
    transition: all 0.2s;
}

.selection-mode .data-checkbox {
    display: block;
}

.selection-mode .data-item-info {
    pointer-events: none;
}

.data-item.selected .data-checkbox {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
}

.data-item.selected .data-checkbox::after {
    content: '';
    position: absolute;
    left: 6px;
    top: 2px;
    width: 6px;
    height: 11px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* Selection toolbar */
.selection-toolbar {
    background: rgba(88, 166, 255, 0.08);
    border-color: var(--accent-blue);
}

.btn-select-all {
    color: var(--accent-blue);
    border: 1px solid var(--accent-blue);
    background: transparent;
}

.btn-select-all:hover {
    background: var(--accent-blue);
    color: #fff;
}

.btn-cancel {
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    background: transparent;
}

.data-item-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.data-item-time {
    font-family: var(--font-mono);
    font-size: 0.9rem;
}

.data-item-size {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.data-item-actions {
    display: flex;
    gap: 8px;
}

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: center;
    padding: 8px 20px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    z-index: 100;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 24px;
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.2s ease;
    font-size: 0.75rem;
    font-family: inherit;
}

.nav-item span {
    font-weight: 500;
}

.nav-item.active {
    color: var(--accent-blue);
}

.nav-item:hover {
    color: var(--text-primary);
}

.footer {
    display: none;
}

@media (max-width: 480px) {
    .header {
        padding: 12px 16px;
    }

    .main {
        padding: 16px;
    }

    .status-bar {
        gap: 12px;
        width: 100%;
        justify-content: flex-end;
    }

    .status-text {
        display: none;
    }

    .start-info {
        flex-direction: column;
        gap: 16px;
    }

    .controls-card {
        flex-direction: column;
        align-items: stretch;
    }

    .control-group {
        justify-content: center;
    }

    .buffer-info {
        justify-content: center;
    }

    .buffer-bar {
        flex: 1;
    }

    .chart-wrapper {
        height: 220px;
    }

    .data-actions {
        flex-wrap: wrap;
    }

    .btn-small {
        flex: 1;
    }
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

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

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

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.chart-controls {
    display: flex;
    align-items: center;
    gap: 16px;
}

.chart-info {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--accent-purple);
}

.axis-select {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 4px 8px;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    cursor: pointer;
}

.axis-select:focus {
    outline: none;
    border-color: var(--accent-blue);
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 900px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

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

.modal-body {
    padding: 20px;
}

.modal-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
    padding: 16px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
}

.stat-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-family: var(--font-mono);
    font-size: 1rem;
    color: var(--accent-blue);
}

.modal-chart-container {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 16px;
    height: 300px;
}

.modal-chart-container:last-child {
    margin-bottom: 0;
}

/* ── Live-Readout (sticky, always-on) ── */
.live-readout {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 16px;
    position: sticky;
    top: 73px;
    z-index: 50;
}

.readout-item {
    display: flex;
    align-items: baseline;
    gap: 6px;
    padding: 12px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-family: var(--font-mono);
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.readout-label {
    font-size: 0.8rem;
    font-weight: 600;
    min-width: 28px;
}

.readout-value {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text-primary);
    flex: 1;
    text-align: right;
}

.readout-unit {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.readout-magnitude .readout-label {
    color: var(--accent-purple);
}

/* ── Tab Content ── */
.tab-content {
    margin-bottom: 24px;
}

.tab-view {
    animation: ctxFadeIn 0.2s ease;
}

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

/* ── Debug Collapsible ── */
.debug-collapsible {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-bottom: 16px;
}

.debug-collapsible summary {
    padding: 12px 16px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    user-select: none;
}

.debug-collapsible summary:hover {
    color: var(--text-primary);
}

.debug-collapsible[open] summary {
    border-bottom: 1px solid var(--border-color);
}

/* ── Messung Tab ── */
.record-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px 20px;
}

.record-setup {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group input {
    padding: 14px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent-blue);
}

.btn-record-start {
    padding: 16px 24px;
    font-size: 1rem;
}

.btn-record-stop {
    width: 100%;
    padding: 16px;
    font-size: 1rem;
    margin-top: 16px;
}

.record-active {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.record-name-display {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
    padding: 8px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
}

.record-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.record-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 8px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    border: 1px solid var(--accent-red);
}

.record-stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.record-stat-value {
    font-family: var(--font-mono);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--accent-red);
}

.record-mini-chart {
    height: 180px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 8px;
}

/* Saving indicator */
.record-saving {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 40px 20px;
}

.saving-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.record-saving span {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* ── Error-Banner ── */
.error-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: rgba(248, 81, 73, 0.1);
    border: 1px solid var(--accent-red);
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    color: var(--accent-red);
    font-size: 0.9rem;
}

.error-banner svg {
    flex-shrink: 0;
}

.error-banner span {
    flex: 1;
}

.error-close {
    background: none;
    border: none;
    color: var(--accent-red);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.error-close:hover {
    color: #fff;
}

/* ── Data-Item mit Name ── */
.data-item-name {
    font-size: 0.85rem;
    color: var(--text-primary);
    font-weight: 500;
    margin-bottom: 2px;
}

/* ── Responsive: Live-Readout ── */
@media (max-width: 480px) {
    .live-readout {
        grid-template-columns: repeat(2, 1fr);
    }

    .readout-value {
        font-size: 0.95rem;
    }

    .record-stats {
        grid-template-columns: 1fr;
    }

    .modal-chart-container {
        height: 220px;
    }
}