/* ── Variables ───────────────────────────────────────────────────────────── */
:root {
    --bg:         #0e1217;
    --card-bg:    #161c23;
    --card-bg2:   #1b2127;
    --border:     #2a3540;
    --text:       #f0f2f5;
    --muted:      #8a9bab;
    --accent:     #3d98f4;
    --accent-h:   #5aaaf6;
    --good:       #4caf50;
    --warn:       #f4a23d;
    --bad:        #ff6b6b;
    --font:       'Inter', system-ui, sans-serif;
    --radius:     12px;
    --radius-sm:  8px;
}

/* ── Reset / Base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 20px;
    font-size: 15px;
    line-height: 1.5;
}
h3 {
    margin: 0 0 14px;
    font-size: 0.78em;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.07em;
}
label { font-weight: 500; font-size: 0.93em; }
canvas { width: 100% !important; display: block; }

/* ── Layout ──────────────────────────────────────────────────────────────── */
#app-container { max-width: 1400px; margin: 0 auto; }

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 16px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 10px;
}
.logo { display: flex; align-items: center; gap: 12px; }
.logo svg { color: var(--accent); flex-shrink: 0; }
.logo h1 { font-size: 1.3em; margin: 0; line-height: 1.1; }
.logo .subtitle { margin: 0; font-size: 0.8em; color: var(--muted); }

#status-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85em;
    color: var(--muted);
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 6px 14px;
}
#statusDot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--muted);
    transition: background 0.3s;
    flex-shrink: 0;
}

main { display: flex; flex-direction: column; gap: 16px; }

.main-row {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: stretch;
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    flex: 1;
    min-width: 280px;
}

/* ── Parameters card ─────────────────────────────────────────────────────── */
.control-group {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}
.control-group:last-child { margin-bottom: 0; }
.control-group label { flex-shrink: 0; }

/* ── Actions card ────────────────────────────────────────────────────────── */
#actions-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.capture-wrap { position: relative; }
#captureSample { width: 100%; position: relative; overflow: hidden; }
#countdownOverlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6em;
    font-weight: 700;
    letter-spacing: 0;
}
.toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.9em;
    color: var(--muted);
    user-select: none;
}
.toggle-label input[type="checkbox"] { cursor: pointer; accent-color: var(--accent); }
#loadingSpinner {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
    font-size: 0.9em;
}
.spinner-ring {
    width: 18px; height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
#qualityWarning {
    background: rgba(244,162,61,0.12);
    border: 1px solid var(--warn);
    color: var(--warn);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-size: 0.85em;
}

/* ── Results card ────────────────────────────────────────────────────────── */
#results-card { display: flex; flex-direction: column; gap: 12px; }
#results-display {
    display: flex;
    justify-content: space-around;
    flex: 1;
    gap: 8px;
}
.metric {
    text-align: center;
    padding: 12px 8px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    flex: 1;
    transition: border-color 0.3s, background 0.3s;
}
.metric span { display: block; color: var(--muted); font-size: 0.8em; margin-bottom: 4px; }
.metric p { margin: 0; font-size: 1.9em; font-weight: 700; color: var(--text); line-height: 1; }

/* Color-coded metric states */
.metric.good { border-color: var(--good); background: rgba(76,175,80,0.07); }
.metric.good p { color: var(--good); }
.metric.warn { border-color: var(--warn); background: rgba(244,162,61,0.07); }
.metric.warn p { color: var(--warn); }
.metric.bad  { border-color: var(--bad);  background: rgba(255,107,107,0.07); }
.metric.bad p  { color: var(--bad); }

/* ── Monitoring card ─────────────────────────────────────────────────────── */
.monitor-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}
#peak-meter {
    height: 6px;
    border-radius: 3px;
    background: #222d36;
    overflow: hidden;
    margin-bottom: 10px;
}
#peak-meter-bar {
    height: 100%;
    width: 0%;
    background: var(--good);
    transition: width 0.04s, background-color 0.1s;
    border-radius: 3px;
}

/* ── History card ────────────────────────────────────────────────────────── */
#history-card { }
#historyList {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
#historyList li {
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--card-bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-size: 0.88em;
    flex-wrap: wrap;
}
.hist-time { color: var(--muted); min-width: 80px; }
.hist-empty { color: var(--muted); font-size: 0.9em; border: none !important; background: none !important; }

/* ── Chart cards ─────────────────────────────────────────────────────────── */
.chart-card { display: flex; flex-direction: column; min-height: 240px; }
.chart-card canvas { flex: 1; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
select, input[type="text"] {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 7px 10px;
    font-size: 0.92em;
    font-family: var(--font);
    min-width: 0;
}
select { cursor: pointer; }
input[type="text"]::placeholder { color: var(--muted); }
input[type="range"] {
    flex: 1;
    accent-color: var(--accent);
}
select.highlight { animation: flash 0.5s ease; }
@keyframes flash {
    0%, 100% { border-color: var(--border); }
    50% { border-color: var(--good); box-shadow: 0 0 0 2px rgba(76,175,80,0.3); }
}

button {
    padding: 10px 16px;
    border: none;
    background: var(--accent);
    color: #fff;
    font-family: var(--font);
    font-size: 0.95em;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
    width: 100%;
}
button:hover:not(:disabled) { background: var(--accent-h); }
button:disabled { background: #1e2933; color: #4a5a6a; cursor: not-allowed; }
button.secondary {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    font-weight: 500;
}
button.secondary:hover:not(:disabled) { background: var(--card-bg2); color: var(--text); }

/* ── Tooltip ─────────────────────────────────────────────────────────────── */
.tooltip {
    display: inline-block;
    font-size: 0.8em;
    color: var(--muted);
    cursor: help;
    position: relative;
    vertical-align: middle;
}
.tooltip[title]:hover::after {
    content: attr(title);
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(100% + 6px);
    background: #222d36;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 10px;
    width: 220px;
    font-size: 0.88em;
    line-height: 1.4;
    z-index: 10;
    white-space: normal;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

/* ── Footer ──────────────────────────────────────────────────────────────── */
footer {
    text-align: center;
    padding: 20px 0 4px;
    color: var(--muted);
    font-size: 0.8em;
}

/* ── Mobile ──────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
    body { padding: 12px; }
    .card { min-width: 0; padding: 16px; }
    #results-display { flex-direction: column; }
    .metric p { font-size: 1.5em; }
    header { flex-direction: column; align-items: flex-start; }
    #historyList li { gap: 8px; }
}
