:root {
  color-scheme: light;
  --bg: oklch(97.8% 0.006 165);
  --surface: oklch(99.1% 0.004 165);
  --surface-2: oklch(95.2% 0.01 175);
  --line: oklch(86.5% 0.018 175);
  --text: oklch(24% 0.025 180);
  --muted: oklch(47% 0.028 185);
  --accent: oklch(46% 0.12 168);
  --accent-strong: oklch(37% 0.13 168);
  --warning: oklch(69% 0.14 78);
  --danger: oklch(55% 0.16 28);
  --ok: oklch(56% 0.13 148);
  --shadow: 0 12px 30px oklch(38% 0.03 180 / 12%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1, h2 {
  margin: 0;
  letter-spacing: 0;
}
h1 { font-size: 1.55rem; line-height: 1.15; }
h2 { font-size: 1rem; line-height: 1.25; }

.top-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 7px;
  min-height: 36px;
  padding: 0 12px;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 650;
  cursor: pointer;
  transition: background 180ms ease, border-color 180ms ease, color 180ms ease, transform 180ms ease;
}
.button:hover { background: var(--surface-2); }
.button:active { transform: translateY(1px); }
.button:focus-visible {
  outline: 3px solid oklch(74% 0.12 168 / 45%);
  outline-offset: 2px;
}
.button:disabled {
  opacity: 0.55;
  cursor: progress;
}
.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: oklch(98% 0.006 165);
}
.button.primary:hover { background: var(--accent-strong); }
.button.secondary { border-color: oklch(76% 0.045 168); }
.button.ghost { color: var(--muted); }
.button.small {
  min-height: 30px;
  padding: 0 10px;
  font-size: 0.8rem;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 18px;
  padding: 18px 24px;
}

.main-panel,
.side-panel,
.bottom-panel,
.stack-section,
.login-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.main-panel { min-width: 0; }
.side-panel {
  display: grid;
  gap: 14px;
  background: transparent;
  border: 0;
}
.stack-section { overflow: hidden; }
.bottom-panel {
  margin: 0 24px 24px;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.panel-head.compact { padding: 12px 14px; }
.head-badges {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.muted {
  color: var(--muted);
  margin: 4px 0 0;
  font-size: 0.86rem;
}
.panel-note {
  margin: 0;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.8rem;
}
.status-pill,
.count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}
.status-pill.ok { color: var(--ok); border-color: oklch(74% 0.11 148); }
.status-pill.warn { color: var(--warning); border-color: oklch(78% 0.12 78); }

.table-shell { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}
th, td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  font-size: 0.9rem;
}
th {
  color: var(--muted);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: oklch(97% 0.008 175);
}
th:nth-child(1), td:nth-child(1) { width: 110px; }
th:nth-child(3), td:nth-child(3) { width: 140px; }
th:nth-child(4), td:nth-child(4) { width: 170px; }
th:nth-child(5), td:nth-child(5) { width: 160px; text-align: right; }
tbody tr:hover { background: oklch(97.2% 0.009 170); }
.name {
  display: grid;
  gap: 3px;
}
.name strong { font-size: 0.94rem; }
.name span { color: var(--muted); font-size: 0.78rem; }
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 0.78rem;
  font-weight: 700;
}
.badge.ok { color: var(--ok); border-color: oklch(76% 0.12 148); background: oklch(96% 0.025 148); }
.badge.warn { color: var(--warning); border-color: oklch(79% 0.12 78); background: oklch(96% 0.035 78); }
.empty {
  color: var(--muted);
  text-align: center;
  padding: 28px;
}

.file-list {
  display: grid;
  max-height: 390px;
  overflow-y: auto;
  overflow-x: hidden;
}
.file-item {
  display: grid;
  gap: 3px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
  color: var(--text);
}
.file-item:hover { background: var(--surface-2); }
.file-item span {
  color: var(--muted);
  font-size: 0.76rem;
}
.file-item strong,
.file-item span {
  overflow-wrap: anywhere;
}

.log,
.memoire {
  margin: 0;
  white-space: pre-wrap;
  color: var(--text);
  background: oklch(96.4% 0.008 185);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
  line-height: 1.55;
}
.log {
  max-height: 300px;
  overflow: auto;
  padding: 12px 14px;
}
.memoire {
  max-height: 260px;
  overflow: auto;
  padding: 14px 16px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: min(420px, calc(100vw - 40px));
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--text);
  color: var(--surface);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
  font-size: 0.88rem;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.login-body {
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-panel {
  width: min(420px, 100%);
  padding: 24px;
  box-shadow: var(--shadow);
}
.login-form {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}
label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}
input {
  min-height: 40px;
  border-radius: 7px;
  border: 1px solid var(--line);
  padding: 0 11px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
input:focus {
  outline: 3px solid oklch(74% 0.12 168 / 42%);
  border-color: var(--accent);
}
.table-note-input {
  margin-top: 6px;
  min-height: 34px;
  font-size: 0.82rem;
}

textarea {
  width: 100%;
  min-height: 92px;
  resize: vertical;
  border-radius: 7px;
  border: 1px solid var(--line);
  padding: 10px 11px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  line-height: 1.45;
}
textarea:focus {
  outline: 3px solid oklch(74% 0.12 168 / 42%);
  border-color: var(--accent);
}
.form-error {
  min-height: 20px;
  color: var(--danger);
  margin: 0;
  font-size: 0.86rem;
}

.agent-form,
.rag-form {
  display: grid;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.rag-form {
  grid-template-columns: 1fr;
}
.job-list {
  display: grid;
  max-height: 330px;
  overflow: auto;
}
.job-item {
  display: grid;
  gap: 8px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
}
.job-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.job-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.job-task {
  margin: 0;
  font-size: 0.86rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.job-output {
  margin: 0;
  max-height: 160px;
  overflow: auto;
  padding: 9px 10px;
  border-radius: 7px;
  background: oklch(96.4% 0.008 185);
  color: var(--text);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.74rem;
  line-height: 1.45;
  white-space: pre-wrap;
}
.badge.running { color: var(--accent); border-color: oklch(72% 0.11 168); background: oklch(95% 0.028 168); }
.badge.failed { color: var(--danger); border-color: oklch(74% 0.13 28); background: oklch(96% 0.026 28); }
.badge.cancelled { color: var(--muted); border-color: var(--line); background: var(--surface-2); }

.cockpit {
  display: grid;
  gap: 18px;
  padding: 18px 24px 24px;
}

.pilotage-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(420px, 0.8fr);
  gap: 18px;
  align-items: stretch;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.recommendations {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.recommendation {
  display: grid;
  gap: 3px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: oklch(96.6% 0.012 165);
}
.recommendation strong {
  font-size: 0.92rem;
}
.recommendation span {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.project-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0 0;
}
.project-strip div {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
}
.project-strip dt {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 750;
  text-transform: uppercase;
}
.project-strip dd {
  margin: 3px 0 0;
  font-size: 0.84rem;
  font-weight: 750;
  overflow-wrap: anywhere;
}

.settings-panel {
  overflow: hidden;
}
.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(260px, 0.82fr) minmax(260px, 0.82fr);
  gap: 14px;
  padding: 14px;
}
.settings-form {
  display: grid;
  align-content: start;
  gap: 10px;
}
.settings-form h3 {
  margin: 0;
  font-size: 0.92rem;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.metric {
  display: grid;
  gap: 4px;
  align-content: center;
  min-height: 82px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
}
.metric strong {
  font-size: 1.28rem;
  line-height: 1.1;
}
.metric span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  align-items: start;
}
.primary-column,
.secondary-column {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.split-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.inline-form,
.mini-form,
.pack-form,
.finance-form {
  display: grid;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.inline-form {
  grid-template-columns: minmax(0, 1fr) 140px 110px;
  align-items: center;
}
.mini-form {
  grid-template-columns: minmax(0, 1fr) 96px;
}
.pack-form {
  grid-template-columns: 1fr;
}
.finance-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: center;
}
.finance-form button {
  grid-column: 1 / -1;
}
.search-form {
  grid-template-columns: minmax(0, 1fr) 104px;
}
.filter-row {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: oklch(97.6% 0.007 175);
}
.filter-row select {
  min-height: 34px;
  font-size: 0.82rem;
}

select {
  min-height: 40px;
  border-radius: 7px;
  border: 1px solid var(--line);
  padding: 0 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
}
select:focus {
  outline: 3px solid oklch(74% 0.12 168 / 42%);
  border-color: var(--accent);
}
select[multiple] {
  min-height: 156px;
  padding: 8px;
}

.item-list {
  display: grid;
  max-height: 460px;
  overflow: auto;
}
.compact-list {
  max-height: 330px;
}
.work-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.work-item.compact {
  padding: 11px 14px;
}
.work-item:hover {
  background: oklch(97.2% 0.009 170);
}
.rag-result p {
  max-height: 86px;
  overflow: auto;
}
.item-main {
  display: grid;
  gap: 4px;
  min-width: 0;
  flex: 1;
}
.item-title {
  font-weight: 750;
  font-size: 0.92rem;
  overflow-wrap: anywhere;
}
.item-meta {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}
.work-item p,
.timeline-item p {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.item-actions,
.row-actions,
.finance-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
  flex-shrink: 0;
}

.inline-editor {
  margin-top: 3px;
}
.inline-editor summary {
  width: max-content;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 750;
  cursor: pointer;
}
.editor-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}
.editor-grid textarea,
.editor-grid button {
  grid-column: 1 / -1;
}

.priority-urgent,
.severity-critical {
  background: oklch(96% 0.025 28);
}
.priority-high,
.severity-high {
  background: oklch(96.4% 0.022 62);
}
.severity-medium,
.priority-medium {
  background: oklch(97% 0.014 168);
}

.finance-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 12px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
}
.finance-row span {
  font-weight: 700;
  overflow-wrap: anywhere;
}
.finance-row strong {
  text-align: right;
}
.finance-row small {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.76rem;
}
.finance-actions {
  grid-column: 1 / -1;
  justify-content: flex-start;
}

.timeline {
  display: grid;
  max-height: 420px;
  overflow: auto;
}
.timeline-item {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 14px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.timeline-item time {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}
.timeline-item strong {
  display: block;
  margin-bottom: 4px;
  font-size: 0.9rem;
}

@media (max-width: 980px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }
  .top-actions { justify-content: flex-start; }
  .layout,
  .workbench,
  .pilotage-hero,
  .split-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }
  .metric-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .project-strip {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .topbar,
  .layout,
  .cockpit { padding-left: 14px; padding-right: 14px; }
  .bottom-panel { margin-left: 14px; margin-right: 14px; }
  .pilotage-hero { padding: 14px; }
  .metric-grid,
  .project-strip,
  .inline-form,
  .mini-form,
  .finance-form,
  .editor-grid {
    grid-template-columns: 1fr;
  }
  .work-item {
    display: grid;
  }
  .item-actions,
  .row-actions {
    justify-content: stretch;
  }
  .table-shell { overflow-x: hidden; }
  table, thead, tbody, tr, th, td { display: block; }
  thead { display: none; }
  tbody tr {
    display: grid;
    grid-template-columns: 86px minmax(0, 1fr);
    align-items: center;
    border-bottom: 1px solid var(--line);
  }
  td {
    border-bottom: 0;
    padding: 11px 10px;
  }
  td:nth-child(1),
  td:nth-child(2),
  td:nth-child(3),
  td:nth-child(4),
  td:nth-child(5) {
    width: auto;
  }
  td:nth-child(4) {
    display: none;
  }
  td:nth-child(5) {
    grid-column: 1 / -1;
    text-align: left;
  }
  .name { min-width: 0; }
  .name strong,
  .name span {
    display: block;
    max-width: 180px;
    overflow-wrap: anywhere;
  }
  .button { width: 100%; }
  .top-actions { width: 100%; }
  .timeline-item {
    grid-template-columns: 1fr;
    gap: 5px;
  }
}
