﻿/* ============================================================
   PRO AV System Designer — Unified Design System v3.0
   Professional Wiring Diagram & Code Generation Tool
   ============================================================ */

/* Google Fonts removed - using system-ui */
:root {
    --bg-dark: #090e17;
    --bg-panel: rgba(13, 18, 30, 0.75);
    --bg-panel-alt: rgba(20, 26, 40, 0.75);
    --bg-surface: rgba(255, 255, 255, 0.04);
    --text-main: #e2e8f0;
    --text-muted: #64748b;
    --text-bright: #f1f5f9;
    --border-color: #1e293b;
    --border-hover: #334155;
    --clr-accent: #3b82f6;
    --clr-jbl: #FF6B00;
    --clr-crown: #DC143C;
    --clr-bss: #0284c7;
    --clr-amx: #6366f1;
    --clr-akg: #8b5cf6;
    --clr-analog: #10b981;
    --clr-speaker: #f59e0b;
    --clr-power: #ef4444;
    --clr-network: #0ea5e9;
    --clr-danger: #ef4444;
    --radius: 6px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg-dark);
    color: var(--text-main);
    font-family: system-ui,-apple-system,'Segoe UI',Roboto,sans-serif;
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* ═══ HEADER ═══ */
.app-header {
    background: var(--bg-panel);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    padding: 0 16px;
    display: flex;
    align-items: center;
    height: 52px;
    gap: 12px;
    flex-shrink: 0;
    z-index: 100;
}

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

.brand .logo {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--clr-accent), var(--clr-amx));
    flex-shrink: 0;
}

.brand h1 {
    font-size: 0.85rem;
    font-weight: 700;
    white-space: nowrap;
    color: var(--text-bright);
}

.brand span {
    font-size: 0.55rem;
    font-weight: 600;
    color: var(--clr-analog);
    background: rgba(34, 197, 94, 0.1);
    padding: 1px 6px;
    border-radius: 8px;
    border: 1px solid rgba(34, 197, 94, 0.2);
    margin-left: 4px;
}

.toolbar-actions {
    display: flex;
    gap: 6px;
    margin-left: 24px;
}

.header-right {
    margin-left: auto;
    display: flex;
    gap: 6px;
}

.tool-btn {
    padding: 6px 14px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.05) 0%, rgba(255, 255, 255, 0.01) 100%);
    color: var(--text-main);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    font-family: system-ui,-apple-system,'Segoe UI',Roboto,sans-serif;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.tool-btn:hover {
    border-color: rgba(59, 130, 246, 0.6);
    color: var(--text-bright);
    background: rgba(59, 130, 246, 0.15);
    box-shadow: 0 0 12px rgba(59, 130, 246, 0.3);
    transform: translateY(-1px);
}

.tool-btn:active {
    transform: translateY(1px);
}

.tool-btn.accent {
    background: linear-gradient(135deg, var(--clr-accent), #2563eb);
    border-color: #3b82f6;
    color: white;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.4);
}

.tool-btn.accent:hover {
    background: linear-gradient(135deg, #60a5fa, var(--clr-accent));
    box-shadow: 0 0 16px rgba(59, 130, 246, 0.6);
}

.tool-btn.danger:hover {
    border-color: var(--clr-danger);
    color: var(--clr-danger);
}

.tool-btn .tool-icon {
    font-family: 'Cascadia Code','Fira Code',Consolas, monospace;
    font-size: 0.75rem;
}

/* ═══ MAIN WORKSPACE ═══ */
.main-workspace {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ═══ INVENTORY (LEFT) ═══ */
.inventory-panel {
    width: 250px;
    min-width: 240px;
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 50;
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.2);
}

.inventory-header {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
}

.inventory-header h2 {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-bright);
    letter-spacing: 0.5px;
}

.inventory-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-color);
}

.tab-btn {
    flex: 1 1 auto;
    background: var(--bg-surface);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: var(--radius);
    color: var(--text-muted);
    padding: 4px 6px;
    font-size: 0.6rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: all 0.15s;
    white-space: nowrap;
}

.tab-btn.active {
    background: rgba(59, 130, 246, 0.12);
    border-color: rgba(59, 130, 246, 0.4);
    color: var(--text-bright);
}

.tab-btn:hover:not(.active) {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-main);
}

.inventory-list {
    padding: 8px;
    overflow-y: auto;
    flex: 1;
}

.inventory-list.hidden {
    display: none;
}

.device-item {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.01));
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: var(--radius);
    padding: 8px 10px;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: grab;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.device-item:hover {
    border-color: rgba(59, 130, 246, 0.4);
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(255, 255, 255, 0.02));
    transform: translateY(-2px) translateX(2px);
    box-shadow: 2px 4px 12px rgba(0, 0, 0, 0.3), 0 0 10px rgba(59, 130, 246, 0.2);
}

.device-item:active {
    cursor: grabbing;
    transform: scale(0.98);
}

.item-icon {
    width: 28px;
    height: 28px;
    border-radius: 5px;
    flex-shrink: 0;
}

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

.item-name {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-bright);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

/* ═══ DESIGN CANVAS (CENTER) ═══ */
.design-canvas {
    flex: 1;
    position: relative;
    overflow: auto;
    background: var(--bg-dark);
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
    background-size: 20px 20px;
}

.design-canvas.drag-over {
    background-color: rgba(59, 130, 246, 0.03);
}

/* Rack View Mode Background */
#design-canvas.rack-view {
    background-color: #1e293b;
    background-image:
        repeating-linear-gradient(0deg,
            transparent,
            transparent 43px,
            rgba(0, 0, 0, 0.5) 43px,
            rgba(0, 0, 0, 0.5) 44.45px),
        linear-gradient(90deg, #0f172a 0%, #334155 4%, #334155 96%, #0f172a 100%);
    background-size: 100% 44.45px, 600px 100%;
    background-position: center top, center top;
    background-repeat: repeat-y, no-repeat;
}

#cablesCanvas {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 5;
}

.canvas-empty-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-muted);
    pointer-events: none;
    user-select: none;
}

.hint-icon {
    font-size: 3rem;
    margin-bottom: 12px;
    opacity: 0.4;
}

.canvas-empty-hint p {
    font-size: 0.85rem;
    margin-bottom: 4px;
}

.canvas-empty-hint .hint-sub {
    font-size: 0.7rem;
    opacity: 0.6;
}

/* Cable Labels */
.cable-label {
    position: absolute;
    background: rgba(15, 23, 42, 0.9);
    color: #e2e8f0;
    font-family: 'Cascadia Code','Fira Code',Consolas, monospace;
    font-size: 0.55rem;
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    pointer-events: none;
    transform: translate(-50%, -50%);
    z-index: 100;
    white-space: nowrap;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

/* ═══ DEVICE NODES (on canvas) ═══ */
.device-node {
    position: absolute;
    background: #111827;
    border: 2px solid #374151;
    border-radius: var(--radius);
    min-width: 180px;
    display: flex;
    flex-direction: column;
    cursor: move;
    z-index: 10;
    box-shadow: var(--shadow);
    transition: border-color 0.15s, box-shadow 0.15s;
    user-select: none;
}

.device-node:hover {
    border-color: var(--border-hover);
}

.device-node.selected {
    border-color: var(--clr-accent);
    box-shadow: 0 0 0 1px var(--clr-accent), 0 4px 12px rgba(59, 130, 246, 0.15);
}

.device-node.dragging {
    opacity: 0.8;
    z-index: 999;
}

/* Device Header — colored brand bar */
.device-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 4px 4px 0 0;
    background: rgba(0, 0, 0, 0.4);
}

.device-brand-bar {
    width: 4px;
    height: 16px;
    border-radius: 2px;
    flex-shrink: 0;
}

.device-title {
    font-family: 'Cascadia Code','Fira Code',Consolas, monospace;
    font-size: 0.65rem;
    font-weight: 600;
    color: #e2e8f0;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.device-type-tag {
    font-size: 0.5rem;
    color: var(--text-muted);
    font-family: 'Cascadia Code','Fira Code',Consolas, monospace;
    background: rgba(255, 255, 255, 0.05);
    padding: 1px 5px;
    border-radius: 3px;
}

/* Device Ports */
.device-ports {
    display: flex;
    justify-content: space-between;
    padding: 6px 8px;
    gap: 6px;
}

.ports-in,
.ports-out {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.ports-out {
    align-items: flex-end;
}

.port-row {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.55rem;
    font-family: 'Cascadia Code','Fira Code',Consolas, monospace;
    color: var(--text-muted);
}

.ports-out .port-row {
    flex-direction: row-reverse;
}

.port-socket {
    width: 10px;
    height: 10px;
    background: #0a0a0a;
    border: 2px solid;
    border-radius: 50%;
    cursor: crosshair;
    position: relative;
    z-index: 10;
    transition: transform 0.15s;
    flex-shrink: 0;
}

.port-socket:hover {
    transform: scale(1.4);
}

.port-socket.connecting {
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.8);
    background: white;
}

.port-name {
    white-space: nowrap;
}

/* Smart Connect */
body.is-drawing .port-socket.invalid-target {
    opacity: 0.12;
    pointer-events: none;
    filter: grayscale(1);
}

body.is-drawing .port-socket.valid-target {
    animation: flashValid 0.8s infinite alternate;
}

@keyframes flashValid {
    from {
        box-shadow: 0 0 2px rgba(255, 255, 255, 0.3);
    }

    to {
        box-shadow: 0 0 10px rgba(255, 255, 255, 0.9);
        transform: scale(1.3);
    }
}

/* ═══ INSPECTOR (RIGHT) ═══ */
.inspector-panel {
    width: 290px;
    min-width: 280px;
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-left: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow-y: auto;
    z-index: 50;
    box-shadow: -2px 0 12px rgba(0, 0, 0, 0.2);
}

.no-selection {
    padding: 40px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.no-sel-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
    opacity: 0.3;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0% {
        transform: translateY(0px);
    }

    50% {
        transform: translateY(-8px);
    }

    100% {
        transform: translateY(0px);
    }
}

.inspector-header {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-color);
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.2), transparent);
}

.inspector-header h3 {
    font-size: 0.9rem;
    margin-bottom: 4px;
    color: var(--text-bright);
    font-weight: 700;
}

.device-type-badge {
    font-family: 'Cascadia Code','Fira Code',Consolas, monospace;
    font-size: 0.58rem;
    font-weight: 600;
    padding: 2px 7px;
    background: rgba(59, 130, 246, 0.15);
    color: var(--clr-accent);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: 8px;
}

.inspector-body {
    padding: 12px;
}

/* 網格屬性面板設計 (Property Grid) */
.eng-section {
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    margin-bottom: 12px;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.eng-section h4 {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.8px;
    padding: 8px 12px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.04) 0%, rgba(255, 255, 255, 0.01) 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    text-transform: uppercase;
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.7rem;
    padding: 6px 12px;
    color: var(--text-main);
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
}

.info-row:last-child {
    border-bottom: none;
}

.info-row>span:first-child {
    color: var(--text-muted);
    font-weight: 500;
}

.info-row>span:last-child,
.info-row input[type="text"],
.info-row input[type="number"],
.info-row select {
    font-family: 'Cascadia Code','Fira Code',Consolas, monospace;
    color: var(--text-bright);
    text-align: right;
}

.info-row input[type="text"]:focus,
.info-row input[type="number"]:focus,
.info-row select:focus {
    outline: none;
    border-color: rgba(59, 130, 246, 0.8) !important;
    background: rgba(0, 0, 0, 0.8) !important;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.control-group {
    margin-bottom: 8px;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
}

.control-group h4 {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    padding: 8px 10px;
    background: var(--bg-surface);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
    border-bottom: 1px solid transparent;
}

.control-group h4::after {
    content: '▼';
    font-size: 0.5rem;
    transition: transform 0.2s;
    color: var(--text-muted);
}

.control-group.collapsed h4::after {
    transform: rotate(-90deg);
}

.control-group.collapsed h4~* {
    display: none !important;
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 10px;
    font-size: 0.7rem;
    font-family: 'Cascadia Code','Fira Code',Consolas, monospace;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.info-row:last-child {
    border-bottom: none;
}

.fader-row {
    display: flex;
    justify-content: space-around;
    gap: 10px;
    padding: 10px;
}

.fader-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.val-display {
    font-size: 0.6rem;
    color: var(--clr-accent);
    font-family: 'Cascadia Code','Fira Code',Consolas, monospace;
    width: 40px;
    text-align: center;
    background: rgba(0, 0, 0, 0.6);
    padding: 2px;
    border-radius: 3px;
    border: 1px solid var(--border-color);
}

.fader-container label {
    font-size: 0.6rem;
    font-weight: 600;
    color: var(--text-muted);
}

input[type=range].vertical-fader {
    writing-mode: bt-lr;
    appearance: slider-vertical;
    -webkit-appearance: slider-vertical;
    width: 8px;
    height: 80px;
    padding: 0 5px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 4px;
    outline: none;
    border: 1px solid var(--border-color);
}

/* ═══ STATUS BAR ═══ */
.status-bar {
    background: var(--bg-panel);
    border-top: 1px solid var(--border-color);
    padding: 0 16px;
    height: 28px;
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
    font-size: 0.65rem;
    font-family: 'Cascadia Code','Fira Code',Consolas, monospace;
}

.status-item {
    color: var(--text-muted);
}

.status-item.muted {
    opacity: 0.4;
}

.status-sep {
    flex: 1;
}

/* ═══ MODAL ═══ */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal-content {
    background: var(--bg-panel);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.05) inset;
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.98);
    animation: modalPop 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes modalPop {
    to {
        transform: scale(1);
    }
}

.modal-header,
.modal-head {
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.04) 0%, transparent 100%);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2,
.modal-head h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text-bright);
    font-weight: 700;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.2);
}

.modal-close {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
}

.modal-close:hover {
    color: white;
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.4);
    transform: rotate(90deg);
}

.close-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
}

.close-btn:hover {
    color: white;
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.4);
    transform: rotate(90deg);
}

/* ═══ SCROLLBAR ═══ */
::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}

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

::-webkit-scrollbar-thumb {
    background: rgba(100, 116, 139, 0.3);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(100, 116, 139, 0.5);
}