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

:root {
    --bg-canvas: #e8e4dd;
    --bg-panel: #ffffff;
    --bg-topbar: #1a1a1a;
    --bg-statusbar: #2a2a2a;
    --text-primary: #1a1a1a;
    --text-secondary: #6b6b6b;
    --text-muted: #999;
    --text-inverse: #f0f0f0;
    --border: #e2e2e2;
    --border-light: #f0f0f0;
    --accent: #4a7cff;
    --accent-hover: #3a6aee;
    --danger: #e74c3c;
    --success: #27ae60;
    --panel-width: 220px;
    --topbar-height: 48px;
    --statusbar-height: 28px;
    --radius: 6px;
    --radius-sm: 4px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --transition: 150ms ease;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 13px;
    color: var(--text-primary);
    background: var(--bg-canvas);
    overflow: hidden;
    height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ===== App Layout ===== */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ===== Top Bar ===== */
#topbar {
    height: var(--topbar-height);
    background: var(--bg-topbar);
    color: var(--text-inverse);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    flex-shrink: 0;
    z-index: 100;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.topbar-left, .topbar-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.topbar-center {
    flex: 1;
    display: flex;
    justify-content: center;
}

#project-name {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-inverse);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    text-align: center;
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    width: 200px;
    transition: var(--transition);
}

#project-name:hover {
    border-color: rgba(255,255,255,0.15);
}

#project-name:focus {
    outline: none;
    border-color: var(--accent);
    background: rgba(255,255,255,0.08);
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 14px;
    color: #fff;
    letter-spacing: -0.3px;
}

.logo svg {
    color: var(--accent);
}

.topbar-sep {
    width: 1px;
    height: 24px;
    background: rgba(255,255,255,0.12);
    margin: 0 6px;
}

.tool-group {
    display: flex;
    gap: 2px;
}

.tool-btn {
    width: 34px;
    height: 34px;
    border: none;
    background: transparent;
    color: rgba(255,255,255,0.6);
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    position: relative;
}

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

.tool-btn.active {
    background: var(--accent);
    color: #fff;
}

.action-btn {
    width: 30px;
    height: 30px;
    border: none;
    background: transparent;
    color: rgba(255,255,255,0.5);
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

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

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(255,255,255,0.08);
    border-radius: var(--radius-sm);
    padding: 2px;
}

.zoom-controls button {
    width: 26px;
    height: 26px;
    border: none;
    background: transparent;
    color: rgba(255,255,255,0.7);
    border-radius: 3px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.zoom-controls button:hover {
    background: rgba(255,255,255,0.15);
    color: #fff;
}

#zoom-level {
    font-size: 11px;
    font-weight: 500;
    color: rgba(255,255,255,0.6);
    min-width: 40px;
    text-align: center;
}

.primary-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border: none;
    background: var(--accent);
    color: #fff;
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.primary-btn:hover {
    background: var(--accent-hover);
}

.secondary-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border: 1px solid rgba(255,255,255,0.2);
    background: rgba(255,255,255,0.08);
    color: rgba(255,255,255,0.85);
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.secondary-btn:hover {
    background: rgba(255,255,255,0.15);
    border-color: rgba(255,255,255,0.3);
    color: #fff;
}

/* ===== Workspace ===== */
#workspace {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ===== Panels ===== */
#left-panel, #right-panel {
    width: var(--panel-width);
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
}

/* ===== Panel Tabs ===== */
.panel-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    background: var(--bg-panel);
    z-index: 10;
}

.panel-tab {
    flex: 1;
    padding: 10px 4px;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
    border-bottom: 2px solid transparent;
}

.panel-tab:hover {
    color: var(--text-primary);
    background: #f8f8f8;
}

.panel-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.tab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
}

.tab-content.active {
    display: block;
}

/* Tab content scrollbar */
.tab-content::-webkit-scrollbar {
    width: 4px;
}
.tab-content::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 2px;
}

#right-panel {
    border-right: none;
    border-left: 1px solid var(--border);
}

/* Scrollbar */
#left-panel::-webkit-scrollbar, #right-panel::-webkit-scrollbar {
    width: 4px;
}
#left-panel::-webkit-scrollbar-thumb, #right-panel::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 2px;
}

.panel-section {
    border-bottom: 1px solid var(--border-light);
}

.layers-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px 8px;
}

.panel-header h3 {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

.icon-btn {
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.icon-btn:hover {
    background: #f5f5f5;
    color: var(--danger);
}

/* ===== Shape Grid ===== */
.shape-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 4px 14px 14px;
}

.shape-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 4px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
    background: #fafafa;
}

.shape-item:hover {
    border-color: var(--accent);
    background: #f0f4ff;
}

.shape-item.active {
    border-color: var(--accent);
    background: #e8eeff;
    box-shadow: 0 0 0 2px rgba(74, 124, 255, 0.15);
}

.shape-item span {
    font-size: 10px;
    color: var(--text-secondary);
    font-weight: 500;
}

.shape-preview {
    display: block;
}

/* ===== Color Palette ===== */
.color-palette {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 4px 14px 14px;
}

.color-swatch {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
}

.color-swatch:hover {
    transform: scale(1.15);
}

.color-swatch.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(74, 124, 255, 0.3);
}

/* ===== Height Control ===== */
.height-control {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 14px 14px;
}

.height-control input[type="range"] {
    flex: 1;
    -webkit-appearance: none;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    outline: none;
}

.height-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
}

.height-control span {
    font-size: 11px;
    color: var(--text-muted);
    min-width: 32px;
    font-weight: 500;
}

/* ===== Canvas ===== */
#canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    cursor: crosshair;
}

#iso-canvas {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    background: transparent;
}

/* ===== VFM Background Animation ===== */
.canvas-bg-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    overflow: hidden;
    background: #0b0f19; /* Premium deep tech dark background */
    transition: opacity 0.3s ease;
    pointer-events: none; /* Make sure interactions pass through to the canvas */
}

.vfm-bg-svg {
    width: 100%;
    height: 100%;
    opacity: 0.85;
}

.bg-flow-gas {
    stroke-dasharray: 25, 120;
    animation: bgFlowSpeed 5s linear infinite;
}

.bg-flow-oil {
    stroke-dasharray: 20, 100;
    animation: bgFlowSpeed 7s linear infinite;
}

.bg-flow-water {
    stroke-dasharray: 30, 130;
    animation: bgFlowSpeed 6s linear infinite;
}

.bg-flow-combined {
    stroke-dasharray: 35, 90;
    animation: bgFlowSpeed 4s linear infinite;
}

@keyframes bgFlowSpeed {
    to {
        stroke-dashoffset: -290;
    }
}

.bg-node-pulse {
    transform-origin: center;
    animation: bgNodeGlow 2.5s ease-in-out infinite;
}

@keyframes bgNodeGlow {
    0%, 100% { transform: scale(1); opacity: 0.15; }
    50% { transform: scale(1.6); opacity: 0.45; }
}

.canvas-hint {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(26, 26, 26, 0.75);
    backdrop-filter: blur(8px);
    color: rgba(255,255,255,0.8);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 11px;
    pointer-events: none;
    transition: opacity 0.3s;
    white-space: nowrap;
}

/* ===== Properties Panel ===== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30px 14px;
    text-align: center;
    color: var(--text-muted);
    gap: 10px;
}

.empty-state.small {
    padding: 16px 14px;
}

.empty-state p {
    font-size: 12px;
    line-height: 1.5;
}

.prop-group {
    padding: 8px 14px;
    border-bottom: 1px solid var(--border-light);
}

.prop-group label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 6px;
}

.prop-group input[type="text"],
.prop-group input[type="number"],
.prop-group select {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 12px;
    color: var(--text-primary);
    background: #fafafa;
    transition: var(--transition);
}

.prop-group input:focus,
.prop-group select:focus {
    outline: none;
    border-color: var(--accent);
    background: #fff;
}

.prop-group input[type="color"] {
    width: 100%;
    height: 30px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    padding: 2px;
}

.prop-group input[type="range"] {
    width: 100%;
    -webkit-appearance: none;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    outline: none;
}

.prop-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
}

.prop-row {
    display: flex;
    gap: 8px;
}

.prop-field {
    flex: 1;
    display: flex;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: #fafafa;
}

.prop-field:focus-within {
    border-color: var(--accent);
    background: #fff;
}

.prop-prefix {
    padding: 0 6px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--border-light);
    height: 28px;
    display: flex;
    align-items: center;
}

.prop-field input {
    border: none !important;
    background: transparent !important;
    padding: 4px 6px !important;
    width: 100%;
}

.prop-field input:focus {
    outline: none;
}

/* ===== Layers List ===== */
.layers-list {
    flex: 1;
    overflow-y: auto;
    min-height: 60px;
    max-height: none;
}

.layer-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    cursor: pointer;
    transition: var(--transition);
    border-bottom: 1px solid var(--border-light);
    font-size: 12px;
}

.layer-item:hover {
    background: #f5f5f5;
}

.layer-item.selected {
    background: #e8eeff;
}

.layer-icon {
    width: 16px;
    height: 16px;
    border-radius: 3px;
    flex-shrink: 0;
}

.layer-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.layer-type {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.group-header {
    background: rgba(0, 0, 0, 0.02);
    border-left: 3px solid var(--accent);
}
.group-toggle {
    transition: transform var(--transition-fast);
}
.group-toggle:hover {
    color: var(--accent);
}
.nested-layer-item {
    border-left: 1px dashed var(--border-color);
}

.layer-order-btns {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex-shrink: 0;
  margin-left: 2px;
}

.layer-order-btn {
  width: 18px;
  height: 14px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 8px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.layer-order-btn:hover:not([disabled]) {
  background: var(--accent);
  color: #fff;
}

.layer-order-btn[disabled] {
  opacity: 0.25;
  cursor: default;
}

.layer-tier-label {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  padding: 4px 14px 2px;
  background: #f8f8f8;
  border-bottom: 1px solid var(--border-light);
  user-select: none;
}

/* ===== Status Bar ===== */
#statusbar {
    height: var(--statusbar-height);
    background: var(--bg-statusbar);
    color: rgba(255,255,255,0.5);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    font-size: 11px;
    flex-shrink: 0;
}

.status-left, .status-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-sep {
    color: rgba(255,255,255,0.15);
}

/* ===== Cursor States ===== */
#canvas-container[data-tool="select"] { cursor: default; }
#canvas-container[data-tool="box"] { cursor: crosshair; }
#canvas-container[data-tool="connect"] { cursor: crosshair; }
#canvas-container[data-tool="label"] { cursor: text; }
#canvas-container[data-tool="delete"] { cursor: not-allowed; }
#canvas-container.panning { cursor: grabbing !important; }
#canvas-container.dragging { cursor: move !important; }

/* ===== Toggle Switch ===== */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background: #ccc;
    border-radius: 20px;
    transition: var(--transition);
}

.toggle-slider::before {
    content: "";
    position: absolute;
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: var(--transition);
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--accent);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(16px);
}

/* ===== Animations ===== */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.panel-section {
    animation: fadeIn 0.3s ease;
}

/* ===== Connection Anchor Offset UI ===== */
.prop-section-divider {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px 4px;
    border-top: 1px solid var(--border-light);
    margin-top: 2px;
}

.prop-section-divider > span:first-child {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.prop-hint {
    font-size: 9px;
    color: #ff7b00;
    font-weight: 500;
    letter-spacing: 0.2px;
    opacity: 0.8;
}

.conn-action-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 5px 8px;
    border: 1px solid #ff7b00;
    background: rgba(255,123,0,0.08);
    color: #ff7b00;
    font-family: inherit;
    font-size: 11px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.conn-action-btn:hover {
    background: rgba(255,123,0,0.18);
    border-color: #e06500;
    color: #e06500;
}

/* Offset range slider with orange thumb */
#prop-from-offset::-webkit-slider-thumb,
#prop-to-offset::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: #ff7b00;
    border-radius: 50%;
    cursor: pointer;
}

#prop-from-offset,
#prop-to-offset {
    background: linear-gradient(to right, var(--border) 0%, var(--border) 50%, var(--border) 100%);
}

/* ===== Export Split Button + Dropdown ===== */
.export-group {
    position: relative;
    display: flex;
    align-items: stretch;
    gap: 0;
}

.export-group .primary-btn {
    border-radius: var(--radius-sm) 0 0 var(--radius-sm);
    border-right: 1px solid rgba(255,255,255,0.25);
}

.export-group .export-caret {
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    padding: 6px 8px;
    min-width: 28px;
    justify-content: center;
}

.export-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 170px;
    background: #2a2a2a;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0,0,0,0.35);
    z-index: 9999;
    overflow: hidden;
    animation: fadeIn 0.12s ease;
}

.export-dropdown.open {
    display: block;
}

.export-dropdown button {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border: none;
    background: transparent;
    color: rgba(255,255,255,0.85);
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    transition: var(--transition);
}

.export-dropdown button:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

.export-dropdown button svg {
    flex-shrink: 0;
    opacity: 0.7;
}

/* ===== Support Button ===== */
.support-section {
    padding: 14px;
    background: #fdfdfd;
    border-top: 1px solid var(--border-light);
    flex-shrink: 0;
}

.tng-support-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 10px 14px;
    background: #0059ab; /* TNG Blue */
    color: #fff;
    text-decoration: none;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 6px rgba(0, 89, 171, 0.25);
}

.tng-support-btn:hover {
    background: #004a8f;
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 89, 171, 0.35);
}

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

.tng-logo {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.1));
}

/* ===== Toast Notification ===== */
@keyframes toastIn {
    from { opacity: 0; transform: translateX(-50%) translateY(10px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ===== Rename Dialog ===== */
@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

/* ===== Custom Components Library ===== */
.custom-components-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 4px 14px 14px;
}

.custom-component-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    background: #fafafa;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
}

.custom-component-item:hover {
    border-color: var(--accent);
    background: #f0f4ff;
}

.custom-component-item.active {
    border-color: var(--accent);
    background: #e8eeff;
    box-shadow: 0 0 0 2px rgba(74, 124, 255, 0.15);
}

.custom-component-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    flex: 1;
}

.custom-component-icon {
    width: 20px;
    height: 20px;
    background: rgba(74, 124, 255, 0.1);
    color: var(--accent);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 11px;
}

.custom-component-name {
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    user-select: none;
}

.custom-component-delete {
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    opacity: 0;
    transition: opacity var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-radius: 4px;
}

.custom-component-item:hover .custom-component-delete {
    opacity: 1;
}

.custom-component-delete:hover {
    color: var(--danger);
    background: rgba(231, 76, 60, 0.1);
}

/* ===== Database Settings & Status Badges ===== */
.db-status-badge {
    text-align: center;
    font-size: 9px;
    font-weight: 700;
    padding: 5px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: var(--transition);
}

.db-status-badge.online {
    background: rgba(39, 174, 96, 0.12);
    color: var(--success);
    border: 1px solid rgba(39, 174, 96, 0.2);
}

.db-status-badge.offline {
    background: rgba(231, 76, 60, 0.12);
    color: var(--danger);
    border: 1px solid rgba(231, 76, 60, 0.2);
}

.db-status-badge.testing {
    background: rgba(243, 156, 18, 0.12);
    color: #e67e22;
    border: 1px solid rgba(243, 156, 18, 0.2);
}

/* ===== Oil & Gas Component Library ===== */
.oil-desc {
    font-size: 11px;
    color: var(--text-muted);
    padding: 0 14px 10px;
    line-height: 1.5;
}

.oil-component-grid {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0 14px 14px;
}

.oil-component-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: #fafafa;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
}

.oil-component-item:hover {
    border-color: #0d9488;
    background: #f0fdf9;
}

.oil-component-item.active {
    border-color: #0d9488;
    background: #e6fbf5;
    box-shadow: 0 0 0 2px rgba(13, 148, 136, 0.15);
}

.oil-preview-wrap {
    width: 56px;
    height: 42px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f5f5f5;
    border-radius: 4px;
    border: 1px solid var(--border-light);
}

.oil-preview-canvas {
    display: block;
}

.oil-component-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
    flex: 1;
}

.oil-component-name {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    user-select: none;
}

.oil-component-size {
    font-size: 9px;
    color: var(--text-muted);
    font-weight: 500;
    letter-spacing: 0.2px;
}

#canvas-container[data-tool="oil-component"] { cursor: crosshair; }

/* ===== Floating Panel Styles ===== */
.floating-panel {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 240px;
    height: 320px;
    min-width: 180px;
    min-height: 120px;
    background: rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(12px) saturate(180%);
    -webkit-backdrop-filter: blur(12px) saturate(180%);
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: var(--radius-lg);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.05);
    z-index: 100;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    user-select: none;
    transition: box-shadow 0.2s ease, background-color 0.2s ease;
}

.floating-panel:focus-within,
.floating-panel.dragging {
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.12), 0 1px 4px rgba(0, 0, 0, 0.06);
}

.floating-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--bg-topbar);
    color: var(--text-inverse);
    cursor: default;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.floating-panel-title {
    display: flex;
    align-items: center;
}

.floating-panel-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.panel-control-btn {
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.6);
    padding: 2px;
    cursor: pointer;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.panel-control-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

.floating-panel-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.floating-panel-content .layers-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px 0;
}

/* Custom scrollbars inside floating panel */
.floating-panel-content .layers-list::-webkit-scrollbar {
    width: 6px;
}

.floating-panel-content .layers-list::-webkit-scrollbar-track {
    background: transparent;
}

.floating-panel-content .layers-list::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 3px;
}

.floating-panel-content .layers-list::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.25);
}

/* Resizing handles */
.floating-panel .resize-handle {
    position: absolute;
    background: transparent;
    z-index: 101;
}

.floating-panel .resize-handle.se {
    bottom: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    cursor: nwse-resize;
    background-image: linear-gradient(135deg, 
        transparent 30%, rgba(0, 0, 0, 0.25) 30%, rgba(0, 0, 0, 0.25) 40%, 
        transparent 40%, transparent 55%, rgba(0, 0, 0, 0.25) 55%, rgba(0, 0, 0, 0.25) 65%, 
        transparent 65%, transparent 80%, rgba(0, 0, 0, 0.25) 80%, rgba(0, 0, 0, 0.25) 90%, 
        transparent 90%
    );
    z-index: 102;
    transition: opacity 0.2s;
    opacity: 0.6;
}

.floating-panel .resize-handle.se:hover {
    opacity: 1;
}

.floating-panel .drag-handle:hover {
    opacity: 1 !important;
}

/* Minimized styling */
.floating-panel.minimized {
    min-height: 0 !important;
    height: auto !important;
}

/* Toggle Layers button styling */
#toggle-layers-btn.active {
    background: var(--accent);
    color: #fff;
}
#toggle-layers-btn:hover {
    background: var(--accent-hover);
    color: #fff;
}
#toggle-layers-btn.active:hover {
    background: var(--accent-hover);
    opacity: 0.9;
}


/* ================================================================
   MOBILE RESPONSIVE DESIGN
   ================================================================ */

/* Mobile Toggle Buttons (hidden on desktop) */
#mobile-panel-toggles {
    display: none;
}

#mobile-backdrop {
    display: none;
}

/* ===== Tablet Breakpoint (≤ 768px) ===== */
@media (max-width: 768px) {
    :root {
        --panel-width: 260px;
        --topbar-height: 44px;
    }

    /* --- Topbar Compact --- */
    #topbar {
        padding: 0 8px;
        gap: 4px;
    }

    .topbar-center {
        display: none;
    }

    .topbar-right .secondary-btn {
        padding: 6px 8px;
        font-size: 0;
    }

    .topbar-right .secondary-btn svg {
        margin: 0;
    }

    .primary-btn {
        padding: 6px 10px;
        font-size: 11px;
    }

    .topbar-sep {
        margin: 0 3px;
    }

    .zoom-controls {
        gap: 2px;
    }

    #zoom-level {
        display: none;
    }

    /* --- Panels as slide-out overlays --- */
    #left-panel, #right-panel {
        position: fixed;
        top: var(--topbar-height);
        bottom: var(--statusbar-height);
        width: var(--panel-width);
        z-index: 200;
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
    }

    #left-panel {
        left: 0;
        transform: translateX(-100%);
        border-right: 1px solid var(--border);
    }

    #right-panel {
        right: 0;
        transform: translateX(100%);
        border-left: 1px solid var(--border);
    }

    #left-panel.mobile-open {
        transform: translateX(0);
    }

    #right-panel.mobile-open {
        transform: translateX(0);
    }

    /* --- Mobile backdrop overlay --- */
    #mobile-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 199;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.28s ease;
        backdrop-filter: blur(2px);
        -webkit-backdrop-filter: blur(2px);
    }

    #mobile-backdrop.active {
        opacity: 1;
        pointer-events: auto;
    }

    /* --- Mobile toggle buttons --- */
    #mobile-panel-toggles {
        display: flex;
        position: fixed;
        left: 8px;
        bottom: calc(var(--statusbar-height) + 12px);
        gap: 8px;
        z-index: 150;
    }

    .mobile-toggle-btn {
        width: 44px;
        height: 44px;
        border: none;
        border-radius: 12px;
        background: rgba(26, 26, 26, 0.85);
        color: rgba(255, 255, 255, 0.8);
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        transition: all 0.2s ease;
    }

    .mobile-toggle-btn:active {
        transform: scale(0.92);
    }

    .mobile-toggle-btn.active {
        background: var(--accent);
        color: #fff;
    }

    /* --- Floating Layers Panel --- */
    .floating-panel {
        width: 200px !important;
        max-width: 70vw;
        max-height: 45vh;
    }

    /* --- Canvas hint --- */
    .canvas-hint {
        font-size: 10px;
        padding: 6px 12px;
        bottom: 60px;
        max-width: 85vw;
        white-space: normal;
        text-align: center;
        line-height: 1.4;
    }

    /* --- Tool buttons touch-friendly --- */
    .tool-btn {
        width: 36px;
        height: 36px;
    }

    .action-btn {
        width: 32px;
        height: 32px;
    }

    /* --- Status bar compact --- */
    #statusbar {
        font-size: 10px;
        padding: 0 8px;
    }

    /* --- Export button text hidden on tablet --- */
    #export-btn {
        font-size: 0;
    }

    #export-btn svg {
        margin: 0;
    }
}


/* ===== Phone Breakpoint (≤ 480px) ===== */
@media (max-width: 480px) {
    :root {
        --topbar-height: 40px;
        --statusbar-height: 24px;
        --panel-width: 85vw;
    }

    /* --- Topbar ultra-compact --- */
    #topbar {
        padding: 0 6px;
    }

    .logo span {
        display: none;
    }

    .topbar-sep {
        display: none;
    }

    .zoom-controls {
        display: none;
    }

    .topbar-right .secondary-btn {
        display: none;
    }

    /* --- Tool buttons smaller --- */
    .tool-btn {
        width: 32px;
        height: 32px;
    }

    .tool-btn svg {
        width: 16px;
        height: 16px;
    }

    .action-btn {
        width: 28px;
        height: 28px;
    }

    .action-btn svg {
        width: 14px;
        height: 14px;
    }

    /* --- Export button compact --- */
    .export-group .primary-btn {
        padding: 5px 8px;
        font-size: 0;
    }

    .export-group .export-caret {
        padding: 5px 6px;
    }

    /* --- Mobile toggle buttons at bottom --- */
    #mobile-panel-toggles {
        left: 6px;
        bottom: calc(var(--statusbar-height) + 8px);
        gap: 6px;
    }

    .mobile-toggle-btn {
        width: 40px;
        height: 40px;
        border-radius: 10px;
    }

    .mobile-toggle-btn svg {
        width: 16px;
        height: 16px;
    }

    /* --- Floating Layers Panel --- */
    .floating-panel {
        width: 180px !important;
        max-width: 75vw;
        max-height: 40vh;
        top: 10px !important;
        right: 10px !important;
    }

    .floating-panel-header {
        padding: 8px 10px;
        font-size: 10px;
    }

    /* --- Canvas hint hidden on phone --- */
    .canvas-hint {
        display: none;
    }

    /* --- Status bar --- */
    #statusbar {
        font-size: 9px;
        padding: 0 6px;
        height: var(--statusbar-height);
    }

    .status-sep {
        margin: 0 2px;
    }

    /* --- Panel tabs smaller --- */
    .panel-tab {
        padding: 8px 4px;
        font-size: 9px;
    }

    /* --- Panel section padding tighter --- */
    .panel-header {
        padding: 10px 10px 6px;
    }

    .shape-grid {
        padding: 4px 10px 10px;
        gap: 4px;
    }

    .color-palette {
        padding: 4px 10px 10px;
    }

    .height-control {
        padding: 4px 10px 10px;
    }

    .prop-group {
        padding: 6px 10px;
    }
}
