/* ================================================================
   LAYOUT STYLES - App Layout & Responsive Design
   ================================================================ */

/* Main App Container */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Toolbar */
#toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 16px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 12px;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.toolbar-right {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

/* Logo */
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  color: var(--accent);
  white-space: nowrap;
}

.logo i {
  font-size: 20px;
}

/* Project Name Input */
#project-name {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-1);
  font-size: 14px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  text-align: center;
  width: 220px;
  transition: all var(--transition);
}

#project-name:hover {
  border-color: var(--border-light);
  background: var(--bg-2);
}

#project-name:focus {
  border-color: var(--accent);
  outline: none;
  background: var(--bg-2);
}

/* Workspace */
#workspace {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* Timeline Panel */
#timeline {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-0);
  border-right: 1px solid var(--border);
  min-width: 0;
}

#timeline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-1);
}

#timeline-header h2 {
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

#block-count {
  font-size: 12px;
  color: var(--text-3);
}

#timeline-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

/* Palette Panel */
#palette {
  width: 240px;
  display: flex;
  flex-direction: column;
  background: var(--bg-1);
  flex-shrink: 0;
  transition: transform var(--transition);
}

#palette-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-2);
}

#palette-header h2 {
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

#palette-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

/* Palette Toggle Button (mobile) */
#palette-toggle {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 20px;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-3);
  text-align: center;
  padding: 40px;
}

.empty-state i {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 14px;
  max-width: 280px;
  line-height: 1.6;
}

/* Homepage Layout */
.homepage {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.homepage-header {
  padding: 24px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-1);
}

.homepage-header h1 {
  font-size: 24px;
  margin-bottom: 4px;
}

.homepage-header p {
  color: var(--text-3);
  margin: 0;
}

.homepage-content {
  flex: 1;
  padding: 32px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

/* Story Grid */
.story-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 24px;
}

/* Story Card */
.story-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}

.story-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.story-card.new-story {
  border-style: dashed;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 160px;
  color: var(--text-3);
}

.story-card.new-story:hover {
  border-color: var(--success);
  color: var(--success);
}

.story-card.new-story i {
  font-size: 32px;
  margin-bottom: 12px;
}

.story-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
}

.story-card-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-1);
  margin: 0;
  word-break: break-word;
}

.story-card-meta {
  font-size: 12px;
  color: var(--text-3);
  margin-bottom: 16px;
}

.story-card-actions {
  display: flex;
  gap: 8px;
}

.story-card-actions button {
  flex: 1;
  padding: 8px 12px;
  font-size: 12px;
}

/* Action Bar */
.action-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

/* ================================================================
   RESPONSIVE DESIGN - Mobile & Tablet
   ================================================================ */

/* Tablet (max-width: 1024px) */
@media (max-width: 1024px) {
  .homepage-content {
    padding: 24px;
  }

  .story-grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
  }
}

/* Mobile (max-width: 768px) */
@media (max-width: 768px) {
  /* Allow body scrolling on mobile editor */
  html, body {
    overflow: auto;
    height: auto;
  }
  
  #app {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  /* Toolbar adjustments */
  #toolbar {
    height: auto;
    min-height: 56px;
    padding: 12px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .toolbar-left {
    order: 1;
  }

  .toolbar-right {
    order: 3;
    width: 100%;
    justify-content: center;
    padding-top: 8px;
    border-top: 1px solid var(--border);
  }

  #project-name {
    order: 2;
    width: auto;
    flex: 1;
    min-width: 150px;
  }

  .logo span {
    display: none;
  }

  /* Hide button text on mobile, show only icons */
  .toolbar-right .btn-text {
    display: none;
  }

  .toolbar-right .btn i {
    margin-right: 0;
    font-size: 14px;
  }

  .toolbar-right .btn {
    padding: 10px;
    min-width: 44px;
    min-height: 44px;
  }

  /* Button adjustments */
  .btn {
    padding: 8px 12px;
    font-size: 12px;
  }

  .btn i {
    margin-right: 4px;
  }

  /* Hero section button adjustments */
  .hero-section .btn {
    padding: 10px 16px;
  }

  /* Story cards - always show actions on mobile */
  .story-card-actions {
    opacity: 1;
  }

  .story-card .file-actions {
    opacity: 1;
  }

  /* Workspace - Stack vertically and allow scrolling */
  #workspace {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }

  /* Timeline takes full width and scrolls properly */
  #timeline {
    border-right: none;
    border-bottom: 1px solid var(--border);
    min-height: 60vh;
  }

  #timeline-content {
    overflow-y: visible;
    padding: 12px;
    min-height: 400px;
  }

  /* Palette becomes slide-out drawer */
  #palette {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 280px;
    max-width: 85vw;
    z-index: 200;
    transform: translateX(100%);
    box-shadow: var(--shadow-lg);
  }

  #palette.open {
    transform: translateX(0);
  }

  #palette-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 199;
  }

  #palette-overlay.open {
    display: block;
  }

  #palette-toggle {
    display: flex;
  }

  /* Homepage mobile */
  .homepage-header {
    padding: 16px 20px;
  }

  .homepage-header h1 {
    font-size: 20px;
  }

  .homepage-content {
    padding: 16px 20px;
  }

  .story-grid {
    grid-template-columns: 1fr;
  }

  .action-bar {
    flex-direction: column;
  }

  .action-bar .btn {
    width: 100%;
    justify-content: center;
  }

  /* Footer mobile */
  footer {
    padding: 16px 20px !important;
    font-size: 11px !important;
  }

  footer p {
    margin: 0;
    line-height: 1.5;
  }
}

/* Small Mobile (max-width: 480px) */
@media (max-width: 480px) {
  body {
    font-size: 13px;
  }

  #timeline-content {
    padding: 8px;
  }

  .btn {
    padding: 6px 10px;
  }

  /* Make modals fullscreen */
  .modal {
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    border-radius: 0;
  }

  .modal-overlay {
    padding: 0;
  }

  /* Story cards more compact */
  .story-card {
    padding: 16px;
  }
}

/* Touch-friendly adjustments */
@media (pointer: coarse) {
  .btn,
  .pal-btn,
  .block-header,
  .block-toggle {
    min-height: 44px;
  }

  .block-btns {
    opacity: 1;
  }

  .block-btns button {
    min-width: 36px;
    min-height: 36px;
  }
}

/* Landscape mobile adjustments */
@media (max-height: 500px) and (orientation: landscape) {
  #toolbar {
    min-height: 48px;
  }

  .logo span {
    display: inline;
  }

  /* Modal adjustments */
  .modal {
    max-height: 95vh;
  }
}