/* Reset & Base */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: #1a1a2e; color: #e0e0e0; }

/* Toolbar */
#toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 48px;
    background: #16213e;
    border-bottom: 1px solid #0f3460;
    padding: 0 12px;
    z-index: 100;
}
.toolbar-left { display: flex; align-items: center; gap: 8px; }
.app-logo { font-size: 22px; }
.app-title { font-size: 15px; font-weight: 600; color: #e94560; }
.toolbar-center, .toolbar-right { display: flex; align-items: center; gap: 6px; }
.separator { width: 1px; height: 24px; background: #0f3460; margin: 0 4px; }

#toolbar button {
    background: #0f3460;
    border: 1px solid #1a1a5e;
    color: #e0e0e0;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
    white-space: nowrap;
}
#toolbar button:hover { background: #1a1a5e; border-color: #e94560; }
#toolbar button.btn-primary { background: #0f3460; border-color: #533483; }
#toolbar button.btn-primary:hover { background: #533483; }
#toolbar button.btn-success { background: #1b4332; border-color: #2d6a4f; }
#toolbar button.btn-success:hover { background: #2d6a4f; }
#toolbar button.btn-new { background: #0f3460; border-color: #58a6ff; color: #58a6ff; }
#toolbar button.btn-new:hover { background: #1a1a5e; border-color: #79c0ff; color: #fff; }

/* Pages Tab Bar */
#pages-bar {
    display: flex;
    align-items: center;
    height: 36px;
    background: #121a30;
    border-bottom: 1px solid #0f3460;
    padding: 0 12px;
    gap: 4px;
    z-index: 99;
}
#pages-tabs {
    display: flex;
    align-items: center;
    gap: 2px;
    overflow-x: auto;
    flex: 1;
    scrollbar-width: none;
}
#pages-tabs::-webkit-scrollbar { display: none; }
.page-tab {
    padding: 5px 16px;
    font-size: 12px;
    color: #8b949e;
    background: transparent;
    border: 1px solid transparent;
    border-bottom: 2px solid transparent;
    border-radius: 4px 4px 0 0;
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
    transition: all 0.15s;
}
.page-tab:hover {
    color: #e0e0e0;
    background: rgba(255,255,255,0.04);
}
.page-tab.active {
    color: #e94560;
    background: #1a1a2e;
    border-color: #0f3460 #0f3460 #1a1a2e;
    border-bottom-color: #e94560;
    font-weight: 600;
}
.page-tab-input {
    background: #0f3460;
    border: 1px solid #e94560;
    color: #e0e0e0;
    font-size: 12px;
    padding: 2px 6px;
    border-radius: 3px;
    width: 100px;
    outline: none;
}
#btn-add-page {
    width: 28px;
    height: 28px;
    background: #0f3460;
    border: 1px solid #1a1a5e;
    color: #8b949e;
    font-size: 16px;
    line-height: 1;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    flex-shrink: 0;
}
#btn-add-page:hover {
    background: #1a1a5e;
    color: #e94560;
    border-color: #e94560;
}

/* Breakpoint Indicator */
.bp-indicator {
    font-size: 10px;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
    margin-left: auto;
}
.bp-desktop { background: #0f346030; color: #58a6ff; border: 1px solid #58a6ff40; }
.bp-tablet  { background: #7c3aed30; color: #bc8cff; border: 1px solid #bc8cff40; }
.bp-mobile  { background: #e9456030; color: #e94560; border: 1px solid #e9456040; }

/* Page Context Menu */
#page-context-menu {
    position: fixed;
    background: #16213e;
    border: 1px solid #0f3460;
    border-radius: 6px;
    padding: 4px 0;
    min-width: 140px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    z-index: 2000;
}
#page-context-menu .ctx-item {
    padding: 7px 14px;
    font-size: 12px;
    color: #e0e0e0;
    cursor: pointer;
    transition: background 0.1s;
}
#page-context-menu .ctx-item:hover {
    background: #0f3460;
}
#page-context-menu .ctx-item.ctx-danger {
    color: #f85149;
}
#page-context-menu .ctx-item.ctx-danger:hover {
    background: rgba(248,81,73,0.15);
}

/* Main Layout */
#main-container {
    display: flex;
    height: calc(100vh - 84px);
}

/* Left Sidebar */
#sidebar-left {
    width: 220px;
    min-width: 220px;
    background: #16213e;
    border-right: 1px solid #0f3460;
    overflow-y: auto;
    padding: 10px;
}
#sidebar-left h3 {
    font-size: 14px;
    color: #e94560;
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid #0f3460;
}
.component-group { margin-bottom: 12px; }
.component-group h4 {
    font-size: 11px;
    text-transform: uppercase;
    color: #888;
    letter-spacing: 1px;
    margin-bottom: 6px;
}
.component-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    background: #1a1a3e;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: grab;
    font-size: 12px;
    margin-bottom: 3px;
    transition: all 0.2s;
    user-select: none;
}
.component-item:hover { border-color: #e94560; background: #0f3460; }
.component-item:active { cursor: grabbing; }
.comp-icon { font-size: 14px; width: 18px; text-align: center; }

/* Canvas Area */
#canvas-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #111;
}
#canvas-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: #1a1a2e;
    border-bottom: 1px solid #0f3460;
    font-size: 12px;
    flex-wrap: wrap;
}
#canvas-controls label { color: #aaa; }
#canvas-controls select, #canvas-controls input[type="number"] {
    background: #0f3460;
    border: 1px solid #1a1a5e;
    color: #e0e0e0;
    padding: 3px 6px;
    border-radius: 3px;
    font-size: 12px;
}
#canvas-controls input[type="number"] { width: 65px; }
#canvas-controls input[type="range"] { width: 80px; }
#canvas-controls input[type="checkbox"] { accent-color: #e94560; }
#zoom-value { min-width: 35px; }

#canvas-scroll {
    flex: 1;
    overflow: auto;
    padding: 30px;
    background:
        radial-gradient(circle at center, #1a1a3e 0%, #111 100%);
}

#canvas {
    background: #ffffff;
    position: relative;
    box-shadow: 0 4px 30px rgba(0,0,0,0.5);
    transition: transform 0.3s;
    transform-origin: top left;
    overflow: visible;
    margin: 0 auto;
}
#canvas.show-grid {
    background-image:
        linear-gradient(rgba(0,0,0,0.04) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0,0,0,0.04) 1px, transparent 1px);
    background-size: 20px 20px;
}

.canvas-placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #bbb;
    font-size: 16px;
    pointer-events: none;
    text-align: center;
}

/* Builder Elements on Canvas */
.builder-element {
    position: absolute;
    cursor: move;
    min-width: 20px;
    min-height: 16px;
    outline: 1px solid transparent;
    transition: outline-color 0.15s;
}
.builder-element:hover {
    outline: 1px dashed #4dabf7;
}
.builder-element.selected {
    outline: 2px solid #e94560 !important;
}
.builder-element.selected::after {
    content: attr(data-label);
    position: absolute;
    top: -20px;
    left: 0;
    background: #e94560;
    color: #fff;
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 2px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 999;
}

/* Resize handles */
.resize-handle {
    position: absolute;
    width: 8px;
    height: 8px;
    background: #e94560;
    border: 1px solid #fff;
    border-radius: 50%;
    z-index: 10;
}
.resize-handle.nw { top: -4px; left: -4px; cursor: nw-resize; }
.resize-handle.ne { top: -4px; right: -4px; cursor: ne-resize; }
.resize-handle.sw { bottom: -4px; left: -4px; cursor: sw-resize; }
.resize-handle.se { bottom: -4px; right: -4px; cursor: se-resize; }
.resize-handle.n { top: -4px; left: 50%; transform: translateX(-50%); cursor: n-resize; }
.resize-handle.s { bottom: -4px; left: 50%; transform: translateX(-50%); cursor: s-resize; }
.resize-handle.w { top: 50%; left: -4px; transform: translateY(-50%); cursor: w-resize; }
.resize-handle.e { top: 50%; right: -4px; transform: translateY(-50%); cursor: e-resize; }

/* Rotation handle */
.rotate-line {
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    width: 1px;
    height: 26px;
    background: #e94560;
    z-index: 11;
    pointer-events: none;
}
.rotate-handle {
    position: absolute;
    top: -40px;
    left: 50%;
    transform: translateX(-50%);
    width: 14px;
    height: 14px;
    background: #e94560;
    border: 2px solid #fff;
    border-radius: 50%;
    cursor: grab;
    z-index: 12;
    transition: background 0.15s;
}
.rotate-handle:hover {
    background: #ff6b8a;
    box-shadow: 0 0 8px rgba(233,69,96,0.6);
}
.rotate-handle:active {
    cursor: grabbing;
    background: #ff6b8a;
    box-shadow: 0 0 12px rgba(233,69,96,0.8);
}

/* Drop indicator */
#canvas.drag-over {
    outline: 2px dashed #e94560;
    outline-offset: -2px;
}

/* Right Sidebar */
#sidebar-right {
    width: 280px;
    min-width: 280px;
    background: #16213e;
    border-left: 1px solid #0f3460;
    overflow-y: auto;
    padding: 10px;
    display: flex;
    flex-direction: column;
}
#sidebar-right h3 {
    font-size: 14px;
    color: #e94560;
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid #0f3460;
}
#no-selection { text-align: center; color: #666; padding: 20px 10px; font-size: 13px; }

.prop-section { margin-bottom: 12px; }
.prop-section h4 {
    font-size: 11px;
    text-transform: uppercase;
    color: #888;
    letter-spacing: 1px;
    margin-bottom: 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid #0f3460;
}
.prop-row { margin-bottom: 6px; }
.prop-row label { display: block; font-size: 11px; color: #aaa; margin-bottom: 2px; }
.prop-row span { font-size: 12px; color: #e94560; font-weight: 600; }
.prop-row input[type="text"],
.prop-row input[type="number"],
.prop-row select {
    width: 100%;
    background: #0f3460;
    border: 1px solid #1a1a5e;
    color: #e0e0e0;
    padding: 4px 8px;
    border-radius: 3px;
    font-size: 12px;
}
.prop-row input[type="color"] { width: 100%; height: 28px; border: none; background: none; cursor: pointer; }
.prop-row input[type="range"] { width: 100%; accent-color: #e94560; }
.prop-row-inline { display: flex; gap: 8px; margin-bottom: 6px; }
.prop-row-inline > div { flex: 1; }
.prop-row-inline > div label { display: block; font-size: 11px; color: #aaa; margin-bottom: 2px; }
.prop-row-inline > div input,
.prop-row-inline > div select {
    width: 100%;
    background: #0f3460;
    border: 1px solid #1a1a5e;
    color: #e0e0e0;
    padding: 4px 8px;
    border-radius: 3px;
    font-size: 12px;
}
.prop-row-inline > div input[type="color"] { width: 100%; height: 28px; border: none; background: none; }

.prop-btn {
    flex: 1;
    background: #0f3460;
    border: 1px solid #1a1a5e;
    color: #e0e0e0;
    padding: 4px 8px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 11px;
}
.prop-btn:hover { background: #1a1a5e; }

/* Rotation controls */
.rotation-control {
    display: flex;
    align-items: center;
    gap: 6px;
}
.rotation-control input[type="range"] { flex: 1; accent-color: #e94560; }
.rotation-control input[type="number"] {
    background: #0f3460;
    border: 1px solid #1a1a5e;
    color: #e0e0e0;
    padding: 3px 6px;
    border-radius: 3px;
    font-size: 12px;
}
.rotation-control span { color: #e94560; font-weight: 600; font-size: 13px; }
.rotation-presets {
    display: flex;
    gap: 4px;
    margin-top: 5px;
}
.rot-preset {
    flex: 1;
    background: #0f3460;
    border: 1px solid #1a1a5e;
    color: #c0c0d0;
    padding: 3px 0;
    border-radius: 3px;
    cursor: pointer;
    font-size: 10px;
    text-align: center;
    transition: all 0.15s;
}
.rot-preset:hover { background: #1a1a5e; border-color: #e94560; color: #fff; }

/* Layers Panel */
#layers-panel {
    margin-top: auto;
    border-top: 1px solid #0f3460;
    padding-top: 10px;
}
#layers-list { max-height: 200px; overflow-y: auto; }
.layer-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    font-size: 11px;
    cursor: pointer;
    border-radius: 3px;
    margin-bottom: 2px;
}
.layer-item:hover { background: #0f3460; }
.layer-item.active { background: #0f3460; border-left: 2px solid #e94560; }
.layer-icon { width: 16px; text-align: center; font-size: 12px; }
.layer-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-visibility {
    cursor: pointer;
    opacity: 0.5;
    font-size: 12px;
}
.layer-visibility:hover { opacity: 1; }
.layer-visibility.hidden { opacity: 0.2; }

/* Modal */
#modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.7);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
#modal {
    background: #16213e;
    border: 1px solid #0f3460;
    border-radius: 8px;
    width: 80%;
    max-width: 900px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}
#modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid #0f3460;
}
#modal-header h3 { color: #e94560; font-size: 16px; }
#modal-close {
    background: none;
    border: none;
    color: #e0e0e0;
    font-size: 22px;
    cursor: pointer;
}
#modal-body {
    flex: 1;
    overflow: auto;
    padding: 16px;
}
#modal-body pre {
    background: #0a0a1e;
    padding: 16px;
    border-radius: 4px;
    font-size: 12px;
    color: #4dabf7;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 60vh;
    overflow: auto;
}
#screenshot-preview {
    max-width: 100%;
    border: 1px solid #0f3460;
    border-radius: 4px;
}
#modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid #0f3460;
}
#modal-footer button {
    padding: 6px 16px;
    border-radius: 4px;
    border: 1px solid #1a1a5e;
    cursor: pointer;
    font-size: 13px;
    color: #e0e0e0;
}
#modal-footer button.btn-primary { background: #533483; }
#modal-footer button.btn-primary:hover { background: #6c44a0; }
#modal-footer button.btn-success { background: #2d6a4f; }
#modal-footer button.btn-success:hover { background: #40916c; }

/* Scrollbar Styling */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #0a0a1e; }
::-webkit-scrollbar-thumb { background: #0f3460; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #1a1a5e; }

/* Selection box for multi-select */
.selection-box {
    position: absolute;
    border: 1px dashed #e94560;
    background: rgba(233,69,96,0.08);
    pointer-events: none;
    z-index: 9999;
}

/* ===== Bridge Button ===== */
#toolbar button.btn-claude {
    background: linear-gradient(135deg, #7c3aed, #e94560);
    border: none;
    color: #fff;
    font-weight: 700;
    padding: 5px 14px;
    font-size: 13px;
    letter-spacing: 0.3px;
    display: flex;
    align-items: center;
    gap: 8px;
}
#toolbar button.btn-claude:hover {
    background: linear-gradient(135deg, #8b5cf6, #f06580);
    box-shadow: 0 0 16px rgba(233,69,96,0.4);
}

/* Toolbar dot indicator */
.bridge-toolbar-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}
.bridge-toolbar-dot-connected { background: #3fb950; box-shadow: 0 0 6px #3fb950; }
.bridge-toolbar-dot-disconnected { background: #484f58; }
.bridge-toolbar-dot-error { background: #f85149; }
.bridge-toolbar-dot-connecting { background: #d29922; animation: bridge-blink 1s infinite; }
@keyframes bridge-blink { 0%,100% { opacity:1; } 50% { opacity:0.3; } }

/* ===== Bridge Modal ===== */
#bridge-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.75);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}
#bridge-modal-inner {
    background: #0d1117;
    border: 1px solid #7c3aed;
    border-radius: 14px;
    width: 580px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(124,58,237,0.25), 0 0 40px rgba(233,69,96,0.1);
}
#bridge-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    border-bottom: 1px solid #21262d;
    background: linear-gradient(135deg, rgba(124,58,237,0.15), rgba(233,69,96,0.1));
    border-radius: 14px 14px 0 0;
}
#bridge-modal-header h3 {
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
}
#bridge-modal-close {
    background: none;
    border: none;
    color: #8b949e;
    font-size: 22px;
    cursor: pointer;
    padding: 0 4px;
    transition: color 0.15s;
}
#bridge-modal-close:hover { color: #f85149; }

#bridge-modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

/* Status dot in modal header */
.bridge-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}
.bridge-dot-connected { background: #3fb950; box-shadow: 0 0 8px #3fb950; }
.bridge-dot-disconnected { background: #484f58; }
.bridge-dot-error { background: #f85149; box-shadow: 0 0 8px #f85149; }
.bridge-dot-connecting { background: #d29922; animation: bridge-blink 1s infinite; }

/* Connection string box */
.bridge-conn-box {
    margin-bottom: 16px;
}
.bridge-conn-box label {
    display: block;
    color: #8b949e;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}
.bridge-conn-row {
    display: flex;
    gap: 8px;
    align-items: stretch;
}
.bridge-conn-row code {
    flex: 1;
    background: #0d1b2a;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 10px 14px;
    color: #64ffda;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 13px;
    word-break: break-all;
    display: flex;
    align-items: center;
}
.bridge-btn {
    background: linear-gradient(135deg, #7c3aed, #e94560);
    border: none;
    color: #fff;
    padding: 10px 18px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.5px;
    transition: all 0.2s;
    white-space: nowrap;
}
.bridge-btn:hover {
    box-shadow: 0 4px 16px rgba(124,58,237,0.4);
    transform: translateY(-1px);
}

/* Status box */
.bridge-status-box {
    background: #161b22;
    border: 1px solid #21262d;
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 16px;
}
.bridge-status-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
}
.bridge-label {
    color: #8b949e;
    font-size: 12px;
}
.bridge-value {
    color: #c9d1d9;
    font-size: 12px;
    font-weight: 600;
}

/* Steps */
.bridge-steps {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 16px;
}
.bridge-step {
    background: #161b22;
    border: 1px solid #21262d;
    border-radius: 8px;
    padding: 10px 12px;
    color: #8b949e;
    font-size: 11px;
    line-height: 1.5;
}
.bridge-step span {
    display: inline-block;
    width: 18px;
    height: 18px;
    background: linear-gradient(135deg, #7c3aed, #e94560);
    color: #fff;
    border-radius: 50%;
    text-align: center;
    line-height: 18px;
    font-size: 10px;
    font-weight: 800;
    margin-right: 6px;
}
.bridge-step code {
    color: #64ffda;
    font-size: 11px;
    background: rgba(100,255,218,0.08);
    padding: 1px 4px;
    border-radius: 3px;
}

/* API section */
.bridge-api-section {
    margin-bottom: 16px;
}
.bridge-api-section h4 {
    color: #c9d1d9;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.bridge-api-list {
    background: #161b22;
    border: 1px solid #21262d;
    border-radius: 8px;
    padding: 10px 14px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 16px;
}
.bridge-api-list div {
    font-size: 11px;
    color: #8b949e;
    padding: 2px 0;
}
.bridge-api-list code {
    color: #7c3aed;
    font-weight: 700;
    font-size: 10px;
    background: rgba(124,58,237,0.1);
    padding: 1px 5px;
    border-radius: 3px;
    margin-right: 3px;
}
.bridge-api-list small {
    color: #484f58;
}

/* Log section */
.bridge-log-section h4 {
    color: #c9d1d9;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.bridge-log {
    background: #0d1b2a;
    border: 1px solid #21262d;
    border-radius: 8px;
    padding: 10px;
    max-height: 120px;
    overflow-y: auto;
    font-family: 'Consolas', monospace;
    font-size: 11px;
}
.bridge-log-entry {
    padding: 2px 0;
    border-bottom: 1px solid rgba(33,38,45,0.5);
}
.bridge-log-entry:last-child { border-bottom: none; }
.bridge-log-info { color: #58a6ff; }
.bridge-log-success { color: #3fb950; }
.bridge-log-error { color: #f85149; }
.bridge-log-cmd { color: #d29922; }
