/* style.css - Modern UI Redesign - Updated 2025-12-27 21:35 */

/* --- 1. Modern Color Palette & Variables --- */
:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-hover: #475569;

    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --accent-primary: #3b82f6;
    --accent-secondary: #0ea5e9;
    --accent-gradient: linear-gradient(135deg, #3b82f6 0%, #0ea5e9 100%);

    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;

    --border-subtle: rgba(148, 163, 184, 0.1);
    --border-medium: rgba(148, 163, 184, 0.2);

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;

    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 350ms ease;
}

/* Light Theme */
[data-theme="light"] {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e2e8f0;
    --bg-hover: #cbd5e1;

    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;

    --border-subtle: rgba(71, 85, 105, 0.15);
    --border-medium: rgba(71, 85, 105, 0.25);

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.12), 0 2px 4px -1px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.12), 0 4px 6px -2px rgba(0, 0, 0, 0.08);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.12), 0 10px 10px -5px rgba(0, 0, 0, 0.08);
}

/* --- 2. Base & Layout Styles --- */
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", sans-serif;
    margin: 0;
    display: flex;
    height: 100vh;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    font-size: 14px;
    line-height: 1.5;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
}

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

/* Controls Panel */
#controls-panel {
    width: 320px;
    padding: 16px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-subtle);
    box-sizing: border-box;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-shadow: var(--shadow-xl);
    z-index: 10;
}

/* Canvas Container */
#canvas-container {
    flex-grow: 1;
    position: relative;
    background: var(--bg-primary);
    background-image: 
        radial-gradient(circle at 1px 1px, rgba(99, 102, 241, 0.08) 1px, transparent 0);
    background-size: 24px 24px;
    overflow: hidden;
}

#design-canvas {
    position: absolute;
    top: 0;
    left: 0;
    cursor: crosshair;
    transition: cursor 0.15s ease;
}

/* --- 3. Top Navigation --- */
.top-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: linear-gradient(135deg, var(--accent-primary) 0%, #2563eb 100%);
    margin: -20px -20px 15px -20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.nav-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-info {
    color: white;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-info::before {
    content: '👤';
    font-size: 18px;
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logout-btn-top {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    padding: 8px 20px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    gap: 6px;
}

.logout-btn-top:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

/* --- 4. Header --- */
.header-container {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 20px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-lg);
    margin: 15px -20px 0 -20px;
    border-bottom: 1px solid var(--border-subtle);
}

.header-container img {
    height: 40px;
    width: auto;
    object-fit: contain;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.header-container h2 {
    margin: 0;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

/* --- 4. Control Groups (Modern Card Styling) --- */
.control-group {
    background: var(--bg-tertiary);
    padding: 18px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-medium);
    position: relative;
    transition: border-color var(--transition-fast);
}

.control-group:hover {
    border-color: var(--accent-primary);
}

.control-group label {
    display: block;
    margin-bottom: 10px;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 13px;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

.control-group > label:first-child {
    color: var(--accent-secondary);
    font-size: 12px;
    letter-spacing: 1px;
    margin-bottom: 14px;
}

/* --- 5. Form Inputs & Buttons --- */
.control-group input[type="file"],
.control-group input[type="text"],
.control-group input[type="number"],
.control-group select {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    box-sizing: border-box;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: all var(--transition-fast);
    font-size: 14px;
}

.control-group input:hover,
.control-group select:hover {
    border-color: var(--bg-hover);
}

.control-group input:focus,
.control-group select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15), var(--shadow-sm);
}

.control-group input::placeholder {
    color: var(--text-muted);
}

.control-group select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.control-group input[type="color"] {
    width: 100%;
    height: 44px;
    padding: 4px;
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    cursor: pointer;
    background: var(--bg-secondary);
    transition: all var(--transition-fast);
}

#ip-address {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    letter-spacing: 1px;
}

.ip-hint {
    color: var(--text-muted);
    font-style: italic;
}

#ip-address {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    letter-spacing: 1px;
}

.ip-hint {
    color: var(--text-muted);
    font-style: italic;
}

.control-group input[type="color"]:hover {
    border-color: var(--accent-primary);
}

/* Modern Range Slider */
input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    background: var(--bg-secondary);
    border-radius: 4px;
    outline: none;
    margin: 14px 0;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: var(--accent-gradient);
    border-radius: 50%;
    cursor: grab;
    border: 3px solid var(--bg-tertiary);
    box-shadow: 0 2px 6px rgba(99, 102, 241, 0.4);
    transition: all var(--transition-fast);
}

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

input[type="range"]::-webkit-slider-thumb:active {
    cursor: grabbing;
    transform: scale(1.15);
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--accent-gradient);
    border-radius: 50%;
    cursor: grab;
    border: 3px solid var(--bg-tertiary);
    box-shadow: 0 2px 6px rgba(99, 102, 241, 0.4);
}

.control-group span {
    display: inline-block;
    text-align: right;
    width: 50px;
    font-weight: 600;
    color: var(--accent-secondary);
    font-size: 13px;
}

/* Choice Buttons - Fresh Redesign */
.choice-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    width: 100%;
}

.choice-buttons .action-btn {
    background: var(--bg-secondary);
    color: var(--text-primary) !important;
    border: 1px solid var(--border-medium);
    font-weight: 500;
    font-size: 11px;
    padding: 8px 4px;
    border-radius: 6px;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
}

.choice-buttons .action-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-primary);
    transform: translateY(-1px);
}

.choice-buttons .action-btn.active {
    background: var(--accent-primary);
    color: #ffffff !important;
    border-color: var(--accent-primary);
}

.choice-buttons .action-btn span {
    color: inherit !important;
}

.choice-buttons .action-btn, .choice-buttons .action-btn span {
    flex: 1;
    background: var(--bg-secondary);
    color: var(--text-primary) !important;
    border: 1px solid var(--border-medium);
    font-weight: 500;
    padding: 3px 6px;
    border-radius: 4px;
    font-size: 9px;
    line-height: 1.1;
    white-space: nowrap;
    text-align: left;
    padding-left: 8px;
}

/* Help Icon */
#help-icon-btn {
    cursor: pointer;
    transition: all var(--transition-fast);
}

#help-icon-btn:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-md);
}

#open-manual-btn {
    cursor: pointer;
    transition: all var(--transition-fast);
}

#open-manual-btn:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-md);
}

.choice-buttons .action-btn:hover, .choice-buttons .action-btn:hover span {
    background: var(--bg-tertiary);
    border-color: var(--bg-hover);
    color: var(--text-primary) !important;
}

.choice-buttons .action-btn.active {
    background: var(--accent-gradient);
    color: white;
    border-color: transparent;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

/* Action Buttons */
.action-btn, .action-btn span {
    width: 100%;
    padding: 12px 16px;
    background: var(--accent-gradient);
    color: #ffffff !important;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all var(--transition-fast);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.25);
    position: relative;
    overflow: hidden;
}

.action-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, transparent 50%);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.35);
}

.action-btn:hover::before {
    opacity: 1;
}

.action-btn:active {
    transform: translateY(0);
}

.clear-btn {
    background: var(--danger);
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.25);
}

.clear-btn:hover {
    background: #dc2626;
    box-shadow: 0 6px 16px rgba(239, 68, 68, 0.35);
}

/* --- 6. Icon Toolbar --- */
.toolbar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.toolbar button {
    aspect-ratio: 1;
    padding: 0;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 600;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.toolbar button:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-primary);
    color: var(--text-primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.toolbar button.active {
    background: var(--accent-gradient);
    color: white;
    border-color: transparent;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.toolbar button.active:hover {
    transform: translateY(-2px);
}

.toolbar button img {
    width: 24px;
    height: 24px;
    object-fit: contain;
    filter: brightness(0.9);
    transition: filter var(--transition-fast);
}

.toolbar button:hover img,
.toolbar button.active img {
    filter: brightness(1.2);
}

.toolbar button svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: all var(--transition-fast);
}

.toolbar button:hover svg {
    stroke: var(--accent-primary);
}

.toolbar button.active svg {
    stroke: white;
}

/* Theme Toggle - Now part of map controls */
#theme-toggle {
    position: relative;
    width: 36px;
    height: 36px;
    padding: 0;
    border: none;
}

#theme-toggle svg {
    width: 18px;
    height: 18px;
    stroke: var(--text-primary);
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

#theme-toggle .moon-icon { display: block; }
#theme-toggle .sun-icon { display: none; }

[data-theme="light"] #theme-toggle .sun-icon { display: block; }
[data-theme="light"] #theme-toggle .moon-icon { display: none; }

.toolbar button, .toolbar button span {
    aspect-ratio: 1;
    padding: 0;
    background: var(--bg-secondary);
    color: var(--text-primary) !important;
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 600;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.toolbar button:hover, .toolbar button:hover span {
    background: var(--bg-tertiary);
    border-color: var(--accent-primary);
    color: var(--text-primary) !important;
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.toolbar button.active {
    background: var(--accent-gradient);
    color: white;
    border-color: transparent;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.toolbar button.active:hover {
    transform: translateY(-2px);
}

.toolbar button img {
    width: 24px;
    height: 24px;
    object-fit: contain;
    filter: brightness(0.9);
    transition: filter var(--transition-fast);
}

.toolbar button:hover img,
.toolbar button.active img {
    filter: brightness(1.2);
}

.toolbar button.action-btn,
.toolbar button.clear-btn {
    grid-column: span 4;
    aspect-ratio: auto;
    padding: 12px;
}

/* --- 7. Panels & Lists --- */
.info-panel {
    background: linear-gradient(135deg, var(--bg-tertiary) 0%, rgba(99, 102, 241, 0.1) 100%);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-lg);
    padding: 18px;
    margin-top: auto;
    font-size: 13px;
}

.info-panel h4 {
    margin: 0 0 12px 0;
    color: var(--accent-secondary);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 700;
}

.info-panel strong {
    color: var(--text-primary);
}

.info-panel hr {
    border: none;
    height: 1px;
    background: var(--border-medium);
    margin: 12px 0;
}

.info-panel ul {
    font-size: 12px;
    padding-left: 20px;
    margin: 5px 0;
    color: var(--text-secondary);
}

.info-panel li {
    margin-bottom: 6px;
    line-height: 1.6;
}

.layer-control label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
    font-size: 14px;
    padding: 8px 0;
    cursor: pointer;
    transition: color var(--transition-fast);
}

.layer-control label:hover {
    color: var(--text-primary);
}

.layer-control input[type="checkbox"] {
    appearance: none;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-medium);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
}

.layer-control input[type="checkbox"]:checked {
    background: var(--accent-gradient);
    border-color: var(--accent-primary);
}

.layer-control input[type="checkbox"]:checked::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 12px;
    font-weight: bold;
}

#device-list-container {
    max-height: 180px;
    overflow-y: auto;
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    padding: 8px;
    margin-top: 12px;
    background: var(--bg-secondary);
}

#device-list ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

#device-list li {
    padding: 10px 14px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-size: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all var(--transition-fast);
    margin-bottom: 4px;
    gap: 12px;
}

#device-list li span:first-child {
    flex-shrink: 0;
    font-weight: 600;
    color: var(--accent-secondary);
}

#device-list li .device-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#device-list li:hover {
    background: var(--bg-tertiary);
    transform: translateX(4px);
}

#device-list li.selected {
    background: var(--accent-gradient);
    color: white;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

#device-list li .device-name {
    font-style: normal;
    color: var(--text-secondary);
}

#device-list li.selected .device-name {
    color: rgba(255, 255, 255, 0.85);
}

/* --- 8. Other UI Elements --- */
#logo-upload-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 80px;
    border: 2px dashed var(--border-medium);
    border-radius: var(--radius-lg);
    padding: 16px;
    cursor: pointer;
    transition: all var(--transition-normal);
    margin-top: 8px;
    color: var(--text-muted);
    background: var(--bg-secondary);
}

#logo-upload-container:hover {
    border-color: var(--accent-primary);
    background: var(--bg-tertiary);
    color: var(--accent-secondary);
    transform: scale(1.02);
}

#custom-logo-preview {
    max-height: 60px;
    max-width: 100%;
    object-fit: contain;
    margin-bottom: 8px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

/* Context Menu */
.context-menu {
    position: fixed;
    background: var(--bg-secondary);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    z-index: 1000;
    padding: 8px;
    display: none;
    min-width: 180px;
}

.context-menu-item {
    padding: 10px 16px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.context-menu-item:hover {
    background: var(--bg-tertiary);
    color: var(--accent-secondary);
}

/* Scale Instructions */
.scale-instructions {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.1) 0%, rgba(245, 158, 11, 0.05) 100%);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: var(--radius-md);
    padding: 14px;
    margin-top: 12px;
    font-size: 13px;
    text-align: center;
    color: var(--warning);
}

.export-note {
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
    margin-top: 12px;
    padding: 8px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
}

.scale-display {
    font-size: 13px;
    color: var(--accent-secondary);
    text-align: center;
    padding: 8px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    margin-top: 8px;
    font-weight: 600;
}

/* --- 9. Map Section Styles --- */
#map {
    height: 280px;
    width: 100%;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-medium);
    margin-top: 10px;
    background: var(--bg-primary);
    overflow: hidden;
}

#map::before {
    content: '📍 Map View';
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: 14px;
}

/* --- 10. Live Map Modal --- */
.map-modal-content {
    max-width: 90vw;
    max-height: 90vh;
    padding: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.map-modal-header {
    padding: 20px 28px;
    border-bottom: 1px solid var(--border-medium);
    background: var(--bg-tertiary);
}

.map-modal-header h2 {
    margin: 0;
    color: var(--text-primary);
    font-size: 20px;
}

.map-modal-body {
    flex: 1;
    overflow: hidden;
    background: var(--bg-primary);
}

.map-modal-body #map {
    width: 100%;
    height: 60vh;
    border: none;
    border-radius: 0;
}

.map-modal-footer {
    padding: 20px 28px;
    border-top: 1px solid var(--border-medium);
    background: var(--bg-tertiary);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.map-modal-footer .action-btn {
    width: 100%;
    max-width: 400px;
}

.map-close-btn {
    top: 16px;
    right: 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-medium);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 20px;
    transition: all var(--transition-fast);
}

.map-close-btn:hover {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
    transform: rotate(90deg);
}

/* --- 11. Help Modal --- */
#help-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(4px);
}

/* --- User Manual Modal --- */
#manual-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9998;
    backdrop-filter: blur(4px);
}

/* --- Notes Modal --- */
#notes-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9997;
    backdrop-filter: blur(4px);
}

.notes-modal-content {
    background: var(--bg-secondary);
    width: 90%;
    max-width: 900px;
    max-height: 90vh;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.notes-modal-header {
    padding: 20px 28px;
    border-bottom: 1px solid var(--border-medium);
    background: var(--bg-tertiary);
}

.notes-modal-header h2 {
    margin: 0;
    color: var(--text-primary);
    font-size: 20px;
}

.notes-modal-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 20px 28px;
    background: var(--bg-primary);
    overflow: hidden;
}

#notes-textarea {
    flex: 1;
    width: 100%;
    min-height: 50vh;
    padding: 16px;
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: 'Courier New', Courier, monospace;
    font-size: 14px;
    line-height: 1.6;
    resize: none;
    outline: none;
    transition: border-color var(--transition-fast);
}

#notes-textarea:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

#notes-textarea::placeholder {
    color: var(--text-muted);
}

.notes-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 12px;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    font-size: 12px;
}

.notes-save-status {
    color: var(--success);
    font-weight: 600;
}

.notes-char-count {
    color: var(--text-secondary);
}

.notes-close-btn:hover {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

/* --- User Manual Modal --- */
#manual-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9998;
    backdrop-filter: blur(4px);
}

.manual-modal-content {
    background: var(--bg-secondary);
    width: 90%;
    max-width: 900px;
    max-height: 90vh;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.manual-modal-header {
    padding: 20px 28px;
    border-bottom: 1px solid var(--border-medium);
    background: var(--bg-tertiary);
}

.manual-modal-header h2 {
    margin: 0;
    color: var(--text-primary);
    font-size: 20px;
}

.manual-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 28px;
    background: var(--bg-primary);
    line-height: 1.6;
    color: var(--text-primary);
}

.manual-modal-body h1 {
    color: var(--accent-secondary);
    border-bottom: 2px solid var(--accent-primary);
    padding-bottom: 10px;
    margin-top: 30px;
    margin-bottom: 15px;
}

.manual-modal-body h2 {
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-medium);
    padding-bottom: 8px;
    margin-top: 25px;
    margin-bottom: 12px;
}

.manual-modal-body h3 {
    color: var(--accent-secondary);
    margin-top: 20px;
    margin-bottom: 10px;
}

.manual-modal-body h4 {
    color: var(--text-primary);
    margin-top: 15px;
    margin-bottom: 8px;
}

.manual-modal-body p {
    margin-bottom: 12px;
}

.manual-modal-body ul {
    margin-bottom: 12px;
    padding-left: 20px;
}

.manual-modal-body li {
    margin-bottom: 6px;
}

.manual-modal-body code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 13px;
}

.manual-modal-body strong {
    color: var(--accent-secondary);
}

.manual-modal-body a {
    color: var(--accent-secondary);
    text-decoration: underline;
    transition: color var(--transition-fast);
}

.manual-modal-body a:hover {
    color: var(--accent-primary);
}

.manual-modal-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 15px 0;
}

.manual-modal-body th,
.manual-modal-body td {
    border: 1px solid var(--border-medium);
    padding: 10px;
    text-align: left;
}

.manual-modal-body th {
    background: var(--bg-tertiary);
    font-weight: bold;
}

.manual-modal-body tr:nth-child(even) {
    background: var(--bg-secondary);
}

.manual-close-btn:hover {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

/* --- General Modal Content --- */
.modal {
    z-index: 10000;
    display: none;
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--bg-secondary);
    margin: auto;
    padding: 28px;
    border: 1px solid var(--border-medium);
    width: 90%;
    max-width: 800px;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    position: relative;
    animation: slideUp var(--transition-normal);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.close-btn {
    color: var(--text-muted);
    position: absolute;
    top: 16px;
    right: 16px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    z-index: 100;
    background: var(--bg-secondary);
    border: 1px solid var(--border-medium);
}

.close-btn:hover,
.close-btn:focus {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

/* --- Auto-Save Indicator --- */
#autosave-indicator {
    background: var(--bg-tertiary);
    border-radius: 8px;
    padding: 12px;
    border: 1px solid var(--border-subtle);
    transition: all var(--transition-fast);
}

#autosave-indicator:hover {
    background: var(--bg-secondary);
    border-color: var(--border-medium);
}

#autosave-indicator .autosave-status {
    font-weight: 600;
    transition: color var(--transition-fast);
}

#autosave-indicator .autosave-time {
    font-family: monospace;
    font-size: 11px;
}

/* --- Auto-Save Restore Modal --- */
#autosave-restore-modal .modal-content {
    max-width: 500px;
}

#autosave-restore-modal h2 {
    color: var(--accent-secondary);
    margin-bottom: 12px;
}

#autosave-restore-modal p {
    color: var(--text-secondary);
    line-height: 1.6;
}

#autosave-restore-modal .action-btn {
    min-width: 150px;
    padding: 12px 20px;
    font-size: 14px;
    margin: 0 5px;
}

#autosave-restore-modal .action-btn:first-child {
    background: var(--accent-gradient);
    color: white;
    border: none;
}

#autosave-restore-modal .action-btn:first-child:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

/* --- Notification Toast --- */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10001;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: var(--bg-secondary);
    border: 1px solid var(--border-medium);
    border-left: 4px solid var(--accent-primary);
    border-radius: var(--radius-md);
    padding: 14px 18px;
    box-shadow: var(--shadow-xl);
    animation: slideIn 0.3s ease;
    max-width: 300px;
    font-size: 14px;
    pointer-events: auto;
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(50px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideOut {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(50px);
    }
}

/* --- Scale Bar --- */
#scale-bar {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-secondary);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 100;
    box-shadow: var(--shadow-lg);
    font-size: 13px;
}

#scale-bar-line {
    height: 3px;
    background: var(--accent-primary);
    min-width: 50px;
    position: relative;
}

#scale-bar-line::before,
#scale-bar-line::after {
    content: '';
    position: absolute;
    width: 2px;
    height: 10px;
    background: var(--accent-primary);
    top: 50%;
    transform: translateY(-50%);
}

#scale-bar-line::before { left: 0; }
#scale-bar-line::after { right: 0; }

#scale-bar-label {
    color: var(--text-primary);
    font-weight: 600;
    min-width: 60px;
}

/* --- Collapsible Sections --- */
.collapsible .section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    user-select: none;
    padding: 8px 0;
    margin: -14px -18px 12px -18px;
    padding-left: 18px;
    padding-right: 18px;
    border-radius: var(--radius-md);
    transition: background var(--transition-fast);
}

.collapsible .section-header:hover {
    background: var(--bg-hover);
}

.collapsible .section-header label {
    margin: 0;
    cursor: pointer;
}

.collapse-icon {
    font-size: 12px;
    color: var(--text-secondary);
    transition: transform var(--transition-fast);
}

.collapsible.collapsed .collapse-icon {
    transform: rotate(-90deg);
}

.section-content {
    transition: max-height 0.3s ease, opacity 0.3s ease;
    max-height: 2000px;
    opacity: 1;
}

.collapsible.collapsed .section-content {
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
}

/* --- Tooltips --- */
[data-tooltip] {
    position: relative;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-8px);
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-medium);
    pointer-events: none;
    z-index: 10000;
}

[data-tooltip]:hover::after {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(-4px);
}

/* --- Map Controls --- */
.map-controls {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    padding: 8px;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
}

.control-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
    padding: 0;
}

.control-btn svg {
    width: 18px;
    height: 18px;
    stroke-width: 2;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.control-btn:hover {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    transform: scale(1.05);
}

.control-btn:active {
    transform: scale(0.95);
}

.control-row {
    display: flex;
    gap: 4px;
}

.control-separator {
    width: 100%;
    height: 1px;
    background: var(--border-medium);
    margin: 4px 0;
}

/* --- Network Diagram Modal --- */
.network-diagram-modal-content {
    max-width: 1200px;
    width: 95%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin: auto;
    max-width: 1200px;
}

.network-diagram-modal-header {
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-medium);
    flex-shrink: 0;
    min-height: 70px;
}

.network-diagram-modal-header h2 {
    margin: 0 0 8px 0;
    font-size: 24px;
    color: var(--text-primary);
}

.network-diagram-modal-header p {
    margin: 0;
    font-size: 14px;
    color: var(--text-secondary);
}

.network-diagram-modal-body {
    flex: 1;
    min-height: 300px;
    overflow: hidden;
    background: #0a0a0a;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-medium);
    position: relative;
}

#network-canvas {
    width: 100%;
    height: 100%;
    display: block;
    cursor: grab;
}

#network-canvas:active {
    cursor: grabbing;
}

.network-diagram-modal-footer {
    margin-top: 16px;
    padding-top: 16px;
    padding-bottom: 8px;
    border-top: 1px solid var(--border-medium);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    min-height: 60px;
}

.network-diagram-modal-footer p {
    margin: 0;
    font-size: 11px;
    color: var(--text-muted);
}

.network-diagram-close-btn:hover {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}
