/*
 * SPDX-FileCopyrightText: 2026 André Fiedler
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

@import url('../../src/styles/altium-renderers.css');

:root {
    color-scheme: light;
    --page: #f6f1e8;
    --panel: #fffaf3;
    --panel-strong: #ffffff;
    --ink: #172228;
    --muted: #52636c;
    --border: rgba(57, 73, 82, 0.16);
    --copper: #c35f35;
    --copper-dark: #824127;
    --board: #1f7a68;
    --board-dark: #15594f;
    --blue: #2a6fbb;
    --danger: #b4233d;
    --shadow: 0 18px 40px rgba(45, 55, 62, 0.14);
    font-family:
        Inter,
        ui-sans-serif,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        'Segoe UI',
        sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    min-width: 320px;
    margin: 0;
    color: var(--ink);
    background: var(--page);
}

html.is-svg-panning,
html.is-svg-panning body {
    overflow: hidden;
}

a {
    color: var(--blue);
    text-decoration-thickness: 0.08em;
    text-underline-offset: 0.18em;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-rows: auto 1fr;
}

.app-header {
    min-height: 8.5rem;
    display: flex;
    justify-content: space-between;
    gap: 1.5rem;
    align-items: center;
    padding: 1.5rem clamp(1rem, 4vw, 3rem);
    border-bottom: 1px solid var(--border);
    background: var(--panel);
}

.eyebrow,
.credit,
.status,
.source-facts,
.metadata-panel p,
.empty-state p {
    color: var(--muted);
}

.eyebrow {
    margin: 0 0 0.4rem;
    font-size: 0.76rem;
    font-weight: 700;
    text-transform: uppercase;
}

h1 {
    margin: 0;
    font-size: clamp(1.65rem, 3vw, 2.35rem);
    line-height: 1.08;
}

.credit {
    max-width: 54rem;
    margin: 0.55rem 0 0;
    line-height: 1.55;
}

.source-link {
    flex: 0 0 auto;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    min-height: 2.5rem;
    padding: 0.65rem 0.95rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--ink);
    background: var(--panel-strong);
    font-weight: 700;
    text-decoration: none;
}

.workspace {
    display: grid;
    grid-template-columns: minmax(18rem, 24rem) minmax(0, 1fr);
    min-height: 0;
}

.control-panel {
    display: grid;
    align-content: start;
    gap: 1.25rem;
    padding: 1.25rem;
    border-right: 1px solid var(--border);
    background: rgba(255, 250, 243, 0.72);
}

.file-picker {
    display: grid;
    gap: 0.7rem;
    font-weight: 700;
}

.file-picker input {
    width: 100%;
    padding: 0.8rem;
    border: 1px dashed rgba(57, 73, 82, 0.28);
    border-radius: 8px;
    background: var(--panel-strong);
}

.status {
    min-height: 3rem;
    margin: 0;
    padding: 0.8rem 0.9rem;
    border-left: 4px solid var(--blue);
    background: rgba(255, 255, 255, 0.62);
    line-height: 1.45;
}

.status[data-tone='busy'] {
    border-left-color: var(--copper);
}

.status[data-tone='error'] {
    border-left-color: var(--danger);
}

.source-facts {
    display: grid;
    gap: 0.85rem;
    margin: 0;
}

.source-facts div {
    display: grid;
    gap: 0.2rem;
    padding-top: 0.85rem;
    border-top: 1px solid var(--border);
}

.source-facts dt {
    color: var(--ink);
    font-weight: 800;
}

.source-facts dd {
    margin: 0;
    line-height: 1.45;
}

.viewer-panel {
    min-width: 0;
    overflow: hidden;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
}

.viewer-toolbar {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    padding: 1rem clamp(1rem, 3vw, 1.5rem);
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.54);
}

.tabs {
    display: flex;
    gap: 0.35rem;
    overflow-x: auto;
}

.tab {
    flex: 0 0 auto;
    min-height: 2.35rem;
    padding: 0.55rem 0.78rem;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--muted);
    background: transparent;
    font: inherit;
    font-weight: 750;
    cursor: pointer;
}

.tab:hover,
.tab:focus-visible {
    color: var(--ink);
    border-color: var(--border);
    background: var(--panel-strong);
}

.tab.is-active {
    color: var(--ink);
    border-color: rgba(31, 122, 104, 0.36);
    background: #e8f1eb;
}

.output {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    overflow: auto;
    padding: clamp(1rem, 3vw, 1.5rem);
}

.schematic-svg,
.pcb-svg {
    cursor: grab;
    user-select: none;
    touch-action: none;
}

.schematic-svg.is-panning,
.pcb-svg.is-panning {
    cursor: grabbing;
}

.empty-state,
.metadata-panel {
    max-width: 56rem;
    padding: 1.25rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel-strong);
}

.empty-state h2,
.metadata-panel h2,
.metadata-panel h3 {
    margin: 0;
}

.empty-state p,
.metadata-panel p {
    margin: 0.6rem 0 0;
    line-height: 1.55;
}

.empty-state--error {
    border-color: rgba(180, 35, 61, 0.35);
}

.metadata-panel {
    display: grid;
    gap: 1rem;
}

.metadata-panel table {
    width: 100%;
    border-collapse: collapse;
    overflow-wrap: anywhere;
}

.metadata-panel th,
.metadata-panel td {
    padding: 0.72rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

.metadata-panel th {
    width: 14rem;
    color: var(--copper-dark);
}

.metadata-panel ul {
    margin: 0;
    padding-left: 1.2rem;
    line-height: 1.6;
}

.bom-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--panel-strong);
}

.bom-table th,
.bom-table td {
    padding: 0.7rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

.scene-3d {
    display: grid;
    gap: 1rem;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    min-height: min(42rem, calc(100vh - 13rem));
}

.scene-3d__header {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: end;
    min-width: 0;
}

.scene-3d__header h2,
.scene-3d__header p,
.scene-3d__diagnostics {
    margin: 0;
}

.scene-3d__header p,
.scene-3d__diagnostics {
    color: var(--muted);
    line-height: 1.45;
}

.scene-3d__toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.scene-3d__preset {
    min-height: 2.25rem;
    padding: 0.5rem 0.76rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--ink);
    background: var(--panel-strong);
    font: inherit;
    font-weight: 750;
    cursor: pointer;
}

.scene-3d__preset:hover,
.scene-3d__preset:focus-visible {
    border-color: rgba(31, 122, 104, 0.36);
    background: #eef6f2;
}

.scene-3d__preset.is-active,
.scene-3d__preset[aria-pressed='true'] {
    border-color: rgba(31, 122, 104, 0.46);
    color: #0f3f37;
    background: #dcece6;
}

.scene-3d__stage {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    min-height: min(38rem, calc(100vh - 18rem));
    display: grid;
    grid-template-columns: minmax(0, 1fr) 13rem;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel-strong);
    box-shadow: var(--shadow);
}

.scene-3d__viewport {
    position: relative;
    min-width: 0;
    max-width: 100%;
    min-height: 28rem;
    background:
        radial-gradient(
            circle at 50% 0%,
            rgba(255, 255, 255, 0.82),
            rgba(255, 255, 255, 0) 46%
        ),
        linear-gradient(180deg, #f8f3ea 0%, #e7f0ed 100%);
}

.scene-3d__canvas-mount {
    position: absolute;
    inset: 0;
    min-width: 0;
}

.scene-3d__canvas {
    display: block;
    width: 100%;
    max-width: 100%;
    height: 100%;
    cursor: grab;
    touch-action: none;
}

.scene-3d__canvas:active {
    cursor: grabbing;
}

.scene-3d__loading {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 1rem;
    color: var(--muted);
    background: rgba(255, 250, 243, 0.86);
}

.scene-3d__loading[hidden] {
    display: none;
}

.scene-3d__loading p {
    margin: 0;
}

.scene-3d__controls {
    display: grid;
    align-content: start;
    gap: 0.75rem;
    padding: 1rem;
    border-left: 1px solid var(--border);
    background: rgba(255, 250, 243, 0.76);
}

.scene-3d__toggle {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    line-height: 1.35;
    font-weight: 700;
}

.scene-3d__toggle input {
    width: 1rem;
    height: 1rem;
    accent-color: var(--board);
}

.scene-3d__stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(5.5rem, 1fr));
    gap: 0.65rem;
    min-width: 0;
    margin: 0;
}

.scene-3d__stats div {
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.72);
}

.scene-3d__stats dt {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
}

.scene-3d__stats dd {
    margin: 0.22rem 0 0;
    font-weight: 800;
}

@media (max-width: 860px) {
    .app-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .workspace {
        grid-template-columns: 1fr;
    }

    .control-panel {
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .scene-3d__header {
        align-items: start;
        flex-direction: column;
    }

    .scene-3d__stage {
        grid-template-columns: 1fr;
    }

    .scene-3d__controls {
        border-top: 1px solid var(--border);
        border-left: 0;
    }
}

@media (max-width: 520px) {
    .app-header,
    .control-panel,
    .viewer-toolbar,
    .output {
        padding-inline: 0.85rem;
    }

    .source-link {
        width: 100%;
    }

    .metadata-panel th,
    .metadata-panel td {
        display: block;
        width: 100%;
    }

    .scene-3d__viewport {
        min-height: 20rem;
    }

    .scene-3d__stats {
        width: 100%;
        grid-template-columns: 1fr;
    }
}
