/* ============================================================
   Sampler App — Dark Theme
   ============================================================ */

:root {
    --bg:           #0d1117;
    --surface:      #161b27;
    --surface2:     #1e2436;
    --border:       #222;
    --border2:      #2a4a2a;

    --green:        #4CAF50;
    --green-dim:    #1a3a1a;
    --green-text:   #7fff7f;
    --green-label:  #6a9a6a;

    --yellow:       #c8a800;
    --yellow-dim:   #2a2a1a;

    --red:          #e05050;
    --red-dim:      #2a1a1a;

    --blue:         #5599ff;
    --blue-dim:     #1a2a4a;

    --text:         #e0e0e0;
    --text-dim:     #aaa;
    --text-faint:   #666;

    --header-h:     52px;
    --banner-h:     36px;
}

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

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 17px;
    -webkit-tap-highlight-color: transparent;
}

/* ── App Shell ───────────────────────────────────────────── */

#appShell {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 480px;
    margin: 0 auto;
    position: relative;
}

/* ── Header ──────────────────────────────────────────────── */

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-h);
    padding: 0 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 10;
}

.app-header .title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: 0.02em;
}

.icon-btn {
    width: 36px;
    height: 36px;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}
.icon-btn:active { background: var(--surface2); }
.icon-btn.hidden { visibility: hidden; pointer-events: none; }

.hamburger-icon {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.hamburger-icon span {
    width: 20px; height: 2px;
    background: var(--text-dim);
    border-radius: 2px;
    display: block;
}

/* ── Warning banner (factory/manual tune mode) ───────────── */

#warnBanner {
    background: var(--yellow-dim);
    border-bottom: 1px solid rgba(200,168,0,0.3);
    height: var(--banner-h);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--yellow);
    letter-spacing: 0.03em;
    flex-shrink: 0;
}
#warnBanner.hidden { display: none; }

/* ── Screens ─────────────────────────────────────────────── */

.screen {
    display: none;
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.screen.active { display: flex; flex-direction: column; }

.screen-body {
    padding: 14px 14px 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
}

/* ── Section heading ─────────────────────────────────────── */

.section-heading {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-faint);
    padding: 4px 2px 0;
}

/* ── Cards / rows ────────────────────────────────────────── */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
}

/* ── Device row (home) ───────────────────────────────────── */

.device-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.device-name { font-size: 17px; font-weight: 600; color: var(--text); }
.device-serial { font-size: 13px; color: var(--text-faint); margin-top: 2px; }

.conn-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 600;
    padding: 5px 12px;
    border-radius: 20px;
    cursor: pointer;
    white-space: nowrap;
}
.conn-badge.connected    { background: var(--green-dim); color: var(--green); border: 1px solid var(--green); }
.conn-badge.disconnected { background: var(--red-dim);   color: var(--red);   border: 1px solid var(--red); }

.conn-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.conn-dot.on  { background: var(--green); box-shadow: 0 0 5px var(--green); }
.conn-dot.off { background: var(--red); }

/* ── Arm button ──────────────────────────────────────────── */

.arm-btn {
    width: 100%;
    padding: 16px;
    border-radius: 12px;
    border: 2px solid;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    letter-spacing: 0.04em;
    transition: opacity 0.2s;
}
.arm-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.arm-btn.armed    { background: var(--green-dim); color: var(--green);  border-color: var(--green); }
.arm-btn.sleeping { background: var(--yellow-dim); color: var(--yellow); border-color: var(--yellow); }

/* ── Status panel ────────────────────────────────────────── */

.status-panel {
    background: #0e1e0e;
    border: 1px solid var(--border2);
    border-radius: 12px;
    padding: 12px 14px;
}
.panel-title {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
    margin-bottom: 8px;
}
.status-panel .panel-title { color: var(--green); }
.session-panel .panel-title { color: #8888cc; }

.kv-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 7px 10px;
}
.kv-key { font-size: 12px; color: var(--green-label); text-transform: uppercase; letter-spacing: 0.05em; }
.kv-val { font-size: 17px; color: var(--green-text); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ── Session panel ───────────────────────────────────────── */

.session-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
}
.session-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 4px 0;
    border-bottom: 1px solid var(--surface2);
}
.session-row:last-child { border-bottom: none; }
.session-key { font-size: 15px; color: var(--text-dim); }
.session-val { font-size: 22px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.session-unit { font-size: 13px; color: var(--text-faint); margin-left: 2px; }
.session-row.hidden { display: none; }

/* ── Buttons ─────────────────────────────────────────────── */

.btn {
    width: 100%;
    padding: 14px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-dim);
    transition: opacity 0.15s;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:active:not(:disabled) { opacity: 0.75; }

.btn-primary { background: var(--blue-dim);   color: var(--blue);   border-color: var(--blue); }
.btn-success { background: var(--green-dim);  color: var(--green);  border-color: var(--green); }
.btn-danger  { background: var(--red-dim);    color: var(--red);    border-color: var(--red); }
.btn-warn    { background: var(--yellow-dim); color: var(--yellow); border-color: var(--yellow); }

.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* ── Form rows (settings) ────────────────────────────────── */

.form-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.form-label { font-size: 16px; color: var(--text); }
.form-sub   { font-size: 13px; color: var(--text-faint); margin-top: 2px; }

.form-input {
    font-size: 15px;
    font-weight: 600;
    color: var(--green-text);
    background: #0e1e0e;
    border: 1px solid var(--border2);
    border-radius: 8px;
    padding: 6px 10px;
    width: 80px;
    text-align: right;
    outline: none;
}
.form-input:focus { border-color: var(--green); }

/* ── Toggle ──────────────────────────────────────────────── */

.toggle-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}
.toggle {
    width: 44px; height: 24px;
    border-radius: 12px;
    position: relative;
    transition: background 0.2s;
    border: 1px solid;
    flex-shrink: 0;
}
.toggle.on  { background: var(--green-dim); border-color: var(--green); }
.toggle.off { background: #222;            border-color: #444; }
.toggle::after {
    content: '';
    width: 18px; height: 18px;
    border-radius: 50%;
    position: absolute;
    top: 2px;
    transition: left 0.2s, background 0.2s;
}
.toggle.on::after  { left: calc(100% - 20px); background: var(--green); }
.toggle.off::after { left: 2px;               background: #555; }

/* ── BT device list (connections screen) ────────────────── */

.bt-device {
    display: flex;
    align-items: stretch;
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    background: var(--surface);
}
.bt-device.active-conn { border-color: var(--green); }
.bt-indicator { width: 6px; flex-shrink: 0; background: var(--border); }
.bt-indicator.on { background: var(--green); }
.bt-info { padding: 10px 12px; flex: 1; }
.bt-name { font-size: 14px; font-weight: 600; color: var(--text); }
.bt-sub  { font-size: 11px; color: var(--text-faint); margin-top: 2px; }

/* ── Full signal meters (calibration screen) ─────────────── */

.signal-meter { display: flex; flex-direction: column; gap: 4px; }
.meter-label { font-size: 11px; color: #888; text-transform: uppercase; letter-spacing: 0.06em; }
.meter-bar-bg { height: 10px; background: #1a2a1a; border-radius: 5px; overflow: hidden; }
.meter-bar-fill {
    height: 100%; border-radius: 5px;
    background: linear-gradient(90deg, #2a7a2a, var(--green));
    transition: width 0.3s ease;
}
.meter-bar-fill.yellow { background: linear-gradient(90deg, #7a7a2a, #c8c820); }
.meter-bar-fill.red    { background: linear-gradient(90deg, #7a2a2a, var(--red)); }
.meter-val { font-size: 12px; color: var(--green-text); text-align: right; font-variant-numeric: tabular-nums; }

/* ── Compact inline meters (manual tune screen) ─────────── */

.compact-meters {
    background: #0e1e0e;
    border: 1px solid var(--border2);
    border-radius: 12px;
    padding: 10px 12px;
}
.compact-meters .panel-title { color: var(--green); }

.cm-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.cm-label {
    font-size: 11px; color: var(--green-label);
    text-transform: uppercase; letter-spacing: 0.04em;
    width: 70px; flex-shrink: 0;
}
.cm-bar-bg { flex: 1; height: 7px; background: #1a2a1a; border-radius: 4px; overflow: hidden; }
.cm-bar-fill {
    height: 100%; border-radius: 4px;
    background: linear-gradient(90deg, #2a7a2a, var(--green));
    transition: width 0.3s ease;
}
.cm-bar-fill.yellow { background: linear-gradient(90deg, #7a7a2a, #c8c820); }
.cm-val {
    font-size: 12px; color: var(--green-text);
    font-weight: 700; font-variant-numeric: tabular-nums;
    width: 58px; text-align: right; flex-shrink: 0;
}

/* ── Calibration nudge rows ──────────────────────────────── */

.cal-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px 12px;
}
.cal-label { font-size: 13px; color: var(--text); }
.cal-index { font-size: 10px; color: var(--text-faint); margin-top: 1px; }

.nudge-group { display: flex; align-items: center; gap: 7px; }
.nudge-btn {
    width: 32px; height: 32px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text-dim);
    font-size: 20px;
    font-weight: 300;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    line-height: 1;
    flex-shrink: 0;
}
.nudge-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.nudge-btn:active:not(:disabled) { background: #333; }

.nudge-val {
    min-width: 48px; text-align: center;
    font-size: 14px; font-weight: 700;
    color: var(--green-text);
    background: #0e1e0e;
    border: 1px solid var(--border2);
    border-radius: 6px;
    padding: 4px 2px;
    font-variant-numeric: tabular-nums;
}

/* ── Menu overlay ────────────────────────────────────────── */

#menuOverlay {
    position: absolute;
    top: var(--header-h);
    left: 0; right: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: 20;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
#menuOverlay.hidden { display: none; }

.menu-list { padding: 8px; }
.menu-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 13px 12px;
    border-radius: 10px;
    cursor: pointer;
    color: var(--text);
    font-size: 15px;
}
.menu-item:hover, .menu-item:active { background: var(--surface2); }
.menu-item .menu-icon { margin-right: 12px; font-size: 17px; }
.menu-item .chevron { color: var(--text-faint); font-size: 18px; }
.menu-divider { height: 1px; background: var(--border); margin: 4px 8px; }

/* ── PIN modal ───────────────────────────────────────────── */

#pinModal {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 30;
    display: flex;
    align-items: flex-end;
}
#pinModal.hidden { display: none; }

.pin-sheet {
    background: var(--surface);
    border-radius: 20px 20px 0 0;
    padding: 20px 16px 32px;
    width: 100%;
}
.pin-title {
    text-align: center;
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}
.pin-subtitle {
    text-align: center;
    font-size: 12px;
    color: var(--text-faint);
    margin-bottom: 16px;
}
.pin-dots {
    display: flex;
    justify-content: center;
    gap: 14px;
    margin-bottom: 20px;
}
.pin-dot {
    width: 14px; height: 14px;
    border-radius: 50%;
    border: 2px solid #444;
    background: transparent;
    transition: background 0.15s, border-color 0.15s;
}
.pin-dot.filled { background: var(--yellow); border-color: var(--yellow); }
.pin-dot.error  { background: var(--red);    border-color: var(--red); }

.pin-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}
.pin-key {
    padding: 15px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 12px;
    text-align: center;
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    user-select: none;
}
.pin-key:active { background: #2a3040; }
.pin-key.del { font-size: 15px; color: var(--text-dim); }
.pin-key.empty { background: transparent; border-color: transparent; cursor: default; }
.pin-cancel-btn { margin-top: 12px; }

/* ── Misc helpers ────────────────────────────────────────── */

.info-text {
    font-size: 14px;
    color: var(--text-faint);
    text-align: center;
    padding: 2px 0;
}
.info-text.left { text-align: left; }
.info-text.error { color: var(--red); }

.hidden { display: none !important; }
.mt-auto { margin-top: auto; }

/* ── Scrollbar styling ───────────────────────────────────── */

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 4px; }

/* ── Save Session sheet ──────────────────────────────────── */

.save-sheet-bg {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 200;
    display: flex; align-items: flex-end;
}
.save-sheet {
    background: var(--surface);
    border-radius: 20px 20px 0 0;
    padding: 20px 20px 32px;
    width: 100%; max-width: 480px;
    margin: 0 auto;
    display: flex; flex-direction: column; gap: 14px;
}
.save-sheet-title {
    font-size: 17px; font-weight: 700;
    color: var(--text); text-align: center;
    margin-bottom: 2px;
}

/* Summary row */
.save-summary {
    display: flex; gap: 8px; justify-content: center;
}
.save-summary-item {
    flex: 1;
    background: var(--surface2);
    border-radius: 10px;
    padding: 10px 6px;
    text-align: center;
}
.save-summary-key {
    font-size: 11px; color: var(--text-dim);
    text-transform: uppercase; letter-spacing: 0.04em;
    margin-bottom: 3px;
}
.save-summary-val {
    font-size: 20px; font-weight: 700; color: var(--yellow);
}

/* Site name input */
.save-field-block { display: flex; flex-direction: column; gap: 5px; }
.save-field-label { font-size: 13px; color: var(--text-dim); }
.save-site-input {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-size: 15px;
    padding: 10px 12px;
    outline: none;
    width: 100%;
    box-sizing: border-box;
}
.save-site-input:focus { border-color: var(--blue); }

/* GPS checkbox row */
.save-checkbox-row {
    display: flex; align-items: flex-start; gap: 10px;
}
.save-checkbox { width: 18px; height: 18px; accent-color: var(--blue); flex-shrink: 0; margin-top: 1px; }
.save-checkbox-label { font-size: 13px; color: var(--text-dim); line-height: 1.4; }

/* Button row */
.save-btn-row { display: flex; gap: 10px; margin-top: 4px; }
.save-btn-row .btn { flex: 1; }

/* ── Sessions list screen ────────────────────────────────── */

.sess-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px;
    display: flex; flex-direction: column; gap: 10px;
    margin-bottom: 10px;
}
.sess-card-header {
    display: flex; justify-content: space-between; align-items: baseline;
}
.sess-site {
    font-size: 15px; font-weight: 700; color: var(--text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    max-width: 65%;
}
.sess-date { font-size: 12px; color: var(--text-faint); flex-shrink: 0; }
.sess-badge {
    display: inline-block;
    font-size: 10px; font-weight: 600;
    background: var(--blue); color: #fff;
    border-radius: 5px; padding: 2px 6px;
    margin-left: 6px; vertical-align: middle;
}

.sess-stats {
    display: flex; gap: 6px;
}
.sess-stat {
    flex: 1;
    background: var(--surface2);
    border-radius: 9px;
    padding: 8px 6px;
    text-align: center;
}
.sess-stat-val {
    font-size: 18px; font-weight: 700; color: var(--yellow);
}
.sess-stat-unit {
    font-size: 10px; color: var(--text-faint);
}
.sess-stat-key {
    font-size: 10px; color: var(--text-dim);
    text-transform: uppercase; letter-spacing: 0.04em;
    margin-top: 2px;
}

.sess-gps {
    font-size: 12px; color: var(--text-dim);
    display: flex; align-items: center; gap: 4px;
}
.sess-gps.no-gps { color: var(--text-faint); font-style: italic; }

/* Action buttons */
.sess-actions {
    display: flex; gap: 6px; flex-wrap: wrap;
}
.sess-action {
    flex: 1; min-width: 56px;
    padding: 7px 4px;
    border-radius: 9px;
    font-size: 12px; font-weight: 600;
    border: none; cursor: pointer;
    color: #fff;
    text-align: center;
}
.sess-action.download { background: #1a6b3a; }
.sess-action.download:active { background: #145430; }
.sess-action.share    { background: #1a4d8c; }
.sess-action.share:active    { background: #143a6e; }
.sess-action.email    { background: #5a3e80; }
.sess-action.email:active    { background: #452f63; }
.sess-action.delete   { background: #7a1f1f; }
.sess-action.delete:active   { background: #5e1818; }
