/* ─────────────────────────────────────────────────────────────
   SOUND METER — common shell (header, side menu, footer, toast)
   ───────────────────────────────────────────────────────────── */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #faf9f7;
    --bg-card: #ffffff;
    --bg-elevated: #f5f4f2;
    --bg-input: #f0efed;
    --text: #2d2b28;
    --text-secondary: #78756f;
    --text-tertiary: #a09d97;
    --border: #e8e6e3;
    --border-strong: #d4d1cc;
    --accent: #c96442;
    --accent-soft: rgba(201, 100, 66, 0.1);
    --accent-hover: #b5573a;
    --green: #3d8b5e;
    --green-soft: rgba(61, 139, 94, 0.1);
    --yellow: #c49530;
    --yellow-soft: rgba(196, 149, 48, 0.1);
    --orange: #cf7c3a;
    --orange-soft: rgba(207, 124, 58, 0.1);
    --red: #c4463a;
    --red-soft: rgba(196, 70, 58, 0.1);
    --red-dark: #8b2e25;
    --red-dark-soft: rgba(139, 46, 37, 0.12);
    --blue: #4a7ec7;
    --blue-soft: rgba(74, 126, 199, 0.1);
    --purple: #8b6cc7;
    --purple-soft: rgba(139, 108, 199, 0.1);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 6px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.06);
    --font: 'DM Sans', system-ui, sans-serif;
    --mono: 'JetBrains Mono', monospace;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --sidebar-w: 300px;
    --bottombar-h: 72px;
    --header-h: 56px;
}

[data-theme="dark"] {
    --bg: #1a1918;
    --bg-card: #242322;
    --bg-elevated: #2d2c2a;
    --bg-input: #333230;
    --text: #e8e6e3;
    --text-secondary: #a09d97;
    --text-tertiary: #78756f;
    --border: #3a3835;
    --border-strong: #4a4845;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.2), 0 1px 2px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.2);
}

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    transition: background var(--transition), color var(--transition);
    overflow-x: hidden;
}

body.has-bottombar {
    padding-bottom: calc(var(--bottombar-h) + env(safe-area-inset-bottom, 0px));
}

html[dir="rtl"] body { text-align: right; }

/* ── HEADER ── */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

.header-inner {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 16px;
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.site-title {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.3px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    text-align: center;
    margin: 0;
}

.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    flex-shrink: 0;
}

.icon-btn:hover {
    background: var(--bg-input);
    color: var(--text);
    border-color: var(--border-strong);
}

.icon-btn svg { width: 18px; height: 18px; }

/* ── OVERLAY ── */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 199;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}
.overlay.active { opacity: 1; visibility: visible; }

/* ── SIDE MENU ── */
.sidemenu {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-w);
    max-width: 85vw;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}
.sidemenu.open { transform: translateX(0); }
html[dir="rtl"] .sidemenu { left: auto; right: 0; border-right: none; border-left: 1px solid var(--border); transform: translateX(100%); }
html[dir="rtl"] .sidemenu.open { transform: translateX(0); }

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

.sidemenu-brand {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.3px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
    text-decoration: none;
}
.sidemenu-brand svg { width: 22px; height: 22px; color: var(--accent); }

.sidemenu-body { flex: 1; overflow-y: auto; padding: 8px 12px; }

.sidemenu-footer {
    border-top: 1px solid var(--border);
    padding: 12px;
    flex-shrink: 0;
}
.sidemenu-footer-note { font-size: 11px; color: var(--text-tertiary); text-align: center; }

.nav-section { margin-bottom: 4px; }

.nav-section-title {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-tertiary);
    padding: 10px 8px 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-family: var(--font);
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 400;
    text-decoration: none;
}

.nav-item:hover { background: var(--bg-elevated); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.7; }
.nav-item.active svg { opacity: 1; }

.nav-divider { height: 1px; background: var(--border); margin: 8px 0; }

/* ── LANG TRIGGER ── */
.lang-trigger {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-family: var(--font);
    font-size: 14px;
    color: var(--text-secondary);
}
.lang-trigger:hover { background: var(--bg-elevated); color: var(--text); }
.lang-trigger svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.7; }
.lang-trigger .chevron { margin-left: auto; width: 14px; height: 14px; transition: transform 0.2s; }
.lang-trigger.expanded .chevron { transform: rotate(180deg); }

.lang-submenu { display: none; padding: 2px 0 2px 24px; max-height: 260px; overflow-y: auto; }
.lang-submenu.open { display: block; }
.lang-opt {
    display: block;
    width: 100%;
    padding: 7px 12px;
    border: none;
    background: none;
    text-align: left;
    font-family: var(--font);
    font-size: 13px;
    color: var(--text-secondary);
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: background var(--transition);
    text-decoration: none;
}
.lang-opt:hover { background: var(--bg-elevated); color: var(--text); }
.lang-opt.active { color: var(--accent); font-weight: 500; }

/* ── MAIN ── */
.main {
    max-width: 960px;
    margin: 0 auto;
    padding: 20px 16px;
}

.section-gap { margin-top: 16px; }

/* ── CONTENT SECTIONS (SEO) ── */
.content-area {
    margin-top: 32px;
    border-top: 1px solid var(--border);
    padding-top: 28px;
}

.content-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 16px;
}

.content-section h2 {
    font-size: 19px;
    font-weight: 700;
    margin-bottom: 12px;
    letter-spacing: -0.3px;
}
.content-section h3 {
    font-size: 15px;
    font-weight: 600;
    margin: 16px 0 6px;
    color: var(--text);
}
.content-section p {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: 10px;
}
.content-section ul, .content-section ol { padding-left: 20px; margin-bottom: 12px; }
.content-section li { font-size: 14px; color: var(--text-secondary); line-height: 1.7; margin-bottom: 4px; }
.content-section strong { color: var(--text); }

.content-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 12px;
    margin: 14px 0;
}
.content-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 18px;
}
.content-card h3 { margin-top: 0; font-size: 14px; }
.content-card p { font-size: 13px; margin-bottom: 0; }

.tip-box {
    background: var(--blue-soft);
    border: 1px solid rgba(74, 126, 199, 0.15);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin: 14px 0;
    font-size: 13px;
    color: var(--text);
    line-height: 1.6;
}
.tip-box strong { color: var(--blue); }

.warn-box {
    background: var(--orange-soft);
    border: 1px solid rgba(207, 124, 58, 0.15);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin: 14px 0;
    font-size: 13px;
    color: var(--text);
    line-height: 1.6;
}
.warn-box strong { color: var(--orange); }

/* ── FAQ ── */
.faq-list { margin-top: 8px; }
.faq-item { border-bottom: 1px solid var(--border); }
.faq-item:last-child { border-bottom: none; }
.faq-q {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 14px 0;
    border: none;
    background: none;
    cursor: pointer;
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    text-align: left;
    gap: 12px;
    transition: color var(--transition);
}
.faq-q:hover { color: var(--accent); }
.faq-q svg { width: 16px; height: 16px; flex-shrink: 0; transition: transform 0.25s; color: var(--text-tertiary); }
.faq-item.open .faq-q svg { transform: rotate(180deg); }
.faq-a { max-height: 0; overflow: hidden; transition: max-height 0.35s ease; }
.faq-item.open .faq-a { max-height: 500px; }
.faq-a-inner { padding: 0 0 14px; font-size: 13px; color: var(--text-secondary); line-height: 1.7; }

.exposure-table {
    width: 100%;
    border-collapse: collapse;
    margin: 14px 0;
    font-size: 13px;
}
.exposure-table th {
    text-align: left;
    padding: 10px 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-tertiary);
}
.exposure-table td {
    padding: 10px 12px;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}
.exposure-table tr:hover td { background: var(--bg-elevated); }

/* ── FOOTER ── */
.site-footer {
    margin-top: 28px;
    padding: 20px 0 8px;
    border-top: 1px solid var(--border);
    text-align: center;
}
.site-footer-inner { max-width: 960px; margin: 0 auto; }
.footer-links { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 8px; font-size: 13px; flex-wrap: wrap; }
.footer-links a { color: var(--text-secondary); text-decoration: none; transition: color var(--transition); }
.footer-links a:hover { color: var(--accent); }
.footer-copy { font-size: 12px; color: var(--text-tertiary); }

body.has-bottombar .site-footer {
    padding-bottom: calc(var(--bottombar-h) + 12px);
}

/* ═══════════════════════════════════════════════════════════════
   Shared form controls (used by Sound Meter, Spectrum Analyzer,
   Speaker Test, Microphone Test)
   ═══════════════════════════════════════════════════════════════ */

.setting-select {
    width: 100%;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg fill='%2378756f' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 20px;
    padding-right: 32px;
    transition: border-color var(--transition);
}
.setting-select:focus { outline: none; border-color: var(--accent); }

.setting-range {
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    border-radius: 2px;
    background: var(--bg-input);
    outline: none;
}
.setting-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px; height: 18px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--bg-card);
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.setting-range::-moz-range-thumb {
    width: 18px; height: 18px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--bg-card);
}

.setting-number {
    width: 68px;
    padding: 6px 8px;
    border-radius: var(--radius-xs);
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text);
    font-family: var(--mono);
    font-size: 13px;
    text-align: center;
}
.setting-number:focus { outline: none; border-color: var(--accent); }

.setting-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
}
.toggle-track {
    width: 44px;
    height: 24px;
    border-radius: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    position: relative;
    transition: all var(--transition);
    flex-shrink: 0;
}
.toggle-track.on { background: var(--accent); border-color: var(--accent); }
.toggle-knob {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    position: absolute;
    top: 2px;
    left: 2px;
    transition: transform var(--transition);
    box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.toggle-track.on .toggle-knob { transform: translateX(20px); }

.setting-disclaimer {
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    padding: 12px;
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.6;
    border: 1px solid var(--border);
}

.setting-range-wrap { display: flex; align-items: center; gap: 10px; }
.setting-range-wrap .setting-range { flex: 1; }

/* ─── Shared button family (used by Speaker Test, Microphone Test, Analyzer) ─── */
.ctrl-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    padding: 12px 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    color: var(--text);
    cursor: pointer;
    text-decoration: none;
    transition: all var(--transition);
    white-space: nowrap;
}
.ctrl-btn:hover           { background: var(--bg-input); border-color: var(--border-strong); }
.ctrl-btn:active          { transform: scale(0.97); }
.ctrl-btn:disabled,
.ctrl-btn.is-disabled     { opacity: 0.4; cursor: not-allowed; pointer-events: none; }

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

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

.ctrl-btn--ghost          { background: transparent; }
.ctrl-btn--ghost:hover    { background: var(--bg-elevated); }

/* ─── Segmented button group (used by Speaker Test channel switcher) ─── */
.seg-group {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    overflow: hidden;
}
.seg-group button {
    border: none;
    background: none;
    padding: 9px 16px;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}
.seg-group button + button { border-left: 1px solid var(--border); }
.seg-group button:hover    { background: var(--bg-input); color: var(--text); }
.seg-group button.on,
.seg-group button.active   { background: var(--accent); color: #fff; }

/* ── TOAST ── */
.toast {
    position: fixed;
    bottom: calc(var(--bottombar-h) + 12px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 20px;
    font-size: 13px;
    box-shadow: var(--shadow-lg);
    z-index: 300;
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    max-width: 90vw;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; pointer-events: auto; }

body:not(.has-bottombar) .toast { bottom: 20px; }

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

/* ── ANIMATIONS ── */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fadeIn 0.4s ease-out both; }

/* ── RESPONSIVE ── */
@media (max-width: 600px) {
    .header-inner { padding: 0 12px; height: 48px; }
    .site-title   { font-size: 15px; }
    .main         { padding: 12px; }
    .section-gap  { margin-top: 10px; }
    .content-section { padding: 18px; }
    .content-section h2 { font-size: 17px; }
}
