/* ============================================================
   Canvas Studio — shadcn/ui design system, hand-rolled.
   Zinc palette + tokens replicated from shadcn defaults so the
   UI matches shadcn/ui without React/Node.
   ============================================================ */

:root {
  --background: hsl(0 0% 100%);
  --foreground: hsl(240 10% 3.9%);
  --card: hsl(0 0% 100%);
  --card-foreground: hsl(240 10% 3.9%);
  --muted: hsl(240 4.8% 95.9%);
  --muted-foreground: hsl(240 3.8% 46.1%);
  --border: hsl(240 5.9% 90%);
  --input: hsl(240 5.9% 90%);
  --primary: hsl(240 5.9% 10%);
  --primary-foreground: hsl(0 0% 98%);
  --secondary: hsl(240 4.8% 95.9%);
  --secondary-foreground: hsl(240 5.9% 10%);
  --accent: hsl(240 4.8% 95.9%);
  --accent-foreground: hsl(240 5.9% 10%);
  --destructive: hsl(0 84.2% 60.2%);
  --destructive-foreground: hsl(0 0% 98%);
  --ring: hsl(240 5.9% 10%);
  --success: hsl(142 71% 35%);
  --warning: hsl(38 92% 40%);
  --radius: 0.5rem;
  --sidebar: hsl(240 4.8% 97.5%);
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.08), 0 1px 2px -1px rgb(0 0 0 / 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: hsl(240 10% 3.9%);
    --foreground: hsl(0 0% 98%);
    --card: hsl(240 10% 5.5%);
    --card-foreground: hsl(0 0% 98%);
    --muted: hsl(240 3.7% 15.9%);
    --muted-foreground: hsl(240 5% 64.9%);
    --border: hsl(240 3.7% 15.9%);
    --input: hsl(240 3.7% 15.9%);
    --primary: hsl(0 0% 98%);
    --primary-foreground: hsl(240 5.9% 10%);
    --secondary: hsl(240 3.7% 15.9%);
    --secondary-foreground: hsl(0 0% 98%);
    --accent: hsl(240 3.7% 15.9%);
    --accent-foreground: hsl(0 0% 98%);
    --ring: hsl(240 4.9% 83.9%);
    --success: hsl(142 69% 58%);
    --warning: hsl(38 92% 60%);
    --sidebar: hsl(240 8% 6.5%);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--background);
  color: var(--foreground);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
[x-cloak] { display: none !important; }

/* ---------- Layout ---------- */
.layout { display: flex; height: 100vh; overflow: hidden; }
.sidebar {
  width: 260px; flex-shrink: 0; background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 1rem 0.75rem;
  overflow-y: auto;
}
.main { flex: 1; overflow-y: auto; padding: 1.5rem 2rem 4rem; }

.brand { display: flex; align-items: center; gap: 0.6rem; padding: 0.25rem 0.5rem 1rem; }
.brand-logo {
  width: 32px; height: 32px; border-radius: 8px; background: var(--primary);
  color: var(--primary-foreground); display: grid; place-items: center;
  font-weight: 700; font-size: 15px;
}
.brand-name { font-weight: 600; font-size: 15px; }
.brand-sub { font-size: 11px; color: var(--muted-foreground); }

.nav-label {
  font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted-foreground); padding: 0.75rem 0.5rem 0.35rem;
}
.nav-item {
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  width: 100%; text-align: left; padding: 0.45rem 0.6rem; border: 0; background: transparent;
  border-radius: calc(var(--radius) - 2px); color: var(--foreground);
  font: inherit; font-size: 13.5px; cursor: pointer;
}
.nav-item:hover { background: var(--accent); }
.nav-item.active { background: var(--accent); font-weight: 600; }
.nav-item .pct { font-size: 11px; color: var(--muted-foreground); font-variant-numeric: tabular-nums; }

/* ---------- Components ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  border-radius: calc(var(--radius) - 2px); border: 1px solid transparent;
  font: inherit; font-size: 13.5px; font-weight: 500; cursor: pointer;
  padding: 0.45rem 0.9rem; transition: background 0.15s, opacity 0.15s;
  white-space: nowrap; user-select: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.btn-primary { background: var(--primary); color: var(--primary-foreground); }
.btn-primary:hover:not(:disabled) { opacity: 0.9; }
.btn-secondary { background: var(--secondary); color: var(--secondary-foreground); }
.btn-secondary:hover:not(:disabled) { opacity: 0.85; }
.btn-outline { background: var(--background); border-color: var(--input); color: var(--foreground); }
.btn-outline:hover:not(:disabled) { background: var(--accent); }
.btn-ghost { background: transparent; color: var(--foreground); }
.btn-ghost:hover:not(:disabled) { background: var(--accent); }
.btn-destructive { background: var(--destructive); color: var(--destructive-foreground); }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 12.5px; }
.btn-icon { padding: 0.35rem; width: 30px; height: 30px; }

.card {
  background: var(--card); color: var(--card-foreground);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-header { padding: 1rem 1.25rem 0.5rem; }
.card-title { font-size: 15px; font-weight: 600; margin: 0; display: flex; align-items: center; gap: 0.5rem; }
.card-desc { font-size: 12.5px; color: var(--muted-foreground); margin: 0.2rem 0 0; }
.card-content { padding: 0.75rem 1.25rem 1.25rem; }

.input, .textarea, .select {
  width: 100%; font: inherit; font-size: 13.5px; color: var(--foreground);
  background: var(--background); border: 1px solid var(--input);
  border-radius: calc(var(--radius) - 2px); padding: 0.45rem 0.7rem;
}
.textarea { min-height: 90px; resize: vertical; line-height: 1.5; }
.input:focus, .textarea:focus, .select:focus { outline: 2px solid var(--ring); outline-offset: -1px; }
.label { font-size: 12.5px; font-weight: 500; display: block; margin-bottom: 0.3rem; }
.field-group { margin-bottom: 0.85rem; }

.badge {
  display: inline-flex; align-items: center; gap: 0.25rem;
  border-radius: 999px; padding: 0.1rem 0.6rem; font-size: 11.5px; font-weight: 600;
  border: 1px solid transparent; white-space: nowrap;
}
.badge-default { background: var(--primary); color: var(--primary-foreground); }
.badge-secondary { background: var(--secondary); color: var(--secondary-foreground); }
.badge-outline { border-color: var(--border); color: var(--foreground); }
.badge-success { background: color-mix(in srgb, var(--success) 15%, transparent); color: var(--success); }
.badge-warning { background: color-mix(in srgb, var(--warning) 15%, transparent); color: var(--warning); }
.badge-destructive { background: color-mix(in srgb, var(--destructive) 12%, transparent); color: var(--destructive); }

/* Tabs */
.tabs { display: inline-flex; background: var(--muted); border-radius: var(--radius); padding: 3px; gap: 2px; }
.tab {
  border: 0; background: transparent; font: inherit; font-size: 13px; font-weight: 500;
  padding: 0.35rem 0.9rem; border-radius: calc(var(--radius) - 3px);
  color: var(--muted-foreground); cursor: pointer;
}
.tab.active { background: var(--background); color: var(--foreground); box-shadow: var(--shadow-sm); }

/* Progress */
.progress { height: 7px; background: var(--muted); border-radius: 999px; overflow: hidden; flex: 1; }
.progress > div { height: 100%; background: var(--primary); border-radius: 999px; transition: width 0.3s; }
.progress.good > div { background: var(--success); }
.progress.mid > div { background: var(--warning); }
.progress.low > div { background: var(--destructive); }

/* Dialog */
.dialog-backdrop {
  position: fixed; inset: 0; background: rgb(0 0 0 / 0.55); z-index: 50;
  display: grid; place-items: center; padding: 1.5rem;
}
.dialog {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  width: 100%; max-width: 620px; max-height: 88vh; overflow-y: auto;
  padding: 1.5rem; box-shadow: 0 10px 40px rgb(0 0 0 / 0.25);
}
.dialog h3 { margin: 0 0 0.25rem; font-size: 16px; }
.dialog .dialog-desc { color: var(--muted-foreground); font-size: 12.5px; margin: 0 0 1rem; }
.dialog-footer { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1rem; }

/* Table */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted-foreground); font-weight: 500; padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
.table td { padding: 0.55rem 0.75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:hover td { background: var(--accent); }

/* Toast */
.toast {
  position: fixed; bottom: 1.25rem; right: 1.25rem; z-index: 100;
  background: var(--primary); color: var(--primary-foreground);
  border-radius: var(--radius); padding: 0.6rem 1rem; font-size: 13px;
  box-shadow: var(--shadow); max-width: 380px;
}
.toast.error { background: var(--destructive); color: var(--destructive-foreground); }

/* ---------- Page pieces ---------- */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.page-title { font-size: 22px; font-weight: 700; margin: 0; letter-spacing: -0.02em; }
.page-sub { color: var(--muted-foreground); font-size: 13px; margin: 0.25rem 0 0; max-width: 720px; }

.canvas-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 1rem; margin-top: 1rem; }
.zone-label {
  grid-column: 1 / -1; font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--muted-foreground); margin-top: 0.5rem;
}
.field-nr {
  width: 22px; height: 22px; border-radius: 6px; background: var(--secondary);
  color: var(--secondary-foreground); display: inline-grid; place-items: center;
  font-size: 11.5px; font-weight: 700; flex-shrink: 0;
}
.leitfragen { margin: 0.4rem 0 0.6rem; }
.leitfragen summary {
  cursor: pointer; font-size: 12px; color: var(--muted-foreground); user-select: none;
  list-style: none; display: inline-flex; align-items: center; gap: 0.3rem;
}
.leitfragen summary::before { content: '?'; font-weight: 700; width: 15px; height: 15px; border-radius: 50%; border: 1px solid var(--border); display: inline-grid; place-items: center; font-size: 10px; }
.leitfragen ul { margin: 0.4rem 0 0; padding-left: 1.1rem; font-size: 12.5px; color: var(--muted-foreground); }
.leitfragen li { margin-bottom: 0.2rem; }
.save-dot { font-size: 11px; color: var(--muted-foreground); transition: opacity 0.3s; }
.save-dot.saved { color: var(--success); }

.persona-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1rem; }
.persona-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem; }
.persona-meta { font-size: 12.5px; color: var(--muted-foreground); margin: 0.15rem 0 0; }
.persona-block { margin-top: 0.6rem; }
.persona-block b { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted-foreground); display: block; margin-bottom: 0.15rem; }
.persona-block p { margin: 0; white-space: pre-wrap; font-size: 13px; }

.swimlane { margin-bottom: 1.25rem; }
.swimlane h4 { margin: 0 0 0.5rem; font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted-foreground); }
.milestone-row { display: flex; align-items: center; gap: 0.6rem; padding: 0.4rem 0.25rem; border-bottom: 1px solid var(--border); }
.milestone-row .titel { flex: 1; }
.milestone-row .titel.done { text-decoration: line-through; color: var(--muted-foreground); }

.ai-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 0.75rem; margin-bottom: 1.5rem; }
.ai-output {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem 1.5rem; margin-bottom: 1rem;
}
.ai-output .md h1, .ai-output .md h2, .ai-output .md h3 { margin: 1rem 0 0.4rem; line-height: 1.3; }
.ai-output .md h1 { font-size: 17px; } .ai-output .md h2 { font-size: 15.5px; } .ai-output .md h3 { font-size: 14px; }
.ai-output .md p, .ai-output .md li { font-size: 13.5px; }
.ai-output .md ul, .ai-output .md ol { padding-left: 1.3rem; }
.ai-output .md code { background: var(--muted); padding: 0.1em 0.35em; border-radius: 4px; font-size: 12.5px; }
.ai-output .md hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }
.ai-meta { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.5rem; }

.empty {
  border: 1px dashed var(--border); border-radius: var(--radius);
  padding: 2.5rem 1.5rem; text-align: center; color: var(--muted-foreground); font-size: 13.5px;
}
.missing-list { font-size: 12.5px; color: var(--muted-foreground); columns: 2; gap: 2rem; padding-left: 1.1rem; margin: 0.5rem 0 0; }
/* AI health indicator */
.ai-status { display: flex; align-items: flex-start; gap: 0.45rem; cursor: pointer; margin-top: 4px; }
.status-dot {
  width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; margin-top: 4px;
  background: var(--muted-foreground);
}
.status-dot.ok { background: var(--success); box-shadow: 0 0 6px color-mix(in srgb, var(--success) 60%, transparent); }
.status-dot.error { background: var(--destructive); box-shadow: 0 0 6px color-mix(in srgb, var(--destructive) 60%, transparent); }
.status-dot.checking { animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }
.ai-status-error { color: var(--destructive); font-size: 11px; line-height: 1.35; word-break: break-word; }

.spinner {
  width: 15px; height: 15px; border: 2px solid currentColor; border-top-color: transparent;
  border-radius: 50%; animation: spin 0.7s linear infinite; display: inline-block; vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .main { padding: 1rem; }
  .missing-list { columns: 1; }
}
