:root {
  --bg: #0b1021;
  --card: #0f172a;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #7c3aed;
  --accent-strong: #a855f7;
  --border: rgba(255, 255, 255, 0.08);
  --panel: rgba(15, 23, 42, 0.7);
}

[data-theme='light'] {
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --border: rgba(15, 23, 42, 0.08);
  --panel: rgba(255, 255, 255, 0.8);
}

[data-theme='sand'] {
  --bg: #f6f0e7;
  --card: #fffaf3;
  --text: #2f2a25;
  --muted: #6b5f57;
  --accent: #c05621;
  --accent-strong: #9c4221;
  --border: rgba(47, 42, 37, 0.12);
  --panel: rgba(255, 250, 243, 0.8);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 24px;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px;
  border: 1px solid var(--border);
  background: linear-gradient(135deg, rgba(124, 58, 237, 0.08), rgba(37, 99, 235, 0.1));
  border-radius: 16px;
  margin-bottom: 24px;
}

.hero h1 {
  margin: 0 0 8px;
  font-size: 28px;
}

.hero .lede {
  margin: 0;
  color: var(--muted);
}

.hero .eyebrow {
  margin: 0;
  color: var(--accent-strong);
  font-weight: 700;
  letter-spacing: 0.3px;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr) minmax(260px, 320px);
  gap: 16px;
  align-items: start;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 12px;
}

.card h2 {
  margin: 0;
  font-size: 18px;
}

.editor-card h2 {
  margin: 0;
}

.editor-shell {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.view-toggle {
  display: inline-flex;
  gap: 6px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
}

#viewOnBlogBtn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

#viewOnBlogHint {
  margin: 0 0 8px;
}

.view-toggle .ghost {
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
}

.view-toggle .is-active {
  background: rgba(124, 58, 237, 0.2);
  color: var(--accent-strong);
  border: 1px solid transparent;
}

.editor-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  align-items: stretch;
}

.preview-pane {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
  padding: 12px;
  min-height: 100%;
  overflow: hidden;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-weight: 700;
}

.pill {
  background: rgba(124, 58, 237, 0.12);
  color: var(--accent-strong);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

input,
textarea,
select,
button {
  font: inherit;
}

input,
textarea,
select {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  transition: border 0.2s ease, box-shadow 0.2s ease;
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.12);
}

button {
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 700;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s ease;
  white-space: nowrap;
}

button:active {
  transform: translateY(1px);
}

.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
  box-shadow: 0 10px 30px rgba(124, 58, 237, 0.25);
}

.ghost {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid var(--border);
}

.actions {
  display: flex;
  gap: 8px;
}

.row {
  display: flex;
  align-items: center;
}

.row.between {
  justify-content: space-between;
  gap: 12px;
}

.row.gap {
  gap: 8px;
}

.muted {
  color: var(--muted);
  font-size: 14px;
}

.error {
  color: #f87171;
}

.session {
  margin-top: 12px;
  padding: 12px;
  border-radius: 10px;
  background: rgba(124, 58, 237, 0.08);
  color: var(--accent-strong);
  font-weight: 700;
  min-height: 44px;
}

.debug-line {
  margin-bottom: 12px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.4);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  word-break: break-all;
}

.login-hint {
  margin-top: 10px;
  font-size: 13px;
}

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

.posts-toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.posts-toolbar-inputs {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(120px, 160px);
  gap: 8px;
}

.posts-table {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.02);
}

.posts-body {
  display: flex;
  flex-direction: column;
}

.posts-row {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) 0.6fr 0.9fr 0.9fr;
  gap: 8px;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.posts-row:last-child {
  border-bottom: none;
}

.posts-row--head {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  background: rgba(15, 23, 42, 0.4);
  cursor: default;
}

.posts-row.active {
  background: rgba(124, 58, 237, 0.18);
}

.posts-row:not(.posts-row--head):hover {
  background: rgba(124, 58, 237, 0.08);
}

.posts-cell {
  font-size: 13px;
}

.posts-title {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.posts-id {
  font-size: 11px;
}

.posts-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 12px;
}

.posts-state {
  padding: 20px 12px;
  color: var(--muted);
  text-align: center;
  border-top: 1px solid var(--border);
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: var(--accent-strong);
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.badge-draft {
  background: rgba(148, 163, 184, 0.2);
  color: #cbd5f5;
}

.badge-published {
  background: rgba(34, 197, 94, 0.2);
  color: #4ade80;
}

.list-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
  transition: border 0.2s ease, background 0.2s ease;
}

.list-item:hover {
  border-color: var(--accent);
  background: rgba(124, 58, 237, 0.08);
}

.list-item.active {
  border-color: var(--accent-strong);
  background: rgba(124, 58, 237, 0.18);
}

.list-item .meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  gap: 8px;
}

.job-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.job-item {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
}

.status-chip {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
}

.status-queued {
  background: #f59e0b;
}

.status-building {
  background: #2563eb;
}

.status-success {
  background: #16a34a;
}

.status-failed {
  background: #dc2626;
}

.preview {
  min-height: 120px;
  padding: 0;
  border-radius: 10px;
  background: transparent;
  flex: 1;
  overflow-y: auto;
}

.preview h1,
.preview h2,
.preview h3 {
  margin-top: 0;
}

.preview p {
  margin: 0 0 12px;
}

.preview code {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, SFMono-Regular, Menlo, monospace;
  background: rgba(148, 163, 184, 0.2);
  padding: 2px 6px;
  border-radius: 6px;
}

.preview pre {
  background: rgba(15, 23, 42, 0.6);
  padding: 12px;
  border-radius: 10px;
  overflow-x: auto;
}

.editor-card[data-view-mode='edit'] .preview-pane {
  display: none;
}

.editor-card[data-view-mode='preview'] .editor-pane {
  display: none;
}

.link-row a {
  color: var(--accent-strong);
  text-decoration: none;
  font-weight: 700;
}

.link-row a:hover {
  text-decoration: underline;
}

.hidden {
  display: none;
}

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

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .editor-split {
    grid-template-columns: 1fr;
  }

  .editor-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 720px) {
  body {
    padding: 16px;
  }

  .hero {
    flex-direction: column;
    align-items: flex-start;
  }

  .row.between {
    flex-direction: column;
    align-items: flex-start;
  }

  .posts-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .posts-row--head {
    display: none;
  }

  .posts-pagination {
    flex-direction: column;
    align-items: flex-start;
  }
}
