:root {
  --bg-app: #0f1115;
  --bg-panel: #16181d;
  --bg-header: #0D2034;
  --bg-input: #0f1115;
  
  --border-color: #2b303b;
  --border-active: #4a5160;
  
  --text-primary: #e0e4eb;
  --text-secondary: #8b949e;
  
  --accent-color: #3b82f6;
  --accent-hover: #2563eb;
  
  --lang-html: #e34c26;
  --lang-css: #563d7c;
  --lang-js: #f1e05a;
  
  --font-ui: 'Inter', system-ui, -apple-system, sans-serif;
  --font-code: 'JetBrains Mono', monospace;
  
  --header-height: 60px;
}

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

body {
  font-family: var(--font-ui);
  background-color: var(--bg-app);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Header */
.app-header {
  height: var(--header-height);
  background-color: var(--bg-header);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  flex-shrink: 0;
  gap: 1rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

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

.logo h1 {
  font-size: 1.1rem;
}

.actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  overflow-x: auto; /* Allow scrolling on very small screens if needed */
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none; /* Hide scrollbar */
}
.actions::-webkit-scrollbar { display: none; }

.divider {
  width: 1px;
  height: 24px;
  background-color: var(--border-color);
  margin: 0 0.25rem;
  flex-shrink: 0;
}

/* Import Bar */
.import-bar {
  height: auto;
  min-height: 48px;
  background-color: var(--bg-app);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0.5rem 1rem;
  gap: 0.75rem;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.import-input-wrapper {
  flex: 1;
  min-width: 200px; /* Ensure input doesn't get too small */
  display: flex;
  align-items: center;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0 0.75rem;
  color: var(--text-secondary);
  transition: border-color 0.2s;
}

.import-input-wrapper:focus-within {
  border-color: var(--accent-color);
  color: var(--text-primary);
}

.import-input-wrapper svg {
  margin-right: 0.5rem;
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.import-input-wrapper input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 0.875rem;
  height: 32px;
  outline: none;
  width: 100%;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid transparent;
  font-family: var(--font-ui);
  white-space: nowrap;
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  height: 32px;
}

.btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.btn-primary {
  background-color: var(--accent-color);
  color: white;
}
.btn-primary:hover {
  background-color: var(--accent-hover);
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.btn-secondary {
  background-color: transparent;
  border-color: var(--border-color);
  color: var(--text-primary);
}
.btn-secondary:hover {
  border-color: var(--border-active);
  background-color: rgba(255, 255, 255, 0.03);
}

.btn-ghost {
  background-color: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover {
  color: #ef4444;
  background-color: rgba(239, 68, 68, 0.1);
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover {
  color: var(--text-primary);
  background-color: rgba(255,255,255,0.1);
}

/* Editor Grid */
.editor-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background-color: var(--border-color); 
  overflow: hidden;
}

.editor-pane {
  background-color: var(--bg-panel);
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
  min-width: 0; /* Prevent flex item from overflowing */
}

.pane-header {
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.8rem;
  background-color: var(--bg-panel);
}

.lang-tag {
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 0.75rem;
  font-weight: 700;
  color: white;
  display: inline-block;
  line-height: 1.2;
  flex-shrink: 0;
}
.lang-tag.html { background-color: var(--lang-html); }
.lang-tag.css { background-color: var(--lang-css); }
.lang-tag.md { background-color: #083fa1; }
.lang-tag.js { background-color: var(--lang-js); }

.file-name {
  color: var(--text-secondary);
  font-family: var(--font-code);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

textarea {
  flex: 1;
  background-color: var(--bg-input);
  color: var(--text-primary);
  border: none;
  resize: none;
  padding: 1rem;
  font-family: var(--font-code);
  font-size: 0.9rem;
  line-height: 1.5;
  outline: none;
  width: 100%;
}
textarea:focus {
  background-color: #13151a; 
}

/* Preview Section */
.preview-container {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 40vh;
  background-color: var(--bg-panel);
  border-top: 1px solid var(--border-color);
  box-shadow: 0 -4px 20px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  z-index: 50; /* Higher than header */
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.preview-container.hidden {
  transform: translateY(100%);
  display: flex;
}

.preview-header {
  padding: 0.5rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #1a1d23;
  border-bottom: 1px solid var(--border-color);
}
.preview-header h3 {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.iframe-wrapper {
  flex: 1;
  background-color: white;
  position: relative;
}

iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background-color: var(--accent-color);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 99px;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 100;
  text-align: center;
  max-width: 90vw;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast.error {
  background-color: #ef4444;
}

/* --- RESPONSIVE ADJUSTMENTS --- */

/* Tablet and below */
@media (max-width: 1024px) {
  .editor-grid {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr 1fr;
    overflow-y: auto; /* Allow grid to scroll if content is tall */
  }
  
  .editor-pane {
     min-height: 0; /* Let grid control height */
  }
}

/* Mobile */
@media (max-width: 768px) {
  :root {
    --header-height: 56px;
  }
  
  /* Header adjustments */
  .app-header {
    padding: 0 0.75rem;
  }
  
  .logo h1 {
    display: none; /* Hide title on mobile to save space */
  }
  
  .actions .btn span {
    display: none; /* Hide button text, show icons only */
  }
  
  .actions .btn {
    padding: 0.5rem;
  }
  
  .actions {
    gap: 0.25rem;
  }

  /* Import bar adjustments */
  .import-bar {
    padding: 0.5rem 0.75rem;
  }
  
  .btn-sm span {
    display: none; /* Hide text on mobile for this button too */
  }
  
  /* Editor Layout: Stack vertically and allow body scroll */
  body {
    height: auto;
    min-height: 100vh;
    overflow-y: auto;
  }
  
  .editor-grid {
    display: flex;
    flex-direction: column;
    overflow: visible;
  }
  
  .editor-pane {
    height: 400px; /* Fixed height per pane on mobile for better editing */
    min-height: 400px;
    border-bottom: 1px solid var(--border-color);
  }
  
  /* Preview needs to handle mobile keyboard/height better */
  .preview-container {
    height: 80vh; /* Taller on mobile when open */
    z-index: 999;
  }
}
