/* ==========================================================================
   StoryGrid - Custom Styles
   ========================================================================== */

/* Brand color override - purple for creativity */
:root {
  --brand-hue: 270;
  --header-height: 49px;
}

/* Layout */
body {
  overflow: hidden;
}

.main-content {
  position: fixed;
  top: 56px;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  overflow: hidden;
}

/* Header */
header nav .brand {
  text-decoration: none;
}

/* Grid Table */
.grid-table {
  min-width: max-content;
  padding-top: 0;
}

.grid-row {
  min-height: 40px;
}

.sticky-header {
  position: sticky;
}

/* Row Numbers */
.row-number-col {
  width: 40px;
  min-width: 40px;
  max-width: 40px;
  flex-shrink: 0;
  border-right: 1px solid var(--border-color);
}

/* Plot Line Columns */
.plotline-col {
  width: 220px;
  min-width: 220px;
  max-width: 220px;
  flex-shrink: 0;
}

.plotline-col-add {
  width: 120px;
  min-width: 120px;
  flex-shrink: 0;
}

/* Contenteditable in headers */
.plotline-col [contenteditable] {
  outline: none;
  border-radius: var(--radius-sm);
  padding: 2px 4px;
  margin: -2px -4px;
}

.plotline-col [contenteditable]:hover {
  background-color: var(--surface-2);
}

.plotline-col [contenteditable]:focus {
  background-color: var(--surface-2);
  box-shadow: var(--focus-ring);
}

/* Grid Cells */
.grid-cell {
  min-height: 100px;
  padding: var(--space-2);
  transition: background-color var(--transition-fast);
}

.grid-cell:hover {
  background-color: var(--surface-1);
}

.grid-cell.drag-over {
  background-color: var(--brand-2);
}

[data-theme="dark"] .grid-cell.drag-over {
  background-color: var(--brand-9);
}

.add-scene-cell {
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: none;
}

.add-scene-cell:hover {
  background-color: var(--surface-1);
}

/* Scene Cards */
.scene-card {
  background-color: var(--surface-1);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  cursor: pointer;
  transition:
    transform var(--transition-fast),
    box-shadow var(--transition-fast),
    outline var(--transition-fast);
  outline: 2px solid transparent;
  outline-offset: 2px;
}

.scene-card:hover {
  background-color: var(--surface-2);
  box-shadow: var(--shadow-2);
}

.scene-card.focused {
  outline-color: var(--brand-5);
  box-shadow: var(--shadow-2);
}

.scene-card.dragging {
  opacity: 0.5;
  transform: rotate(2deg);
}

.scene-card:focus {
  outline-color: var(--brand-5);
}

.scene-card:focus-visible {
  outline-color: var(--brand-5);
}

.scene-title {
  font-weight: var(--fw-bold);
  line-height: var(--lh-tight);
  margin-bottom: var(--space-1);
}

.scene-summary {
  line-height: var(--lh-normal);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.scene-meta {
  font-size: var(--fs-sm);
}

/* Chapter Dividers */
.chapter-divider {
  background-color: var(--surface-1);
}

.chapter-divider .chapter-chevron {
  padding: 0;
  line-height: 1;
}

.chapter-divider [contenteditable] {
  outline: none;
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  margin: -2px -6px;
}

.chapter-divider [contenteditable]:hover {
  background-color: var(--surface-2);
}

.chapter-divider [contenteditable]:focus {
  background-color: var(--surface-2);
  box-shadow: var(--focus-ring);
}

.chapter-chevron {
  font-size: var(--fs-2xl);
  transition: transform var(--transition-fast);
}

.chapter-chevron:not(.collapsed) {
  transform: rotate(90deg);
}

/* Add Chapter Button */
.row-number-col .chapter-add-btn {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 10px;
  padding: 2px 4px;
  background-color: var(--surface-2);
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
}

.row-number-col:hover .chapter-add-btn {
  opacity: 1;
  pointer-events: auto;
}

/* Group hover utility */
.group:hover .chapter-add-btn {
  display: block;
}

/* Convergence Row Highlight */
.bg-brand-light {
  background-color: oklch(95% 0.03 var(--brand-hue));
}

[data-theme="dark"] .bg-brand-light {
  background-color: oklch(20% 0.03 var(--brand-hue));
}

/* Outline View */
.outline-item {
  background-color: var(--surface-1);
  transition:
    transform var(--transition-fast),
    box-shadow var(--transition-fast),
    outline var(--transition-fast);
  outline: 2px solid transparent;
  outline-offset: 2px;
}

.outline-item:hover {
  background-color: var(--surface-2);
  box-shadow: var(--shadow-2);
}

.outline-item.focused {
  outline-color: var(--brand-5);
}

/* Scene Editor */
.prose-editor {
  font-family: var(--font-family);
  font-size: var(--fs-base);
  line-height: var(--lh-relaxed);
  resize: vertical;
  min-height: 300px;
}

.prose-editor:focus {
  outline: none;
  border-color: var(--brand-5);
  box-shadow: var(--focus-ring);
}

/* Dialog Improvements */
dialog > article {
  animation: dialog-appear 0.15s ease-out;
}

/* Zen Mode */
dialog.zen-dialog {
  padding: 0;
  margin: 0;
  width: 100vw;
  height: 100vh;
  max-width: 100vw;
  max-height: 100vh;
}

dialog.zen-dialog > article.zen-article {
  max-width: 100% !important;
  width: 100%;
  height: 100vh;
  margin: 0;
  border-radius: 0;
  display: flex;
  flex-direction: column;
}

.zen-body {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.zen-title {
  font-size: var(--fs-2xl) !important;
  text-align: center;
  width: 100%;
}

.zen-prose {
  flex: 1;
  font-size: var(--fs-lg);
  line-height: var(--lh-relaxed);
  max-width: 900px;
  margin: 0 auto;
  resize: none;
}

.zen-word-count {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  text-align: right;
}

/* Remove border and margin above dialog footer */
dialog > article > footer {
  border-top: none;
  margin-top: 0;
}

@keyframes dialog-appear {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(-10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

dialog > article > header input[type="text"] {
  border: none;
  background: transparent;
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
}

dialog > article > header input[type="text"]:focus {
  box-shadow: none;
}

/* Story Cards (Dashboard) */
.grid article {
  transition:
    transform var(--transition-fast),
    box-shadow var(--transition-fast);
}

.grid article:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-3);
}

/* Scrollbar Styling */
#grid-body {
  scrollbar-width: thin;
  scrollbar-color: var(--surface-3) transparent;
}

#grid-body::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

#grid-body::-webkit-scrollbar-track {
  background: transparent;
}

#grid-body::-webkit-scrollbar-thumb {
  background-color: var(--surface-3);
  border-radius: 4px;
}

#grid-body::-webkit-scrollbar-thumb:hover {
  background-color: var(--surface-4);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: var(--space-16);
  color: var(--text-muted);
}

/* Color chip for plot line indicator */
.w-1 {
  width: 4px;
}

.h-6 {
  height: 24px;
}

/* Status badges */
.capitalize {
  text-transform: capitalize;
}

/* Button refinements */
button.btn-ghost.btn-sm {
  padding: var(--space-1) var(--space-2);
}

button.btn-ghost.text-muted:hover {
  color: var(--text-color);
}

/* Fix contenteditable cursor */
[contenteditable="true"] {
  cursor: text;
}

/* Drag cursor */
.plotline-col[draggable="true"],
.scene-card[draggable="true"],
.outline-item[draggable="true"] {
  cursor: grab;
}

.plotline-col[draggable="true"]:active,
.scene-card[draggable="true"]:active,
.outline-item[draggable="true"]:active {
  cursor: grabbing;
}

/* Text danger for delete buttons */
.text-danger {
  color: var(--danger);
}

.text-danger:hover {
  color: var(--danger-dark);
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .plotline-col {
    width: 180px;
    min-width: 180px;
    max-width: 180px;
  }

  .grid-cell {
    min-height: 80px;
  }
}

/* Print styles */
@media print {
  header,
  footer,
  dialog {
    display: none !important;
  }

  main {
    padding-top: 0 !important;
  }

  .scene-card {
    break-inside: avoid;
  }
}
