/**
 * QuoteMaster - ADG 2.0
 * 遵循 .cursorrules 規範，純原生 CSS，無外部框架，深色科技擬態風格
 */

/* =========================================
   1. CSS Variables (Design Tokens)
   ========================================= */
:root {
    /* 核心色彩 */
    --bg-dark: #07090f;
    --bg-panel: rgba(16, 22, 35, 0.65);
    /* 高對比亮色 */
    --accent-primary: #00f0ff;
    /* Cyan */
    --accent-secondary: #7000ff;
    /* Neon Purple */
    --accent-warning: #ffb800;
    /* Amber */
    --accent-danger: #ff2a55;
    /* Pinkish Red */
    --text-main: #f0f4fa;
    --text-muted: #8b9bb4;

    /* 玻璃擬態與邊框 */
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-highlight: rgba(255, 255, 255, 0.15);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.4);

    /* 動畫配置 */
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    /* 字體棧 (無外部請求) */
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

/* =========================================
   2. Reset & Typography
   ========================================= */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-sans);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* 自訂捲軸 */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
}

/* =========================================
   3. Background Effects
   ========================================= */
.bg-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    overflow: hidden;
    background: radial-gradient(circle at center, #0c1220 0%, #05070a 100%);
}

.noise-overlay {
    position: absolute;
    inset: 0;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
    mix-blend-mode: overlay;
    pointer-events: none;
}

.glow-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.4;
    animation: float 20s infinite alternate ease-in-out;
}

.glow-orb.primary {
    top: -10%;
    left: -10%;
    width: 50vw;
    height: 50vw;
    background: radial-gradient(circle, rgba(0, 240, 255, 0.15) 0%, transparent 70%);
}

.glow-orb.secondary {
    bottom: -20%;
    right: -10%;
    width: 60vw;
    height: 60vw;
    background: radial-gradient(circle, rgba(112, 0, 255, 0.15) 0%, transparent 70%);
    animation-delay: -5s;
}

@keyframes float {
    0% {
        transform: translate(0, 0) scale(1);
    }

    100% {
        transform: translate(5%, 10%) scale(1.1);
    }
}

/* =========================================
   4. Layout & Grid
   ========================================= */
.app-wrapper {
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 1rem;
    gap: 1rem;
}

/* Header */
.glass-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    height: 70px;
    flex-shrink: 0;
}

.nav-left {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.btn-back {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    border: 1px solid transparent;
    transition: var(--transition-fast);
}

.btn-back:hover {
    color: var(--accent-primary);
    background: rgba(0, 240, 255, 0.05);
    border-color: rgba(0, 240, 255, 0.2);
}

.btn-back svg {
    width: 18px;
    height: 18px;
}

.branding {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.glitch {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    position: relative;
    color: #fff;
    text-shadow: 0 0 10px rgba(0, 240, 255, 0.5);
}

.version-tag {
    font-size: 0.65rem;
    font-weight: 700;
    padding: 0.2rem 0.4rem;
    background: var(--accent-secondary);
    color: #fff;
    border-radius: 4px;
    letter-spacing: 1px;
}

.engine-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--accent-primary);
    background: rgba(0, 240, 255, 0.05);
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    border: 1px solid rgba(0, 240, 255, 0.2);
}

.status-dot {
    width: 8px;
    height: 8px;
    background: var(--accent-primary);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--accent-primary);
    animation: blink 2s infinite ease-in-out;
}

@keyframes blink {

    0%,
    100% {
        opacity: 0.4;
    }

    50% {
        opacity: 1;
    }
}

/* Dashboard Grid */
.dashboard {
    display: grid;
    grid-template-columns: 320px 1fr 400px;
    gap: 1rem;
    flex-grow: 1;
    min-height: 0;
}

/* Glass Panels */
.glass-card {
    background: var(--bg-panel);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: var(--glass-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-head {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--glass-border);
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0.03) 0%, transparent 100%);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-head h2 {
    font-size: 1.1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    letter-spacing: 0.5px;
}

.panel-head .icon {
    font-size: 1.2rem;
    filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.3));
}

.panel-head .subtext {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* =========================================
   5. Form Controls (Left Panel)
   ========================================= */
.config-panel {
    overflow-y: auto;
}

#quote-form {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.input-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Select */
select {
    width: 100%;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--glass-border);
    color: #fff;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.95rem;
    appearance: none;
    cursor: pointer;
    transition: var(--transition-smooth);
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' fill='none' stroke='%238b9bb4' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 16px;
}

select:focus,
select:hover {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(0, 240, 255, 0.1);
}

select option {
    background: var(--bg-dark);
    color: #fff;
    padding: 0.5rem;
}

/* Slider */
.slider-wrapper {
    background: rgba(0, 0, 0, 0.2);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--glass-border);
}

input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    outline: none;
    margin-bottom: 1rem;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent-primary);
    cursor: pointer;
    box-shadow: 0 0 10px rgba(0, 240, 255, 0.5);
    transition: var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.slider-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.slider-labels .active {
    color: var(--accent-primary);
    font-weight: 700;
}

/* Radio Tiles (Quality Tier) */
.radio-tiles {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
}

.tile {
    cursor: pointer;
    position: relative;
}

.tile input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
}

.tile-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 0.5rem;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    transition: var(--transition-smooth);
    text-align: center;
}

.tile-content i {
    font-style: normal;
    color: var(--text-muted);
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    font-family: var(--font-mono);
}

.tile-content strong {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.tile input:checked+.tile-content {
    background: rgba(0, 240, 255, 0.1);
    border-color: var(--accent-primary);
    box-shadow: inset 0 0 15px rgba(0, 240, 255, 0.1);
}

.tile input:checked+.tile-content i,
.tile input:checked+.tile-content strong {
    color: var(--accent-primary);
    text-shadow: 0 0 8px rgba(0, 240, 255, 0.4);
}

/* Checkbox Grid (Sub-systems) */
.checkbox-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.cb-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    cursor: pointer;
    position: relative;
}

.cb-item input {
    position: absolute;
    opacity: 0;
}

.faux-box {
    width: 18px;
    height: 18px;
    border: 1px solid var(--text-muted);
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
}

.cb-item input:checked+.faux-box {
    background: var(--accent-secondary);
    border-color: var(--accent-secondary);
    box-shadow: 0 0 10px rgba(112, 0, 255, 0.4);
}

.cb-item input:checked+.faux-box::after {
    content: '';
    width: 4px;
    height: 8px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    margin-bottom: 2px;
}

.cb-item input:disabled+.faux-box {
    opacity: 0.5;
    cursor: not-allowed;
}

.cb-item input:disabled~span {
    color: var(--text-muted);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.8rem 1.2rem;
    border: none;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.btn.primary {
    background: linear-gradient(135deg, var(--accent-primary) 0%, #0099ff 100%);
    color: #000;
    box-shadow: 0 4px 15px rgba(0, 240, 255, 0.3);
}

.btn.primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 240, 255, 0.4);
}

.btn.primary .icon-svg,
.btn.primary svg {
    color: #000;
}

.btn.secondary {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    border: 1px solid var(--glass-border);
}

.btn.secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn.outline {
    background: transparent;
    border: 1px solid var(--accent-primary);
    color: var(--accent-primary);
}

.btn.outline:hover {
    background: rgba(0, 240, 255, 0.1);
}

.full-width {
    width: 100%;
}

.icon-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    color: var(--text-muted);
}

.icon-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

.icon-btn.active {
    background: rgba(0, 240, 255, 0.1);
    color: var(--accent-primary);
    border-color: rgba(0, 240, 255, 0.3);
}


/* =========================================
   6. Topology Canvas (Center Panel)
   ========================================= */
.canvas-panel {
    display: flex;
    flex-direction: column;
}

.topology-area {
    flex-grow: 1;
    position: relative;
    background: rgba(0, 0, 0, 0.2);
    overflow: hidden;
    /* Grid background */
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
    background-size: 40px 40px;
    background-position: center center;
}

/* 初始化掃描動畫與文字 */
.idle-state {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.9rem;
    letter-spacing: 1px;
}

.radar {
    width: 80px;
    height: 80px;
    border: 2px dashed rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    margin-bottom: 1rem;
    position: relative;
    animation: rotate 4s linear infinite;
}

.radar::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 50%;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent-primary));
    transform-origin: left center;
}

@keyframes rotate {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Node Elements (Dynamically Added) */
.nodes-container {
    position: absolute;
    inset: 0;
    pointer-events: none;
    /* Let SVG clicks pass if needed, nodes will have pointer-events: auto */
}

.tf-node {
    position: absolute;
    background: rgba(16, 22, 35, 0.8);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(8px);
    border-radius: 8px;
    padding: 0.75rem;
    min-width: 140px;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    pointer-events: auto;
    transition: transform 0.2s, border-color 0.2s;
    user-select: none;
}

.tf-node:hover {
    transform: translateY(-2px);
    border-color: rgba(255, 255, 255, 0.3);
}

.tf-node.type-audio {
    border-top: 3px solid #ff2a55;
}

.tf-node.type-video {
    border-top: 3px solid #00f0ff;
}

.tf-node.type-control {
    border-top: 3px solid #ffb800;
}

.tf-node.type-lighting {
    border-top: 3px solid #7000ff;
}

.tf-node.type-core {
    border-top: 3px solid #fff;
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.1);
}

.node-icon {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.node-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: #fff;
    margin-bottom: 0.25rem;
}

.node-model {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

/* SVG Lines Container */
#svg-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.conn-line {
    stroke: rgba(255, 255, 255, 0.15);
    stroke-width: 2;
    fill: none;
    transition: stroke 0.3s;
}

/* =========================================
   7. BOM List (Right Panel)
   ========================================= */
.quote-panel {
    display: flex;
    flex-direction: column;
}

.count-badge {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
    font-size: 0.75rem;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
}

.bom-list-wrapper {
    flex-grow: 1;
    overflow-y: auto;
    padding: 0 1.5rem;
}

.bom-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.bom-table th {
    text-align: left;
    color: var(--text-muted);
    font-weight: 500;
    padding: 1rem 0;
    border-bottom: 1px solid var(--glass-border);
    position: sticky;
    top: 0;
    background: var(--bg-panel);
    z-index: 10;
}

.bom-table td {
    padding: 1rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.bom-table th.num,
.bom-table td.num {
    text-align: right;
    font-family: var(--font-mono);
}

.item-cat {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-size: 0.65rem;
    font-weight: 700;
    background: rgba(255, 255, 255, 0.1);
}

.item-cat.audio {
    color: #ff2a55;
    background: rgba(255, 42, 85, 0.1);
}

.item-cat.video {
    color: #00f0ff;
    background: rgba(0, 240, 255, 0.1);
}

.item-cat.ctrl {
    color: #ffb800;
    background: rgba(255, 184, 0, 0.1);
}

.item-cat.light {
    color: #7000ff;
    background: rgba(112, 0, 255, 0.1);
}

.item-name {
    font-weight: 600;
    display: block;
    margin-bottom: 0.2rem;
}

.item-desc {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.empty-row td {
    text-align: center;
    color: var(--text-muted);
    padding: 3rem 0;
    font-style: italic;
}

/* Summary Footer */
.quote-summary {
    padding: 1.5rem;
    background: rgba(0, 0, 0, 0.3);
    border-top: 1px solid var(--glass-border);
}

.summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.summary-row span:last-child {
    font-family: var(--font-mono);
    color: #fff;
}

.summary-row .highlight {
    color: var(--accent-primary);
}

.summary-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
    margin: 1rem 0;
}

.grand-total {
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
    margin-bottom: 1.5rem;
}

.glitch-price {
    font-size: 1.5rem;
    color: var(--accent-primary) !important;
    text-shadow: 0 0 10px rgba(0, 240, 255, 0.5);
}

.action-group {
    display: flex;
    gap: 1rem;
}

.action-group .btn {
    flex: 1;
}

/* =========================================
   8. Animations & Effects
   ========================================= */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in-up {
    animation: fadeInUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Toast */
#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: rgba(16, 22, 35, 0.9);
    backdrop-filter: blur(10px);
    border: 1px solid var(--accent-primary);
    color: #fff;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
    transform: translateX(120%);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.4s;
    display: flex;
    align-items: center;
    gap: 10px;
}

.toast.show {
    transform: translateX(0);
}

.toast.hide {
    opacity: 0;
    transform: translateX(120%);
}