:root {
  --bg0: #0c1210;
  --bg1: #14201b;
  --bg2: #1b2a24;
  --line: rgba(232, 220, 196, 0.12);
  --text: #f2ebe0;
  --muted: #a39a8c;
  --accent: #d4a35c;
  --accent2: #3d8f6e;
  --danger: #c45c4a;
  --radius: 14px;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Source Sans 3", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  font-family: var(--font-body);
  color: var(--text);
  overflow: hidden;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(212, 163, 92, 0.18), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(61, 143, 110, 0.16), transparent 50%),
    linear-gradient(160deg, var(--bg0), var(--bg1) 45%, #101816);
}

.hidden { display: none !important; }

.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 2rem;
}
.login-card {
  width: min(420px, 100%);
  padding: 2rem;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(20, 32, 27, 0.85);
  backdrop-filter: blur(10px);
}
.login-card h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 2rem;
  margin: 0.2rem 0 0.4rem;
}
.brand {
  font-family: var(--font-display);
  color: var(--accent);
  letter-spacing: 0.02em;
  font-size: 1.05rem;
}
.muted { color: var(--muted); margin: 0 0 1rem; }
.login-card input {
  width: 100%;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg0);
  color: var(--text);
  margin-bottom: 0.75rem;
}
.error { color: var(--danger); min-height: 1.2em; }

.app {
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  display: grid;
  grid-template-columns: 280px 1fr;
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: rgba(12, 18, 16, 0.72);
  display: flex;
  flex-direction: column;
  padding: 1rem;
  gap: 0.75rem;
  min-height: 0;
  overflow: hidden;
}
.brand-block .brand { font-size: 1.35rem; }
.tagline { color: var(--muted); font-size: 0.9rem; margin-top: 0.15rem; }
.session-list {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.sidebar-close { display: none; }
.session-item.session-codex .session-title {
  color: #e8c48a;
}
.session-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 0 0.25rem;
}
.session-item {
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  cursor: pointer;
  font: inherit;
  display: grid;
  gap: 0.2rem;
}
.session-item .session-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session-item .session-meta {
  font-size: 0.78rem;
  color: var(--muted);
}
.session-item:hover, .session-item.active {
  background: var(--bg2);
  border-color: var(--line);
}
.sidebar-foot { display: grid; gap: 0.5rem; }
.sidebar-foot select {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg0);
  color: var(--text);
  font: inherit;
}
.sidebar-foot .small-link {
  font-size: 0.85rem;
  color: var(--muted);
  text-decoration: none;
}
.sidebar-foot .small-link:hover { color: var(--accent); }

.mobile-bar { display: none; }
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 40;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: auto;
  max-height: 100%;
  overflow: hidden;
}
.tabs {
  display: flex;
  gap: 0.35rem;
  padding: 0.85rem 1.25rem 0;
  border-bottom: 1px solid var(--line);
}
.tab {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 0.7rem 1rem;
  font: inherit;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.panel {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
}
.panel.active { display: flex; }

.messages {
  flex: 1 1 0;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.msg {
  max-width: min(760px, 92%);
  padding: 0.9rem 1rem;
  border-radius: 16px;
  line-height: 1.45;
  white-space: pre-wrap;
}
.msg.user {
  align-self: flex-end;
  background: rgba(212, 163, 92, 0.16);
  border: 1px solid rgba(212, 163, 92, 0.28);
}
.msg.assistant {
  align-self: flex-start;
  background: rgba(27, 42, 36, 0.9);
  border: 1px solid var(--line);
}
.msg .who {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
  font-family: var(--font-display);
}

.composer {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 1rem 1.25rem calc(1.25rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
  background: rgba(12, 18, 16, 0.96);
  flex: 0 0 auto;
  position: relative;
  z-index: 5;
}
.composer-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.55rem;
  align-items: end;
}
.composer textarea {
  resize: none;
  min-height: 52px;
  max-height: 160px;
  padding: 0.85rem 1rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--bg2);
  color: var(--text);
  font: inherit;
}
.file-input {
  display: none;
}
.attach-btn {
  min-width: 42px;
  height: 42px;
  margin-bottom: 0.35rem;
}
.attach-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.45rem 0.25rem 0.35rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface) 90%, #000);
  font-size: 0.78rem;
  max-width: 100%;
}
.attach-chip img {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 6px;
}
.attach-chip .attach-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 10rem;
}
.attach-chip button {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 0.15rem;
}
.codex-extra-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.msg-attach {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.4rem;
}
.msg-attach img {
  max-width: 160px;
  max-height: 120px;
  border-radius: 8px;
  border: 1px solid var(--line);
}
.msg-attach .doc-chip {
  font-size: 0.78rem;
  padding: 0.2rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.btn, button[type="submit"] {
  border: none;
  border-radius: 12px;
  padding: 0.7rem 1rem;
  background: var(--accent);
  color: #1a140a;
  font-weight: 600;
  font: inherit;
  cursor: pointer;
}
.btn.ghost, .tab {
  background: transparent;
}
.btn.ghost {
  border: 1px solid var(--line);
  color: var(--text);
}
.btn.small { padding: 0.4rem 0.7rem; font-size: 0.9rem; }

.panel-head {
  padding: 1.1rem 1.25rem 0.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: baseline;
}
.panel-head h2 {
  font-family: var(--font-display);
  margin: 0;
  font-size: 1.5rem;
}
.oi-frame {
  flex: 1;
  width: calc(100% - 2.5rem);
  margin: 0.5rem 1.25rem 1.25rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0f1117;
  min-height: 420px;
}

.codex-head {
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}
.codex-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}
.target-toggle {
  display: inline-flex;
  gap: 0.25rem;
  padding: 0.2rem;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.target-btn.active {
  background: var(--accent);
  color: #1a140a;
  border-color: transparent;
}
.codex-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.doen-ide {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(200px, 0.85fr);
  flex: 1 1 0;
  min-height: 0;
}
.doen-ide .codex-messages {
  border-right: 1px solid color-mix(in srgb, var(--muted, #888) 25%, transparent);
}
.doen-diff-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: color-mix(in srgb, var(--muted, #888) 6%, transparent);
}
.doen-diff-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.4rem 0.7rem;
  border-bottom: 1px solid color-mix(in srgb, var(--muted, #888) 20%, transparent);
  font-size: 0.85rem;
}
.doen-diff-body {
  flex: 1;
  overflow: auto;
  padding: 0.55rem 0.7rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.72rem;
  white-space: pre-wrap;
  line-height: 1.35;
}
@media (max-width: 900px) {
  .doen-ide { grid-template-columns: 1fr; }
  .doen-diff-panel { max-height: 30vh; border-top: 1px solid color-mix(in srgb, var(--muted, #888) 20%, transparent); }
  .doen-ide .codex-messages { border-right: 0; }
}
.codex-messages {
  flex: 1 1 0;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
}
.codex-pane > .composer {
  flex-shrink: 0;
}
.codex-vps-note { padding: 0 1.25rem; }
.patch-undo, .patch-undo-job { margin-top: 0.35rem; }
.codex-body + .patch-undo { margin-left: 0.25rem; }

.watch-layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(260px, 0.9fr);
  gap: 0.85rem;
  min-height: 0;
  padding: 0 1.25rem 1.25rem;
}
.watch-screen {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #0a0c10;
}
.watch-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 92%, #000);
}
.watch-view {
  flex: 1;
  min-height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
.watch-placeholder {
  text-align: center;
  padding: 2rem 1.5rem;
  max-width: 28rem;
}
.watch-placeholder > div:first-child {
  font-family: var(--font-display);
  font-size: 1.15rem;
  margin-bottom: 0.4rem;
}
.watch-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  cursor: crosshair;
}
.watch-img.watch-view-only {
  cursor: default;
}
.watch-control-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--muted, #9aa3b2);
  margin-left: auto;
  user-select: none;
}
.watch-type-row {
  display: flex;
  gap: 0.35rem;
  align-items: center;
}
.watch-type-input {
  flex: 1;
  min-width: 0;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: inherit;
  font: inherit;
  font-size: 0.85rem;
}
.watch-side {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  min-height: 0;
}
.watch-composer {
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
}
.watch-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.watch-log {
  flex: 1;
  min-height: 120px;
  max-height: 280px;
  overflow: auto;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  white-space: pre-wrap;
  background: color-mix(in srgb, var(--surface) 88%, #000);
}
@media (max-width: 900px) {
  .watch-layout {
    grid-template-columns: 1fr;
  }
  .watch-view {
    min-height: 220px;
  }
}
.codex-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.75rem;
}
.btn.approve {
  background: #c45c4a;
  color: #fff;
}
#panel-code.panel.active {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.home-grid {
  padding: 0.5rem 1.25rem 1.25rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  overflow: auto;
}
.block {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  background: rgba(20, 32, 27, 0.65);
}
.block.wide { grid-column: 1 / -1; }
.block h3 {
  margin: 0 0 0.75rem;
  font-family: var(--font-display);
  font-size: 1.1rem;
}
.block textarea {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg0);
  color: var(--text);
  padding: 0.7rem;
  font: inherit;
  margin-bottom: 0.6rem;
}
.row { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.entity-list { display: grid; gap: 0.45rem; }
.entity-list.lights {
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}
.entity {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  background: var(--bg0);
  border: 1px solid var(--line);
  font-size: 0.92rem;
}
.pill {
  font-size: 0.75rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: rgba(61, 143, 110, 0.2);
  color: #9fd6bd;
}
.pill.off { background: rgba(196, 92, 74, 0.2); color: #efb4aa; }

.status-grid {
  padding: 0.5rem 1.25rem 1.25rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
}
.status-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  background: rgba(20, 32, 27, 0.65);
}
.status-card strong {
  display: block;
  font-family: var(--font-display);
  margin-bottom: 0.35rem;
}
.ok { color: #9fd6bd; }
.bad { color: #efb4aa; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .mobile-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.65rem 0.85rem;
    border-bottom: 1px solid var(--line);
    background: rgba(12, 18, 16, 0.9);
  }
  .mobile-brand {
    font-family: var(--font-display);
    font-size: 1rem;
    white-space: nowrap;
  }
  .sidebar-close { display: inline-flex; justify-self: end; }
  .sidebar-top {
    display: grid;
    gap: 0.5rem;
  }
  .sidebar {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(86vw, 320px);
    z-index: 50;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: 8px 0 28px rgba(0, 0, 0, 0.35);
  }
  .app.history-open .sidebar {
    transform: translateX(0);
  }
  .app.history-open .sidebar-backdrop {
    display: block;
  }
  .home-grid { grid-template-columns: 1fr; }
  .tabs {
    padding: 0.55rem 0.75rem 0;
    overflow-x: auto;
  }
  .messages { padding: 0.9rem; }
  .composer { padding: 0.75rem; }
}
.composer.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -4px;
}
.panel-hint {
  margin: 0.75rem 1rem 0;
  font-size: 0.9rem;
  flex-shrink: 0;
}
.tabs, .mobile-bar, .chat-agent-bar, .codex-head, .panel-head {
  flex-shrink: 0;
}
.status-howto {
  margin: 1rem 0 0;
  padding: 0.9rem 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.status-howto h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  color: var(--text, inherit);
}
.status-howto ol {
  margin: 0;
  padding-left: 1.2rem;
}
.status-howto li {
  margin: 0.35rem 0;
}
.status-howto a {
  color: var(--accent, #7dd3fc);
}
.msg.agent-run {
  border-left: 3px solid var(--accent, #d4a35c);
  background: rgba(212, 163, 92, 0.08);
  animation: agentPulse 1.2s ease-in-out 2;
}
.msg.agent-run.agent-done {
  animation: none;
  border-left-color: #6fbf8a;
}
.msg.agent-run .agent-body {
  white-space: pre-wrap;
  font-size: 0.92rem;
  line-height: 1.45;
  opacity: 0.95;
}
@keyframes agentPulse {
  0%, 100% { box-shadow: none; }
  50% { box-shadow: inset 0 0 0 1px rgba(212, 163, 92, 0.35); }
}
.chat-agent-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin: 0.5rem 0 0.75rem;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  background: rgba(212, 163, 92, 0.18);
  border: 1px solid rgba(212, 163, 92, 0.25);
}
.chat-agent-bar.hidden {
  display: none;
}
.status-workflows {
  margin-top: 1rem;
}
.workflow-list .workflow-row {
  padding: 0.5rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.stuur-box {
  padding: 0 1.25rem 1.25rem;
}
.stuur-box textarea {
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(0,0,0,0.2);
  color: inherit;
  padding: 0.85rem 1rem;
  font: inherit;
  resize: vertical;
}
.mode-row { display: flex; gap: 0.4rem; margin-bottom: 0.65rem; }
.mode-btn {
  flex: 1;
  border: 1px solid rgba(255,255,255,0.12);
  background: transparent;
  color: inherit;
  opacity: 0.7;
  padding: 0.45rem;
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.mode-btn.active {
  opacity: 1;
  background: var(--accent, #d4a35c);
  color: #1a1510;
  border-color: transparent;
}
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.04);
  color: inherit;
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}
.stuur-log {
  margin-top: 0.75rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(0,0,0,0.18);
  min-height: 8rem;
  max-height: 45vh;
  overflow: auto;
  white-space: pre-wrap;
  font-size: 0.92rem;
}
.status-memory {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.status-memory .panel-head {
  align-items: center;
}
.status-memory h3 {
  margin: 0;
  font-size: 1rem;
}
.mem-list {
  display: grid;
  gap: 0.45rem;
  margin-top: 0.5rem;
  max-height: 280px;
  overflow: auto;
}
.knowledge-upload {
  margin: 0.85rem 0 1rem;
  padding: 0.85rem 1rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.18);
}
.knowledge-upload h4 {
  margin: 0 0 0.35rem;
  font-size: 0.98rem;
}
.knowledge-upload input[type="text"],
.knowledge-upload textarea {
  width: 100%;
  margin-top: 0.45rem;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.25);
  color: inherit;
  font: inherit;
}
.knowledge-upload textarea {
  resize: vertical;
  min-height: 8rem;
  line-height: 1.4;
}
#knowList {
  max-height: 180px;
}
.mem-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  font-size: 0.88rem;
}
.mem-item .meta {
  opacity: 0.7;
  font-size: 0.78rem;
}
