:root {
    --bg-app: #f1f5f9;
    --bg-panel: #ffffff;
    --bg-canvas: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --border: #e2e8f0;
    --danger: #ef4444;
    --grid-color: #e2e8f0;

    --font-ui: 'Inter', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

/* Feature Toggles */
.restricted-feature {
    display: none !important;
}

body.test-mode .restricted-feature {
    display: flex !important;
}

* {
    box-sizing: border-box;
    margin: 0;
    border-color: #3b82f6;
    outline: none;
}

/* Floating Ad */
.ad-floating-bottom {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 900;
    /* Above canvas actions but below modals/menus */
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--border);
    border-radius: 4px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    min-width: 300px;
    /* Minimum for mobile banner */
    min-height: 50px;
}

body {
    font-family: var(--font-ui);
    background-color: var(--bg-app);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    user-select: none;
    /* Prevent selection while dragging */
}

a {
    text-decoration: none;
    color: inherit;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Header */
.app-header {
    height: 60px;
    background-color: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    z-index: 100;
    /* Above canvas */
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 1.2rem;
    color: var(--text-primary);
}

/* --- Dropdown Menu System --- */
.dropdown {
    position: relative;
    display: inline-block;
}

.menu-btn {
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.menu-btn:hover {
    background-color: #f1f5f9;
}

.dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    /* Menu opens to the left/below */
    top: 100%;
    margin-top: 5px;
    background-color: var(--bg-panel);
    min-width: 220px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    border: 1px solid var(--border);
    border-radius: 6px;
    z-index: 101;
    padding: 5px 0;
}

.dropdown:hover .dropdown-content {
    display: block;
}

/* To keep menu open when hovering bridge */
.dropdown-content::before {
    content: '';
    position: absolute;
    top: -10px;
    left: 0;
    width: 100%;
    height: 10px;
}

.menu-group {
    display: flex;
    flex-direction: column;
}

.dropdown-content a,
.dropdown-content .menu-item-row {
    color: var(--text-primary);
    padding: 10px 16px;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9em;
    cursor: pointer;
    transition: background 0.1s;
}

.dropdown-content a:hover,
.dropdown-content .menu-item-row:hover {
    background-color: #f8fafc;
}

.dropdown-content .icon {
    width: 20px;
    text-align: center;
    font-size: 1.1em;
}

.menu-divider {
    border: 0;
    border-top: 1px solid var(--border);
    margin: 4px 0;
}

.danger-text {
    color: var(--danger) !important;
}

/* Submenu System */
.submenu-trigger {
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 0.9em;
}

.submenu-trigger:hover {
    background-color: #f8fafc;
}

.submenu-msg {
    color: var(--text-secondary);
    font-size: 0.8em;
}

.submenu-content {
    display: none;
    position: absolute;
    top: -5px;
    right: 100%;
    /* Show to the left */
    margin-right: 5px;
    background-color: var(--bg-panel);
    min-width: 150px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    border: 1px solid var(--border);
    border-radius: 6px;
    z-index: 102;
    padding: 5px 0;
}

.submenu-trigger:hover .submenu-content {
    display: block;
}

/* Hover bridge */
.submenu-content::after {
    content: '';
    position: absolute;
    top: 0;
    left: 100%;
    width: 10px;
    height: 100%;
}

.submenu-item {
    padding: 8px 16px;
    display: block;
    color: var(--text-primary);
    text-decoration: none;
    cursor: pointer;
    transition: background 0.1s;
}

.submenu-item:hover {
    background-color: #f8fafc;
}

.submenu-item.active {
    font-weight: 600;
    color: var(--accent);
    background-color: #eff6ff;
}

/* Legacy mini-select (keep for System if needed, or replace later) */
.mini-select {
    padding: 2px 5px;
    font-size: 0.8em;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: #fff;
}


/* Main Layout */
.main-content {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 260px;
    min-width: 200px;
    max-width: 500px;
    background-color: var(--bg-panel);
    border-right: 1px solid var(--border);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    resize: horizontal;
    /* User can resize */
    overflow-x: hidden;
}

.right-sidebar {
    width: var(--right-sidebar-width, 500px);
    background-color: var(--bg-panel);
    border-left: 1px solid var(--border);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    z-index: 10;
}

.sidebar h3,
.right-sidebar h3 {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 0.05em;
    margin-bottom: 5px;
}

.component-grid {
    display: grid;
    /* Dynamic columns based on width */
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 10px;
}

.comp-btn {
    background: #f8fafc;
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 12px 0;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.comp-btn:hover {
    border-color: var(--accent);
    background: #eff6ff;
    color: var(--accent);
}

.comp-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.comp-btn .icon {
    font-size: 1.5rem;
    font-weight: bold;
}

.comp-btn span:nth-child(2) {
    font-size: 0.8rem;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 4px;
}

/* Properties Panel Content */
.properties-panel-content {
    flex: 1;
}

.empty-msg {
    color: var(--text-secondary);
    font-style: italic;
    font-size: 0.9rem;
    text-align: center;
    padding: 20px 0;
}

.prop-group {
    margin-bottom: 12px;
}

.prop-group label {
    display: block;
    margin-bottom: 4px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.prop-input {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: var(--font-ui);
}

.prop-input:focus {
    border-color: var(--accent);
}

/* Canvas Area */
.canvas-wrapper {
    flex: 1;
    background-color: #e5e5e5;
    position: relative;
    overflow: hidden;
    cursor: default;
}

.canvas-wrapper:active {
    cursor: grabbing;
}

#schematic-canvas {
    display: block;
    background-color: var(--bg-canvas);
    background-image: radial-gradient(var(--grid-color) 1px, transparent 1px);
    background-size: 20px 20px;
}

.zoom-controls {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 5px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.zoom-controls button {
    width: 30px;
    height: 30px;
    border: none;
    background: #f1f5f9;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    color: var(--text-primary);
}

.zoom-controls button:hover {
    background: #e2e8f0;
}

.zoom-controls span {
    font-size: 0.9rem;
    min-width: 50px;
    text-align: center;
}

/* Sheet Controls */
.sheet-controls {
    position: absolute;
    bottom: 20px;
    left: 20px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 5px;
    display: flex;
    align-items: center;
    gap: 5px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    z-index: 50;
}

.sheet-tab-btn {
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 0.85rem;
    white-space: nowrap;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: var(--font-ui);
    transition: all 0.2s;
}

.sheet-tab-btn:hover {
    background: #e2e8f0;
}

.sheet-tab-btn.active {
    background: var(--accent);
    color: #fff;
    font-weight: 500;
}

.btn-icon {
    width: 30px;
    height: 30px;
    border: none;
    background: #f1f5f9;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    font-size: 1.2rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background: var(--accent);
    color: white;
}


/* Cable Schedule Table */
.cable-schedule-section {
    margin-top: 20px;
    border-top: 2px solid var(--border);
    padding-top: 10px;
}

.cable-schedule-container {
    overflow-x: auto;
}

#cable-schedule-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    text-align: left;
}

#cable-schedule-table th,
#cable-schedule-table td {
    padding: 8px;
    border-bottom: 1px solid var(--border);
}

#cable-schedule-table th {
    background-color: #f8fafc;
    font-weight: 600;
    color: var(--text-secondary);
}

#cable-schedule-table tbody tr:hover {
    background-color: #f1f5f9;
}

/* Modal System */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(2px);
    animation: fadeIn 0.2s ease-out;
}

.modal-content {
    background-color: var(--bg-panel);
    border-radius: 8px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    width: 500px;
    max-width: 90vw;
    padding: 24px;
    border: 1px solid var(--border);
    animation: slideUp 0.2s ease-out;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.modal-body textarea {
    width: 100%;
    min-height: 120px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    resize: vertical;
    font-family: var(--font-ui);
    margin-bottom: 16px;
    font-size: 0.9rem;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.btn-secondary {
    background: white;
    border: 1px solid var(--border);
    padding: 8px 16px;
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    font-weight: 500;
}

.btn-secondary:hover {
    background: #f8fafc;
    color: var(--text-primary);
}

.btn-primary {
    background: var(--accent);
    border: 1px solid var(--accent);
    padding: 8px 16px;
    border-radius: 6px;
    color: white;
    cursor: pointer;
    font-weight: 500;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-primary.danger {
    background: var(--danger);
    border-color: var(--danger);
}

.btn-primary.danger:hover {
    background: #dc2626;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(10px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Split Properties Panel */
.prop-split-layout {
    display: flex;
    gap: 15px;
    height: 100%;
}

.prop-left-col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.prop-right-col {
    flex: 1;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 15px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.prop-info-title {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
    display: block;
    border-bottom: 1px solid var(--border);
    padding-bottom: 5px;
}

/* Sidebar Tabs (Segmented Control) */
.sidebar-tabs {
    display: flex;
    background: #e2e8f0;
    padding: 4px;
    border-radius: 6px;
    margin-bottom: 20px;
    gap: 4px;
}

.tab-btn {
    flex: 1;
    border: none;
    background: transparent;
    padding: 8px;
    border-radius: 4px;
    font-size: 0.9em;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font-ui);
}

.tab-btn:hover {
    color: var(--text-primary);
}

.tab-btn.active {
    background: white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    color: var(--accent);
    font-weight: 600;
}

/* Context Menu */
.context-menu {
    position: absolute;
    z-index: 1000;
    background-color: var(--bg-panel);
    border: 1px solid var(--border);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    border-radius: 6px;
    padding: 5px 0;
    min-width: 150px;
    display: none;
    /* Hidden by default */
}

.context-menu-item {
    padding: 8px 16px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-primary);
    transition: background 0.1s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.context-menu-item:hover {
    background-color: #f1f5f9;
}