/* crm-shell.css — deepIng base shell + design tokens.
   Load this first; theme-brand.css overrides the tokens. */

:root {
  /* Typography */
  --font-sans: 'IBM Plex Sans', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', 'Courier New', monospace;

  /* Brand palette (overridden by theme-brand.css) */
  --accent:       #2563eb;
  --accent-tint:  #eff6ff;
  --accent-dark:  #1d4ed8;

  /* Neutrals */
  --primary:   #111827;
  --ink-1:     #374151;
  --ink-2:     #6b7280;
  --ink-3:     #9ca3af;
  --muted:     #d1d5db;
  --muted-2:   #e5e7eb;
  --surface:   #ffffff;
  --surface-2: #f9fafb;
  --surface-3: #f3f4f6;
  --line:      #e5e7eb;

  /* Ampel signal palette */
  --success:      #16a34a;
  --success-tint: #f0fdf4;
  --warn:         #d97706;
  --warn-tint:    #fffbeb;
  --danger:       #dc2626;
  --danger-tint:  #fef2f2;

  /* Layout */
  --sidebar-w:    220px;
  --header-h:     48px;
  --topstrip-h:   28px;
  --radius:       6px;
  --radius-lg:    10px;
  --shadow-sm:    0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow:       0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-md:    0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

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

html, body {
  height: 100%;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--primary);
  background: var(--surface-2);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── App chrome ───────────────────────────────────────────── */

.topstrip {
  height: var(--topstrip-h);
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 16px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .04em;
  gap: 8px;
  flex-shrink: 0;
}

.app-header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  flex-shrink: 0;
}

.app-header__logo {
  font-weight: 700;
  font-size: 15px;
  color: var(--accent);
  text-decoration: none;
}

.app-shell {
  display: flex;
  height: calc(100vh - var(--topstrip-h) - var(--header-h));
  overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}

.sidebar__section {
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.sidebar__label {
  padding: 6px 16px 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 16px;
  color: var(--ink-1);
  text-decoration: none;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-size: 13.5px;
  font-family: var(--font-sans);
  border-left: 3px solid transparent;
  transition: background .1s, color .1s;
}

.nav-item:hover { background: var(--surface-3); color: var(--primary); }
.nav-item.active {
  background: var(--accent-tint);
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 500;
}

/* ── Main content area ────────────────────────────────────── */

.main-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Routed panel components are inserted as direct children of main-content.
   They need to fill the column and establish their own flex context so that
   inner elements like .editor-split { height:100% } and .chat-messages { flex:1 }
   resolve against a known height instead of an unsized block.
   router-outlet is a marker element (no visual content) — exclude it so it
   doesn't steal flex space from the actual panel component. */
.main-content > *:not(router-outlet) {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.page-header {
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.page-header__title {
  font-size: 16px;
  font-weight: 600;
  color: var(--primary);
}

/* ── Chip ──────────────────────────────────────────────────── */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  background: var(--surface-3);
  color: var(--ink-2);
  border: 1px solid var(--line);
}

/* ── Card ─────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.card-hd {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-body { padding: 16px; }

/* ── KPI ──────────────────────────────────────────────────── */

.kpi {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.kpi__value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  color: var(--primary);
}

.kpi__label {
  font-size: 11px;
  color: var(--ink-2);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* ── Table ────────────────────────────────────────────────── */

.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
  text-align: left;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--ink-2);
  border-bottom: 2px solid var(--line);
  white-space: nowrap;
}
.tbl td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--muted-2);
  color: var(--ink-1);
  vertical-align: middle;
}
.tbl tr:last-child td { border-bottom: none; }
.tbl tr:hover td { background: var(--surface-3); }
.tbl tr.selected td { background: var(--accent-tint); }

/* ── Stage pill ───────────────────────────────────────────── */

.stage-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.stage-pill.queued    { background: var(--surface-3);    color: var(--ink-2); }
.stage-pill.running   { background: var(--accent-tint);  color: var(--accent); }
.stage-pill.succeeded { background: var(--success-tint); color: var(--success); }
.stage-pill.failed    { background: var(--danger-tint);  color: var(--danger); }
.stage-pill.cancelled { background: var(--muted-2);      color: var(--ink-2); }

/* ── Health dot ───────────────────────────────────────────── */

.health {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
}
.health.g { background: var(--success); }
.health.y { background: var(--warn); }
.health.r { background: var(--danger); }
.health.n { background: var(--muted); }

/* ── Buttons ──────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .1s, border-color .1s, opacity .1s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn.ghost {
  background: transparent;
  color: var(--accent);
}
.btn.ghost:hover:not(:disabled) { background: var(--accent-tint); }

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

.btn.success {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}
.btn.success:hover:not(:disabled) { background: #15803d; border-color: #15803d; }

.btn.sm { padding: 3px 10px; font-size: 12px; }

.btn-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ── Forms ────────────────────────────────────────────────── */

.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-label { font-size: 12px; font-weight: 500; color: var(--ink-1); }

.form-input,
.form-select,
.form-textarea {
  border: 1px solid var(--muted);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--primary);
  background: var(--surface);
  width: 100%;
  transition: border-color .15s;
  outline: none;
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 20%, transparent); }

.form-textarea { resize: vertical; min-height: 80px; font-family: var(--font-mono); font-size: 12px; }
.form-select { appearance: none; cursor: pointer; }

.form-hint { font-size: 11px; color: var(--ink-3); }
.form-error { font-size: 11px; color: var(--danger); }

/* ── Tabs / sub-nav ───────────────────────────────────────── */

.tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  gap: 0;
}

.tab {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
  border: none;
  background: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color .1s, border-color .1s;
}
.tab:hover { color: var(--primary); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.sub-nav {
  display: flex;
  gap: 4px;
  padding: 6px 8px;
  background: var(--surface-3);
  border-radius: var(--radius);
}

.sub-nav__item {
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
  cursor: pointer;
  border: none;
  background: none;
  transition: background .1s, color .1s;
}
.sub-nav__item:hover { background: var(--surface); color: var(--primary); }
.sub-nav__item.active { background: var(--surface); color: var(--accent); }

/* ── Diff / compare ───────────────────────────────────────── */

.lc-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: 12px;
}

.lc-compare__pane {
  background: var(--surface);
  padding: 12px;
  overflow: auto;
  max-height: 400px;
}

.lc-compare__pane-hd {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.lc-compare-value.diff { background: var(--warn-tint); color: var(--warn); }
.lc-compare-value.add  { background: var(--success-tint); color: var(--success); }
.lc-compare-value.del  { background: var(--danger-tint); color: var(--danger); text-decoration: line-through; }

/* ── AI surfaces ──────────────────────────────────────────── */

.ai-brief {
  background: var(--accent-tint);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--ink-1);
}

.side-card.ai {
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.ai-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}

/* ── Scrollbar ────────────────────────────────────────────── */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--muted); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-3); }

/* ── Utilities ────────────────────────────────────────────── */

.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.p-4 { padding: 16px; }
.p-3 { padding: 12px; }
.flex-1 { flex: 1; }
.overflow-auto { overflow: auto; }
.overflow-hidden { overflow: hidden; }
.text-muted { color: var(--ink-2); }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }
.font-mono { font-family: var(--font-mono); }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-full { width: 100%; }
.h-full { height: 100%; }

/* Token prompt overlay */
.token-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
}
.token-dialog {
  background: var(--surface);
  border: 1px solid var(--muted);
  border-radius: 10px;
  padding: 28px 32px;
  width: 420px;
  max-width: 90vw;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
}
.token-dialog h2 { margin: 0 0 8px; font-size: 16px; font-weight: 600; }
.token-dialog p  { margin: 0 0 16px; color: var(--ink-2); font-size: 13px; }
.token-dialog button {
  width: 100%; padding: 8px;
  background: var(--accent); color: #fff;
  border: none; border-radius: 6px; font-size: 14px; font-weight: 500; cursor: pointer;
}
.token-dialog button:hover { background: var(--accent-dark); }
