/* ── ECNX Ambient — Microphone Configuration & Calibration ─────────────────
   Dark-theme styles matching the existing ECNX design system.
   Scoped under .mic-config-page to avoid leaking into global styles.
   ─────────────────────────────────────────────────────────────────────── */

/* ── Page shell ─────────────────────────────────────────────────────────── */
.mic-config-page {
    max-width: 960px;
    margin: 0 auto;
    padding: 1.5rem 1rem 3rem;
    color: #e2e8f0;
    font-family: 'Inter', system-ui, sans-serif;
}

.mic-page-header {
    display: flex;
    align-items: center;
    gap: .9rem;
    margin-bottom: 1.6rem;
}

.mic-page-icon {
    font-size: 2rem;
    line-height: 1;
}

.mic-page-title {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    color: #1e293b;
    letter-spacing: -.02em;
}

.mic-page-sub {
    margin: .1rem 0 0;
    font-size: .85rem;
    color: #475569;
}

/* ── Status bar ─────────────────────────────────────────────────────────── */
.mic-status-bar {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .6rem 1rem;
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 8px;
    margin-bottom: 1.4rem;
    font-size: .82rem;
    color: #cbd5e1;
    flex-wrap: wrap;
}

.mic-status-badge {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .22rem .65rem;
    border-radius: 20px;
    font-size: .75rem;
    font-weight: 600;
    letter-spacing: .03em;
}

.mic-status-badge.ok       { background: #0d2f20; color: #3fb950; border: 1px solid #238636; }
.mic-status-badge.warning  { background: #2d1f00; color: #d29922; border: 1px solid #9e6a03; }
.mic-status-badge.error    { background: #3d0d0d; color: #f85149; border: 1px solid #b91c1c; }
.mic-status-badge.idle     { background: #1c2128; color: #8b949e; border: 1px solid #30363d; }

.mic-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

/* ── Tabs ───────────────────────────────────────────────────────────────── */
.mic-tabs {
    display: flex;
    gap: 2px;
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 10px;
    padding: 4px;
    margin-bottom: 1.4rem;
    overflow-x: auto;
    scrollbar-width: none;
}
.mic-tabs::-webkit-scrollbar { display: none; }

.mic-tab {
    flex: 1;
    min-width: max-content;
    padding: .45rem .8rem;
    background: transparent;
    border: none;
    border-radius: 7px;
    color: #8b949e;
    font-size: .8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s ease;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: .35rem;
    justify-content: center;
}

.mic-tab:hover { background: #21262d; color: #c9d1d9; }

.mic-tab.active {
    background: #0d419d;
    color: #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,.4);
}

/* ── Cards ──────────────────────────────────────────────────────────────── */
.mic-card {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 10px;
    padding: 1.2rem 1.4rem;
    margin-bottom: 1rem;
}

.mic-card-title {
    font-size: .78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .09em;
    color: #6e7681;
    margin: 0 0 1rem;
    display: flex;
    align-items: center;
    gap: .4rem;
}

.mic-card-title::after {
    content: '';
    flex: 1;
    height: 1px;
    background: #30363d;
    margin-left: .4rem;
}

/* ── Form controls ──────────────────────────────────────────────────────── */
.mic-form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .8rem 1.2rem;
}

@media (max-width: 640px) { .mic-form-row { grid-template-columns: 1fr; } }

.mic-field { display: flex; flex-direction: column; gap: .35rem; }

.mic-label {
    font-size: .78rem;
    font-weight: 600;
    color: #8b949e;
    letter-spacing: .02em;
}

.mic-select,
.mic-input {
    background: #0d1117;
    border: 1px solid #30363d;
    border-radius: 6px;
    color: #e2e8f0;
    font-size: .85rem;
    padding: .45rem .7rem;
    transition: border-color .15s;
    width: 100%;
    box-sizing: border-box;
}
.mic-select:focus,
.mic-input:focus  { outline: none; border-color: #388bfd; box-shadow: 0 0 0 2px rgba(56,139,253,.2); }

.mic-select option { background: #161b22; }

/* Toggle switch */
.mic-toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .55rem 0;
    border-bottom: 1px solid #21262d;
}
.mic-toggle-row:last-child { border-bottom: none; }

.mic-toggle-label { font-size: .85rem; color: #c9d1d9; }
.mic-toggle-desc  { font-size: .74rem; color: #6e7681; margin-top: .12rem; }

.mic-switch {
    position: relative;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}
.mic-switch input { opacity: 0; width: 0; height: 0; }
.mic-switch-track {
    position: absolute;
    inset: 0;
    background: #30363d;
    border-radius: 12px;
    cursor: pointer;
    transition: background .2s;
}
.mic-switch input:checked + .mic-switch-track { background: #238636; }
.mic-switch-track::before {
    content: '';
    position: absolute;
    left: 3px; top: 3px;
    width: 18px; height: 18px;
    background: #fff;
    border-radius: 50%;
    transition: transform .2s;
}
.mic-switch input:checked + .mic-switch-track::before { transform: translateX(20px); }

/* Slider */
.mic-slider-row {
    display: flex;
    align-items: center;
    gap: .7rem;
}
.mic-slider {
    -webkit-appearance: none;
    flex: 1;
    height: 5px;
    background: #30363d;
    border-radius: 3px;
    outline: none;
}
.mic-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px; height: 16px;
    border-radius: 50%;
    background: #388bfd;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,.5);
}
.mic-slider::-moz-range-thumb {
    width: 16px; height: 16px;
    border-radius: 50%;
    background: #388bfd;
    cursor: pointer;
    border: none;
}
.mic-slider-val {
    min-width: 3rem;
    text-align: right;
    font-size: .82rem;
    font-weight: 600;
    color: #58a6ff;
    font-variant-numeric: tabular-nums;
}

/* ── Canvas visualizers ─────────────────────────────────────────────────── */
.mic-canvas-wrap {
    background: #0d1117;
    border: 1px solid #21262d;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: .6rem;
}

.mic-canvas-label {
    font-size: .72rem;
    color: #6e7681;
    padding: .3rem .7rem 0;
    font-weight: 600;
    letter-spacing: .05em;
    text-transform: uppercase;
}

canvas.mic-canvas {
    display: block;
    width: 100%;
    height: 44px;
}

canvas.mic-spectrum-canvas {
    height: 80px;
}

/* ── Buttons ────────────────────────────────────────────────────────────── */
.mic-btn {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    padding: .48rem 1.1rem;
    border-radius: 6px;
    font-size: .83rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all .15s;
    white-space: nowrap;
}
.mic-btn:disabled { opacity: .45; cursor: not-allowed; }

.mic-btn-primary   { background: #238636; color: #fff; border-color: #2ea043; }
.mic-btn-primary:hover:not(:disabled) { background: #2ea043; }

.mic-btn-danger    { background: #b91c1c; color: #fff; border-color: #dc2626; }
.mic-btn-danger:hover:not(:disabled) { background: #dc2626; }

.mic-btn-secondary { background: #21262d; color: #c9d1d9; border-color: #30363d; }
.mic-btn-secondary:hover:not(:disabled) { background: #30363d; }

.mic-btn-accent    { background: #0d419d; color: #fff; border-color: #1f6feb; }
.mic-btn-accent:hover:not(:disabled) { background: #1f6feb; }

.mic-btn-ghost     { background: transparent; color: #58a6ff; border-color: #30363d; }
.mic-btn-ghost:hover:not(:disabled) { background: #161b22; }

.mic-btn-row {
    display: flex;
    gap: .6rem;
    flex-wrap: wrap;
    margin-top: .9rem;
}

/* ── Calibration ────────────────────────────────────────────────────────── */
.mic-cal-step {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: .9rem 0;
    border-bottom: 1px solid #21262d;
}
.mic-cal-step:last-child { border-bottom: none; }

.mic-cal-num {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #0d419d;
    color: #fff;
    font-size: .78rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: .1rem;
}

.mic-cal-num.done { background: #238636; }

.mic-cal-body { flex: 1; }
.mic-cal-title { font-size: .88rem; font-weight: 600; color: #c9d1d9; margin: 0 0 .2rem; }
.mic-cal-desc  { font-size: .78rem; color: #6e7681; margin: 0 0 .5rem; }
.mic-cal-result {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .25rem .6rem;
    background: #0d1117;
    border: 1px solid #30363d;
    border-radius: 5px;
    font-size: .8rem;
    font-variant-numeric: tabular-nums;
    color: #58a6ff;
    margin-top: .3rem;
}

/* Progress bar for calibration */
.mic-progress {
    width: 100%;
    height: 6px;
    background: #21262d;
    border-radius: 3px;
    overflow: hidden;
    margin-top: .5rem;
}
.mic-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #388bfd, #58a6ff);
    border-radius: 3px;
    transition: width .3s ease;
}

/* ── Health monitor ─────────────────────────────────────────────────────── */
.mic-health-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: .7rem;
}

.mic-health-card {
    background: #0d1117;
    border: 1px solid #21262d;
    border-radius: 8px;
    padding: .8rem .9rem;
    text-align: center;
}

.mic-health-value {
    font-size: 1.4rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: #f8fafc;
    line-height: 1;
}
.mic-health-label {
    font-size: .72rem;
    color: #6e7681;
    margin-top: .3rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    font-weight: 600;
}

.mic-health-ok      .mic-health-value { color: #3fb950; }
.mic-health-warn    .mic-health-value { color: #d29922; }
.mic-health-bad     .mic-health-value { color: #f85149; }

/* History log */
.mic-log {
    background: #0d1117;
    border: 1px solid #21262d;
    border-radius: 8px;
    padding: .7rem .9rem;
    max-height: 200px;
    overflow-y: auto;
    font-size: .78rem;
    font-family: 'Consolas', 'Courier New', monospace;
    color: #8b949e;
}

.mic-log-entry { padding: .1rem 0; line-height: 1.5; }
.mic-log-entry.ok   { color: #3fb950; }
.mic-log-entry.warn { color: #d29922; }
.mic-log-entry.err  { color: #f85149; }
.mic-log-ts { color: #484f58; margin-right: .5rem; }

/* ── Audio routing ──────────────────────────────────────────────────────── */
.mic-routing-diagram {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: 1rem;
    background: #0d1117;
    border: 1px solid #21262d;
    border-radius: 8px;
    overflow-x: auto;
    margin-bottom: 1rem;
}

.mic-routing-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .3rem;
    min-width: 70px;
}

.mic-routing-box {
    background: #161b22;
    border: 1px solid #388bfd;
    border-radius: 6px;
    padding: .4rem .65rem;
    font-size: .72rem;
    font-weight: 600;
    color: #58a6ff;
    text-align: center;
    white-space: nowrap;
}

.mic-routing-box.inactive { border-color: #30363d; color: #6e7681; }

.mic-routing-arrow {
    font-size: .9rem;
    color: #30363d;
    flex-shrink: 0;
}

.mic-routing-label {
    font-size: .66rem;
    color: #484f58;
    text-align: center;
}

/* ── Test & playback ────────────────────────────────────────────────────── */
.mic-test-timer {
    font-size: 2rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: #f8fafc;
    text-align: center;
    letter-spacing: .05em;
    margin: .5rem 0;
}

.mic-playback-bar {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .65rem .9rem;
    background: #0d1117;
    border: 1px solid #21262d;
    border-radius: 8px;
    margin-top: .8rem;
}

.mic-playback-icon { font-size: 1.2rem; }

.mic-playback-info { flex: 1; }
.mic-playback-name { font-size: .82rem; font-weight: 600; color: #c9d1d9; }
.mic-playback-dur  { font-size: .74rem; color: #6e7681; }

/* ── Device info table ──────────────────────────────────────────────────── */
.mic-info-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .82rem;
}

.mic-info-table tr { border-bottom: 1px solid #21262d; }
.mic-info-table tr:last-child { border-bottom: none; }

.mic-info-table td {
    padding: .45rem .3rem;
    vertical-align: top;
}

.mic-info-table td:first-child {
    color: #6e7681;
    font-weight: 600;
    width: 42%;
    padding-right: .8rem;
    white-space: nowrap;
}

.mic-info-table td:last-child {
    color: #c9d1d9;
    word-break: break-all;
}

/* ── Permission prompt ──────────────────────────────────────────────────── */
.mic-permission-prompt {
    text-align: center;
    padding: 2.5rem 1.5rem;
    background: #161b22;
    border: 2px dashed #30363d;
    border-radius: 12px;
    margin: 1rem 0;
}

.mic-permission-icon { font-size: 2.5rem; margin-bottom: .8rem; }
.mic-permission-title { font-size: 1.05rem; font-weight: 700; color: #f8fafc; margin-bottom: .4rem; }
.mic-permission-desc  { font-size: .83rem; color: #8b949e; margin-bottom: 1.1rem; max-width: 380px; margin-left: auto; margin-right: auto; }

/* ── Alert / inline messages ────────────────────────────────────────────── */
.mic-alert {
    display: flex;
    align-items: flex-start;
    gap: .55rem;
    padding: .65rem .9rem;
    border-radius: 7px;
    font-size: .82rem;
    margin-bottom: .8rem;
}
.mic-alert-icon { font-size: 1rem; line-height: 1.3; flex-shrink: 0; }
.mic-alert-info    { background: #0d1f3b; border: 1px solid #1f6feb; color: #79c0ff; }
.mic-alert-success { background: #0d2f20; border: 1px solid #238636; color: #56d364; }
.mic-alert-warning { background: #2d1f00; border: 1px solid #9e6a03; color: #e3b341; }
.mic-alert-error   { background: #3d0d0d; border: 1px solid #b91c1c; color: #ff7b72; }

/* ── Spinner ────────────────────────────────────────────────────────────── */
.mic-spinner {
    display: inline-block;
    width: 14px; height: 14px;
    border: 2px solid rgba(255,255,255,.25);
    border-top-color: #fff;
    border-radius: 50%;
    animation: mic-spin .7s linear infinite;
    flex-shrink: 0;
}
@keyframes mic-spin { to { transform: rotate(360deg); } }

/* ── Section divider ────────────────────────────────────────────────────── */
.mic-divider {
    border: none;
    border-top: 1px solid #21262d;
    margin: 1rem 0;
}

/* ── Native audio player (Test & Playback tab) ──────────────────────────── */
.mic-playback-bar audio {
    display: block;
    width: 100%;
    height: 36px;
    border-radius: 6px;
    background: #0d1117;
    /* accent-color is set inline per browser support; filter darkens the default chrome controls */
    filter: invert(0.85) hue-rotate(180deg);
}

/* ── Chip row (location tags) ───────────────────────────────────────────── */
.mic-chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    margin-top: .3rem;
}

.mic-chip {
    padding: .28rem .7rem;
    border-radius: 20px;
    border: 1px solid #30363d;
    background: #21262d;
    color: #8b949e;
    font-size: .78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
    user-select: none;
}

.mic-chip:hover { border-color: #388bfd; color: #58a6ff; }
.mic-chip.selected { background: #0d419d; border-color: #1f6feb; color: #fff; }
