/* Scoped additions for EVAN in the existing CFW owner Portal. */
#evan-view { color-scheme: dark; }
#evan-view [hidden] { display: none !important; }
#evan-view .module-content,
#evan-view .evan-conversation,
#evan-view .evan-evidence-card { min-width: 0; }
.evan-saved-toolbar { display: grid; gap: .75rem; padding: 1rem 0; border-block: 1px solid #626a66; margin-bottom: 1rem; }
.evan-conversation-picker { display: grid; gap: .4rem; color: #e3e8e5; font-size: .8rem; font-weight: 700; }
.evan-conversation-picker select { width: 100%; min-width: 0; min-height: 2.75rem; padding: .55rem .65rem; background: #171a18; color: #edf2ef; border: 1px solid #626a66; border-radius: .45rem; font: inherit; }
.evan-saved-actions { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.evan-detail-status { margin: 0; color: #b7c3bc; font-size: .83rem; line-height: 1.6; overflow-wrap: anywhere; }
.evan-earlier-messages { display: block; margin: .5rem auto; }
.evan-section-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.25rem; }
.evan-section-heading h3 { margin: .25rem 0 .5rem; }
.evan-section-heading p { max-width: 48rem; }
.evan-evidence-grid { display: grid; gap: .85rem; }
.evan-evidence-card { padding: 1rem; color: #edf2ef; border: 1px solid #626a66; border-radius: .65rem; background: #171a18; }
.evan-evidence-card h4 { margin: 0 0 .6rem; font-size: .95rem; }
.evan-evidence-card p { margin: .35rem 0; font-size: .85rem; line-height: 1.6; }
.evan-evidence-card dl { display: grid; grid-template-columns: minmax(7rem, 1fr) minmax(0, 3fr); gap: .5rem .75rem; font-size: .8rem; }
.evan-evidence-card dt { color: #b7c3bc; }
.evan-evidence-card dd { margin: 0; overflow-wrap: anywhere; }
.evan-evidence-card code { font-size: .75rem; overflow-wrap: anywhere; }
.evan-memory-editor { padding: 1.1rem; margin-top: 1rem; color: #edf2ef; border: 1px solid #626a66; background: #151a17; border-radius: .65rem; }
.evan-memory-editor > p { color: #b7c3bc; font-size: .85rem; line-height: 1.6; }
.evan-memory-fields { display: grid; grid-template-columns: minmax(0, 1fr); gap: .65rem; margin-block: 1rem; }
.evan-memory-fields label { display: grid; gap: .4rem; font-size: .85rem; font-weight: 700; }
.evan-memory-fields textarea { width: 100%; min-height: 8rem; resize: vertical; padding: .65rem; color: #edf2ef; background: #0f1411; border: 1px solid #626a66; border-radius: .4rem; font: inherit; font-weight: 400; line-height: 1.5; }
.evan-memory-fields textarea + label { margin-top: .6rem; }
.evan-memory-editor pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.evan-memory-editor .evan-detail-status { margin-block: 1rem; }
.evan-role-profile { margin-top: 1.5rem; font-size: .85rem; }
.evan-role-profile summary { cursor: pointer; font-weight: 600; }
#evan-view :is(button, select, textarea, summary):focus-visible { outline: 3px solid #6ee7b7; outline-offset: 3px; }
#evan-view .evan-model-controls { border-color: #626a66; background: #151a17; }
#evan-view .evan-model-controls select { color: #edf2ef; background: #0f1411; border-color: #626a66; }
#evan-view .evan-model-status { color: #b7c3bc; }
@media (max-width: 760px) {
  .evan-section-heading { flex-direction: column; }
  .evan-memory-fields { grid-template-columns: minmax(0, 1fr); }
  .evan-evidence-card dl { grid-template-columns: minmax(0, 1fr); }
  .evan-evidence-card dt:not(:first-child) { margin-top: .5rem; }
  .evan-saved-actions button { min-height: 2.75rem; }
}

/* Chat-first layout. Every override stays inside the existing EVAN view. */
#evan-view .evan-heading { margin-bottom: .8rem; }
#evan-view .evan-heading h2 { margin: 0; font-size: 1.3rem; letter-spacing: -.03em; }
#evan-view .module-layout { display: block; min-height: 0; overflow: visible; }
#evan-view .module-content { padding: 0; border-radius: 0 0 .6rem .6rem; }
#evan-view [data-module-panel="evan"]:not([data-module-view="chat"]) { padding: clamp(1rem, 3vw, 1.5rem); }
#evan-view .evan-chat-navigation { flex-direction: row; align-items: center; justify-content: space-between; padding: .45rem .8rem; border: 0; border-bottom: 1px solid #303532; overflow: visible; border-radius: .6rem .6rem 0 0; }
#evan-view .evan-chat-navigation > button { width: auto; min-width: 4.5rem; min-height: 2.75rem; text-align: center; }
#evan-view :is(.evan-settings, .evan-history-menu) { position: relative; }
#evan-view :is(.evan-settings, .evan-history-menu, .evan-response-details) > summary { cursor: pointer; padding: .65rem .7rem; color: #b7c3bc; font-size: .85rem; line-height: 1.4; border-radius: .4rem; }
#evan-view :is(.evan-settings, .evan-history-menu) > summary:hover { background: #222825; color: #edf2ef; }
#evan-view .evan-settings-content { position: absolute; top: calc(100% + .5rem); right: 0; z-index: 20; width: min(22rem, calc(100vw - 4rem)); max-height: 70vh; overflow-y: auto; padding: .75rem; border: 1px solid #626a66; border-radius: .6rem; background: #171d19; box-shadow: 0 .8rem 2.5rem #0007; }
#evan-view .evan-settings-content > button { display: block; min-height: 2.75rem; }
#evan-view .evan-connection-details { padding: .85rem .4rem .2rem; border-top: 1px solid #39443d; margin-top: .6rem; }
#evan-view .evan-connection-details p { margin: .7rem 0; color: #b7c3bc; font-size: .78rem; line-height: 1.5; overflow-wrap: anywhere; }
#evan-view .evan-connection-details :is(.connection-badge, .evan-live-connection) { white-space: normal; line-height: 1.5; }
#evan-view .evan-conversation { border: 0; border-radius: 0 0 .6rem .6rem; box-shadow: none; background: #131714; }
#evan-view .evan-chat-toolbar { display: flex; align-items: flex-start; gap: .7rem; padding: .85rem 1rem; border-bottom: 1px solid #303532; min-width: 0; }
#evan-view #evan-live-model-controls { flex: 0 1 30rem; min-width: 0; max-width: 100%; }
#evan-view .evan-chat-toolbar > button { flex: 0 0 auto; min-height: 2.75rem; margin: 0; font-size: .82rem; }
#evan-view .evan-history-menu { flex: 0 0 auto; }
#evan-view .evan-history-menu > .evan-saved-toolbar { position: absolute; right: 0; top: calc(100% + .5rem); z-index: 15; width: min(28rem, calc(100vw - 4rem)); margin: 0; padding: 1rem; border: 1px solid #626a66; border-radius: .6rem; background: #171d19; box-shadow: 0 .8rem 2.5rem #0007; }
#evan-view .evan-chat-history-status { padding: .6rem 1rem; }
#evan-view .evan-chat-history-status[data-tone="ready"] { display: none; }
#evan-view .evan-chat-history-status[data-tone="denied"] { color: #f3b6ae; }
#evan-view .evan-chat-empty { display: grid; place-content: center; min-height: clamp(12rem, 30vh, 22rem); padding: 2rem 1rem; text-align: center; }
#evan-view .evan-chat-empty h3 { margin: 0 0 .6rem; color: #edf2ef; font-size: clamp(1.35rem, 3vw, 1.8rem); font-weight: 600; letter-spacing: -.035em; }
#evan-view .evan-chat-empty p { margin: 0; color: #a7b6ad; font-size: .95rem; line-height: 1.6; }
#evan-view .evan-live-messages { max-height: none; overflow: visible; gap: 1.5rem; padding: 1.5rem clamp(1rem, 4vw, 3rem); border: 0; }
#evan-view .evan-live-message { width: min(100%, 48rem); max-width: 100%; margin-inline: auto; padding: .35rem 0; border: 0; background: transparent; color: #e8eee9; font-size: 1rem; line-height: 1.75; }
#evan-view .evan-live-message.is-user { width: auto; max-width: min(85%, 40rem); margin-left: auto; margin-right: 0; padding: .8rem 1rem; border: 1px solid #34453b; border-radius: 1rem 1rem .25rem 1rem; background: #1d2b22; }
#evan-view .evan-live-message strong { margin-bottom: .4rem; color: #a8bdb0; font-size: .75rem; letter-spacing: 0; text-transform: none; }
#evan-view .evan-composer { max-width: 54rem; margin-inline: auto; padding: 1rem; }
#evan-view .evan-composer fieldset { padding: 0; margin: 0; border: 0; }
#evan-view .evan-composer textarea { min-height: 6rem; max-height: 18rem; padding: 1rem; border-color: #53665a; border-radius: .85rem; background: #1a221d; color: #edf2ef; font-size: 1rem; line-height: 1.6; }
#evan-view .evan-composer textarea::placeholder { color: #a4b3a9; }
#evan-view .evan-composer fieldset:disabled textarea { background: #191f1b; color: #a4b3a9; }
#evan-view .composer-actions { align-items: center; flex-wrap: wrap; gap: .65rem; margin-top: .6rem; }
#evan-view .composer-actions > span { color: #a7b6ad; font-size: .75rem; line-height: 1.5; }
#evan-view .evan-live-actions { margin-left: auto; align-items: center; flex-wrap: wrap; }
#evan-view .evan-live-actions button { min-height: 2.75rem; margin: 0; }
#evan-view .evan-chat-feedback { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem .8rem; color: #b7c3bc; }
#evan-view .evan-chat-feedback p { margin: .6rem 0; font-size: .85rem; line-height: 1.6; }
#evan-view #evan-chat-status[data-state="denied"] { color: #f3b6ae; }
#evan-view .evan-response-details { padding: 0 1rem .5rem; }
#evan-view .evan-response-details > summary { width: fit-content; font-size: .75rem; }
#evan-view .evan-live-run { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: .4rem; border-top: 1px solid #303532; }
#evan-view .evan-live-run dd { white-space: normal; overflow-wrap: anywhere; line-height: 1.6; }
#evan-view .evan-visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
@media (max-width: 620px) {
  #evan-view .evan-chat-toolbar { flex-wrap: wrap; padding: .75rem; gap: .5rem; }
  #evan-view #evan-live-model-controls { flex-basis: 100%; }
  #evan-view .evan-chat-toolbar > button { margin-left: auto; }
  #evan-view .evan-history-menu > .evan-saved-toolbar { right: auto; left: 0; width: min(28rem, calc(100vw - 3.5rem)); }
  #evan-view .evan-chat-empty { min-height: 12rem; }
  #evan-view .evan-live-messages { padding: 1rem; gap: 1rem; }
  #evan-view .evan-live-message.is-user { max-width: 92%; }
  #evan-view .evan-composer { padding: .75rem; }
  #evan-view .composer-actions > span { flex-basis: 100%; }
  #evan-view .evan-live-run { grid-template-columns: minmax(0, 1fr); padding: .8rem .2rem; }
}

/* EVAN-only outer role controls. */
.control-stage:has(> .control-panels > #evan-view:not([hidden])) > .control-topbar .role-control,
.control-stage:has(> .control-panels > #evan-view:not([hidden])) > .control-topbar #import-role,
.control-stage:has(> .control-panels > #evan-view:not([hidden])) > #role-description {
  display: none;
}

/* Project memory stays inside the existing EVAN Settings view. */
#evan-view .evan-project-memory { margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid #626a66; min-width: 0; }
#evan-view #evan-project-memory-control { display: grid; gap: .85rem; min-width: 0; }
#evan-view #evan-project-memory-control label { display: grid; gap: .4rem; min-width: 0; color: #e3e8e5; font-size: .85rem; font-weight: 600; }
#evan-view #evan-project-memory-control :is(select, input, textarea) { width: 100%; min-width: 0; min-height: 2.75rem; padding: .65rem; color: #edf2ef; background: #0f1411; border: 1px solid #626a66; border-radius: .4rem; font: inherit; line-height: 1.5; }
#evan-view #evan-project-memory-control textarea { min-height: 9rem; resize: vertical; }
#evan-view #evan-project-memory-control pre { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; font-size: .76rem; line-height: 1.6; }
#evan-view #evan-project-memory-control p { margin: 0; color: #b7c3bc; font-size: .85rem; line-height: 1.6; overflow-wrap: anywhere; }
#evan-view #evan-project-memory-control button { min-height: 2.75rem; justify-self: start; }
#evan-view #evan-project-memory-exact-result:not(:empty) { padding: 1rem; border: 1px solid #626a66; border-radius: .5rem; color: #edf2ef; background: #151a17; }
#evan-view #evan-project-memory-control :is(select, input, textarea):focus-visible { outline: 3px solid #6ee7b7; outline-offset: 3px; }
#evan-view #evan-project-memory-governance { display: grid; gap: .85rem; min-width: 0; margin-block: 1rem 1.5rem; }
#evan-view #evan-project-memory-governance label { display: grid; gap: .4rem; min-width: 0; color: #e3e8e5; font-size: .85rem; font-weight: 600; }
#evan-view #evan-project-memory-governance :is(select, input, textarea) { box-sizing: border-box; width: 100%; min-width: 0; min-height: 2.75rem; padding: .65rem; color: #edf2ef; background: #0f1411; border: 1px solid #626a66; border-radius: .4rem; font: inherit; line-height: 1.5; }
#evan-view #evan-project-memory-governance textarea { resize: vertical; }
#evan-view #evan-project-memory-governance pre { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; font-size: .76rem; line-height: 1.6; }
#evan-view #evan-project-memory-governance p { margin: 0; color: #b7c3bc; font-size: .85rem; line-height: 1.6; overflow-wrap: anywhere; }
#evan-view #evan-project-memory-governance button { min-height: 2.75rem; justify-self: start; }
#evan-view #evan-project-memory-governance details { min-width: 0; padding: .85rem; border: 1px solid #626a66; border-radius: .5rem; }
#evan-view #evan-project-memory-governance details > :not(summary) { margin-top: .85rem; }
#evan-view #evan-project-memory-governance :is(select, input, textarea):focus-visible { outline: 3px solid #6ee7b7; outline-offset: 3px; }
#evan-view #evan-project-memory-control > details > :not(summary) { margin-top: .85rem; }
