:root {
    color-scheme: light;
    --color1: #9f348b;
    --color1-dark: #7d296c;
    --color1-darker: #5d1f51;
    --color1-light: #e6c3dd;
    --color1-lighter: #f7eaf4;
    --almost-black: #2c2c2c;
    --almost-white: #fcfcfc;
    --bg-color: #f0f0f0;

    --bg: var(--bg-color);
    --bg-accent: var(--color1-lighter);
    --panel: rgba(252, 252, 252, 0.92);
    --ink: var(--almost-black);
    --muted: #5e6672;
    --accent: var(--color1);
    --accent-dark: var(--color1-dark);
    --teal: #1f5e6c;
    --line: var(--color1);
    --shadow: 0 14px 40px rgba(44, 44, 44, 0.18);
    --radius: 18px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Sora", sans-serif;
    color: var(--ink);
    background: radial-gradient(circle at top, rgba(255, 255, 255, 0.9), transparent 55%),
        linear-gradient(120deg, var(--bg), var(--bg-accent));
    min-height: 100vh;
    font-size: 0.9rem;
}

#app {
    margin: 0 auto;
    padding: 32px;
    padding-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    min-height: 100vh;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
}

.brand {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 1;
}

.brand-logo {
    height: 44px;
    width: auto;
    display: block;
}

.logo-dot {
    width: 42px;
    height: 42px;
    background: linear-gradient(140deg, var(--accent), var(--teal));
    border-radius: 14px;
    box-shadow: 0 12px 24px rgba(212, 122, 45, 0.35);
}

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

.brand-name {
    font-family: "League Spartan", sans-serif;
    font-size: 2.6rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--accent);
    flex: 0 0 auto;
}

.brand-reload {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
}

.brand-reload:focus-visible {
    outline: 2px solid rgba(159, 52, 139, 0.6);
    outline-offset: 4px;
    border-radius: 6px;
}

.brand-tag {
    font-size: 14px;
    font-weight: bold;
    color: var(--muted);
    flex: 1;
    text-align: center;
    white-space: nowrap;
}

.header-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.layout {
    display: grid;
    grid-template-columns: minmax(520px, 4fr) minmax(280px, 1fr);
    gap: 20px;
    align-items: stretch;
    flex: 1;
    min-height: 0;
}

.legal-link {
    margin-top: auto;
    font-size: 13px;
    color: var(--muted);
    text-decoration: none;
    align-self: center;
}

.legal-link:hover {
    color: var(--accent);
}

.panel {
    background: var(--panel);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.legal-page .panel {
    max-width: 960px;
    width: 100%;
    margin: 0 auto;
}

.legal-title {
    font-family: "Space Grotesk", sans-serif;
    font-size: 28px;
    margin: 0 0 6px;
}

.legal-section h2 {
    font-size: 18px;
    margin: 18px 0 8px;
}

.legal-section p {
    margin: 0;
    color: var(--muted);
    line-height: 1.6;
}

.legal-section ul {
    margin: 0;
    padding-left: 20px;
    color: var(--muted);
    line-height: 1.6;
}

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

.legal-section a:hover {
    text-decoration: underline;
}

.panel-title {
    font-family: "Space Grotesk", sans-serif;
    font-weight: 600;
    font-size: 16px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
}

.panel-lead {
    margin: 0;
    font-size: 15px;
    line-height: 1.6;
}

.drop-zone {
    border: 2px dashed rgba(31, 94, 108, 0.35);
    border-radius: 16px;
    padding: 22px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    text-align: center;
    background: rgba(255, 255, 255, 0.7);
    transition: border-color 0.2s ease, transform 0.2s ease;
}

.drop-zone input[type="file"] {
    display: none;
}

.drop-zone.dragover {
    border-color: var(--accent);
    transform: translateY(-2px);
}

.drop-icon {
    font-size: 28px;
    color: var(--accent-dark);
}

.drop-copy {
    font-weight: 500;
}

.format-hint {
    font-size: 1.2rem;
    color: var(--muted);
}

.viewer-panel {
    gap: 16px;
    min-height: 0;
}

.intro-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: opacity 0.2s ease, max-height 0.2s ease, margin 0.2s ease;
}

.viewer-panel.has-plan .intro-content {
    opacity: 0;
    max-height: 0;
    margin: 0;
    pointer-events: none;
}

.viewer-frame {
    position: relative;
    width: 100%;
    min-height: 0;
    height: 100%;
    flex: 1;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg-color);
    border: 2px solid rgb(233, 233, 233);
    transition: border-color 0.2s ease;
}

.viewer-frame.dragover {
    border-color: var(--accent);
}

.viewer-frame.is-loading .loading-overlay {
    opacity: 1;
    pointer-events: auto;
}

.intro-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 22px;
    background: var(--bg-color);
    backdrop-filter: blur(3px);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.viewer-panel.has-plan .intro-overlay {
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
}

.loading-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    background: rgba(12, 18, 20, 0.68);
    color: #f8f5ef;
    font-family: "Space Grotesk", sans-serif;
    font-weight: 600;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 1000;
}

.spinner {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 3px solid rgba(248, 245, 239, 0.3);
    border-top-color: var(--accent);
    animation: spin 0.9s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.global-drop {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(10, 14, 16, 0.72);
    backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 20;
}

.global-drop.is-active {
    opacity: 1;
    pointer-events: auto;
}

.global-drop-card {
    padding: 28px 32px;
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.92);
    color: var(--ink);
    text-align: center;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3);
    display: grid;
    gap: 10px;
    min-width: 280px;
    border: 2px dashed rgba(212, 122, 45, 0.5);
}

.global-drop-card i {
    font-size: 32px;
    color: var(--accent-dark);
}

.global-drop-title {
    font-family: "Space Grotesk", sans-serif;
    font-size: 20px;
    font-weight: 600;
}

.global-drop-subtitle {
    font-size: 13px;
    color: var(--muted);
}

.viewer {
    width: 100%;
    height: 100%;
}

.viewer-hint {
    position: absolute;
    inset: auto 24px 24px 24px;
    background: rgba(255, 255, 255, 0.92);
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13px;
    color: var(--muted);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.viewer-controls {
    position: absolute;
    top: 20px;
    left: 20px;
    display: flex;
    gap: 10px;
    z-index: 3;
}

.viewer-btn {
    border: none;
    border-radius: 999px;
    padding: 10px 14px;
    font-family: "Space Grotesk", sans-serif;
    font-weight: 600;
    font-size: 14px;
    color: #fff;
    background: linear-gradient(120deg, var(--accent), var(--accent-dark));
    box-shadow: 0 12px 24px rgba(229, 0, 70, 0.3);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.viewer-panel .viewer-controls {
    display: none;
}

.viewer-panel.has-plan .viewer-controls {
    display: flex;
}

.viewer-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 16px 28px rgba(229, 0, 70, 0.35);
}

.viewer-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.measure-overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    --measure-stroke: 4px;
    --measure-label-size: 22px;
}

.measure-overlay line {
    stroke: var(--line);
    stroke-width: var(--measure-stroke);
    stroke-linecap: round;
}

.measure-overlay marker path {
    stroke: var(--line);
    stroke-width: var(--measure-stroke);
}

.measure-overlay circle {
    fill: var(--line);
}

.measure-overlay text {
    font-family: "Space Grotesk", sans-serif;
    font-size: var(--measure-label-size);
    font-weight: 600;
    fill: var(--accent);
    paint-order: stroke;
    stroke: rgba(255, 255, 255, 0.8);
    stroke-width: 4px;
}

.step {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

/* Direct scale input removed; keep calibration steps only. */

.step-number {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(31, 94, 108, 0.15);
    color: var(--teal);
    font-weight: 700;
    display: grid;
    place-items: center;
    flex: 0 0 34px;
    min-width: 34px;
    min-height: 34px;
}

.step-title {
    font-weight: 600;
    margin-bottom: 4px;
}

.step-text {
    color: var(--muted);
    font-size: 14px;
}

.distance-input {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
}

.distance-input input {
    width: 110px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(94, 102, 114, 0.2);
    font-size: 16px;
    font-family: "Space Grotesk", sans-serif;
}

.distance-input select {
    appearance: none;
    padding: 10px 36px 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(94, 102, 114, 0.2);
    background-color: #fff;
    font-size: 15px;
    font-family: "Space Grotesk", sans-serif;
    color: var(--ink);
    background-image:
        linear-gradient(45deg, transparent 50%, var(--accent) 50%),
        linear-gradient(135deg, var(--accent) 50%, transparent 50%),
        linear-gradient(to right, transparent, transparent);
    background-position:
        calc(100% - 18px) calc(50% - 3px),
        calc(100% - 12px) calc(50% - 3px),
        calc(100% - 36px) 50%;
    background-size: 6px 6px, 6px 6px, 1px 60%;
    background-repeat: no-repeat;
}

.distance-input select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(229, 0, 70, 0.12);
}

.primary-btn,
.ghost-btn {
    font-size: 1rem;
    border-radius: 999px;
    padding: 10px 16px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    font-family: "Space Grotesk", sans-serif;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.primary-btn {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 12px 24px rgba(212, 122, 45, 0.35);
}

.primary-btn:hover {
    background: var(--accent-dark);
    transform: translateY(-1px);
}

.ghost-btn {
    background: rgba(31, 94, 108, 0.1);
    color: var(--teal);
}

.ghost-btn:not(:disabled):hover {
    background: rgba(159, 52, 139, 0.12);
    color: var(--accent);
    transform: translateY(-1px);
    box-shadow: 0 6px 12px rgba(87, 28, 76, 0.18);
}

.ghost-btn#export-pdf:not(:disabled) {
    background: linear-gradient(120deg, rgba(159, 52, 139, 0.95), rgba(125, 41, 108, 0.95));
    color: #fff;
    box-shadow: 0 14px 28px rgba(159, 52, 139, 0.35);
}

.ghost-btn#export-pdf:not(:disabled):hover {
    transform: translateY(-1px);
    box-shadow: 0 18px 34px rgba(159, 52, 139, 0.4);
}

.ghost-btn:disabled,
.primary-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.summary {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    color: var(--muted);
    align-items: baseline;
}

.summary-row strong {
    color: var(--ink);
}

.summary-input {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    color: var(--ink);
}

.summary-input select {
    appearance: none;
    padding: 6px 28px 6px 10px;
    border-radius: 10px;
    border: 1px solid rgba(94, 102, 114, 0.2);
    background-color: #fff;
    font-size: 14px;
    font-family: "Space Grotesk", sans-serif;
    color: var(--ink);
    background-image:
        linear-gradient(45deg, transparent 50%, var(--accent) 50%),
        linear-gradient(135deg, var(--accent) 50%, transparent 50%),
        linear-gradient(to right, transparent, transparent);
    background-position:
        calc(100% - 16px) calc(50% - 2px),
        calc(100% - 10px) calc(50% - 2px),
        calc(100% - 28px) 50%;
    background-size: 6px 6px, 6px 6px, 1px 60%;
    background-repeat: no-repeat;
}

.summary-input select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(229, 0, 70, 0.12);
}

.summary-input--scale {
    gap: 10px;
}

.summary-input--scale select {
    min-width: 90px;
}

.summary-input input {
    width: 88px;
    padding: 6px 8px;
    border-radius: 10px;
    border: 1px solid rgba(94, 102, 114, 0.2);
    font-size: 14px;
    font-family: "Space Grotesk", sans-serif;
}

.summary-input--scale input {
    display: none;
    width: 88px;
}

.summary-input--scale.is-other input {
    display: inline-flex;
}

.summary-input input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(229, 0, 70, 0.12);
}

@media (max-width: 1100px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .viewer-frame {
        min-height: 420px;
    }
}

@media (max-width: 720px) {
    #app {
        padding: 24px 18px 32px;
    }

    .app-header {
        flex-direction: column;
        align-items: flex-start;
    }

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

    .viewer-btn {
        padding: 10px;
    }

    .viewer-btn span,
    .viewer-btn .btn-label {
        display: none;
    }

    .viewer-btn i {
        margin: 0;
    }
}
