/* ============================================================================
   JSOND Document Viewer - Stylesheet
   Design system: gray-50 (#fafafa) to gray-900 (#18181b)
   ============================================================================ */

/* ---------------------------------------------------------------------------
   Reset & Base
   --------------------------------------------------------------------------- */

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

[hidden] {
  display: none !important;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: #E5E7EB;
  background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 5 Q25 0 50 5 T100 5' stroke='rgba(0,0,0,0.039)' fill='none' stroke-width='0.8'/%3E%3Cpath d='M0 15 Q25 10 50 15 T100 15' stroke='rgba(0,0,0,0.039)' fill='none' stroke-width='0.8'/%3E%3Cpath d='M0 25 Q25 20 50 25 T100 25' stroke='rgba(0,0,0,0.039)' fill='none' stroke-width='0.8'/%3E%3Cpath d='M0 35 Q25 30 50 35 T100 35' stroke='rgba(0,0,0,0.039)' fill='none' stroke-width='0.8'/%3E%3Cpath d='M0 45 Q25 40 50 45 T100 45' stroke='rgba(0,0,0,0.039)' fill='none' stroke-width='0.8'/%3E%3Cpath d='M0 55 Q25 50 50 55 T100 55' stroke='rgba(0,0,0,0.039)' fill='none' stroke-width='0.8'/%3E%3Cpath d='M0 65 Q25 60 50 65 T100 65' stroke='rgba(0,0,0,0.039)' fill='none' stroke-width='0.8'/%3E%3Cpath d='M0 75 Q25 70 50 75 T100 75' stroke='rgba(0,0,0,0.039)' fill='none' stroke-width='0.8'/%3E%3Cpath d='M0 85 Q25 80 50 85 T100 85' stroke='rgba(0,0,0,0.039)' fill='none' stroke-width='0.8'/%3E%3Cpath d='M0 95 Q25 90 50 95 T100 95' stroke='rgba(0,0,0,0.039)' fill='none' stroke-width='0.8'/%3E%3C/svg%3E");
  background-size: 200px 100px;
  color: #111827;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  min-height: 100vh;
}

/* ---------------------------------------------------------------------------
   State Screens (Loading, Error, Landing)
   --------------------------------------------------------------------------- */

.state-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
  padding: 40px 20px;
  text-align: center;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #E5E7EB;
  border-top-color: #6B7280;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.state-screen p {
  color: #6B7280;
  font-size: 15px;
}

.error-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #FEF2F2;
  color: #EF4444;
  font-size: 24px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}

#error h2 {
  font-size: 20px;
  font-weight: 600;
  color: #111827;
  margin-bottom: 8px;
}

#error p {
  color: #6B7280;
  font-size: 14px;
}

/* Landing */

.landing-title {
  font-size: 48px;
  font-weight: 700;
  color: #111827;
  letter-spacing: -0.04em;
  margin-bottom: 8px;
}

.landing-subtitle {
  font-size: 16px;
  color: #6B7280;
  margin-bottom: 32px;
}

.landing-hint {
  font-size: 14px;
  color: #9CA3AF;
  line-height: 1.7;
}

.landing-hint a {
  color: #3498DB;
  text-decoration: none;
}

.landing-hint a:hover {
  text-decoration: underline;
}

/* ---------------------------------------------------------------------------
   Document Header
   --------------------------------------------------------------------------- */

#doc-header {
  background: #FAFAFA;
  border-bottom: 1px solid #E5E7EB;
  padding: 32px 0;
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 40px;
}

.title-section h1 {
  font-size: 28px;
  font-weight: 700;
  color: #111827;
  letter-spacing: -0.02em;
  line-height: 1.3;
  margin-bottom: 12px;
}

.meta-line {
  display: flex;
  align-items: center;
  gap: 12px;
}

.type-badge {
  display: inline-block;
  padding: 4px 10px;
  background: #E5E7EB;
  color: #374151;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: 4px;
}

.doc-dates {
  font-size: 12px;
  color: #6B7280;
  font-family: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", monospace;
}

/* Meta toggle button */

.header-content {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.meta-toggle {
  flex-shrink: 0;
  padding: 8px 16px;
  background: #334155;
  color: #e2e8f0;
  border: 1px solid #64748b;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 150ms ease-out;
  margin-top: 4px;
}

.meta-toggle:hover {
  background: #475569;
  border-color: #94a3b8;
}

/* ---------------------------------------------------------------------------
   Content Layout
   --------------------------------------------------------------------------- */

.content-wrapper {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 40px;
}

.content {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 32px;
  align-items: start;
}

/* ---------------------------------------------------------------------------
   Sidebar
   --------------------------------------------------------------------------- */

.doc-info {
  background: #FAFAFA;
  border: 1px solid #E5E7EB;
  border-radius: 8px;
  padding: 20px;
  position: sticky;
  top: 24px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
}

.info-section {
  margin-bottom: 24px;
}

.info-section:last-child {
  margin-bottom: 0;
}

.info-section h3 {
  margin: 0 0 10px 0;
  font-size: 11px;
  font-weight: 600;
  color: #6B7280;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.info-section p {
  margin: 0;
  font-size: 13px;
  color: #4B5563;
  line-height: 1.6;
}

.date-line {
  font-family: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", monospace;
  font-size: 12px !important;
  margin-bottom: 4px !important;
}

/* State badges */

.state-badge {
  display: inline-block;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: 4px;
}

.state-started {
  background: #F3F4F6;
  color: #6B7280;
}

.state-in-progress {
  background: #EFF6FF;
  color: #2563EB;
}

.state-complete {
  background: #ECFDF5;
  color: #059669;
}

/* Tags */

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  padding: 4px 10px;
  background: #E5E7EB;
  color: #6B7280;
  font-size: 11px;
  font-weight: 500;
  border-radius: 4px;
}

/* File path / reference */

.file-path {
  display: block;
  font-family: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", monospace;
  font-size: 11px;
  color: #4B5563;
  background: #F3F4F6;
  padding: 8px;
  border-radius: 4px;
  word-break: break-all;
}

/* Iterations */

.iteration-count {
  font-size: 13px;
  color: #4B5563;
}

.iteration-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.iteration-item {
  padding: 10px 12px;
  background: #F3F4F6;
  border-radius: 6px;
  font-size: 12px;
}

.iteration-number {
  font-weight: 600;
  color: #374151;
  margin-right: 8px;
}

.iteration-date {
  color: #9CA3AF;
  font-family: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", monospace;
  font-size: 11px;
}

.iteration-changes {
  margin-top: 6px;
  font-size: 12px;
  color: #6B7280;
  line-height: 1.5;
}

/* ---------------------------------------------------------------------------
   Document Content Area
   --------------------------------------------------------------------------- */

.doc-content {
  background: #FAFAFA;
  border: 1px solid #E5E7EB;
  border-radius: 8px;
  overflow: hidden;
}

/* View toggle bar */

.view-toggle {
  display: flex;
  gap: 0;
  padding: 16px 20px;
  background: #F3F4F6;
  border-bottom: 1px solid #E5E7EB;
}

.toggle-btn {
  padding: 8px 16px;
  background: transparent;
  border: 1px solid #D1D5DB;
  color: #6B7280;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: all 150ms ease-out;
  font-family: inherit;
}

.toggle-btn:first-child {
  border-radius: 6px 0 0 6px;
}

.toggle-btn:nth-child(2) {
  border-radius: 0 6px 6px 0;
  border-left: none;
}

.toggle-btn:hover {
  background: #E5E7EB;
  color: #374151;
}

.toggle-btn.active {
  background: #111827;
  border-color: #111827;
  color: #F9FAFB;
}

.toggle-btn.active:hover {
  background: #374151;
  border-color: #374151;
}

.toggle-spacer {
  flex: 1;
}

.action-btn {
  padding: 8px 12px;
  background: transparent;
  border: 1px solid #D1D5DB;
  color: #6B7280;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: all 150ms ease-out;
  font-family: inherit;
  border-radius: 6px;
  min-width: 36px;
  text-align: center;
}

.action-btn:hover {
  background: #E5E7EB;
  color: #374151;
}

.action-btn.download-btn {
  margin-left: 8px;
}

/* ---------------------------------------------------------------------------
   JSOND Formatted View (extracted from DocViewer.svelte)
   --------------------------------------------------------------------------- */

.jsond-formatted {
  padding: 32px;
  line-height: 1.7;
  max-width: 900px;
}

/* Depth 1 - Top level sections */

.jsond-formatted .depth-1 {
  margin-bottom: 48px;
  padding-bottom: 32px;
  border-bottom: 1px solid #E5E7EB;
}

.jsond-formatted .depth-1:last-child {
  border-bottom: none;
}

.jsond-formatted .depth-1 > .jsond-key {
  font-size: 28px;
  font-weight: 700;
  color: #111827;
  letter-spacing: -0.03em;
  margin-bottom: 20px;
  line-height: 1.3;
  display: block;
}

.jsond-formatted .depth-1 > .jsond-value {
  font-size: 17px;
  color: #374151;
  line-height: 1.8;
  margin-bottom: 16px;
  display: block;
}

/* Depth 2 - Sub-sections */

.jsond-formatted .depth-2 {
  margin-left: 24px;
  margin-bottom: 24px;
}

.jsond-formatted .depth-2 > .jsond-key {
  font-size: 20px;
  font-weight: 600;
  color: #1F2937;
  letter-spacing: -0.01em;
  margin-bottom: 12px;
  line-height: 1.4;
  display: block;
}

.jsond-formatted .depth-2 > .jsond-value {
  font-size: 16px;
  color: #4B5563;
  line-height: 1.7;
  margin-bottom: 12px;
  display: block;
}

/* Depth 3+ - Detail level */

.jsond-formatted .depth-3 {
  margin-left: 48px;
  margin-bottom: 16px;
}

.jsond-formatted .depth-3 > .jsond-key {
  font-size: 16px;
  font-weight: 400;
  color: #374151;
  margin-bottom: 8px;
  line-height: 1.5;
  display: block;
}

.jsond-formatted .depth-3 > .jsond-value {
  font-size: 15px;
  color: #4B5563;
  line-height: 1.7;
  margin-bottom: 10px;
  display: block;
}

/* Generic JSOND value styling */

.jsond-formatted .jsond-value {
  white-space: pre-wrap;
  word-wrap: break-word;
}

.jsond-formatted .jsond-value p {
  margin: 0 0 4px 0;
  line-height: 1.2;
}

.jsond-formatted .jsond-value p:last-child {
  margin-bottom: 0;
}

.jsond-formatted .intro-paragraph {
  margin-bottom: 8px;
}

.jsond-formatted .jsond-value strong {
  font-weight: 600;
  color: #1F2937;
}

.jsond-formatted .jsond-children {
  margin-top: 16px;
}

/* Lists within JSOND */

.jsond-formatted .jsond-value ul {
  margin: 8px 0 16px 0;
  padding-left: 24px;
  list-style: disc;
}

.jsond-formatted .jsond-value li {
  margin-bottom: 4px;
  color: #374151;
  line-height: 1.7;
  font-size: 15px;
}

/* Markdown within JSOND body */

.jsond-formatted .jsond-markdown strong {
  font-weight: 600;
  color: #111827;
}

.jsond-formatted .jsond-markdown code {
  font-family: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", monospace;
  font-size: 13px;
  background: #F3F4F6;
  color: #E74C3C;
  padding: 2px 6px;
  border-radius: 4px;
}

.jsond-formatted .jsond-markdown pre {
  margin: 12px 0;
  padding: 16px;
  background: #F3F4F6;
  border: 1px solid #E5E7EB;
  border-radius: 6px;
  overflow-x: auto;
}

.jsond-formatted .jsond-markdown pre code {
  background: transparent;
  color: #111827;
  padding: 0;
}

/* ---------------------------------------------------------------------------
   Raw JSON View
   --------------------------------------------------------------------------- */

.raw-content {
  margin: 0;
  padding: 24px;
  font-family: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", monospace;
  font-size: 13px;
  line-height: 1.6;
  color: #111827;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-x: auto;
}

.json-key {
  color: #2563EB;
}

/* ---------------------------------------------------------------------------
   Footer
   --------------------------------------------------------------------------- */

.site-footer {
  text-align: center;
  padding: 24px 40px;
  border-top: 1px solid #E5E7EB;
  margin-top: 32px;
}

.site-footer p {
  font-size: 11px;
  color: #9CA3AF;
}

/* ---------------------------------------------------------------------------
   Responsive
   --------------------------------------------------------------------------- */

@media (max-width: 1024px) {
  .content {
    grid-template-columns: 1fr;
  }

  .doc-info {
    position: static;
    max-height: none;
  }

  .header-content,
  .content-wrapper {
    padding-left: 20px;
    padding-right: 20px;
  }

  .title-section h1 {
    font-size: 22px;
  }

  .jsond-formatted {
    padding: 20px;
  }

  .jsond-formatted .depth-2 {
    margin-left: 12px;
  }

  .jsond-formatted .depth-3 {
    margin-left: 24px;
  }
}
