/* ── App shell with sidebar ─────────────────────────── */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 1rem 1.25rem;
  font-weight: 700;
  font-size: 0.95rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand span { color: var(--accent); }

.sidebar-nav { padding: 0.75rem 0; flex: 1; }

.nav-section {
  padding: 0.5rem 1rem 0.25rem;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1.25rem;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.88rem;
  border-left: 3px solid transparent;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
  cursor: pointer;
}

.nav-link:hover {
  color: var(--text);
  background: var(--surface-2);
}

.nav-link.active {
  color: var(--accent);
  background: rgba(124, 92, 255, 0.08);
  border-left-color: var(--accent);
}

.app-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.app-content .main {
  max-width: none;
  flex: 1;
}

/* ── Toolbar & filters ──────────────────────────────── */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
  margin-bottom: 1rem;
}

.toolbar .search-input {
  flex: 1;
  min-width: 180px;
  max-width: 320px;
}

.input, .select, .textarea {
  padding: 0.55rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.88rem;
  font-family: inherit;
}

.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.textarea {
  width: 100%;
  min-height: 100px;
  resize: vertical;
}

.select { cursor: pointer; }

.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.82rem;
}

.btn-success { background: var(--success); color: #0a1a12; }
.btn-success:hover:not(:disabled) { filter: brightness(1.08); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.08); }

.btn-warning { background: var(--warning); color: #1a1500; }

.view-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.view-toggle button {
  padding: 0.4rem 0.75rem;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.82rem;
}

.view-toggle button.active {
  background: var(--accent);
  color: #fff;
}

/* ── Data table ─────────────────────────────────────── */
.data-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

.data-table th {
  text-align: left;
  padding: 0.65rem 0.85rem;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }

.data-table tr:hover td { background: rgba(255, 255, 255, 0.02); }

.data-table .actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

/* ── Status badges ──────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: capitalize;
  white-space: nowrap;
}

.badge-draft, .badge-default { background: var(--surface-2); color: var(--muted); }
.badge-success, .badge-published, .badge-approved { background: rgba(61, 214, 140, 0.15); color: var(--success); }
.badge-paused, .badge-pending, .badge-warning { background: rgba(245, 197, 66, 0.15); color: var(--warning); }
.badge-scheduled, .badge-info { background: rgba(94, 179, 255, 0.15); color: var(--info); }
.badge-failed, .badge-rejected, .badge-danger, .badge-archived { background: rgba(255, 107, 107, 0.15); color: var(--danger); }
.badge-completed { background: rgba(124, 92, 255, 0.15); color: var(--accent); }

/* ── Grid view (content library) ────────────────────── */
.asset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.85rem;
}

.asset-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s;
}

.asset-card:hover, .asset-card.selected {
  border-color: var(--accent);
}

.asset-card .thumb {
  height: 120px;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 2rem;
  overflow: hidden;
}

.asset-card .thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.asset-card .body { padding: 0.75rem; }

.asset-card .title {
  font-weight: 600;
  font-size: 0.88rem;
  margin-bottom: 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.asset-card .meta {
  font-size: 0.75rem;
  color: var(--muted);
}

/* ── Split layout (content preview) ─────────────────── */
.split-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 1rem;
}

.preview-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  position: sticky;
  top: 4.5rem;
  max-height: calc(100vh - 6rem);
  overflow-y: auto;
}

.preview-panel h4 {
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.preview-panel .preview-image {
  width: 100%;
  border-radius: 8px;
  margin-bottom: 0.75rem;
  background: var(--surface-2);
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-panel .detail-row {
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}

.preview-panel .detail-row .label {
  color: var(--muted);
  font-size: 0.75rem;
}

/* ── Modal ──────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 1rem; }

.modal-body { padding: 1.25rem; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.form-row .form-group { margin-bottom: 0.75rem; }

.modal .form-group { margin-bottom: 0.85rem; }

.modal-footer .btn-primary { width: auto; margin-top: 0; }

/* ── Empty state ────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--muted);
}

.empty-state p { margin-bottom: 1rem; }

/* ── Chart placeholders ─────────────────────────────── */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.chart-card h4 {
  font-size: 0.85rem;
  margin-bottom: 1rem;
  color: var(--muted);
}

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  height: 140px;
  padding-top: 0.5rem;
}

.bar-chart .bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  height: 100%;
  justify-content: flex-end;
}

.bar-chart .bar {
  width: 100%;
  max-width: 40px;
  background: var(--accent);
  border-radius: 4px 4px 0 0;
  min-height: 4px;
  opacity: 0.7;
}

.bar-chart .bar-label {
  font-size: 0.68rem;
  color: var(--muted);
}

/* ── Prompt editor ──────────────────────────────────── */
.prompt-editor {
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 0.85rem;
  line-height: 1.6;
  min-height: 180px;
}

.variables-viewer {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 0.82rem;
  white-space: pre-wrap;
  color: var(--info);
}

.version-badge {
  font-size: 0.75rem;
  padding: 0.15rem 0.45rem;
  background: var(--surface-2);
  border-radius: 4px;
  color: var(--muted);
}

/* ── Review panel ───────────────────────────────────── */
.review-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-top: 1rem;
}

.review-panel h4 { margin-bottom: 0.75rem; }

.review-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

/* ── Settings sections ──────────────────────────────── */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.settings-card h4 {
  font-size: 0.85rem;
  margin-bottom: 1rem;
  color: var(--accent);
}

.ai-placeholder {
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 1rem;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  margin-top: 0.75rem;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.tag {
  font-size: 0.72rem;
  padding: 0.15rem 0.45rem;
  background: var(--surface-2);
  border-radius: 4px;
  color: var(--muted);
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.alert-success { background: rgba(61, 214, 140, 0.12); color: var(--success); border: 1px solid rgba(61, 214, 140, 0.25); }
.alert-error { background: rgba(255, 107, 107, 0.12); color: var(--danger); border: 1px solid rgba(255, 107, 107, 0.25); }

@media (max-width: 900px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    flex-direction: row;
    flex-wrap: wrap;
    overflow-x: auto;
  }
  .sidebar-nav { display: flex; flex-wrap: wrap; padding: 0.5rem; }
  .nav-section { width: 100%; }
  .nav-link { padding: 0.45rem 0.85rem; border-left: none; border-bottom: 2px solid transparent; }
  .nav-link.active { border-bottom-color: var(--accent); border-left-color: transparent; }
  .split-layout { grid-template-columns: 1fr; }
  .preview-panel { position: static; max-height: none; }
  .form-row { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar .search-input { max-width: none; }
  .editor-split { grid-template-columns: 1fr; }
}

/* ── Knowledge editor ───────────────────────────────── */
.kb-editor {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.editor-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

.autosave-status {
  font-size: 0.75rem;
  color: var(--muted);
}

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

.editor-pane label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.md-preview-wrap {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  min-height: 300px;
  max-height: 400px;
  overflow-y: auto;
}

.md-preview .md-h2 { font-size: 1.2rem; margin: 0.75rem 0 0.5rem; }
.md-preview .md-h3 { font-size: 1.05rem; margin: 0.65rem 0 0.4rem; color: var(--accent); }
.md-preview .md-h4 { font-size: 0.95rem; margin: 0.5rem 0 0.35rem; }
.md-preview p { margin-bottom: 0.65rem; font-size: 0.88rem; line-height: 1.6; }
.md-preview .md-list { margin: 0.5rem 0 0.75rem 1.25rem; font-size: 0.88rem; }
.md-preview .md-code-block {
  background: var(--surface-2);
  padding: 0.75rem;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 0.82rem;
  margin: 0.5rem 0;
}
.md-preview .md-inline-code {
  background: var(--surface-2);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.85em;
}
.md-preview a { color: var(--accent); }

/* ── AI Memory ──────────────────────────────────────── */
.memory-list { display: flex; flex-direction: column; gap: 0.65rem; }

.memory-item {
  padding: 0.65rem;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.memory-item-header { display: flex; gap: 0.35rem; margin-bottom: 0.35rem; }

.memory-item p { font-size: 0.82rem; color: var(--muted); margin-top: 0.25rem; }

.score-badge {
  font-size: 0.68rem;
  padding: 0.1rem 0.4rem;
  background: rgba(124, 92, 255, 0.15);
  color: var(--accent);
  border-radius: 4px;
}

/* ── Workflows ──────────────────────────────────────── */
.workflow-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
}

.workflow-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.workflow-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.workflow-card-header h4 { font-size: 0.95rem; }

.workflow-steps-preview { display: flex; flex-direction: column; gap: 0.35rem; }

.workflow-step-preview {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  padding: 0.35rem 0.5rem;
  background: var(--bg);
  border-radius: 6px;
}

.workflow-step-preview .step-num {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  font-size: 0.72rem;
  font-weight: 700;
  flex-shrink: 0;
}

.workflow-step {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.workflow-step .step-order {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border-radius: 50%;
  font-size: 0.78rem;
  font-weight: 600;
  flex-shrink: 0;
}

.workflow-step .step-name { flex: 1; }

/* ── Open Beta identity review ──────────────────────── */
.filter-tabs {
  display: flex;
  gap: 0.5rem;
  margin: 1rem 0;
  flex-wrap: wrap;
}

.filter-tab {
  padding: 0.45rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.82rem;
}

.filter-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.identity-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.identity-doc .label {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.identity-img {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #000;
}

.page-subtitle {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 0.35rem;
}
