/* ============================================================================
 * theCortex Responsive Layout Shell (Council Chamber + 1-on-1 Tunnel Split)
 * Loaded after cerebrum.css so theCortex obsidian stage cleanly supersedes
 * legacy painting-overlay rules in .cb-meeting while keeping Cerebrum's
 * right-side Tools drawer and docked/review modes intact.
 * ========================================================================== */

/* ---- Dark Obsidian Shell for #room-panel.cortex-room ---- */
#room-panel.cortex-room {
  background: #06090d;
  color: #eef3f9;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  border-color: rgba(255, 255, 255, 0.08);
}

#room-panel.cortex-room .room-head {
  background: #0a0f16;
  color: #eef3f9;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding: 6px 14px;
  min-height: 36px;
  flex: 0 0 auto;
}

#room-panel.cortex-room .room-head strong {
  display: inline-block;
  color: #F2F6FC;
  font-family: var(--font-display, inherit);
  font-size: 0.9rem;
  letter-spacing: 0.01em;
}

#room-panel.cortex-room .room-status {
  color: #ffb86c;
}

#room-panel.cortex-room .room-pause,
#room-panel.cortex-room .fixture-close {
  color: #dbe4f0;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 4px 10px;
}

#room-panel.cortex-room .room-pause:hover,
#room-panel.cortex-room .fixture-close:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
}

#room-panel.cortex-room .room-paused {
  background: rgba(255, 122, 26, 0.14);
  color: #ffd0ad;
  border-bottom: 1px solid rgba(255, 122, 26, 0.35);
}

#room-panel.cortex-room .room-history {
  background: #0b1018;
  color: #95a5ba;
  border-block: 1px solid rgba(255, 255, 255, 0.07);
}
#room-panel.cortex-room .room-history button {
  color: #dbe4f0;
}
#room-panel.cortex-room .room-history button:disabled {
  color: #4f5e73;
}

/* ---- Obsidian Conversation Transcript ---- */
#room-panel.cortex-room .room-messages {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  background: #080c12;
  padding: 14px 18px;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}

#room-panel.cortex-room .room-msg {
  background: #0e141e;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-left: 3px solid rgba(242, 246, 252, 0.25);
  border-radius: 12px;
  padding: 10px 14px;
  color: #eef3f9;
}

#room-panel.cortex-room .room-msg[data-sender="antigravity"] {
  border-left-color: #F2F6FC;
}
#room-panel.cortex-room .room-msg[data-sender="claude"] {
  border-left-color: #FF7A1A;
}
#room-panel.cortex-room .room-msg[data-sender="codex"] {
  border-left-color: #00A8FF;
}
#room-panel.cortex-room .room-msg[data-sender="ollama"] {
  border-left-color: #00A8FF;
  box-shadow: inset 3px 0 0 rgba(255, 122, 26, 0.45);
}

#room-panel.cortex-room .room-msg.mine {
  background: #141d2b;
  border: 1px solid rgba(242, 246, 252, 0.16);
  border-left: 1px solid rgba(242, 246, 252, 0.16);
}

#room-panel.cortex-room .room-msg-head {
  color: #8b9bb0;
  font-size: 0.76rem;
}

#room-panel.cortex-room .room-msg-head strong {
  color: #F2F6FC;
}
#room-panel.cortex-room .room-msg[data-sender="claude"] .room-msg-head strong { color: #ffab66; }
#room-panel.cortex-room .room-msg[data-sender="codex"] .room-msg-head strong { color: #66cbff; }
#room-panel.cortex-room .room-msg[data-sender="ollama"] .room-msg-head strong { color: #9ad8ff; }

#room-panel.cortex-room .room-msg-body {
  color: #e6edf7;
  font-size: 0.95rem;
  line-height: 1.55;
}

#room-panel.cortex-room .message-link {
  color: #5cc8ff;
}
#room-panel.cortex-room .message-link:visited {
  color: #b7c8e0;
}

#room-panel.cortex-room .room-message-actions button {
  color: #8b9bb0;
}
#room-panel.cortex-room .room-message-actions button:hover,
#room-panel.cortex-room .room-message-actions button:focus-visible {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}
#room-panel.cortex-room .room-action-status,
#room-panel.cortex-room .room-voice-pending {
  color: #93a4ba;
}

#room-panel.cortex-room .room-typing,
#room-panel.cortex-room .room-earlier {
  background: #080c12;
  color: #8fa3bd;
  padding: 2px 18px 4px;
  flex: 0 0 auto;
}

/* ---- Docked Composer ---- */
#room-panel.cortex-room .room-form {
  background: #0a0f17;
  border-top: 1px solid rgba(255, 255, 255, 0.09);
  padding: 8px 16px calc(10px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 0 0 auto;
}

#room-panel.cortex-room .room-form textarea {
  min-height: 44px;
  max-height: 140px;
  resize: none;
  background: #101723;
  color: #f3f7fc;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.96rem;
  line-height: 1.45;
}
#room-panel.cortex-room .room-form textarea::placeholder {
  color: #708299;
}
#room-panel.cortex-room .room-form textarea:focus-visible {
  outline: 2px solid rgba(242, 246, 252, 0.55);
  outline-offset: 1px;
}

#room-panel.cortex-room .room-form-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

#room-panel.cortex-room .room-to,
#room-panel.cortex-room .room-rounds {
  color: #8b9bb0;
  font-size: 0.76rem;
}

#room-panel.cortex-room .room-to-warn {
  color: #ffab66;
}

#room-panel.cortex-room .room-form select {
  background: #111824;
  color: #eef3f9;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 6px;
  padding: 2px 6px;
}

#room-panel.cortex-room .room-form button[type="submit"] {
  margin-left: auto;
  background: #F2F6FC;
  color: #06090d;
  border: 0;
  border-radius: 9px;
  font-weight: 700;
  min-height: 38px;
  padding: 7px 18px;
  font-size: 0.88rem;
}

#room-panel.cortex-room[data-direct-agent="claude"] .room-form button[type="submit"] {
  background: #FF7A1A;
  color: #06090d;
}
#room-panel.cortex-room[data-direct-agent="codex"] .room-form button[type="submit"],
#room-panel.cortex-room[data-direct-agent="ollama"] .room-form button[type="submit"] {
  background: #00A8FF;
  color: #06090d;
}

#room-panel.cortex-room #room-clear-recipients {
  color: #9fb0c6;
}

#room-panel.cortex-room .voice-controls button {
  background: #111824;
  border-color: rgba(255, 255, 255, 0.16);
  color: #e6edf7;
}
#room-panel.cortex-room .voice-controls .voice-talk {
  background: rgba(242, 246, 252, 0.14);
  border-color: rgba(242, 246, 252, 0.35);
  color: #ffffff;
}
#room-panel.cortex-room .voice-controls .voice-talk[aria-pressed="true"],
#room-panel.cortex-room .voice-controls #voice-record[aria-pressed="true"] {
  background: #b91c3c;
  border-color: #ff4f6d;
  color: #ffffff;
}
#room-panel.cortex-room #voice-status,
#room-panel.cortex-room .voice-live-heard {
  color: #9eb0c7;
}

/* Hide legacy painting-overlay art-console buttons inside theCortex */
#room-panel.cortex-room .art-actions,
#room-panel.cortex-room .art-options,
#room-panel.cortex-room .hive-chat-surface {
  display: none !important;
}

/* ---- Direct 1-on-1 Tunnel Clean Composer (zero prefix clutter!) ---- */
#room-panel.cortex-room.is-direct .room-to,
#room-panel.cortex-room.is-direct .room-rounds,
#room-panel.cortex-room.is-direct #room-clear-recipients {
  display: none !important;
}

/* ---- Focused 1-on-1 Presence Desktop 2-Column Split (>= 960px) ---- */
@media (min-width: 960px) {
  #room-panel.cortex-room.is-direct {
    display: grid !important;
    grid-template-columns: minmax(290px, 36%) minmax(0, 1fr);
    grid-template-rows: auto auto auto auto minmax(0, 1fr) auto auto auto;
    align-items: stretch;
  }
  #room-panel.cortex-room.is-direct .room-head {
    grid-column: 1 / -1;
    grid-row: 1;
  }
  #room-panel.cortex-room.is-direct .room-tunnels {
    grid-column: 1 / -1;
    grid-row: 2;
  }
  #room-panel.cortex-room.is-direct .room-paused {
    grid-column: 1 / -1;
    grid-row: 3;
  }
  #room-panel.cortex-room.is-direct .room-scene {
    grid-column: 1;
    grid-row: 4 / 9;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    border-right: 1px solid rgba(255, 255, 255, 0.09);
    border-bottom: 0;
    overflow: auto;
  }
  #room-panel.cortex-room.is-direct .cortex-scene,
  #room-panel.cortex-room.is-direct .cortex-canvas {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    height: 100%;
    border-bottom: 0;
  }
  #room-panel.cortex-room.is-direct .room-history {
    grid-column: 2;
    grid-row: 4;
  }
  #room-panel.cortex-room.is-direct .room-messages {
    grid-column: 2;
    grid-row: 5;
    min-height: 0;
    height: 100%;
  }
  #room-panel.cortex-room.is-direct .room-typing {
    grid-column: 2;
    grid-row: 6;
  }
  #room-panel.cortex-room.is-direct .room-earlier {
    grid-column: 2;
    grid-row: 7;
  }
  #room-panel.cortex-room.is-direct .room-form {
    grid-column: 2;
    grid-row: 8;
  }
}

/* ---- Cerebrum Integration: Supersede legacy .cb-meeting painting-overlay rules ---- */
@media (min-width: 1001px) {
  #boardroom.cerebrum[data-cerebrum-view="hive"] #room-panel.cortex-room.home,
  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room {
    position: absolute;
    inset: 0 var(--hive-side, 0px) 0 0;
    width: auto;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: #06090d;
    overflow: hidden;
  }

  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room::before {
    display: none !important;
  }

  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room.is-direct {
    display: grid !important;
    grid-template-columns: minmax(290px, 36%) minmax(0, 1fr);
    grid-template-rows: auto auto auto auto minmax(0, 1fr) auto auto auto;
  }

  /* Reset legacy left-drawer absolute positioning & hover-hiding from cerebrum.css */
  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room :is(
    .room-head,
    .room-tunnels,
    .room-scene,
    .room-paused,
    .room-history,
    .room-messages,
    .room-typing,
    .room-earlier,
    .room-form
  ) {
    position: relative;
    inset: auto;
    left: auto;
    right: auto;
    top: auto;
    bottom: auto;
    width: 100%;
    max-width: none;
    translate: none !important;
    transform: none;
    opacity: 1 !important;
    pointer-events: auto !important;
    z-index: auto;
  }

  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room .room-scene {
    flex: 0 0 auto;
    height: auto;
    overflow: visible;
  }
  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room.is-direct .room-scene {
    height: 100%;
    overflow: auto;
  }
  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room .scene,
  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room .scene-canvas {
    position: relative;
    inset: auto;
    top: auto;
    left: auto;
    transform: none;
    width: 100%;
    height: auto;
    aspect-ratio: auto;
    margin: 0;
  }
  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room .scene-toolbar {
    position: relative;
    inset: auto;
    background: transparent;
    border: 0;
    border-radius: 0;
    backdrop-filter: none;
    padding: 8px 16px 4px;
  }
  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room #room-messages {
    flex: 1 1 0;
    height: auto;
    min-height: 0;
    padding: 14px 20px;
    background: #080c12;
  }
  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room #room-form {
    display: flex;
    background: #0a0f17;
    border-top: 1px solid rgba(255, 255, 255, 0.09);
    padding: 8px 16px 10px;
  }
  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room #room-form > #voice-controls {
    display: flex;
  }
  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room .room-form-row {
    display: flex;
  }
  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room .room-form-row > :not([type="submit"]) {
    display: initial;
  }
  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room .room-form-row > #room-clear-recipients[hidden] {
    display: none;
  }
  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room #room-input {
    position: static;
    width: 100%;
    height: auto !important;
    min-height: 44px;
    max-height: 140px;
    padding: 10px 12px;
    border-radius: 10px;
    background: #101723;
    border: 1px solid rgba(255, 255, 255, 0.14);
    color: #f3f7fc;
  }
  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room #room-form button[type="submit"] {
    position: static;
    transform: none;
    width: auto;
    height: auto;
    min-height: 38px;
    padding: 7px 18px;
    border-radius: 9px;
    font-size: 0.88rem;
    color: #06090d;
    background: #F2F6FC;
  }
  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room[data-direct-agent="claude"] #room-form button[type="submit"] {
    background: #FF7A1A;
  }
  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room[data-direct-agent="codex"] #room-form button[type="submit"],
  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room[data-direct-agent="ollama"] #room-form button[type="submit"] {
    background: #00A8FF;
  }

  /* Keep Council droid cards clean inside cb-meeting (undo old holographic marker rules) */
  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room .scene-canvas .scene-seat {
    position: relative;
    left: auto;
    top: auto;
    width: auto;
    min-width: 0;
    height: auto;
    transform: none;
    padding: 12px 10px 10px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 18px;
    background: linear-gradient(180deg, rgba(16, 23, 34, 0.76), rgba(6, 9, 13, 0.94));
  }
  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room .scene-canvas .scene-seat.picked {
    border-color: color-mix(in srgb, var(--droid-accent) 72%, transparent);
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--droid-accent) 26%, transparent), 0 8px 26px rgba(0, 0, 0, 0.45);
  }
  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room .scene-canvas .scene-seat.is-speaking {
    transform: translateY(-4px) scale(1.035);
    border-color: var(--droid-accent);
    box-shadow: 0 0 28px var(--droid-glow-strong), 0 12px 32px rgba(0, 0, 0, 0.6);
  }
  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room .scene-canvas .scene-seat[data-theme="nexx"].is-speaking {
    box-shadow: -10px 0 28px rgba(0, 168, 255, 0.45), 10px 0 28px rgba(255, 122, 26, 0.45), 0 0 22px rgba(242, 246, 252, 0.28), 0 12px 32px rgba(0, 0, 0, 0.6);
  }
  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room .scene-canvas .scene-seat::before,
  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room .scene-canvas .scene-seat::after {
    display: none;
  }
  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room .scene-canvas .scene-seat .scene-pick {
    height: auto;
    min-height: 30px;
    flex-direction: row;
    justify-content: center;
    padding: 4px 8px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.04);
    text-shadow: none;
  }
  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room .scene-canvas .scene-seat.picked .scene-pick {
    border-color: var(--droid-accent);
    background: color-mix(in srgb, var(--droid-accent) 16%, #0b1017);
  }
  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room .scene-canvas .scene-seat .sc-name {
    font-size: 0.84rem;
    padding: 0;
    background: transparent;
  }
  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room .scene-canvas .scene-bubble {
    display: flex;
  }
  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room .scene-canvas .sc-tag {
    display: inline;
  }
  #boardroom.cerebrum.cb-meeting #room-panel.cortex-room .scene-extra-seats {
    position: relative;
    inset: auto;
    justify-content: flex-start;
  }
}

/* Cerebrum docked side panel (narrower width: keep single-column even on desktop) */
@media (min-width: 1001px) {
  #boardroom.cerebrum.cb-docked:not([data-cerebrum-view="hive"]) #room-panel.cortex-room.is-direct {
    display: flex !important;
    flex-direction: column;
  }
  #boardroom.cerebrum.cb-docked:not([data-cerebrum-view="hive"]) #room-panel.cortex-room .cortex-chamber {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  #boardroom.cerebrum.cb-docked:not([data-cerebrum-view="hive"]) #room-panel.cortex-room .cortex-portrait-wrap {
    width: 68px;
    height: 68px;
  }
  #boardroom.cerebrum.cb-docked:not([data-cerebrum-view="hive"]) #room-panel.cortex-room .cortex-card-bubble {
    display: none;
  }
  #boardroom.cerebrum.cb-docked:not([data-cerebrum-view="hive"]) #room-panel.cortex-room .cortex-direct-hero {
    flex-direction: row;
    text-align: left;
  }
  #boardroom.cerebrum.cb-docked:not([data-cerebrum-view="hive"]) #room-panel.cortex-room .cortex-direct-portrait-wrap {
    width: 72px;
    height: 72px;
    flex: 0 0 72px;
  }
  #boardroom.cerebrum.cb-docked:not([data-cerebrum-view="hive"]) #room-panel.cortex-room .cortex-direct-meta {
    align-items: flex-start;
    flex: 1 1 auto;
  }
}

/* Mobile adjustments — keep chat replies generous, visible, and cleanly scrollable */
@media (max-width: 959px) {
  #room-panel.cortex-room {
    overflow-y: auto;
  }
  #room-panel.cortex-room .room-head {
    padding: 3px 10px;
    min-height: 30px;
  }
  #room-panel.cortex-room .room-head strong {
    font-size: 0.8rem;
  }
  #room-panel.cortex-room .room-head #room-pause {
    min-height: 26px;
    padding: 2px 8px;
    font-size: 0.7rem;
  }
  #room-panel.cortex-room .room-tunnels {
    padding: 4px 8px;
    gap: 5px;
  }
  #room-panel.cortex-room .room-history {
    padding: 0 8px;
    font-size: 0.7rem;
  }
  #room-panel.cortex-room .room-history button {
    min-height: 30px;
    padding: 2px 6px;
  }
  #room-panel.cortex-room .room-messages {
    flex: 1 1 240px;
    min-height: 220px;
    padding: 10px 10px;
    gap: 8px;
  }
  #room-panel.cortex-room .room-earlier {
    padding: 2px 10px;
    font-size: 0.72rem;
  }
  #room-panel.cortex-room .room-form {
    padding: 5px 10px calc(6px + env(safe-area-inset-bottom, 0px));
    gap: 4px;
  }
  #room-panel.cortex-room .room-form textarea {
    min-height: 38px;
    max-height: 90px;
    padding: 7px 10px;
    font-size: 0.9rem;
  }
  #room-panel.cortex-room .room-form-row {
    gap: 6px;
  }
  #room-panel.cortex-room .room-to {
    font-size: 0.7rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  #room-panel.cortex-room .room-rounds {
    font-size: 0.7rem;
    white-space: nowrap;
  }
  #room-panel.cortex-room .room-form button[type="submit"] {
    min-height: 34px;
    padding: 5px 14px;
    font-size: 0.82rem;
  }
}
