:root {
    --sv-primary: #0f172a;
    --sv-secondary: #2563eb;
    --sv-secondary-soft: #e0edff;
    --sv-bg: #f9fafb;
    --sv-panel-bg: #ffffff;
    --sv-border: #e5e7eb;
    --sv-text: #111827;
    --sv-muted: #64748b;
    --sv-radius-lg: 18px;
    --sv-radius-full: 999px;
    --sv-shadow-soft: 0 8px 24px rgba(15, 23, 42, 0.06);
}

/* Reset light */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background:
        radial-gradient(circle at top left, #e0f2fe 0, #e5edff 42%, #f9fafb 80%);
    color: var(--sv-text);
}

/* Page structure */

.mic-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header de l’outil (clair, comme les autres mini-apps) */
.mic-header {
    padding: 14px 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--sv-border);
    background: #ffffff;
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.03);
    color: var(--sv-primary);
}

.mic-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

/* Nouveau logo header (remplace cercle + texte) */
.mic-header-logo {
    display: block;
    height: 46px;
    width: auto;
    max-width: min(42vw, 220px);
    object-fit: contain;
}

/* (Anciennes classes supprimées : .mic-logo-circle, .mic-header-text h1, .mic-header-text p) */

.mic-header-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

/* Layout principal */

.mic-main {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 2.7fr) minmax(320px, 1.1fr);
    gap: 18px;
    padding: 18px;
}

/* View area */

.mic-view {
    background: var(--sv-panel-bg);
    border-radius: 20px;
    box-shadow: var(--sv-shadow-soft);
    padding: 14px 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    border: 1px solid var(--sv-border);
}

.mic-video-wrapper {
    position: relative;
    border-radius: 16px;
    overflow: hidden;
    background: radial-gradient(circle at center, #020617, #020617);
    min-height: 420px;
    height: min(72vh, 640px);
}

.mic-video-inner {
    position: absolute;
    inset: 0;
    transform-origin: center center;
}

/* Video / image / overlay */

#video,
#stillImage,
#overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}

#video,
#stillImage {
    object-fit: contain;
    background: #020617;
}

.mic-still.hidden {
    display: none;
}

#overlay {
    pointer-events: none;
}

/* Barre d'échelle (HTML) */

.mic-scale-bar {
    position: absolute;
    left: 14px;
    bottom: 14px;
    height: 3px;
    border-radius: 999px;
    background: #e5e7eb;
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.6);
    min-width: 0;
    pointer-events: none;
}

/* HUD analyse */

.mic-analysis-hud {
    position: absolute;
    left: 14px;
    top: 12px;
    padding: 6px 10px;
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.86);
    color: #e5e7eb;
    font-size: 11px;
    backdrop-filter: blur(6px);
    border: 1px solid rgba(148, 163, 184, 0.6);
    max-width: 240px;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.mic-analysis-hud.off {
    opacity: 0.4;
}

.mic-analysis-hud .hud-line {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Label texte de l'échelle */

.mic-scale-label {
    position: absolute;
    right: 14px;
    top: 12px;
    font-size: 12px;
    color: #f9fafb;
    background: rgba(15, 23, 42, 0.86);
    padding: 3px 8px;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.7);
    pointer-events: none;
}

/* Histogrammes RGB */

.mic-histo-canvas {
    position: absolute;
    right: 14px;
    bottom: 14px;
    width: 220px;
    height: 80px;
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid rgba(148, 163, 184, 0.65);
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.75);
    pointer-events: none;
}

/* Footer de la vue */

.mic-view-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    justify-content: flex-start;
    padding: 4px 4px 0;
}

/* Panels */

.mic-panels {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.panel {
    background: var(--sv-panel-bg);
    border-radius: 18px;
    padding: 12px 14px;
    border: 1px solid var(--sv-border);
    box-shadow: var(--sv-shadow-soft);
}

.panel h2 {
    margin: 0 0 8px;
    font-size: 15px;
    font-weight: 600;
    color: var(--sv-primary);
}

.field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 10px;
    font-size: 13px;
}

.field label {
    font-weight: 500;
    color: var(--sv-muted);
}

.field select,
.field input[type="range"] {
    font-size: 13px;
}

.field select {
    border-radius: 999px;
    border: 1px solid var(--sv-border);
    padding: 6px 10px;
    background: #f9fafb;
    outline: none;
    color: var(--sv-primary);
}

.field select:focus {
    border-color: var(--sv-secondary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.slider-field input[type="range"] {
    width: 100%;
}

.toggles-row {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    font-size: 12px;
}

.toggles-row label {
    display: flex;
    align-items: center;
    gap: 5px;
}

/* Panel info */

.panel-info {
    padding: 6px 8px;
    border-radius: 12px;
    background: var(--sv-secondary-soft);
    border: 1px dashed rgba(37, 99, 235, 0.45);
    font-size: 12px;
    color: #1e3a8a;
}

.panel-info.small {
    background: #f9fafb;
    border-style: solid;
    border-color: #e5e7eb;
    color: var(--sv-muted);
}

/* Tool buttons */

.tool-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.tool-btn {
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
    border: 1px solid var(--sv-border);
    background: #f9fafb;
    cursor: pointer;
    color: var(--sv-muted);
    transition:
        background 0.15s ease,
        color 0.15s ease,
        border-color 0.15s ease,
        box-shadow 0.15s ease;
}

.tool-btn:hover {
    background: #eff6ff;
    border-color: rgba(37, 99, 235, 0.6);
    color: #1e3a8a;
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.08);
}

.tool-btn.active {
    background: var(--sv-secondary);
    border-color: var(--sv-secondary);
    color: #f9fafb;
}

/* Analyse toggle */

.analysis-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
}

/* Buttons & badges */

.btn {
    border-radius: 999px;
    border: 1px solid var(--sv-border);
    background: #f9fafb;
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
    color: var(--sv-primary);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition:
        background 0.15s ease,
        transform 0.05s ease,
        box-shadow 0.15s ease,
        border-color 0.15s ease;
}

.btn:disabled {
    opacity: 0.6;
    cursor: default;
}

.btn:hover:not(:disabled) {
    background: #e5f0ff;
    transform: translateY(-0.5px);
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.08);
}

.btn-primary {
    background: var(--sv-secondary);
    color: #f9fafb;
    border-color: var(--sv-secondary);
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.35);
}

.btn-primary:hover:not(:disabled) {
    background: #1d4ed8;
}

.btn-secondary {
    background: #f3f4f6;
    color: var(--sv-primary);
}

.btn-ai {
    background: linear-gradient(135deg, #22c55e, #0ea5e9);
    border: 1px solid rgba(56, 189, 248, 0.7);
    color: #ecfeff;
    box-shadow: 0 8px 18px rgba(59, 130, 246, 0.65);
    font-size: 13px;
    padding-inline: 14px;
}

.btn-ai:hover {
    filter: brightness(1.05);
}

/* Captures */

.captures-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 6px;
    align-items: flex-start;
}

.capture-item {
    background: #f9fafb;
    border-radius: 10px;
    border: 1px solid var(--sv-border);
    padding: 4px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 11px;
}

.capture-item img,
.capture-item video {
    width: 100%;
    border-radius: 8px;
    display: block;
}

.capture-item a {
    color: var(--sv-secondary);
    text-decoration: none;
    font-size: 10px;
}

.capture-item a:hover {
    text-decoration: underline;
}

/* Text utils */

.muted {
    margin: 0;
    font-size: 12px;
    color: var(--sv-muted);
}

.tiny {
    font-size: 11px;
}

/* Panel actions */

.panel-actions {
    margin-top: 4px;
}

/* Badge */

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
}

.badge-recording {
    background: #fee2e2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

/* Footer */

.mic-footer {
    padding: 8px 18px 12px;
    font-size: 11px;
    color: var(--sv-muted);
    display: flex;
    justify-content: flex-end;
}

/* Hidden util */

.hidden {
    display: none !important;
}

/* === Mode "caméra fixe, barre droite scrollable" sur grand écran === */
@media (min-width: 961px) {
    body {
        overflow-y: hidden;
    }

    .mic-page {
        height: 100vh;
    }

    .mic-main {
        flex: 1 1 auto;
        min-height: 0;
    }

    .mic-panels {
        overflow-y: auto;
        padding-right: 4px;
    }
}

/* Responsive */

@media (max-width: 960px) {
    body {
        overflow-y: auto;
    }

    .mic-main {
        grid-template-columns: minmax(0, 1fr);
    }

    .mic-panels {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .panel {
        flex: 1 1 260px;
    }

    .mic-video-wrapper {
        height: min(60vh, 520px);
    }

    .mic-header-logo {
        height: 42px;
        max-width: min(56vw, 200px);
    }
}

@media (max-width: 640px) {
    .mic-main {
        padding: 12px;
    }

    .mic-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        padding-inline: 16px;
    }

    .mic-header-left {
        width: 100%;
    }

    .mic-header-right {
        width: 100%;
    }

    .mic-header-logo {
        height: 38px;
        max-width: 100%;
    }

    .mic-view {
        padding: 10px;
    }

    .mic-panels {
        flex-direction: column;
    }
}