/* One stylesheet for the console. No framework, no build step — the same rules
   as every other castomapi front end, and the same dark palette as
   castomapi-media-php so the two consoles read as one estate.

   The layout is a fixed top bar over a two-pane workspace: a list on the left,
   the thing you are editing on the right. Agents are the centre of gravity, so
   the agent workspace is the one place that gets three columns. */

:root {
  color-scheme: dark;

  --bg: #0c0d10;
  --bg-raised: #141619;
  --bg-sunken: #08090b;
  --bg-hover: #1b1e23;
  --line: #24272e;
  --line-strong: #363a44;

  --text: #e8eaee;
  --text-dim: #9aa1ad;
  --text-faint: #666d7a;

  --accent: #6ea8fe;
  --accent-soft: rgba(110, 168, 254, 0.14);
  --ok: #56d3a0;
  --warn: #f0b849;
  --bad: #f2777a;

  --radius: 10px;
  --radius-sm: 6px;
  --gap: 16px;
  --bar-height: 56px;
  --sidebar: 268px;

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, monospace;

  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

/* The parts we did not draw still carry the design. */
::selection {
  background: var(--accent-soft);
  color: var(--text);
}

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border: 3px solid var(--bg);
  border-radius: 100px;
}

*::-webkit-scrollbar-thumb:hover {
  background: var(--text-faint);
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}

h1 {
  font-size: 19px;
}

h2 {
  font-size: 15px;
}

code,
kbd {
  font-family: var(--mono);
  font-size: 0.92em;
}

.icon {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  color: currentColor;
}

/* The chevron is drawn pointing right and rotated to face where it is used,
   so the set carries one glyph rather than four that must be kept identical. */
.icon.up svg {
  transform: rotate(-90deg);
}

.icon.down svg {
  transform: rotate(90deg);
}

.mono {
  font-family: var(--mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-faint);
}

.dim {
  color: var(--text-dim);
}

.faint {
  color: var(--text-faint);
}

/* --- controls ----------------------------------------------------------- */

input,
select,
textarea,
button {
  font: inherit;
  color: inherit;
}

input[type='text'],
input[type='search'],
input[type='password'],
select,
textarea {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: none;
  caret-color: var(--accent);
  transition: border-color 0.12s, box-shadow 0.12s;
}

textarea {
  resize: vertical;
  min-height: 84px;
  line-height: 1.55;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-faint);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  background: var(--bg-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

button:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--text-faint);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #08111f;
  font-weight: 600;
}

button.primary:hover:not(:disabled) {
  background: #8bbcff;
  border-color: #8bbcff;
}

button.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-dim);
}

button.ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text);
}

button.danger:hover:not(:disabled) {
  border-color: var(--bad);
  color: var(--bad);
}

button.small {
  padding: 4px 9px;
  font-size: 12px;
}

button.icon-only {
  padding: 6px;
}

label {
  display: block;
  margin-bottom: 5px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
}

.field {
  margin-bottom: 14px;
}

.field .hint {
  margin-top: 5px;
  font-size: 12px;
  color: var(--text-faint);
}

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

.row.wrap {
  flex-wrap: wrap;
}

.spacer {
  flex: 1;
}

/* --- chrome ------------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--gap);
  height: var(--bar-height);
  padding: 0 20px;
  background: rgba(12, 13, 16, 0.86);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.brand:hover {
  text-decoration: none;
}

.brand span {
  color: var(--text-faint);
  font-weight: 400;
  font-size: 12px;
}

.nav {
  display: flex;
  gap: 4px;
  margin-left: 8px;
}

.nav button {
  background: transparent;
  border-color: transparent;
  color: var(--text-dim);
  font-weight: 500;
}

.nav button:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.nav button[aria-current='page'] {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
}

/* --- workspace ---------------------------------------------------------- */

.workspace {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  align-items: start;
  gap: var(--gap);
  padding: var(--gap) 20px 40px;
  max-width: 1500px;
  margin: 0 auto;
}

.workspace.wide {
  grid-template-columns: var(--sidebar) minmax(0, 1fr) minmax(0, 1fr);
}

.pane {
  min-width: 0;
}

.panel {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}

.panel + .panel {
  margin-top: var(--gap);
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.panel-head h2 {
  margin-right: auto;
}

.sublabel {
  font-size: 12px;
  color: var(--text-faint);
  margin: 0 0 10px;
  max-width: 62ch;
}

/* An editor is read line by line, so it keeps a comfortable measure however
   wide the pane gets. Without this a bio field runs to 120 characters on a
   large screen and the eye loses the line it was on. */
.editor {
  max-width: 660px;
}

/* --- list ---------------------------------------------------------------- */

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

.list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 11px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  text-align: left;
  font-weight: 500;
  cursor: pointer;
}

.list-item:hover {
  background: var(--bg-hover);
  border-color: transparent;
  color: var(--text);
}

.list-item[aria-current='true'] {
  background: var(--accent-soft);
  color: var(--accent);
}

.list-item .sub {
  display: block;
  font-size: 12px;
  font-weight: 400;
  color: var(--text-faint);
  margin-top: 1px;
}

.list-item[aria-current='true'] .sub {
  color: color-mix(in srgb, var(--accent) 65%, var(--text-faint));
}

.list-item .label {
  min-width: 0;
  flex: 1;
}

.list-item .label > span:first-child {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.count {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

/* --- notices, empties, chips -------------------------------------------- */

.notice {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg-sunken);
  color: var(--text-dim);
}

.notice + * {
  margin-top: 14px;
}

.notice.bad {
  border-color: color-mix(in srgb, var(--bad) 45%, var(--line));
  color: var(--bad);
}

.notice.warn {
  border-color: color-mix(in srgb, var(--warn) 40%, var(--line));
  color: var(--warn);
}

.empty {
  padding: 34px 20px;
  text-align: center;
  color: var(--text-faint);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
}

.empty p {
  margin: 0 0 12px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 100px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  color: var(--text-dim);
  font-size: 12px;
}

.chip.upstream {
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 35%, var(--line));
}

/* --- drag and drop ------------------------------------------------------- */

.stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 56px;
}

.stack.drop-target {
  outline: 1px dashed var(--accent);
  outline-offset: 6px;
  border-radius: var(--radius-sm);
}

.draggable {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: grab;
  /* Transform only — a list that reflows on hover is a list you cannot aim at. */
  transition: border-color 0.14s var(--ease), background 0.14s var(--ease), transform 0.14s var(--ease);
}

.draggable:hover {
  border-color: var(--line-strong);
}

.draggable:active {
  cursor: grabbing;
}

.draggable.dragging {
  opacity: 0.4;
  transform: scale(0.99);
}

.draggable.over {
  border-color: var(--accent);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 18px -6px rgba(110, 168, 254, 0.45);
}

.grip {
  color: var(--text-faint);
  cursor: grab;
}

.draggable:hover .grip {
  color: var(--text-dim);
}

.order {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  width: 1.4em;
  text-align: right;
  flex: none;
}

.draggable .body {
  min-width: 0;
  flex: 1;
}

.draggable .body strong {
  display: block;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.draggable .body .sub {
  display: block;
  font-size: 12px;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- prompt preview ------------------------------------------------------ */

.prompt {
  margin: 0;
  padding: 14px 16px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.65;
  color: var(--text-dim);
  white-space: pre-wrap;
  overflow-x: auto;
  max-height: 340px;
}

details.fold > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  padding: 4px 0;
}

details.fold > summary::-webkit-details-marker {
  display: none;
}

details.fold > summary:hover {
  color: var(--text);
}

details.fold > summary .icon {
  transition: transform 0.16s var(--ease);
}

details.fold[open] > summary .icon {
  transform: rotate(90deg);
}

details.fold > *:not(summary) {
  margin-top: 10px;
}

/* --- conversation -------------------------------------------------------- */

.chat {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 260px;
  max-height: min(58vh, 560px);
  overflow-y: auto;
  padding-right: 4px;
  scroll-behavior: smooth;
}

.bubble {
  max-width: 88%;
  padding: 10px 13px;
  border-radius: var(--radius);
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  animation: rise 0.22s var(--ease) both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .bubble {
    animation: none;
  }
  .chat {
    scroll-behavior: auto;
  }
}

.bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: #08111f;
  border-bottom-right-radius: 3px;
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-bottom-left-radius: 3px;
}

.bubble.failed {
  align-self: flex-start;
  background: transparent;
  border: 1px solid color-mix(in srgb, var(--bad) 45%, var(--line));
  color: var(--bad);
}

.turn-meta {
  margin-top: 6px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
}

.composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  margin-top: 14px;
}

.composer textarea {
  min-height: 42px;
  max-height: 160px;
  resize: none;
}

/* Three dots that keep their own rhythm while the model is thinking. */
.thinking {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 4px 0;
}

.thinking i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-faint);
  animation: pulse 1.1s var(--ease) infinite;
}

.thinking i:nth-child(2) {
  animation-delay: 0.15s;
}

.thinking i:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes pulse {
  0%,
  60%,
  100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .thinking i {
    animation: none;
  }
}

/* --- toasts -------------------------------------------------------------- */

.toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 10px 14px;
  background: var(--bg-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3), 0 12px 32px -12px rgba(0, 0, 0, 0.8);
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
  animation: rise 0.2s var(--ease) both;
}

.toast.bad {
  border-color: color-mix(in srgb, var(--bad) 55%, var(--line));
  color: var(--bad);
}

.toast.ok {
  border-color: color-mix(in srgb, var(--ok) 45%, var(--line));
}

/* --- login --------------------------------------------------------------- */

body.centered {
  display: grid;
  place-items: center;
  padding: 20px;
}

.login {
  width: 100%;
  max-width: 380px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px;
}

.login h1 {
  margin-bottom: 8px;
}

.login p {
  color: var(--text-dim);
  margin: 0 0 18px;
}

/* --- responsive ---------------------------------------------------------- */

@media (max-width: 1180px) {
  .workspace.wide {
    grid-template-columns: var(--sidebar) minmax(0, 1fr);
  }
}

@media (max-width: 860px) {
  .workspace,
  .workspace.wide {
    grid-template-columns: minmax(0, 1fr);
    padding: 12px;
  }

  .topbar {
    padding: 0 12px;
    gap: 8px;
  }

  .brand span {
    display: none;
  }

  /* The running tally is a convenience on a wide screen and the thing that
     pushes the section switch off the edge on a narrow one. */
  #counts {
    display: none;
  }

  /* All three sections have to fit without swiping: a switch you cannot see
     is a switch nobody presses. The icons are the first thing to go — the
     labels carry the meaning on their own. */
  .nav {
    margin-left: 0;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .nav::-webkit-scrollbar {
    display: none;
  }

  .nav .icon {
    display: none;
  }

  .nav button {
    padding: 6px 9px;
  }

  .brand {
    font-size: 13px;
  }

  .bubble {
    max-width: 96%;
  }
}
