/* USBMCA web layout + native control styles (themes supply colours). */

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

html,
body {
    margin: 0;
    height: 100%;
}

body {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#app {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    padding-left: calc(10px + env(safe-area-inset-left));
    padding-right: calc(10px + env(safe-area-inset-right));
    gap: 6px;
}

#titlebar {
    display: none;
}

.app-title {
    font-family: "IBM Plex Mono", "Cascadia Mono", Consolas, monospace;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: inherit;
    opacity: 0.85;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#toolbar,
#tools,
#threshold-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

#toolbar {
    flex-shrink: 0;
    position: relative;
    z-index: 5;
    overflow: visible;
}

#tools {
    gap: 4px;
    flex-shrink: 0;
}

#totalEventsBox {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-width: 220px;
    padding: 3px 12px 4px 8px;
    margin-left: auto;
}

#totalEventsCap {
    align-self: flex-start;
}

#totalEvents {
    align-self: flex-end;
    line-height: 1;
}

#workspace {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.view {
    display: none;
    flex: 1;
    min-height: 0;
    flex-direction: column;
    overflow: auto;
}

.view.active {
    display: flex;
}

#view-hist {
    overflow: hidden;
}

#plot_frame {
    flex: 1;
    min-height: 180px;
    border: 1px solid #2c3648;
    border-radius: 4px;
    position: relative;
    overflow: hidden;
}

html[data-theme="light"] #plot_frame {
    border-color: #c5ced8;
}

#hist-canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
    cursor: crosshair;
}

#statusLabel {
    flex-shrink: 0;
}

button.toolBtn {
    width: 34px;
    height: 34px;
    min-width: 34px;
    padding: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

button.toolBtn svg,
button.toolBtn img {
    width: 22px;
    height: 22px;
    pointer-events: none;
}

#recordBtn,
#clearBtn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.record-group {
    display: inline-flex;
    flex-direction: row;
    align-items: stretch;
    gap: 0;
}

#recordBtn {
    height: 36px;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

#timerBtn {
    position: relative;
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    padding: 2px;
    margin-left: -1px;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

#recordBtn img,
#clearBtn img {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    pointer-events: none;
}

#timerBtn img {
    width: 20px;
    height: 20px;
}

#timerLeft {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 1px;
    font-size: 9px;
    font-weight: 700;
    line-height: 1;
    text-align: center;
    pointer-events: none;
    font-family: "IBM Plex Mono", "Cascadia Mono", Consolas, monospace;
}

#timerBtn.active {
    border-width: 2px;
    border-style: solid;
}

#timerBtn:disabled {
    cursor: default;
    opacity: 1;
}

#analysisIcon {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    cursor: pointer;
}

#analysisLabel {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}

.analysis-wrap {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 118px;
    min-height: 34px;
    padding: 0 10px 0 8px;
    border-radius: 5px;
    user-select: none;
}

#analysisText {
    border: none;
    background: transparent;
    padding: 0;
    min-width: 0;
    font-weight: 800;
    letter-spacing: 0.08em;
    cursor: pointer;
}

#liveResults {
    flex-shrink: 0;
    font-family: "IBM Plex Mono", "Cascadia Mono", Consolas, monospace;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.45;
    padding: 2px 4px 0;
    cursor: pointer;
}

.live-row {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#recordBtn[aria-pressed="true"] {
    /* paused — orange RECORD look comes from theme unchecked */
}

label.check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}

label.check input {
    appearance: none;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    margin: 0;
    border-radius: 3px;
    border: 2px solid #6a7a8c;
    background: #0a0e14;
    cursor: pointer;
}

label.check input:hover {
    border-color: #9aa8b8;
    background: #151c28;
}

label.check input:checked {
    background: #1ec97a;
    border-color: #1ec97a;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path fill='none' stroke='%230a1a14' stroke-width='2.4' d='M3 8.5 6.5 12 13 4'/></svg>");
    background-size: 14px 14px;
    background-position: center;
    background-repeat: no-repeat;
}

html[data-theme="light"] label.check input {
    background: #ffffff;
}

html[data-theme="light"] label.check input:hover {
    background: #f0f4f8;
    border-color: #1a2330;
}

html[data-theme="light"] label.check input:checked {
    background-color: #0b8f5a;
    border-color: #0b8f5a;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path fill='none' stroke='%23ffffff' stroke-width='2.4' d='M3 8.5 6.5 12 13 4'/></svg>");
}

select {
    appearance: none;
    -webkit-appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
        linear-gradient(135deg, currentColor 50%, transparent 50%);
    background-position: calc(100% - 14px) calc(50% - 2px), calc(100% - 9px) calc(50% - 2px);
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    padding-right: 28px;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    height: 8px;
    border-radius: 4px;
    background: #1a2230;
    border: 1px solid #2c3648;
    flex: 1;
    min-width: 80px;
}

html[data-theme="light"] input[type="range"] {
    background: #e0e6ec;
    border-color: #c5ced8;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 9px;
    background: #4db8ff;
    border: 1px solid #9ad4ff;
    cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 9px;
    background: #4db8ff;
    border: 1px solid #9ad4ff;
    cursor: pointer;
}

html[data-theme="light"] input[type="range"]::-webkit-slider-thumb {
    background: #2a8ad4;
    border-color: #1a6aa8;
}

html[data-theme="light"] input[type="range"]::-moz-range-thumb {
    background: #2a8ad4;
    border-color: #1a6aa8;
}

#dacEdit,
input.dacEdit {
    width: 56px;
    min-width: 48px;
}

input[type="color"] {
    width: 56px;
    height: 28px;
    padding: 0;
    border-radius: 4px;
    cursor: pointer;
}

.dacVolt,
#dacVolt {
    width: 72px;
    text-align: right;
}

.dac-row,
.form-row {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.view-body {
    max-width: 720px;
    width: 100%;
    margin: 0 auto;
    padding: 8px 4px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.view-body.wide {
    max-width: 960px;
}

.view-head {
    display: flex;
    align-items: center;
    gap: 8px;
}

.view-head h2 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: inherit;
}

.view-head .head-end {
    margin-left: auto;
}

.float-dlg {
    position: fixed;
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px 10px 12px;
    min-width: 280px;
    min-height: 180px;
    border-radius: 8px;
    border: 1px solid #3a4658;
    background: #121820;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
    color: inherit;
}

.float-dlg.hidden {
    display: none !important;
}

.float-dlg-head {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    cursor: grab;
    user-select: none;
    touch-action: none;
}

.float-dlg-head:active {
    cursor: grabbing;
}

.float-dlg-head h2 {
    margin: 0;
    font-size: 14px;
    font-weight: 700;
    flex: 1;
    min-width: 0;
}

.float-dlg-head button {
    cursor: pointer;
    flex-shrink: 0;
}

.float-dlg-resize {
    position: absolute;
    right: 2px;
    bottom: 2px;
    width: 16px;
    height: 16px;
    cursor: nwse-resize;
    touch-action: none;
    background:
        linear-gradient(135deg, transparent 50%, #6a7788 50%, #6a7788 62%, transparent 62%),
        linear-gradient(135deg, transparent 70%, #6a7788 70%, #6a7788 82%, transparent 82%);
}

html[data-theme="light"] .float-dlg {
    background: #ffffff;
    border-color: #c5ced8;
    box-shadow: 0 12px 32px rgba(20, 30, 40, 0.18);
}

html[data-theme="light"] .float-dlg-resize {
    background:
        linear-gradient(135deg, transparent 50%, #8a96a4 50%, #8a96a4 62%, transparent 62%),
        linear-gradient(135deg, transparent 70%, #8a96a4 70%, #8a96a4 82%, transparent 82%);
}

#trendLegend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex-shrink: 0;
}

.trend-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 26px;
    padding: 0 8px 0 6px;
    border-radius: 5px;
    border: 1px solid #3a4658;
    background: #1a2230;
    color: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}

.trend-chip .swatch {
    width: 28px;
    height: 10px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
}

.trend-chip .swatch svg {
    display: block;
}

.trend-chip:hover {
    border-color: #5dffb0;
}

.trend-chip[aria-pressed="false"] {
    opacity: 0.38;
}

html[data-theme="light"] .trend-chip:hover {
    border-color: #0b8f5a;
}

#trendReadout {
    min-height: 16px;
    font-family: "IBM Plex Mono", "Cascadia Mono", Consolas, monospace;
    font-size: 11px;
    font-weight: 600;
    flex-shrink: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#trend_frame {
    flex: 1;
    min-height: 80px;
    border: 1px solid #2c3648;
    border-radius: 4px;
    position: relative;
    overflow: hidden;
}

#trend-canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
}

html[data-theme="light"] .trend-chip {
    background: #ffffff;
    border-color: #c5ced8;
}

html[data-theme="light"] #trend_frame {
    border-color: #c5ced8;
}

button.back-btn {
    font-weight: 700;
    letter-spacing: 0.04em;
}

fieldset {
    border: 1px solid #2c3648;
    border-radius: 5px;
    padding: 10px 12px;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

html[data-theme="light"] fieldset {
    border-color: #c5ced8;
}

fieldset legend {
    padding: 0 6px;
    font-weight: 700;
}

fieldset#dacBox {
    padding: 12px 10px 10px;
}

fieldset#dacBox legend {
    padding: 0 6px;
}

.menu-wrap {
    position: relative;
    flex-shrink: 0;
}

@media (max-width: 720px) {
    .menu-wrap {
        order: 1;
        margin-left: auto;
    }

    #totalEventsBox {
        order: 2;
        margin-left: 0;
        width: 100%;
        min-width: 0;
    }
}

.menu-wrap:has(#shareChip:not(.hidden)) {
    margin-bottom: 26px;
}

.menu {
    display: none;
    position: fixed;
    z-index: 80;
    min-width: 180px;
    max-width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
    overflow-x: hidden;
    overflow-y: auto;
    flex-direction: column;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4);
}

.menu.open {
    display: flex;
}

.menu button {
    width: 100%;
    text-align: left;
    border: none;
    border-radius: 3px;
    background: transparent;
}

.menu hr {
    border: none;
    border-top: 1px solid #2c3648;
    margin: 4px 0;
}

html[data-theme="light"] .menu hr {
    border-top-color: #c5ced8;
}

#connect-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.connect-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid #2c3648;
    border-radius: 5px;
}

html[data-theme="light"] .connect-item {
    border-color: #c5ced8;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

th,
td {
    text-align: right;
}

th:nth-child(1),
td:nth-child(1),
th:nth-child(2),
td:nth-child(2) {
    text-align: center;
}

.color-btn {
    min-width: 56px;
    min-height: 24px;
    border-radius: 4px;
}

.hint {
    opacity: 0.8;
    line-height: 1.4;
}

.grow {
    flex: 1;
}

.tools-end {
    margin-left: auto;
}

.hidden {
    display: none !important;
}

#shareChip {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    z-index: 25;
    font-family: "IBM Plex Mono", "Cascadia Mono", Consolas, monospace;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.12em;
    padding: 4px 8px;
    min-height: 0;
    cursor: pointer;
}

#remoteFlag {
    position: fixed;
    top: calc(6px + env(safe-area-inset-top));
    right: calc(12px + env(safe-area-inset-right));
    z-index: 55;
    display: flex;
    gap: 10px;
    align-items: baseline;
    font-family: "IBM Plex Mono", "Cascadia Mono", Consolas, monospace;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    cursor: pointer;
    pointer-events: auto;
}

#remoteFlag.hidden {
    display: none !important;
}

body.remote-guest::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 8px;
    z-index: 54;
    pointer-events: none;
    box-shadow: 0 10px 28px 6px rgba(59, 130, 246, 0.75);
    background: linear-gradient(180deg, rgba(59, 130, 246, 0.55), transparent);
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 70;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(0, 0, 0, 0.5);
}

.modal.hidden {
    display: none !important;
}

.share-panel {
    width: min(420px, 100%);
    max-height: calc(100vh - 32px);
    overflow: auto;
    padding: 16px 18px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.share-panel h2 {
    margin: 0;
    font-size: 16px;
}

.share-panel .form-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.share-panel input[type="text"] {
    flex: 1;
    min-width: 0;
    font-family: "IBM Plex Mono", "Cascadia Mono", Consolas, monospace;
    font-size: 16px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    padding: 6px 8px;
}

#sharePin,
#joinPin {
    text-transform: none;
    letter-spacing: 0.2em;
}

.share-actions {
    gap: 8px;
}

#clearAllBtn,
#fetchDlgReplace,
#fetchDlgMerge,
#eraseDlgOk {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

#clearAllBtn img,
#fetchDlgReplace img,
#eraseDlgOk img {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    pointer-events: none;
}

#led-picker {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

#led-sv-canvas {
    touch-action: none;
    cursor: crosshair;
}

@media (max-width: 720px) {
    #totalEventsBox {
        min-width: 180px;
    }

    #totalEvents {
        font-size: 22px;
    }

    button#recordBtn,
    button#clearBtn,
    button#themeBtn {
        min-width: 72px;
    }
}
