/*
 * CNC-PART shared UI components — mirrors Apollo kiosk design language.
 * Tokens live in style.css :root; this file defines reusable classes only.
 */

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

.cnc-btn,
.btn-primary,
.btn-secondary,
.gp-btn,
.tool-btn {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: var(--button-height);
    padding: 0 var(--medium-spacing);
    border-radius: var(--small-spacing);
    font: inherit;
    font-size: var(--base-font-size);
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
    touch-action: manipulation;
    text-decoration: none;
    white-space: nowrap;
}

.cnc-btn:active:not(:disabled),
.btn-primary:active:not(:disabled),
.gp-btn:active:not(:disabled),
.tool-btn:active:not(:disabled) {
    transform: scale(0.98);
}

.cnc-btn:focus-visible,
.btn-primary:focus-visible,
.gp-btn:focus-visible,
.tool-btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.cnc-btn:disabled,
.btn-primary:disabled,
.gp-btn:disabled,
.tool-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.cnc-btn-primary,
.btn-primary,
.gp-btn-primary {
    width: 100%;
    color: #fff;
    border: 1px solid rgba(167, 78, 158, 0.35);
    background: linear-gradient(135deg, #3a2d40 0%, #2e2336 55%, #241c2d 100%);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.cnc-btn-primary:hover:not(:disabled),
.btn-primary:hover:not(:disabled),
.gp-btn-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, #4a3852 0%, #3a2d40 55%, #2e2336 100%);
    border-color: rgba(167, 78, 158, 0.55);
    box-shadow: 0 4px 12px rgba(167, 78, 158, 0.2);
    transform: translateY(-1px);
}

.cnc-btn,
.btn-secondary,
.gp-btn,
.tool-btn,
.btn-measure,
.btn-reset {
    color: var(--text-primary);
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.04);
}

.cnc-btn:hover:not(:disabled),
.btn-secondary:hover:not(:disabled),
.gp-btn:hover:not(:disabled),
.tool-btn:hover:not(:disabled),
.btn-measure:hover:not(:disabled),
.btn-reset:hover:not(:disabled) {
    border-color: rgba(167, 78, 158, 0.45);
    background: rgba(167, 78, 158, 0.08);
}

.cnc-btn-danger,
.gp-btn-danger {
    color: #fff;
    border: 1px solid rgba(239, 68, 68, 0.4);
    background: linear-gradient(135deg, #a83a3a 0%, #752525 100%);
}

.cnc-btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.method-block {
    margin-top: 12px;
}

.method-option {
    min-height: var(--button-height);
    border-radius: var(--small-spacing);
    background: linear-gradient(135deg, rgba(58, 45, 64, 0.45) 0%, rgba(36, 28, 45, 0.65) 100%);
    touch-action: manipulation;
}

.method-option.active {
    border-color: rgba(167, 78, 158, 0.55);
    background: linear-gradient(135deg, rgba(74, 56, 82, 0.65) 0%, rgba(46, 35, 54, 0.85) 100%);
    box-shadow: 0 0 0 1px rgba(167, 78, 158, 0.25);
}

.tool-btn.is-active,
.seg-btn.is-active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    font-weight: 600;
}

/* ─── Forms ───────────────────────────────────────────────────────────────── */

.cnc-label,
.stock-label,
.gp-field-label,
.target-form-label {
    display: block;
    font-size: var(--small-font-size);
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.cnc-input,
.cnc-select,
.stock-input,
.gp-input,
.gp-textarea,
.target-form-input,
.target-form-select {
    width: 100%;
    min-height: var(--button-height);
    padding: 10px 12px;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font: inherit;
    font-size: var(--base-font-size);
    outline: none;
    transition: border-color 0.15s ease;
}

.cnc-input:focus,
.cnc-select:focus,
.stock-input:focus,
.gp-input:focus,
.target-form-input:focus,
.target-form-select:focus {
    border-color: var(--primary);
}

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

.cnc-card,
.page-overview,
.home-card {
    background: linear-gradient(145deg, rgba(55, 55, 60, 0.95) 0%, rgba(40, 40, 45, 0.98) 100%);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.page-overview {
    border-left: 3px solid var(--primary);
    padding: 14px 16px;
}

.page-overview.is-collapsed .page-overview-steps {
    display: none;
}

.page-overview-toggle {
    appearance: none;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font: inherit;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    cursor: pointer;
    padding: 0;
    margin-left: auto;
}

.page-overview-head {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

/* ─── Status lines ────────────────────────────────────────────────────────── */

.cnc-status,
.status-idle,
.status-loading,
.status-ok,
.status-error,
.scan-tools-status {
    font-size: var(--small-font-size);
    min-height: 18px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-idle,
.cnc-status.is-idle { color: var(--text-secondary); }

.status-ok,
.cnc-status.is-ok,
.scan-tools-status.status-ok { color: var(--color-success); }

.status-error,
.cnc-status.is-error,
.scan-tools-status.status-error { color: var(--color-error); }

.status-loading,
.cnc-status.is-loading,
.scan-tools-status.status-loading { color: var(--primary); }

.status-loading::before,
.cnc-status.is-loading::before,
.scan-tools-status.status-loading::before {
    content: '';
    width: 14px;
    height: 14px;
    border: 2px solid rgba(167, 78, 158, 0.25);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: cnc-spin 0.7s linear infinite;
    flex-shrink: 0;
}

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

/* ─── Toast ───────────────────────────────────────────────────────────────── */

.cnc-toast-host {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 5000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    max-width: min(520px, 92vw);
}

.cnc-toast {
    padding: 12px 18px;
    border-radius: 12px;
    font-size: var(--base-font-size);
    font-weight: 500;
    color: var(--text-primary);
    background: rgba(22, 22, 27, 0.96);
    border: 1px solid var(--border-light);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(8px);
    animation: cnc-toast-in 0.25s ease;
}

.cnc-toast.is-success { border-color: rgba(34, 197, 94, 0.45); }
.cnc-toast.is-error { border-color: rgba(239, 68, 68, 0.45); }
.cnc-toast.is-loading { border-color: rgba(167, 78, 158, 0.45); }

@keyframes cnc-toast-in {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ─── Step rail (sidebar workflow) ──────────────────────────────────────── */

.cnc-step-rail {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 4px;
}

.cnc-step-pill {
    appearance: none;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-secondary);
    font: inherit;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 6px 10px;
    border-radius: 999px;
    cursor: default;
    pointer-events: none;
}

.cnc-step-pill.is-active {
    border-color: rgba(167, 78, 158, 0.55);
    background: rgba(167, 78, 158, 0.15);
    color: var(--text-primary);
}

.cnc-step-pill.is-done {
    border-color: rgba(34, 197, 94, 0.35);
    color: var(--color-success);
}

/* ─── Viewer empty state + legends ──────────────────────────────────────── */

.viewer-empty {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 32px;
    pointer-events: none;
    gap: 12px;
}

.viewer-empty-icon {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    border: 1px solid var(--border-light);
    background: rgba(167, 78, 158, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: 700;
    color: var(--primary);
}

.viewer-empty-title {
    font-size: var(--large-font-size);
    font-weight: 700;
    color: var(--text-primary);
}

.viewer-empty-sub {
    font-size: var(--base-font-size);
    color: var(--text-secondary);
    max-width: 360px;
    line-height: 1.5;
}

.viewer-legend,
#mesh-legend,
#scan-legend,
#residual-legend {
    position: absolute;
    right: 20px;
    top: 16px;
    background: rgba(10, 10, 15, 0.88);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    pointer-events: none;
    z-index: 10;
}

.viewer-container--has-toolbar .viewer-legend,
.viewer-container--has-toolbar #mesh-legend,
.viewer-container--has-toolbar #scan-legend {
    top: 72px;
}

/* ─── App header chrome ───────────────────────────────────────────────────── */

#app-header {
    height: var(--header-height);
    background: var(--bg-app);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 var(--medium-spacing);
    gap: var(--medium-spacing);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 200;
}

.app-header-brand {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex-shrink: 1;
}

.app-header-wordmark {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--primary);
}

.app-header-title {
    font-size: var(--large-font-size);
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-header-sub {
    font-size: var(--small-font-size);
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-header-nav {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
    flex-shrink: 0;
}

.app-nav-link {
    padding: 8px 12px;
    min-height: 36px;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: var(--small-font-size);
    font-weight: 600;
    text-decoration: none;
    transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
    white-space: nowrap;
}

.app-nav-link:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.04);
    border-color: var(--border);
}

.app-nav-link.is-active {
    color: var(--text-primary);
    background: rgba(167, 78, 158, 0.15);
    border-color: rgba(167, 78, 158, 0.45);
}

.app-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.app-nav-menu-btn {
    display: none;
}

.app-nav-drawer {
    display: none;
}

/* ─── Home hub ────────────────────────────────────────────────────────────── */

.home-workflow-note {
    font-size: var(--small-font-size);
    color: var(--text-secondary);
    margin-top: 8px;
}

.home-card.is-recommended {
    border-color: rgba(167, 78, 158, 0.45);
    box-shadow: 0 8px 28px rgba(167, 78, 158, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

/* ─── Kiosk responsive ──────────────────────────────────────────────────── */

@media (max-width: 1100px) {
    .app-header-sub {
        display: none;
    }

    .app-header-nav {
        display: none;
    }

    .app-nav-menu-btn {
        display: inline-flex;
        margin-left: auto;
    }

    .app-nav-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        top: var(--header-height);
        right: 0;
        width: min(280px, 85vw);
        background: var(--bg-panel);
        border-left: 1px solid var(--border);
        border-bottom: 1px solid var(--border);
        padding: 12px;
        gap: 6px;
        z-index: 199;
        box-shadow: -8px 8px 24px rgba(0, 0, 0, 0.4);
    }

    .app-nav-drawer[hidden] {
        display: none !important;
    }

    .app-nav-drawer .app-nav-link {
        width: 100%;
        justify-content: flex-start;
    }

    main {
        flex-direction: column;
    }

    #sidebar {
        width: 100%;
        min-width: 0;
        max-height: 42vh;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    #viewer-container {
        min-height: 50vh;
    }
}

@media (max-width: 720px) {
    .scan-toolbar {
        left: 8px;
        right: 8px;
        top: 8px;
        padding: 6px;
    }

    .home-card-grid {
        grid-template-columns: 1fr;
    }
}
