/* Enhanced Prompt Studio - Modern Flow-Based Interface */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #0a0a0a;
    color: #ffffff;
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: grid;
    grid-template-columns: 280px 1fr 400px;
    grid-template-rows: 60px 1fr;
    height: 100vh;
    background: linear-gradient(135deg, #0a0a0a 0%, #1a1a2e 50%, #16213e 100%);
}

/* Header */
.header {
    grid-column: 1 / -1;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    padding: 0 20px;
    position: relative;
    z-index: 1000;
}

.logo {
    font-size: 18px;
    font-weight: 800;
    background: linear-gradient(45deg, #ff6b6b, #4ecdc4, #45b7d1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.project-status {
    margin-left: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.status-indicator {
    width: 8px;
    height: 8px;
    background: #4ecdc4;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* Loading animation for chat */
.loading-dots {
    display: inline-block;
    position: relative;
    width: 20px;
    height: 20px;
}

.loading-dots div {
    position: absolute;
    top: 8px;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: #4ecdc4;
    animation-timing-function: cubic-bezier(0, 1, 1, 0);
}

.loading-dots div:nth-child(1) {
    left: 2px;
    animation: loading-dots1 1.2s infinite;
}

.loading-dots div:nth-child(2) {
    left: 2px;
    animation: loading-dots2 1.2s infinite;
}

.loading-dots div:nth-child(3) {
    left: 8px;
    animation: loading-dots2 1.2s infinite;
}

.loading-dots div:nth-child(4) {
    left: 14px;
    animation: loading-dots3 1.2s infinite;
}

@keyframes loading-dots1 {
    0% { transform: scale(0); }
    100% { transform: scale(1); }
}

@keyframes loading-dots2 {
    0% { transform: translate(0, 0); }
    100% { transform: translate(6px, 0); }
}

@keyframes loading-dots3 {
    0% { transform: scale(1); }
    100% { transform: scale(0); }
}

.chat-message.loading {
    opacity: 0.7;
}

.chat-message.loading .message-content {
    display: flex;
    align-items: center;
    gap: 8px;
}

.project-name {
    font-size: 14px;
    color: #aaa;
}

.mobile-nav {
    display: none; /* Hidden by default */
}

.header-actions {
    margin-left: auto;
    display: flex;
    gap: 12px;
}

.header-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 8px 16px;
    border-radius: 8px;
    color: white;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    touch-action: manipulation; /* reduce accidental zoom on tap */
}

.header-btn:hover {
    background: rgba(78, 205, 196, 0.2);
    border-color: #4ecdc4;
}

/* Component Palette */
.component-palette {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(20px);
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    padding: 20px;
    overflow-y: auto;
}

.palette-header { margin-bottom: 20px; }

.palette-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
    color: #4ecdc4;
}

.palette-search {
    width: 100%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 8px 12px;
    color: white;
    font-size: 12px;
    margin-bottom: 16px;
}

.palette-search:focus {
    outline: none;
    border-color: #4ecdc4;
    box-shadow: 0 0 0 2px rgba(78, 205, 196, 0.2);
}

.quick-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.quick-btn {
    flex: 1;
    background: rgba(78, 205, 196, 0.2);
    border: 1px solid rgba(78, 205, 196, 0.3);
    padding: 6px 12px;
    border-radius: 6px;
    color: #4ecdc4;
    font-size: 10px;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s;
}

.quick-btn:hover {
    background: #4ecdc4;
    color: #000;
}

/* Studio Section Styles */
.studio-section {
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.studio-section-title {
    font-size: 12px;
    font-weight: 600;
    color: #4ecdc4;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 280px;
    overflow-y: auto;
}

.history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 8px 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.history-item:hover { 
    background: rgba(78, 205, 196, 0.1);
    border-color: #4ecdc4;
}

.history-item-title {
    font-size: 12px;
    color: #ccc;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.history-item-actions {
    display: flex;
    gap: 6px;
}

.history-delete-btn {
    background: rgba(255, 107, 107, 0.15);
    border: 1px solid rgba(255, 107, 107, 0.35);
    color: #ff6b6b;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.history-delete-btn:hover {
    background: #ff6b6b;
    color: #000;
}

.studio-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.studio-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 6px 8px;
    border-radius: 6px;
    color: #ccc;
    font-size: 10px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
}

.studio-btn:hover {
    background: rgba(78, 205, 196, 0.1);
    border-color: rgba(78, 205, 196, 0.3);
    color: #4ecdc4;
    transform: translateY(-1px);
}

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

.component-section { margin-bottom: 20px; }

.section-header {
    display: flex;
    align-items: center;
    padding: 8px 0;
    cursor: pointer;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 12px;
}

.section-icon {
    margin-right: 8px;
    font-size: 16px;
}

.section-title {
    font-size: 13px;
    font-weight: 600;
    color: #ccc;
    flex: 1;
}

.section-count {
    background: rgba(78, 205, 196, 0.2);
    color: #4ecdc4;
    padding: 2px 6px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 600;
}

.component-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.component-item {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    cursor: grab;
    transition: all 0.2s;
    position: relative;
}

.component-item:hover {
    background: rgba(78, 205, 196, 0.1);
    border-color: #4ecdc4;
    transform: translateX(4px);
}

.component-item-icon {
    margin-right: 8px;
    font-size: 14px;
}

.component-item-name {
    font-size: 12px;
    font-weight: 500;
    color: #ccc;
    flex: 1;
}

.component-complexity {
    display: flex;
    gap: 1px;
}

.complexity-dot {
    width: 3px;
    height: 3px;
    background: #666;
    border-radius: 50%;
}

.complexity-dot.active {
    background: #4ecdc4;
}

/* Main Canvas */
.flow-canvas {
    background: radial-gradient(circle at 20px 20px, #333 1px, transparent 1px);
    background-size: 40px 40px;
    position: relative;
    overflow: hidden;
    cursor: grab;
    transform: translateZ(0); /* enable GPU compositing for smoother pan/zoom */
    touch-action: pan-x pan-y; /* default: allow browser panning */
}

.canvas-inner {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    transform-origin: 0 0;
}

.flow-canvas:active { cursor: grabbing; }

.node {
    position: absolute;
    background: linear-gradient(135deg, rgba(26, 26, 26, 0.9), rgba(42, 42, 42, 0.9));
    backdrop-filter: blur(20px);
    border: 2px solid #444;
    border-radius: 16px;
    padding: 16px;
    min-width: 240px;
    cursor: move;
    transition: all 0.3s ease;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    z-index: 2; /* above connection lines */
}

.node:hover {
    border-color: #4ecdc4;
    transform: translateY(-2px);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
}

.node.selected {
    border-color: #ff6b6b;
    box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.3);
}

.node.ai-modified {
    border-color: #4ecdc4;
    animation: modifiedPulse 2s ease-in-out;
}

@keyframes modifiedPulse {
    0%, 100% { box-shadow: 0 0 0 3px rgba(78, 205, 196, 0.3); }
    50% { box-shadow: 0 0 0 6px rgba(78, 205, 196, 0.1); }
}

.node-header {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
    position: relative;
}

.node-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #4ecdc4, #45b7d1);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 10px;
    font-size: 16px;
    color: #000;
}

.node-title {
    font-weight: 600;
    font-size: 14px;
    color: #ffffff;
    margin-bottom: 2px;
}

.node-type {
    font-size: 10px;
    color: #4ecdc4;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 1px;
}

.node-actions {
    position: absolute;
    top: -4px;
    right: -4px;
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

.node:hover .node-actions {
    opacity: 1;
}

.node-action-btn {
    width: 20px;
    height: 20px;
    background: rgba(0, 0, 0, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 10px;
    transition: all 0.2s;
}

.node-action-btn:hover {
    background: #4ecdc4;
    color: #000;
}

.node-content { margin-bottom: 12px; }

.node-description {
    font-size: 11px;
    color: #aaa;
    line-height: 1.3;
    margin-bottom: 8px;
}

.node-properties {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.property-pill {
    background: rgba(78, 205, 196, 0.1);
    border: 1px solid rgba(78, 205, 196, 0.2);
    border-radius: 12px;
    padding: 4px 8px;
    font-size: 10px;
    color: #4ecdc4;
    text-align: center;
}

.node-ports {
    display: flex;
    justify-content: space-between;
    margin-top: 12px;
}

.port {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid #333;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.port.input { background: #45b7d1; }
.port.output { background: #ff6b6b; }

.port:hover {
    transform: scale(1.3);
    box-shadow: 0 0 12px currentColor;
}

.port.connecting {
    animation: connecting 1s ease-in-out infinite;
}

@keyframes connecting {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.5); }
}

/* AI Sidebar */
.ai-sidebar {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(20px);
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    height: calc(100vh - 60px); /* subtract header height */
    overflow: hidden;
}

.ai-header {
    padding: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.ai-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
    color: #4ecdc4;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: #aaa;
}

.ai-indicator {
    width: 8px;
    height: 8px;
    background: #4ecdc4;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.ai-chat {
    flex: 1 1 auto; /* grow and shrink, take available space */
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    min-height: 360px; /* a bit taller */
    max-height: none; /* let it grow */
}

.chat-message {
    padding: 10px 12px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.4;
    word-wrap: break-word;
    max-width: 100%;
}

.chat-message.user {
    background: rgba(78, 205, 196, 0.1);
    border: 1px solid rgba(78, 205, 196, 0.2);
    color: #4ecdc4;
    margin-left: 20px;
}

.chat-message.ai {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #ccc;
    margin-right: 20px;
}

.ai-suggestions {
    padding: 0 12px 8px; /* reduced padding */
    flex-shrink: 0;
}

.suggestion-title {
    font-size: 12px;
    color: #aaa;
    margin-bottom: 8px;
    font-weight: 600;
}

.suggestion-buttons {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.suggestion-btn {
    background: rgba(255, 107, 107, 0.1);
    border: 1px solid rgba(255, 107, 107, 0.2);
    padding: 6px 10px; /* reduced padding */
    border-radius: 6px; /* smaller radius */
    color: #ff6b6b;
    font-size: 10px; /* smaller font */
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
}

.suggestion-btn:hover {
    background: #ff6b6b;
    color: #000;
}

/* Compact Dropdown Styles */
.dropdown-section {
    padding: 0 12px 8px;
    flex-shrink: 0;
    position: relative;
}

.dropdown-toggle {
    width: 100%;
    background: rgba(78, 205, 196, 0.1);
    border: 1px solid rgba(78, 205, 196, 0.3);
    padding: 8px 12px;
    border-radius: 6px;
    color: #4ecdc4;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.dropdown-toggle:hover {
    background: rgba(78, 205, 196, 0.2);
    border-color: #4ecdc4;
}

.dropdown-toggle.active {
    background: rgba(78, 205, 196, 0.2);
    border-color: #4ecdc4;
}

.dropdown-arrow {
    font-size: 8px;
    transition: transform 0.2s;
}

.dropdown-toggle.active .dropdown-arrow {
    transform: rotate(180deg);
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 12px;
    right: 12px;
    background: rgba(0, 0, 0, 0.9);
    border: 1px solid rgba(78, 205, 196, 0.3);
    border-radius: 6px;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-5px);
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.dropdown-menu.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-item {
    width: 100%;
    background: transparent;
    border: none;
    padding: 8px 12px;
    color: #ccc;
    font-size: 10px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.dropdown-item:last-child {
    border-bottom: none;
}

.dropdown-item:hover {
    background: rgba(78, 205, 196, 0.1);
    color: #4ecdc4;
}

/* Tools Used Section in Chat */
.tools-section {
    margin-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 6px;
}

.tools-toggle {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 4px 8px;
    border-radius: 4px;
    color: #aaa;
    font-size: 9px;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
    text-align: left;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tools-toggle:hover {
    background: rgba(78, 205, 196, 0.1);
    border-color: rgba(78, 205, 196, 0.3);
    color: #4ecdc4;
}

.tools-toggle.active {
    background: rgba(78, 205, 196, 0.1);
    border-color: rgba(78, 205, 196, 0.3);
    color: #4ecdc4;
}

.tools-arrow {
    font-size: 8px;
    transition: transform 0.2s;
}

.tools-list {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    margin-top: 4px;
}

.tools-list.open {
    max-height: 200px;
    padding: 6px;
}

.tool-item {
    padding: 4px 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 9px;
    color: #ccc;
}

.tool-item:last-child {
    border-bottom: none;
}

.tool-item strong {
    color: #4ecdc4;
    font-size: 10px;
}

.tool-item small {
    color: #999;
    font-size: 8px;
}

.ai-input-area {
    padding: 12px; /* reduced padding */
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0; /* prevent input area from shrinking */
    background: rgba(0, 0, 0, 0.8); /* stronger background for visibility */
    position: relative;
    min-height: 120px; /* taller to comfortably contain larger input and buttons */
}

.ai-input {
    width: 100%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    padding: 16px 90px 16px 16px; /* extra right padding for three inline buttons */
    color: white;
    font-size: 13px;
    resize: none;
    min-height: 80px; /* ~4x taller */
    max-height: 240px;
    line-height: 1.5;
    font-family: inherit;
    overflow-y: auto;
    touch-action: manipulation; /* Avoid double-tap zoom on iOS */
}

.ai-input:focus {
    outline: none;
    border-color: #4ecdc4;
    box-shadow: 0 0 0 2px rgba(78, 205, 196, 0.2);
}

/* Upload and Send buttons inside input */
.ai-upload-btn {
    position: absolute;
    right: 86px; /* make space for optimize + send */
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: #4ecdc4;
    cursor: pointer;
    font-size: 18px; /* >=16px to avoid zoom */
    padding: 4px;
    border-radius: 50%;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
}

.ai-upload-btn:hover {
    background: rgba(78, 205, 196, 0.2);
}

.ai-send-btn {
    position: absolute;
    right: 14px; /* inset so it sits fully inside the input */
    top: 50%;
    transform: translateY(-50%);
    background: #4ecdc4;
    border: none;
    color: #000;
    cursor: pointer;
    font-size: 18px; /* >=16px to avoid zoom */
    padding: 0;
    border-radius: 50%;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
}

/* Optimize (Enhance Prompt) button */
.ai-optimize-btn {
    position: absolute;
    right: 50px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: #4ecdc4;
    cursor: pointer;
    font-size: 18px; /* >=16px to avoid zoom */
    padding: 4px;
    border-radius: 50%;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
}

.ai-optimize-btn:hover {
    background: rgba(78, 205, 196, 0.2);
}

.ai-send-btn:hover:not(:disabled) {
    transform: translateY(-50%) scale(1.1);
    box-shadow: 0 4px 16px rgba(78, 205, 196, 0.3);
}

.ai-send-btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

/* Properties Panel */
.properties-panel {
    padding: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    max-height: 150px; /* reduced height */
    overflow-y: auto;
    flex-shrink: 0;
}

.properties-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    color: #ccc;
}

.property-group { margin-bottom: 12px; }

.property-label {
    font-size: 11px;
    color: #aaa;
    margin-bottom: 4px;
    text-transform: uppercase;
    font-weight: 600;
}

.property-input {
    width: 100%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    padding: 6px 8px;
    color: white;
    font-size: 12px;
}

.property-input:focus {
    outline: none;
    border-color: #4ecdc4;
}

/* Connections */
.canvas-inner .connection-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0; /* behind nodes */
}

.connection-path {
    stroke: #4ecdc4;
    stroke-width: 2;
    fill: none;
    opacity: 0.7;
    filter: drop-shadow(0 0 4px rgba(78, 205, 196, 0.3));
}

/* Light Theme */
[data-theme="light"] body {
    background: #f8f9fa;
    color: #212529;
}

[data-theme="light"] .app-container {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 50%, #dee2e6 100%);
}

[data-theme="light"] .header {
    background: rgba(255, 255, 255, 0.9);
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .logo {
    color: #007bff;
    background: none;
    -webkit-text-fill-color: initial;
}

[data-theme="light"] .component-palette,
[data-theme="light"] .ai-sidebar {
    background: rgba(255, 255, 255, 0.8);
    border-color: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .node {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.9), rgba(248, 249, 250, 0.9));
    border-color: #dee2e6;
    color: #212529;
}

/* Scrollbars */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: rgba(255, 255, 255, 0.1); }
::-webkit-scrollbar-thumb { background: rgba(78, 205, 196, 0.5); border-radius: 3px; }

/* ========================================
   RESPONSIVE DESIGN - MOBILE & TABLET
   ======================================== */

/* Mobile-first responsive breakpoints */
@media (max-width: 1200px) {
    /* Tablet landscape - reduce sidebar widths */
    .app-container {
        grid-template-columns: 240px 1fr 320px;
    }
}

@media (max-width: 1400px) {
    /* Large tablet - further reduce sidebars */
    .app-container {
        grid-template-columns: 200px 1fr 300px;
    }
    
    .header-actions {
        gap: 8px;
    }
    
    .header-btn {
        padding: 6px 12px;
        font-size: 11px;
    }
    
    .node {
        min-width: 200px;
        padding: 12px;
    }
}

@media (max-width: 900px) {
    /* Small tablet - stack layout differently */
    .app-container {
        grid-template-columns: 180px 1fr 280px;
    }
    
    .header {
        padding: 0 12px;
    }
    
    .logo {
        font-size: 16px;
    }
    
    .project-status {
        margin-left: 12px;
    }
    
    .project-name {
        font-size: 12px;
    }
}

@media (max-width: 1024px) {
    /* Mobile landscape and small tablets */
    .app-container {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr; /* header becomes fixed */
        position: relative;
        padding-top: calc(60px + env(safe-area-inset-top)); /* room for header + safe area */
        height: calc(100dvh - env(safe-area-inset-top)); /* full viewport minus safe area */
    }
    
    .component-palette {
        position: fixed !important;
        top: 60px;
        left: 0 !important;
        width: min(92vw, 360px); /* fit smaller phones */
        height: calc(100dvh - 60px);
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: 2px 0 20px rgba(0, 0, 0, 0.5);
    }

    .ai-sidebar {
        position: fixed !important;
        top: 60px;
        right: 0 !important;
        left: auto !important;
        width: min(92vw, 360px); /* fit smaller phones */
        height: calc(100dvh - 60px);
        z-index: 1000;
        transform: translateX(100%) !important;
        transition: transform 0.3s ease;
        box-shadow: -2px 0 20px rgba(0, 0, 0, 0.5);
    }
    
    .component-palette.open {
        transform: translateX(0);
    }
    
    .ai-sidebar {
        right: 0 !important;
        left: auto !important;
        transform: translateX(100%) !important;
    }
    
    .ai-sidebar.open {
        transform: translateX(0) !important;
    }
    
    .flow-canvas {
        grid-column: 1;
        grid-row: 2;
        height: calc(100dvh - 60px);
        z-index: 0;
        transform: none;
        touch-action: none; /* let JS handle pan and pinch on mobile */
    }
    .node { touch-action: none; }
    
    /* Add mobile toggle buttons */
    .mobile-nav {
        display: flex !important;
        gap: 8px;
        margin-left: auto;
        margin-right: 12px;
    }

    /* Keep header always visible on mobile */
    .header {
        position: sticky;
        top: 0;
        z-index: 1001;
    }

    /* Use dynamic viewport to avoid 100vh issues on mobile browsers */
    .app-container {
        height: 100dvh;
    }
    
    .mobile-toggle {
        background: rgba(78, 205, 196, 0.2);
        border: 1px solid rgba(78, 205, 196, 0.3);
        color: #4ecdc4;
        padding: 8px 12px;
        border-radius: 6px;
        font-size: 12px;
        cursor: pointer;
        transition: all 0.2s;
    touch-action: manipulation; /* prevent double-tap zoom */
    }

    /* Hide Help on mobile to reduce crowding */
    .header-actions .header-btn[onclick="showHelp()"] { display: none; }
    
    .mobile-toggle:hover,
    .mobile-toggle.active {
        background: #4ecdc4;
        color: #000;
    }
    
    /* Keep header visible and above everything */
    .header {
        position: fixed;
        top: env(safe-area-inset-top);
        left: 0;
        right: 0;
        height: 60px;
        z-index: 1002;
    }

    /* Adjust node sizes for mobile */
    .node {
        min-width: 180px;
        padding: 10px;
    }
    
    .node-title {
        font-size: 13px;
    }
    
    .node-description {
        font-size: 10px;
    }
    
    /* Mobile overlay for open sidebars */
    .mobile-overlay {
        position: fixed;
        top: 60px;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
    }
    
    .mobile-overlay.active {
        opacity: 1;
        visibility: visible;
    }

    /* Ensure header actions do not overflow on very small screens */
    .header-actions {
        display: flex;
        align-items: center;
        overflow: hidden;
        flex-wrap: nowrap;
    }

    .header-actions .header-btn {
        white-space: nowrap;
    }
}

@media (max-width: 768px) {
    /* Mobile portrait */
    .header {
        padding: 0 8px;
    }
    
    .logo {
        font-size: 14px;
    }
    
    .project-status {
        display: none; /* Hide project status on very small screens */
    }
    
    .header-actions { gap: 4px; }
    
    .header-btn {
        padding: 6px 8px;
        font-size: 10px;
    }
    
    /* Hide more header buttons */
    /* Keep View Prompt hidden on very small screens for space */
    .header-actions .header-btn[onclick="viewPrompt()"] { display: none; }
    
    .component-palette,
    .ai-sidebar {
        width: 100vw;
    }
    
    .node {
        min-width: 160px;
        padding: 8px;
    }
    
    .node-title {
        font-size: 12px;
    }
    
    .node-icon {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }
    
    /* Improve mobile chat experience */
    .ai-chat {
        padding: 10px;
        min-height: 250px; /* smaller min-height for mobile */
        overflow-y: auto;
    }
    
    .chat-message {
        font-size: 12px;
        padding: 8px 10px;
    }
    
    .ai-input {
        font-size: 16px; /* Prevent iOS Safari auto-zoom */
        padding: 12px 80px 12px 12px;
        min-height: 70px;
        max-height: 200px;
    }
    
    .properties-panel {
        padding: 10px;
        max-height: 120px; /* further reduced for mobile */
    }
    
    .ai-suggestions {
        padding: 0 10px 6px; /* more compact on mobile */
    }
    
    .ai-input-area {
        padding: 10px; /* more compact on mobile */
        min-height: 100px;
    }
}

@media (max-width: 640px) {
    /* Very small mobile screens */
    .header {
        padding: 0 6px;
    }
    
    .logo {
        font-size: 12px;
    }
    
    .mobile-nav {
        margin-right: 6px;
    }
    
    .mobile-toggle {
        padding: 6px 8px;
        font-size: 11px;
    }
    
    .header-actions {
        gap: 2px;
    }
    
    .header-btn {
        padding: 4px 6px;
        font-size: 9px;
    }
    
    .node {
        min-width: 140px;
        padding: 6px;
    }
    
    .component-palette {
        padding: 12px;
    }
    
    .palette-title {
        font-size: 14px;
    }
    
    .quick-btn {
        font-size: 9px;
        padding: 4px 8px;
    }
    
    .ai-sidebar {
        padding: 0;
    }
    
    .ai-header {
        padding: 10px;
    }
    
    .ai-title {
        font-size: 14px;
    }
    
    .ai-chat {
        padding: 8px;
        min-height: 200px; /* even smaller for very small screens */
    }
    
    .properties-panel {
        padding: 8px;
        max-height: 100px; /* very compact for small screens */
    }
    
    .ai-suggestions {
        padding: 0 8px 4px; /* very compact */
    }
    
    .suggestion-btn {
        font-size: 9px;
        padding: 4px 8px;
    }
    
    .ai-input-area {
        padding: 8px;
        min-height: 45px;
    }
    /* Ensure all inputs/buttons use 16px+ font-size to avoid zoom */
    .header-btn, .mobile-toggle, .quick-btn, .studio-btn, .dropdown-toggle, .dropdown-item, .suggestion-btn {
        font-size: 16px;
    }
    
    /* Compact dropdowns on small screens */
    .dropdown-section {
        padding: 0 8px 6px;
    }
    
    .dropdown-toggle {
        font-size: 10px;
        padding: 6px 10px;
    }
    
    .dropdown-item {
        font-size: 9px;
        padding: 6px 10px;
    }
    
    /* Responsive studio buttons */
    .studio-btn {
        font-size: 9px;
        padding: 5px 6px;
        min-height: 28px;
    }
    
    .studio-section {
        margin-bottom: 12px;
        padding-bottom: 8px;
    }
}
