@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --panel-soft: #f9fafb;
  --line: #e5e7eb;
  --line-light: #f0f1f3;
  --text: #111827;
  --text-secondary: #6b7280;
  --text-tertiary: #9ca3af;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-subtle: #dbeafe;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-light: #fef2f2;
  --success: #10b981;
  --success-light: #ecfdf5;
  --warning: #f59e0b;
  --warning-light: #fffbeb;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --radius: 8px;
  --radius-lg: 12px;
  --transition: 150ms ease;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  background: var(--bg);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ─── Layout Shell ─── */

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 16px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.main-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}

.main-toolbar {
  padding: 10px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  min-height: 48px;
}

.brand {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.content {
  flex: 1;
  overflow: auto;
  padding: 20px 24px;
}

/* ─── Sidebar ─── */

.sidebar-section {
  margin-bottom: 16px;
}

.sidebar-title {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.sidebar-section-title {
  margin: 0 0 6px;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.project-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  padding: 0 4px;
}

.project-list,
.step-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.project-row {
  display: flex;
  align-items: center;
  border-radius: 6px;
  position: relative;
  background: transparent;
  border: none;
}

.project-row:hover {
  background: var(--panel-soft);
}

.project-row.is-active {
  background: var(--primary-light);
}

.project-row.is-active .project-name {
  color: var(--primary);
  font-weight: 600;
}

.project-name {
  flex: 1;
  text-align: left;
  padding: 6px 8px;
  font-size: 13px;
  cursor: pointer;
  border: 0;
  background: transparent;
  color: var(--text);
  border-radius: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.project-menu {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  border: 0;
  background: transparent;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  transition: background var(--transition), color var(--transition);
}

.project-menu:hover {
  background: var(--line-light);
  color: var(--text);
}

/* Context menu / popover */

.popover-menu {
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 50;
  min-width: 140px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 4px;
  animation: popover-in 0.12s ease;
}

.popover-item {
  display: block;
  width: 100%;
  padding: 7px 10px;
  font-size: 13px;
  border: none;
  background: none;
  color: var(--text);
  cursor: pointer;
  border-radius: 5px;
  text-align: left;
  transition: background var(--transition);
}

.popover-item:hover {
  background: var(--panel-soft);
}

.popover-item--danger {
  color: var(--danger);
}

.popover-item--danger:hover {
  background: var(--danger-light);
}

@keyframes popover-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Inline rename input */

.inline-rename {
  flex: 1;
  padding: 4px 8px;
  font-size: 13px;
  border: 1px solid var(--primary);
  border-radius: 5px;
  outline: none;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

/* Inline new project input */

.inline-new-project {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}

.inline-new-project input {
  flex: 1;
  padding: 6px 8px;
  font-size: 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: none;
  background: var(--panel);
  color: var(--text);
}

.inline-new-project input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

/* Step sidebar items */

.step-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  font-size: 13px;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--text);
  border-radius: 6px;
  transition: background var(--transition);
}

.step-row:hover {
  background: var(--panel-soft);
}

.step-row.is-active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 500;
}

.step-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--line);
}

.step-status--done {
  background: var(--success);
}

.step-status--stale {
  background: var(--warning);
}

.step-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ─── Step page content ─── */

.step-page {
  display: grid;
  gap: 16px;
  max-width: 1100px;
  min-width: 0;
}

.step-page--wide {
  max-width: 1480px;
}

.step-header {
  padding: 16px 20px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.step-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.step-subtitle {
  margin: 4px 0 0;
  color: var(--text-tertiary);
  font-size: 12px;
}

.step-state-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* ─── Cards ─── */

.output-card,
.output-area {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius-lg);
  padding: 16px;
  overflow: hidden;
  min-width: 0;
}

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

.output-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.output-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

/* ─── Forms ─── */

.input-text,
.input-textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--panel);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.input-text:focus,
.input-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

.input-textarea {
  min-height: 120px;
  resize: vertical;
}

/* ─── Markdown ─── */

.markdown-body.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.markdown-preview {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
  padding: 12px;
  min-height: 120px;
  overflow: auto;
  font-size: 14px;
  line-height: 1.6;
}

/* ─── Prose typography for rendered markdown ─── */

.markdown-preview h1,
.markdown-preview h2,
.markdown-preview h3,
.markdown-preview h4,
.markdown-preview h5,
.markdown-preview h6 {
  margin: 1.2em 0 0.5em;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
}

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

.markdown-preview h1 { font-size: 1.5em; }
.markdown-preview h2 { font-size: 1.3em; border-bottom: 1px solid var(--line-light); padding-bottom: 0.3em; }
.markdown-preview h3 { font-size: 1.15em; }
.markdown-preview h4 { font-size: 1.05em; }
.markdown-preview h5 { font-size: 1em; }
.markdown-preview h6 { font-size: 0.9em; color: var(--text-secondary); }

.markdown-preview p {
  margin: 0.6em 0;
}

.markdown-preview p:first-child {
  margin-top: 0;
}

.markdown-preview ul,
.markdown-preview ol {
  margin: 0.6em 0;
  padding-left: 1.8em;
}

.markdown-preview li {
  margin: 0.25em 0;
}

.markdown-preview li > ul,
.markdown-preview li > ol {
  margin: 0.2em 0;
}

.markdown-preview strong {
  font-weight: 600;
  color: var(--text);
}

.markdown-preview em {
  font-style: italic;
}

.markdown-preview a {
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.markdown-preview a:hover {
  color: var(--primary-hover);
}

.markdown-preview code {
  background: rgba(0, 0, 0, 0.06);
  border-radius: 4px;
  padding: 0.15em 0.4em;
  font-size: 0.9em;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', ui-monospace, monospace;
}

.markdown-preview pre {
  background: #1e293b;
  color: #e2e8f0;
  border-radius: var(--radius);
  padding: 12px 16px;
  overflow-x: auto;
  margin: 0.8em 0;
  line-height: 1.5;
}

.markdown-preview pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: 13px;
  color: inherit;
}

.markdown-preview blockquote {
  margin: 0.8em 0;
  padding: 0.5em 1em;
  border-left: 3px solid var(--primary-subtle);
  background: var(--primary-light);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-secondary);
}

.markdown-preview blockquote p {
  margin: 0.3em 0;
}

.markdown-preview hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 1.2em 0;
}

.markdown-preview table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.8em 0;
  font-size: 13px;
}

.markdown-preview th,
.markdown-preview td {
  border: 1px solid var(--line);
  padding: 6px 10px;
  text-align: left;
}

.markdown-preview th {
  background: var(--panel-soft);
  font-weight: 600;
  color: var(--text);
}

.markdown-preview tr:nth-child(even) td {
  background: rgba(0, 0, 0, 0.015);
}

.markdown-preview img {
  max-width: 100%;
  border-radius: var(--radius);
}

/* ─── CSV / BPMN ─── */

.csv-table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}

.csv-table-wrap .gridjs-wrapper {
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.csv-table-wrap .gridjs-table {
  font-size: 13px;
}

.csv-table-wrap .gridjs-th {
  white-space: nowrap;
  font-size: 12px;
  background: var(--panel-soft) !important;
  color: var(--text-secondary);
  border-color: var(--line) !important;
}

.csv-table-wrap .gridjs-td {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-color: var(--line-light) !important;
}

.csv-table-wrap .gridjs-footer {
  display: none;
}

.bpmn-layout {
  display: grid;
  grid-template-columns: minmax(240px, 36%) minmax(0, 1fr);
  gap: 12px;
  min-height: 450px;
}

.bpmn-xml {
  min-height: 450px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', ui-monospace, monospace;
  font-size: 12px;
}

.bpmn-canvas {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  overflow: hidden;
}

/* ─── Notes ─── */

.notes-list {
  display: grid;
  gap: 10px;
}

.note-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--panel-soft);
  display: grid;
  gap: 8px;
}

.note-head {
  display: flex;
  gap: 8px;
  align-items: center;
}

.note-index {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-subtle);
  color: var(--primary);
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
}

.note-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.notes-summary {
  margin-top: 12px;
}

.field-label {
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
}

/* ─── Action bar ─── */

.action-bar {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.action-left,
.action-right {
  display: flex;
  gap: 6px;
}

/* ─── Badges ─── */

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge-empty {
  color: var(--text-tertiary);
  background: var(--line-light);
}

.badge-done {
  color: #065f46;
  background: var(--success-light);
}

.badge-stale {
  color: #92400e;
  background: var(--warning-light);
}

/* ─── Buttons ─── */

.btn-primary,
.btn-secondary,
.btn-danger,
.btn-ghost,
.btn-add-project {
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  transition: background var(--transition), color var(--transition), opacity var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.btn-primary:disabled,
.btn-secondary:disabled,
.btn-danger:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.btn-primary {
  color: #fff;
  background: var(--primary);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  color: var(--text-secondary);
  background: var(--panel-soft);
  border: 1px solid var(--line);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--line-light);
  color: var(--text);
}

.btn-danger {
  color: var(--danger);
  background: var(--danger-light);
}

.btn-danger:hover:not(:disabled) {
  background: #fee2e2;
  color: var(--danger-hover);
}

.btn-ghost {
  color: var(--text-secondary);
  background: transparent;
  padding: 4px 8px;
}

.btn-ghost:hover {
  background: var(--panel-soft);
  color: var(--text);
}

.btn-add-project {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  padding: 0;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--line);
  font-size: 15px;
}

.btn-add-project:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary-subtle);
}

.file-input-label {
  display: inline-flex;
  align-items: center;
}

/* ─── Loading ─── */

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
}

.loading-box {
  background: var(--panel);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  width: min(90vw, 280px);
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.loading-spinner {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  margin: 0 auto 10px;
  border: 2.5px solid var(--line);
  border-top-color: var(--primary);
  animation: spin 0.7s linear infinite;
}

.loading-message {
  margin: 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.loading-retry {
  margin: 6px 0 0;
  color: var(--warning);
  font-size: 12px;
}

/* ─── Toast ─── */

.toast-container {
  position: fixed;
  top: 12px;
  right: 12px;
  display: grid;
  gap: 6px;
  z-index: 70;
}

.toast {
  background: var(--text);
  color: #fff;
  border-radius: var(--radius);
  padding: 10px 14px;
  min-width: 200px;
  max-width: 360px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.15s ease;
}

.toast-success {
  background: #065f46;
}

.toast-warning {
  background: #92400e;
}

.toast-error {
  background: #991b1b;
}

.toast-leave {
  opacity: 0;
  transform: translateY(-4px);
  transition: all 0.15s ease;
}

/* ─── Fatal screen ─── */

.fatal-screen {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 80;
}

.fatal-card {
  width: min(90vw, 400px);
  background: var(--panel);
  border-radius: var(--radius-lg);
  padding: 28px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.fatal-title {
  margin: 0 0 6px;
  font-size: 16px;
}

.fatal-message {
  margin: 0 0 16px;
  color: var(--text-secondary);
  font-size: 14px;
}

.fatal-retry {
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  padding: 8px 20px;
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  background: var(--primary);
  font-family: inherit;
}

.fatal-retry:hover {
  background: var(--primary-hover);
}

/* ─── Status ─── */

.save-status {
  font-size: 12px;
  font-weight: 500;
}

.save-status-saving {
  color: var(--warning);
}

.save-status-saved {
  color: var(--success);
}

.save-status-error {
  color: var(--danger);
  cursor: pointer;
}

.guard-message {
  margin: 0;
  color: var(--warning);
  font-size: 12px;
}

/* ─── Confirm inline ─── */

.confirm-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--danger);
  animation: popover-in 0.12s ease;
}

.confirm-inline span {
  font-weight: 500;
}

/* ─── Utilities ─── */

.empty-text {
  color: var(--text-tertiary);
  font-size: 13px;
}

.error-text {
  color: var(--danger);
  font-size: 13px;
}

.hidden {
  display: none !important;
}

/* ─── Keyframes ─── */

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

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ─── Output Mode Selector ─── */

.output-mode-selector {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius-lg);
  padding: 16px;
}

.output-mode-title {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.output-mode-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.output-mode-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.output-mode-btn:hover {
  border-color: var(--primary-subtle);
  background: var(--primary-light);
  color: var(--text);
}

.output-mode-btn--active {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary), inset 0 0 0 1px rgba(37, 99, 235, 0.08);
}

.output-mode-btn--active .output-mode-btn__icon {
  color: var(--primary);
}

.output-mode-btn__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  flex-shrink: 0;
  transition: all var(--transition);
  color: var(--text-tertiary);
}

.output-mode-btn--active .output-mode-btn__icon {
  background: var(--primary-subtle);
  border-color: var(--primary);
  color: var(--primary);
}

.output-mode-btn__label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ─── BPMN Sub-mode Selector ─── */

.bpmn-submode-selector {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line-light);
  animation: bpmn-sub-in 0.2s ease;
}

@keyframes bpmn-sub-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.bpmn-submode-icon {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 4px;
}

/* ─── Viewer Link Button ─── */

.viewer-link-section {
  animation: popover-in 0.2s ease;
}

.viewer-link-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 14px 20px;
  border: 2px solid var(--success);
  border-radius: var(--radius-lg);
  background: var(--success-light);
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: #065f46;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.viewer-link-btn:hover {
  background: #d1fae5;
  border-color: #059669;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.2);
  transform: translateY(-1px);
}

.viewer-link-btn:active {
  transform: translateY(0);
}

.viewer-link-btn__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #d1fae5;
  border: 1px solid rgba(16, 185, 129, 0.3);
  flex-shrink: 0;
  color: #059669;
}

.viewer-link-btn:hover .viewer-link-btn__icon {
  background: #a7f3d0;
}

.viewer-link-btn__arrow {
  margin-left: auto;
  font-size: 18px;
  color: #059669;
  transition: transform var(--transition);
}

.viewer-link-btn:hover .viewer-link-btn__arrow {
  transform: translateX(4px);
}

/* ─── Archive Grid (Goodnotes style) ─── */

.archive-page {
  display: grid;
  gap: 20px;
}

.archive-header {
  display: grid;
  gap: 4px;
}

.archive-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.archive-subtitle {
  margin: 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.archive-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
}

.archive-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel);
  cursor: pointer;
  transition: all var(--transition);
  overflow: hidden;
  position: relative;
}

.archive-card:hover {
  border-color: var(--primary-subtle);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  transform: translateY(-2px);
}

.archive-card--new {
  border: 2px dashed var(--line);
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  gap: 8px;
}

.archive-card--new:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.archive-card__plus {
  font-size: 32px;
  color: var(--text-tertiary);
  font-weight: 300;
  line-height: 1;
}

.archive-card--new:hover .archive-card__plus {
  color: var(--primary);
}

.archive-card__new-label {
  font-size: 13px;
  color: var(--primary);
  font-weight: 500;
}

.archive-card__preview {
  height: 140px;
  padding: 14px;
  overflow: hidden;
  position: relative;
  background: var(--panel-soft);
  border-bottom: 1px solid var(--line-light);
}

.archive-card__preview::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 40px;
  background: linear-gradient(transparent, var(--panel-soft));
}

.archive-card__preview-text {
  margin: 0;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-secondary);
  word-break: break-all;
}

.archive-card__meta {
  padding: 10px 14px;
  display: grid;
  gap: 2px;
}

.archive-card__title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.archive-card__date {
  font-size: 11px;
  color: var(--text-tertiary);
}

.archive-card__badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--success-light);
  color: #065f46;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
}

/* ─── Archive Detail ─── */

.archive-detail {
  display: grid;
  gap: 16px;
}

.archive-detail__header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.archive-detail__back {
  flex-shrink: 0;
}

.archive-detail__title-input {
  flex: 1;
  font-size: 16px;
  font-weight: 600;
}

.archive-source-input {
  min-height: 180px;
  resize: vertical;
}

.archive-generate-section {
  display: flex;
  justify-content: center;
}

.archive-generate-btn {
  padding: 10px 24px;
  font-size: 14px;
  gap: 8px;
}

/* ─── Archive Tags & Filters ─── */

.archive-filter-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.archive-filter-btn {
  padding: 5px 14px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--panel);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.archive-filter-btn:hover {
  border-color: var(--text-tertiary);
}

.archive-filter-btn.is-active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}

.archive-card__tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  white-space: nowrap;
}

.archive-card__info {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.archive-detail__type-select {
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
}

/* ─── Archive Create Modal ─── */

.archive-create-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.15s ease;
}

.archive-create-modal__box {
  background: var(--panel);
  border-radius: var(--radius-lg);
  padding: 24px;
  min-width: 320px;
  max-width: 400px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.archive-create-modal__box h3 {
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 700;
}

.archive-create-modal__label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.archive-create-modal__types {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.archive-type-btn {
  flex: 1;
  padding: 12px;
  border: 2px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  color: var(--type-color);
}

.archive-type-btn:hover {
  border-color: var(--type-color);
  background: color-mix(in srgb, var(--type-color) 8%, transparent);
}

.archive-create-modal__actions {
  display: flex;
  justify-content: flex-end;
}

/* ─── Archive Selector (Expert Step) ─── */

.archive-select-wrap {
  padding: 12px;
}

.archive-select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}

.step-description {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 4px 0 0;
}

.note-archive-select-wrap {
  padding: 0 0 8px;
}

.note-archive-select-wrap .field-label {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-bottom: 4px;
}

.note-archive-select-wrap .archive-select {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ─── To-Be Issue Input ─── */

.tobe-input-section {
  padding: 12px 0;
  border-bottom: 1px solid var(--line-light);
}

.tobe-input-section:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.tobe-section-title {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.tobe-section-desc {
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--text-tertiary);
  line-height: 1.4;
}

.tobe-checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tobe-checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
  cursor: pointer;
  font-size: 13px;
  transition: background var(--transition), border-color var(--transition);
}

.tobe-checkbox-label:hover:not(.tobe-checkbox-disabled) {
  background: var(--primary-light);
  border-color: var(--primary-subtle);
}

.tobe-checkbox-label:has(input:checked) {
  background: var(--primary-light);
  border-color: var(--primary);
}

.tobe-checkbox-disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.tobe-note {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-tertiary);
  font-style: italic;
}

.tobe-auto-ref {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line-light);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.tobe-ref-text {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ─── Detail Accordion ─── */

.detail-accordion {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.detail-accordion-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color var(--transition);
}

.detail-accordion-item.has-detail {
  border-color: var(--success);
}

.detail-accordion-header {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  border: none;
  background: var(--panel-soft);
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  text-align: left;
  transition: background var(--transition);
}

.detail-accordion-header:hover {
  background: var(--primary-light);
}

.detail-accordion-item.has-detail .detail-accordion-header {
  background: var(--panel);
}

.detail-accordion-item.has-detail .detail-accordion-header:hover {
  background: var(--panel-soft);
}

.detail-accordion-icon {
  font-size: 10px;
  color: var(--text-tertiary);
  flex-shrink: 0;
  width: 14px;
  text-align: center;
}

.detail-accordion-id {
  font-weight: 700;
  color: var(--primary);
  flex-shrink: 0;
}

.detail-accordion-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-accordion-badge {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  flex-shrink: 0;
}

.detail-accordion-item:not(.has-detail) .detail-accordion-badge {
  background: #fef3c7;
  color: #92400e;
}

.detail-accordion-item.has-detail .detail-accordion-badge {
  background: var(--success-light);
  color: #065f46;
}

.detail-accordion-panel {
  border-top: 1px solid var(--line-light);
  padding: 16px;
  background: var(--panel);
  animation: accordion-in 0.15s ease;
}

.detail-accordion-panel .markdown-preview {
  font-size: 13px;
  line-height: 1.6;
}

@keyframes accordion-in {
  from {
    opacity: 0;
    max-height: 0;
  }
  to {
    opacity: 1;
    max-height: 2000px;
  }
}

/* ─── Responsive ─── */

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

  .sidebar {
    max-height: 38vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .content {
    padding: 14px;
  }

  .bpmn-layout,
  .markdown-body.split {
    grid-template-columns: 1fr;
  }
}