/*
 * padmon web tester styles.
 *
 * The palette and the measurements are ported from the Windows app:
 *   src/Padmon.App/App.xaml                   (brushes)
 *   src/Padmon.App/Styles/PadmonStyles.xaml   (page, card, text styles)
 *   src/Padmon.App/Views/ControllerDetailPage.xaml
 *   src/Padmon.App/Controls/ControllerDiagram.xaml / StickGraph.xaml
 *
 * Fluent uses Segoe UI Variable; the stack below falls back gracefully on macOS and
 * Linux while keeping the same sizes and weights.
 */

:root {
    --font-ui: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system,
        "Helvetica Neue", Arial, sans-serif;
    --font-display: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system,
        "Helvetica Neue", Arial, sans-serif;
    --font-mono: "Cascadia Mono", Consolas, "SFMono-Regular", "SF Mono", ui-monospace,
        monospace;

    --window-bg: #111214;
    --layer-bg: #16171a;
    --card-bg: #1a1b1f;
    --card-stroke: #2a2c32;
    --divider: #2a2c32;
    --subtle-fill: #25272c;
    --subtle-fill-tertiary: #1f2024;
    --control-fill: #25272c;
    --control-fill-hover: #2c2f35;
    --control-fill-active: #212328;
    --control-stroke: #363940;
    --text-primary: #ecedef;
    --text-secondary: #a6a9b0;
    --text-tertiary: #7a7e86;
    --accent: #7aa2f7;
    --accent-text: #9dbbfa;
    --text-on-accent: #0e1014;
    --highlight: #21f6fa;
    --pad-red: #e53935;

    --diagram-body: #1f2227;
    --diagram-shadow: #2a303b;
    --diagram-outline: #4c5a70;
    --stick-graph-grid: #3e4859;
    --stick-graph-ink: #7fb6ff;

    --info-bg: rgba(122, 162, 247, 0.12);

    color-scheme: dark;
}

:root[data-theme="light"] {
    --window-bg: #f5f5f6;
    --layer-bg: #ffffff;
    --card-bg: #ffffff;
    --card-stroke: #e5e5e5;
    --divider: #e5e5e5;
    --subtle-fill: #f0f0f0;
    --subtle-fill-tertiary: #f2f2f2;
    --control-fill: #fdfdfd;
    --control-fill-hover: #f6f6f6;
    --control-fill-active: #f2f2f2;
    --control-stroke: #e0e0e0;
    --text-primary: #1a1a1a;
    --text-secondary: #5d5d5d;
    --text-tertiary: #8a8a8a;
    --accent: #005fb8;
    --accent-text: #005fb8;
    --text-on-accent: #ffffff;
    --highlight: #3f8f68;

    --diagram-body: #ffffff;
    --diagram-shadow: #edf3fa;
    --diagram-outline: #c5d6ea;
    --stick-graph-grid: #d5deea;
    --stick-graph-ink: #0b3a6b;

    --info-bg: rgba(0, 95, 184, 0.08);

    color-scheme: light;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html,
body {
    margin: 0;
    padding: 0;
}

html {
    background: var(--window-bg);
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    font-family: var(--font-ui);
    font-size: 14px;
    line-height: 1.4;
    color: var(--text-primary);
    background: var(--window-bg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

button,
select,
input {
    font: inherit;
}

a {
    color: var(--accent-text);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* ---------------------------------------------------------------- app bar ---- */

.app-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    height: 42px;
    padding: 0 16px;
    background: var(--window-bg);
}

.app-bar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.app-bar-mark {
    width: 28px;
    height: 28px;
    flex: none;
    color: var(--highlight);
}

.app-bar-name {
    font-family: var(--font-display);
    font-size: 15px;
    font-weight: 600;
}

.app-bar-note {
    font-size: 12px;
    color: var(--text-tertiary);
    white-space: nowrap;
}

.app-bar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.segmented {
    display: inline-flex;
    padding: 2px;
    border: 1px solid var(--card-stroke);
    border-radius: 6px;
    background: var(--subtle-fill-tertiary);
}

.segmented-button {
    padding: 4px 10px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
}

.segmented-button:hover {
    color: var(--text-primary);
}

.segmented-button.is-selected {
    background: var(--control-fill);
    color: var(--text-primary);
}

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
}

.icon-button:hover {
    background: var(--subtle-fill);
    color: var(--text-primary);
}

.icon-button svg {
    width: 16px;
    height: 16px;
}

.select {
    height: 28px;
    max-width: 220px;
    padding: 0 6px;
    border: 1px solid var(--control-stroke);
    border-radius: 5px;
    background: var(--control-fill);
    color: var(--text-primary);
    font-size: 12px;
}

/* ------------------------------------------------------------------- page ---- */

.page {
    display: flex;
    flex-direction: column;
    flex: 1 0 auto;
    background: var(--layer-bg);
}

.page-root {
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 22px;
    width: 100%;
    max-width: 1480px;
    margin: 0 auto;
    padding: 12px 36px 40px;
}

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

/* Placeholder while no controller has been detected, in the app's empty-state style. */
.waiting-view {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px 16px 48px;
    text-align: center;
}

.waiting-glyph {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 96px;
    height: 96px;
    margin-bottom: 24px;
    border-radius: 50%;
    background: var(--subtle-fill);
    color: var(--accent);
}

.waiting-glyph svg {
    width: 46px;
    height: 46px;
}

.waiting-glyph::after {
    content: "";
    position: absolute;
    inset: 0;
    border: 2px solid var(--accent);
    border-radius: 50%;
    opacity: 0;
    pointer-events: none;
    animation: waiting-pulse 2.4s ease-out infinite;
}

@keyframes waiting-pulse {
    0% {
        transform: scale(0.98);
        opacity: 0.45;
    }

    80%,
    100% {
        transform: scale(1.5);
        opacity: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .waiting-glyph::after {
        animation: none;
    }
}

.waiting-title {
    margin: 0 0 8px;
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 600;
}

.waiting-message {
    margin: 0;
    max-width: 430px;
    font-size: 14px;
    color: var(--text-secondary);
}

.waiting-hint {
    margin: 16px 0 0;
    max-width: 430px;
    font-size: 12px;
    color: var(--text-tertiary);
}

.page-head-text {
    min-width: 0;
}

.page-title {
    margin: 0 0 5px;
    font-family: var(--font-display);
    font-size: 32px;
    font-weight: 600;
    line-height: 1.15;
    overflow-wrap: anywhere;
}

.page-subtitle {
    margin: 0;
    font-size: 14px;
    color: var(--text-secondary);
}

.page-head-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: none;
}

.pill {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 12px;
    background: var(--subtle-fill);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    padding: 5px 12px;
    border: 1px solid var(--control-stroke);
    border-radius: 5px;
    background: var(--control-fill);
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
}

.button:hover {
    background: var(--control-fill-hover);
}

.button:active {
    background: var(--control-fill-active);
    color: var(--text-secondary);
}

/* --------------------------------------------------------------- info bars ---- */

.info-bar {
    display: flex;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--card-stroke);
    border-radius: 8px;
    background: var(--info-bg);
}

.info-bar-icon {
    width: 18px;
    height: 18px;
    flex: none;
    margin-top: 1px;
    color: var(--accent);
}

.info-bar-text {
    min-width: 0;
}

.info-bar-title {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
}

.info-bar-message {
    margin: 2px 0 0;
    font-size: 13px;
    color: var(--text-secondary);
}

.info-bar-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    margin-left: auto;
    padding: 0;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
}

.info-bar-close:hover {
    background: var(--subtle-fill);
    color: var(--text-primary);
}

.info-bar-close svg {
    width: 12px;
    height: 12px;
}

/* ------------------------------------------------------------ diagram view ---- */

.diagram-view {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 470px;
    column-gap: 40px;
    row-gap: 28px;
    align-items: start;
}

.stats-panel {
    display: flex;
    flex-direction: column;
    gap: 26px;
    min-width: 0;
}

.stats-row {
    display: flex;
    flex-wrap: wrap;
    column-gap: 30px;
    row-gap: 14px;
}

.stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stat-timestamp {
    width: 150px;
}

.stat-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
}

.stat-value {
    font-size: 15px;
    color: var(--text-primary);
    overflow-wrap: anywhere;
}

.pad-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
    column-gap: 10px;
    row-gap: 12px;
}

.pad-grid-axes {
    grid-template-columns: 104px;
    row-gap: 14px;
}

.pad-cell {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    column-gap: 7px;
    align-items: center;
}

.pad-cell-bar {
    display: flex;
    align-items: flex-end;
    width: 5px;
    height: 34px;
    background: var(--subtle-fill);
}

.pad-cell-fill {
    width: 100%;
    height: 0;
    background: var(--pad-red);
}

.pad-cell-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.pad-cell-label {
    font-size: 11px;
    color: var(--text-secondary);
}

.pad-cell-value {
    font-size: 17px;
    line-height: 1.2;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.stick-groups {
    display: flex;
    flex-wrap: wrap;
    column-gap: 44px;
    row-gap: 26px;
}

.stick-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.stick-group-row {
    display: flex;
    align-items: center;
    column-gap: 22px;
}

.stick-graph-host {
    width: 130px;
    height: 130px;
    flex: none;
}

.stick-graph {
    display: block;
    width: 130px;
    height: 130px;
}

.stick-graph-grid {
    fill: none;
    stroke: var(--stick-graph-grid);
    stroke-width: 1.5;
}

.stick-graph-needle {
    stroke: var(--stick-graph-ink);
    stroke-width: 1.5;
}

.stick-graph-dot {
    fill: var(--stick-graph-ink);
}

/* ------------------------------------------------------------------ cards ---- */

.card {
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 20px;
    border: 1px solid var(--card-stroke);
    border-radius: 16px;
    background: var(--card-bg);
    min-width: 0;
}

.card-header {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.card-header-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.card-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.card-subtitle {
    margin: 0;
    font-size: 12px;
    color: var(--text-secondary);
}

.diagram-card {
    width: 470px;
    gap: 18px;
}

/* Card content spacing follows each StackPanel Spacing value in the page XAML. */
.card-triggers {
    gap: 16px;
}

.card-buttons {
    gap: 14px;
}

.card-details {
    gap: 12px;
}

.diagram-host {
    width: 100%;
}

.divider {
    height: 1px;
    background: var(--divider);
}

.controller-diagram {
    display: block;
    width: 100%;
    height: auto;
}

.diagram-body-shadow {
    fill: var(--diagram-shadow);
}

.diagram-body {
    fill: var(--diagram-body);
    stroke: var(--diagram-outline);
    stroke-width: 5;
    stroke-linejoin: round;
}

.diagram-crease {
    stroke: var(--diagram-shadow);
    stroke-width: 3;
}

.diagram-well {
    fill: none;
    stroke: var(--diagram-outline);
    stroke-width: 5;
}

.diagram-outline-shape {
    fill: none;
    stroke: var(--text-primary);
    stroke-width: 5;
}

.diagram-trigger-fill {
    fill: var(--pad-red);
}

.diagram-button {
    fill: transparent;
    stroke: var(--text-primary);
    stroke-width: 5;
    stroke-linejoin: round;
    transition: fill 40ms linear;
}

.diagram-knob-backdrop {
    fill: var(--diagram-body);
}

.diagram-knob {
    fill: transparent;
    stroke: var(--text-primary);
    stroke-width: 5;
    transition: fill 40ms linear;
}

.diagram-button.is-pressed,
.diagram-knob.is-pressed {
    fill: var(--pad-red);
}

.readout-grid {
    display: grid;
    grid-template-columns: 80px repeat(3, minmax(0, 1fr));
    column-gap: 14px;
    row-gap: 12px;
    align-items: start;
}

.readout-row-label {
    align-self: center;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
}

.readout {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.readout-value {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------ classic view ---- */

.classic-view {
    display: flex;
    flex-direction: column;
    gap: 22px;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.sticks-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 16px;
}

.stick-dial-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.stick-dial {
    display: block;
    width: 142px;
    height: 142px;
}

.dial-bg {
    fill: var(--subtle-fill);
    stroke: var(--card-stroke);
    stroke-width: 1;
}

.dial-inner {
    fill: none;
    stroke: var(--card-stroke);
    stroke-width: 1;
    stroke-dasharray: 3 4;
}

.dial-dot {
    fill: var(--accent);
}

.stick-dial-caption {
    font-size: 12px;
    color: var(--text-secondary);
    text-align: center;
}

.caption {
    margin: 0;
    font-size: 12px;
    color: var(--text-secondary);
}

.body-text {
    margin: 0;
    font-size: 14px;
    color: var(--text-primary);
}

.mono {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.trigger-block {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.trigger-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.progress {
    height: 8px;
    border-radius: 4px;
    background: var(--subtle-fill);
    overflow: hidden;
}

.progress-fill {
    width: 0;
    height: 100%;
    border-radius: 4px;
    background: var(--accent);
}

.toggle-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(94px, 1fr));
    gap: 8px;
}

.pad-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    padding: 4px 8px;
    border: 1px solid var(--control-stroke);
    border-radius: 4px;
    background: var(--control-fill);
    color: var(--text-primary);
    font-size: 12px;
    text-align: center;
    overflow-wrap: anywhere;
}

.pad-toggle.is-pressed {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--text-on-accent);
}

.axis-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.axis-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.axis-label {
    font-size: 12px;
    color: var(--text-secondary);
}

.axis-value {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.device-grid {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    column-gap: 12px;
    row-gap: 7px;
    align-items: baseline;
}

.device-label {
    font-size: 12px;
    color: var(--text-secondary);
}

.device-value {
    font-size: 14px;
    color: var(--text-primary);
    overflow-wrap: anywhere;
}

.device-value.mono {
    font-size: 12px;
    color: var(--text-secondary);
    text-overflow: ellipsis;
}

.device-note {
    margin: 8px 0 0;
    font-size: 12px;
    color: var(--text-secondary);
}

.card-note {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.card-note .caption:last-child {
    margin-top: 6px;
}

/* ----------------------------------------------------------------- footer ---- */

.page-footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 8px 16px;
    margin-top: auto;
    padding-top: 14px;
    border-top: 1px solid var(--divider);
    font-size: 12px;
    color: var(--text-tertiary);
}

.page-footer p {
    margin: 0;
}

/* ------------------------------------------------------------- responsive ---- */

.page-root.is-narrow .diagram-view {
    grid-template-columns: minmax(0, 1fr);
}

.page-root.is-narrow .diagram-card {
    width: auto;
    max-width: 560px;
}

@media (max-width: 900px) {
    .card-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 760px) {
    .app-bar {
        height: auto;
        flex-wrap: wrap;
        row-gap: 8px;
        padding: 8px 12px;
    }

    .app-bar-actions {
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .page-root {
        padding: 14px 18px 32px;
        gap: 18px;
    }

    .page-head {
        flex-wrap: wrap;
        row-gap: 12px;
    }

    .page-title {
        font-size: 26px;
    }

    .page-head-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .stick-groups {
        column-gap: 24px;
    }

    .readout-grid {
        grid-template-columns: 64px repeat(3, minmax(0, 1fr));
        column-gap: 10px;
    }
}

@media (max-width: 520px) {
    .app-bar-note {
        display: none;
    }

    .sticks-grid {
        grid-template-columns: minmax(0, 1fr);
        row-gap: 18px;
    }

    .stat-timestamp {
        width: auto;
    }
}
