/* Screens and controls the WebUI adds, drawn with the same Material 3 tokens as style.css:
   SettingsScaffold, SettingsGroup (24/5 dp corners, 2 dp gaps), switches, dialogs, message
   action rows, the interaction bar and the Loop bar. */

:root {
  --surface-1: color-mix(in srgb, var(--md-primary) 5%, var(--md-surface));
  --surface-2: color-mix(in srgb, var(--md-primary) 8%, var(--md-surface));
  --state-hover: color-mix(in srgb, var(--md-on-surface) 8%, transparent);
  --state-press: color-mix(in srgb, var(--md-on-surface) 12%, transparent);
}

/* ── Pages ─────────────────────────────────────────────────────────────── */
.page-layer { position: fixed; inset: 0; }
.app-page {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  background: var(--md-background); color: var(--md-on-background);
  animation: page-enter 280ms cubic-bezier(0.2, 0, 0, 1);
}
@keyframes page-enter { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
[data-reduce-motion="true"] .app-page { animation: none; }
.page-bar {
  flex: none; display: flex; align-items: center; gap: 4px; height: 64px; padding: 8px 4px 0 4px;
  background: var(--md-background); transition: background 200ms, box-shadow 200ms;
}
.page-bar.docked { background: var(--surface-2); box-shadow: 0 1px 0 var(--md-outline-variant); }
.page-bar-title {
  flex: 1; min-width: 0; margin: 0; font-size: 22px; line-height: 28px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  opacity: 0; transform: translateY(8px); transition: opacity 200ms, transform 200ms;
}
.page-bar.docked .page-bar-title { opacity: 1; transform: none; }
.page-actions { display: flex; align-items: center; gap: 4px; padding-right: 8px; }
.page-back { flex: none; }
.page-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.page-content { max-width: 840px; margin: 0 auto; padding: 0 24px calc(96px + env(safe-area-inset-bottom)); }
.page-big-title { margin: 8px 0 24px; font-size: 32px; line-height: 40px; font-weight: 700; }
.page-loading { display: grid; place-items: center; padding: 48px 0; }
.page-note { margin: 0 0 16px; padding: 12px 16px; border-radius: 16px; background: var(--md-secondary-container); color: var(--md-on-secondary-container); font-size: 14px; }
.page-form { margin-bottom: 24px; }

/* ── Settings groups and rows ──────────────────────────────────────────── */
.settings-group { margin-bottom: 24px; }
.settings-group-title { margin: 0; padding: 12px 16px; font-size: 14px; line-height: 20px; font-weight: 500; color: var(--md-primary); }
.settings-group-items { display: flex; flex-direction: column; gap: 2px; }
.settings-card { overflow: hidden; background: var(--surface-1); border-radius: 5px; }
.settings-card.single { border-radius: 24px; }
.settings-card.first { border-radius: 24px 24px 5px 5px; }
.settings-card.last { border-radius: 5px 5px 24px 24px; }
.settings-group-footer { margin: 8px 16px 0; font-size: 12px; color: var(--md-on-surface-variant); }
.group-subhead { padding: 12px 16px 4px; font-size: 12px; font-weight: 600; color: var(--md-on-surface-variant); text-transform: uppercase; letter-spacing: 0.4px; }
.settings-row {
  position: relative; display: flex; align-items: center; gap: 16px; width: 100%; min-height: 56px; padding: 16px;
  border: 0; background: transparent; color: var(--md-on-surface); font: inherit; text-align: start;
}
button.settings-row { cursor: pointer; }
button.settings-row:hover:not(:disabled) { background: var(--state-hover); }
button.settings-row:active:not(:disabled) { background: var(--state-press); }
.settings-row:disabled, .settings-row.disabled { opacity: 0.5; cursor: default; }
.settings-row-icon { flex: none; display: grid; place-items: center; width: 24px; height: 24px; align-self: flex-start; margin-top: 2px; }
.settings-row-icon svg { width: 24px; height: 24px; fill: var(--md-primary); }
.settings-row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.settings-row-title { font-size: 16px; line-height: 24px; overflow-wrap: anywhere; }
.settings-row-title.danger { color: var(--md-error); }
.settings-row-desc { font-size: 14px; line-height: 20px; color: var(--md-on-surface-variant); overflow-wrap: anywhere; white-space: pre-line; }
.settings-row-chevron { flex: none; display: grid; place-items: center; }
.settings-row-chevron svg { width: 24px; height: 24px; fill: var(--md-on-surface-variant); }
.trailing-value { flex: none; font-size: 14px; color: var(--md-primary); font-weight: 500; }
.settings-add-row {
  display: flex; align-items: center; gap: 8px; width: 100%; min-height: 56px; padding: 0 16px; border: 0;
  background: transparent; color: var(--md-primary); font: inherit; font-size: 14px; font-weight: 500; cursor: pointer;
}
.settings-add-row:hover { background: var(--state-hover); }
.settings-add-row svg { width: 18px; height: 18px; fill: currentColor; }
.settings-add-row:disabled { color: color-mix(in srgb, var(--md-on-surface) 38%, transparent); cursor: default; }
.slider-row { align-items: stretch; }
.slider-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.slider-value { flex: none; color: var(--md-primary); font-weight: 700; font-size: 14px; }
.slider-line { display: flex; align-items: center; gap: 8px; }
.slider-line input[type="range"] { flex: 1; accent-color: var(--md-primary); height: 32px; }
.field-row { padding-top: 12px; padding-bottom: 12px; }
.field-row .app-field { flex: 1; }
.search-row { gap: 12px; padding-top: 8px; padding-bottom: 8px; }
.search-row svg { width: 20px; height: 20px; fill: var(--md-on-surface-variant); flex: none; }
.search-row input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--md-on-surface); font: inherit; font-size: 16px; }
.provider-head .settings-row-title { font-weight: 500; }
.row-file { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.hidden-input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* Switch (M3: 52 x 32 track, 16 → 24 dp thumb with a check). */
.m3-switch {
  position: relative; flex: none; width: 52px; height: 32px; padding: 0; border: 2px solid var(--md-outline); border-radius: 16px;
  background: var(--md-surface-container-highest, var(--md-surface-variant)); cursor: pointer; transition: background 200ms, border-color 200ms;
}
.m3-switch-thumb {
  position: absolute; top: 50%; left: 6px; display: grid; place-items: center; width: 16px; height: 16px; border-radius: 50%;
  background: var(--md-outline); transform: translateY(-50%); transition: left 200ms cubic-bezier(0.2, 0, 0, 1), width 200ms, height 200ms, background 200ms;
}
.m3-switch[aria-checked="true"] { border-color: var(--md-primary); background: var(--md-primary); }
.m3-switch[aria-checked="true"] .m3-switch-thumb { left: 22px; width: 24px; height: 24px; background: var(--md-on-primary); }
.m3-switch-thumb svg { width: 16px; height: 16px; fill: var(--md-primary); }
.m3-switch:disabled { opacity: 0.38; cursor: default; }
.radio { flex: none; width: 20px; height: 20px; border: 2px solid var(--md-on-surface-variant); border-radius: 50%; }
.radio.checked { border-color: var(--md-primary); background: radial-gradient(var(--md-primary) 0 45%, transparent 50%); }
.checkbox { flex: none; display: grid; place-items: center; width: 18px; height: 18px; border: 2px solid var(--md-on-surface-variant); border-radius: 2px; }
.checkbox.checked { border-color: var(--md-primary); background: var(--md-primary); }
.checkbox svg { width: 16px; height: 16px; fill: var(--md-on-primary); }
.inline-switch { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.inline-switch.wide { justify-content: space-between; }
.inline-switch.wide span { display: flex; flex-direction: column; }
.inline-switch small { color: var(--md-on-surface-variant); }

/* Buttons */
.text-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 12px; border: 0; border-radius: 20px;
  background: transparent; color: var(--md-primary); font: inherit; font-size: 14px; font-weight: 500; cursor: pointer;
}
.text-button:hover:not(:disabled) { background: color-mix(in srgb, var(--md-primary) 8%, transparent); }
.text-button.danger { color: var(--md-error); }
.text-button:disabled { color: color-mix(in srgb, var(--md-on-surface) 38%, transparent); cursor: default; }
.filled-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 24px; border: 0; border-radius: 20px;
  background: var(--md-primary); color: var(--md-on-primary); font: inherit; font-size: 14px; font-weight: 500; cursor: pointer;
}
.filled-button.tonal { background: var(--md-secondary-container); color: var(--md-on-secondary-container); padding: 0 16px; }
.filled-button svg { width: 18px; height: 18px; fill: currentColor; }
.filled-button:disabled { background: color-mix(in srgb, var(--md-on-surface) 12%, transparent); color: color-mix(in srgb, var(--md-on-surface) 38%, transparent); cursor: default; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; }
.icon-button { flex: none; display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--md-on-surface-variant); cursor: pointer; font: inherit; }
.icon-button:hover:not(:disabled) { background: var(--state-hover); }
.icon-button svg { width: 22px; height: 22px; fill: currentColor; }
.icon-button:disabled { opacity: 0.38; cursor: default; }
.fab {
  position: absolute; right: max(16px, calc((100% - 840px) / 2)); bottom: calc(16px + env(safe-area-inset-bottom)); display: flex; align-items: center; gap: 12px;
  height: 56px; padding: 0 20px 0 16px; border: 0; border-radius: 16px; background: var(--md-primary-container); color: var(--md-on-primary-container);
  font: inherit; font-size: 15px; font-weight: 500; box-shadow: var(--shadow-3); cursor: pointer;
}
.fab svg { width: 24px; height: 24px; fill: currentColor; }
.file-button { position: relative; display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 16px; border-radius: 20px; background: var(--md-secondary-container); color: var(--md-on-secondary-container); font-size: 14px; font-weight: 500; cursor: pointer; width: fit-content; }
.file-button input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-button svg { width: 18px; height: 18px; fill: currentColor; }
.segmented { display: flex; border: 1px solid var(--md-outline); border-radius: 20px; overflow: hidden; }
.segmented button { flex: 1; min-height: 40px; padding: 0 12px; border: 0; border-left: 1px solid var(--md-outline); background: transparent; color: var(--md-on-surface); font: inherit; font-size: 14px; font-weight: 500; cursor: pointer; }
.segmented button:first-child { border-left: 0; }
.segmented button[aria-pressed="true"] { background: var(--md-secondary-container); color: var(--md-on-secondary-container); }
.segmented.compact button { min-height: 32px; font-size: 12px; padding: 0 8px; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 8px; font-size: 12px; font-weight: 600; background: var(--md-secondary-container); color: var(--md-on-secondary-container); }
.pill svg { width: 14px; height: 14px; fill: currentColor; }
.pill.ok { background: transparent; color: var(--md-primary); padding: 0; }
.status-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--md-outline); }
.status-dot.connected { background: #2e7d32; }
.status-dot.connecting { background: #f9a825; animation: pulse 1s infinite alternate; }
.status-dot.error { background: var(--md-error); }
@keyframes pulse { to { opacity: 0.3; } }
.spinner.small { width: 18px; height: 18px; border-width: 2px; }
.muted { color: var(--md-on-surface-variant); }
.small { font-size: 12px; }
.warning-text { color: var(--md-error); font-size: 13px; }
.section-label { margin: 8px 0 0; font-size: 14px; font-weight: 500; color: var(--md-primary); }
.empty-state { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 64px 24px; text-align: center; color: var(--md-on-surface-variant); }
.empty-state svg { width: 48px; height: 48px; fill: currentColor; opacity: 0.6; }
.empty-title { margin: 0; font-size: 18px; font-weight: 500; color: var(--md-on-surface); }
.empty-desc { margin: 0; font-size: 14px; }

/* ── Fields, dialogs and menus ─────────────────────────────────────────── */
.app-field { position: relative; display: block; }
.app-field input, .app-field textarea {
  display: block; width: 100%; min-height: 56px; padding: 16px; border: 1px solid var(--md-outline); border-radius: 12px;
  background: transparent; color: var(--md-on-surface); font: inherit; font-size: 16px; outline: 0;
}
.app-field textarea { resize: vertical; line-height: 22px; }
.app-field .mono { font-family: var(--mono-font); font-size: 13px; }
.app-field input:focus, .app-field textarea:focus { border: 2px solid var(--md-primary); padding: 15px; }
.app-field-label {
  position: absolute; left: 12px; top: 16px; padding: 0 4px; background: var(--dialog-surface, var(--md-background)); color: var(--md-on-surface-variant);
  font-size: 16px; line-height: 24px; pointer-events: none; transition: top 150ms, font-size 150ms, color 150ms;
}
.app-field input:focus + .app-field-label, .app-field textarea:focus + .app-field-label,
.app-field input:not(:placeholder-shown) + .app-field-label, .app-field textarea:not(:placeholder-shown) + .app-field-label,
.app-field input[type="date"] + .app-field-label, .app-field input[type="time"] + .app-field-label { top: -10px; font-size: 12px; line-height: 16px; }
.app-field input:focus + .app-field-label, .app-field textarea:focus + .app-field-label { color: var(--md-primary); }
.app-field.invalid input, .app-field.invalid textarea { border-color: var(--md-error); }
.app-field-error { display: block; margin: 4px 16px 0; font-size: 12px; color: var(--md-error); }
.settings-card .app-field-label { background: var(--surface-1); }
.app-select { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--md-on-surface-variant); }
.app-select select { min-height: 56px; padding: 0 16px; border: 1px solid var(--md-outline); border-radius: 12px; background: transparent; color: var(--md-on-surface); font: inherit; font-size: 16px; }
.app-select option { background: var(--md-surface-container); color: var(--md-on-surface); }
.form-grid { display: grid; gap: 16px; }
.header-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: center; }
.host-key { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--md-on-surface-variant); overflow-wrap: anywhere; }
.decision-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; }

.app-dialog {
  --dialog-surface: var(--md-surface-container-high, var(--md-surface-container));
  width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); padding: 0; border: 0; border-radius: 28px;
  background: var(--dialog-surface); color: var(--md-on-surface); box-shadow: var(--shadow-8);
  display: flex; flex-direction: column;
}
.app-dialog:not([open]) { display: none; }
.app-dialog.wide { width: min(760px, calc(100vw - 32px)); }
.app-dialog::backdrop { background: rgb(0 0 0 / 0.32); }
.app-dialog > section { padding: 24px 24px 8px; overflow-y: auto; min-height: 0; }
.app-dialog h2 { margin: 0 0 16px; font-size: 24px; line-height: 32px; font-weight: 400; }
.app-dialog-body p { margin: 0 0 8px; font-size: 14px; line-height: 20px; color: var(--md-on-surface-variant); white-space: pre-wrap; }
.app-dialog footer { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; padding: 16px 24px 20px; }
.app-dialog .app-field-label { background: var(--dialog-surface); }
.dialog-tools { display: grid; gap: 8px; margin-bottom: 8px; }
.choice-list { display: flex; flex-direction: column; margin: 0 -24px; }
.choice-list.scroll { max-height: 50dvh; overflow-y: auto; }
.choice {
  position: relative; display: flex; align-items: center; gap: 16px; min-height: 56px; padding: 8px 24px; border: 0; background: transparent;
  color: var(--md-on-surface); font: inherit; font-size: 16px; text-align: start; cursor: pointer;
}
.choice:hover:not(:disabled) { background: var(--state-hover); }
.choice-radio { flex: none; width: 20px; height: 20px; border: 2px solid var(--md-on-surface-variant); border-radius: 50%; }
.choice.selected .choice-radio { border-color: var(--md-primary); background: radial-gradient(var(--md-primary) 0 45%, transparent 50%); }
.choice-text { display: flex; flex-direction: column; min-width: 0; }
.choice-text small { font-size: 13px; color: var(--md-on-surface-variant); overflow-wrap: anywhere; }
.app-menu { position: fixed; z-index: 60; }
.dropdown-item.danger, .dropdown-item.danger svg { color: var(--md-error); fill: var(--md-error); }
.app-snackbar {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 80; max-width: min(560px, calc(100vw - 32px));
  transform: translateX(-50%); padding: 14px 16px; border-radius: 4px; background: var(--md-inverse-surface, #2f312d); color: var(--md-inverse-on-surface, #f0f1eb);
  font-size: 14px; box-shadow: var(--shadow-3);
}
.share-text, .template-preview { margin: 0; padding: 16px; max-height: 50dvh; overflow: auto; border-radius: 12px; background: var(--md-surface-container); font-family: var(--mono-font); font-size: 13px; white-space: pre-wrap; }
.info-lines p { margin: 0 0 8px; color: var(--md-on-surface); }

/* Appearance presets */
.preset-row { align-items: flex-start; }
.preset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 12px; margin-top: 12px; }
.preset { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 0; border: 0; background: transparent; color: var(--md-on-surface); font: inherit; cursor: pointer; }
.preset small { font-size: 12px; }
.preset-swatch { position: relative; display: grid; grid-template-columns: 1fr 1fr; width: 56px; height: 56px; overflow: hidden; border-radius: 50%; background: var(--b, var(--md-surface)); outline: 2px solid transparent; outline-offset: 3px; }
.preset-swatch span:nth-child(1) { grid-column: 1 / 3; background: var(--p, var(--md-primary)); }
.preset-swatch span:nth-child(2) { background: var(--s, var(--md-secondary-container)); }
.preset-swatch span:nth-child(3) { background: var(--t, var(--md-tertiary)); }
.preset.selected .preset-swatch { outline-color: var(--md-primary); }

/* Prompt template editor */
.template-item { display: flex; align-items: flex-start; gap: 8px; }
.template-item .app-field { flex: 1; }
.template-item-actions { display: flex; flex-direction: column; }
.variable-chip { flex: 1; align-self: center; padding: 10px 16px; border-radius: 8px; background: var(--md-secondary-container); color: var(--md-on-secondary-container); font-family: var(--mono-font); font-size: 14px; }
.tabs button { min-height: 40px; }

/* MCP tool list */
.tool-list { display: flex; flex-direction: column; padding: 0 16px 8px 56px; }
.tool-toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--md-outline-variant); }
.tool-toggle span { display: flex; flex-direction: column; min-width: 0; }
.tool-toggle b { font-weight: 500; font-size: 14px; }
.tool-toggle small { font-size: 12px; color: var(--md-on-surface-variant); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.weekday-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.weekday-row button { width: 40px; height: 40px; border: 1px solid var(--md-outline); border-radius: 50%; background: transparent; color: var(--md-on-surface); font: inherit; cursor: pointer; }
.weekday-row button[aria-pressed="true"] { border-color: var(--md-primary); background: var(--md-primary); color: var(--md-on-primary); }
.status-text.success { color: var(--md-primary); }
.status-text.error { color: var(--md-error); }
.about-hero { display: flex; flex-direction: column; align-items: center; gap: 8px; margin: 0 0 24px; text-align: center; }
.about-hero img { width: 72px; height: 72px; }
.about-hero h2 { margin: 0; font-size: 28px; }

/* ── Drawer extensions ─────────────────────────────────────────────────── */
.drawer-section-label { padding: 12px 16px 4px; font-size: 12px; font-weight: 600; color: var(--md-primary); }
.drawer-section-divider { height: 1px; margin: 8px 16px; background: var(--md-outline-variant); }
.drawer-settings {
  flex: none; display: flex; align-items: center; gap: 12px; margin: 8px 12px calc(12px + env(safe-area-inset-bottom)); min-height: 48px; padding: 0 16px;
  border: 0; border-radius: 24px; background: transparent; color: var(--md-on-surface-variant); font: inherit; font-size: 14px; font-weight: 500; cursor: pointer;
}
.drawer-settings:hover { background: var(--state-hover); }
.drawer-settings svg { width: 24px; height: 24px; fill: currentColor; }
.search-results { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 8px; }
.search-empty { padding: 16px; text-align: center; }
.search-result {
  display: flex; flex-direction: column; gap: 2px; width: 100%; padding: 10px 16px; border: 0; border-radius: 16px; background: transparent;
  color: var(--md-on-surface); font: inherit; text-align: start; cursor: pointer;
}
.search-result:hover { background: var(--state-hover); }
.search-result-title { font-size: 14px; font-weight: 500; }
.search-result-snippet { font-size: 13px; color: var(--md-on-surface-variant); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.search-result small { font-size: 11px; color: var(--md-on-surface-variant); }
.search-result mark { background: color-mix(in srgb, var(--md-primary) 30%, transparent); color: inherit; border-radius: 2px; }
.find-bar {
  position: absolute; top: 76px; left: 50%; z-index: 5; display: flex; align-items: center; gap: 4px; width: min(560px, calc(100% - 16px));
  transform: translateX(-50%); padding: 4px 4px 4px 16px; border-radius: 28px; background: var(--md-surface-container); box-shadow: var(--shadow-3);
}
.find-bar > svg { width: 20px; height: 20px; fill: var(--md-on-surface-variant); }
.find-bar input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--md-on-surface); font: inherit; font-size: 16px; }

/* ── Message actions ───────────────────────────────────────────────────── */
.message-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 0; margin: 4px 0 0 0; padding: 0 0 0 0; }
.compact-actions { justify-content: flex-start; margin-left: -4px; }
.action-button {
  display: grid; place-items: center; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 50%; background: transparent;
  color: color-mix(in srgb, var(--md-on-surface-variant) 60%, transparent); cursor: pointer;
}
.action-button:hover:not(:disabled) { background: var(--state-hover); color: var(--md-on-surface-variant); }
.action-button:disabled { opacity: 0.5; cursor: default; }
.action-button svg { width: 17px; height: 17px; fill: currentColor; }
.branch-selector { display: inline-flex; align-items: center; margin-left: 4px; }
.branch-count { min-width: 28px; text-align: center; font-size: 12px; font-weight: 500; color: var(--md-on-surface-variant); }
.user-row { flex-direction: column; align-items: flex-end; }
.user-actions { display: flex; align-items: center; justify-content: flex-end; gap: 0; margin-top: 2px; opacity: 0; transition: opacity 150ms; }
.message-row:hover .user-actions, .user-actions:focus-within, .user-actions:has(.branch-selector) { opacity: 1; }
@media (hover: none) { .user-actions { opacity: 1; } }
.message-source { margin-bottom: 4px; font-size: 12px; font-weight: 500; color: var(--md-primary); }
.ask-user-answers { flex-direction: column; align-items: stretch; gap: 8px; }
.ask-answer { display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.ask-answer b { font-weight: 600; }
.user-edit { width: min(100%, 560px); padding: 12px; border-radius: 24px; background: var(--md-surface-container); }
.user-edit textarea { width: 100%; min-height: 60px; border: 0; outline: 0; resize: vertical; background: transparent; color: var(--md-on-surface); font: inherit; font-size: 16px; line-height: 23px; }
.user-edit-actions { display: flex; justify-content: flex-end; gap: 8px; }
.message-attachments { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; max-width: 300px; margin-bottom: 6px; }
.message-image { position: relative; width: 96px; height: 96px; padding: 0; overflow: hidden; border: 0; border-radius: 16px; background: var(--md-surface-container); cursor: zoom-in; }
.message-image img { width: 100%; height: 100%; object-fit: cover; }
.image-count { position: absolute; right: 6px; bottom: 6px; padding: 0 6px; border-radius: 8px; background: rgb(0 0 0 / 0.6); color: #fff; font-size: 12px; }
.message-file { display: flex; align-items: center; gap: 8px; max-width: 240px; padding: 8px 12px; border: 0; border-radius: 16px; background: var(--md-surface-container); color: var(--md-on-surface); font: inherit; font-size: 13px; }
.message-file small { flex: none; padding: 2px 4px; border-radius: 4px; background: var(--md-primary); color: var(--md-on-primary); font-size: 10px; font-weight: 700; }
.message-file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.generated-images { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 240px)); gap: 8px; padding: 8px 8px 0; }
.generated-image { aspect-ratio: 1; padding: 0; overflow: hidden; border: 0; border-radius: 12px; background: var(--md-surface-container); cursor: zoom-in; }
.generated-image img { width: 100%; height: 100%; object-fit: cover; }
.image-viewer { background: transparent; box-shadow: none; width: min(100vw, 1200px); }
.image-viewer > section { padding: 0; }
.image-viewer-body { position: relative; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.image-viewer-body img { max-width: 100%; max-height: calc(100dvh - 120px); border-radius: 12px; object-fit: contain; }
.image-viewer-nav { display: flex; align-items: center; gap: 12px; padding: 4px 12px; border-radius: 20px; background: var(--md-surface-container); }
.image-viewer-close { position: absolute; top: 8px; right: 8px; background: rgb(0 0 0 / 0.5); color: #fff; }

/* ── Interaction bar and Loop bar (above the composer) ─────────────────── */
.composer-stack { flex: none; position: relative; z-index: 2; display: flex; flex-direction: column; gap: 8px; max-width: 840px; width: 100%; margin: 0 auto; padding: 0 8px; }
.composer-stack:empty { display: none; }
.interaction-bar {
  position: relative; padding: 16px; border-radius: 28px; background: var(--md-surface-container); box-shadow: var(--shadow-3);
  animation: lift 220ms cubic-bezier(0.2, 0, 0, 1);
}
@keyframes lift { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.interaction-minimize { position: absolute; top: 8px; right: 8px; width: 32px; height: 32px; }
.interaction-minimize svg { width: 18px; height: 18px; }
.interaction-pill { align-self: center; display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 16px; border: 0; border-radius: 20px; background: var(--md-primary-container); color: var(--md-on-primary-container); font: inherit; font-weight: 500; cursor: pointer; box-shadow: var(--shadow-3); }
.interaction-pill svg { width: 18px; height: 18px; fill: currentColor; }
.approval h3, .question-card h3 { display: flex; align-items: center; gap: 8px; margin: 0 32px 12px 0; font-size: 16px; line-height: 22px; font-weight: 500; }
.approval h3 svg { width: 20px; height: 20px; fill: var(--md-primary); flex: none; }
.approval-summary { margin: 0 0 12px; padding: 12px; max-height: 180px; overflow: auto; border-radius: 12px; background: var(--md-surface-container-highest, var(--md-surface-variant)); font-family: var(--mono-font); font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; }
.approval-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; margin-top: 8px; }
.question-label { margin: 0 0 4px; font-size: 12px; font-weight: 500; color: var(--md-primary); }
.question-options { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.question-option { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 14px; border: 1px solid var(--md-outline); border-radius: 18px; background: transparent; color: var(--md-on-surface); font: inherit; font-size: 14px; cursor: pointer; }
.question-option.selected { border-color: var(--md-secondary-container); background: var(--md-secondary-container); color: var(--md-on-secondary-container); }
.question-option svg { width: 16px; height: 16px; fill: currentColor; }
.interaction-bar .app-field-label { background: var(--md-surface-container); }
.loop-bar { display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 16px; border-radius: 24px; background: var(--md-secondary-container); color: var(--md-on-secondary-container); }
.loop-text { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.loop-text b { font-size: 14px; font-weight: 500; }
.loop-text small { font-size: 12px; opacity: 0.8; }

@media (max-width: 600px) {
  .page-content { padding-left: 16px; padding-right: 16px; }
  .page-big-title { font-size: 28px; line-height: 36px; }
  .header-row { grid-template-columns: 1fr; }
}

/* ── Drawer Tasks / Remote pair and the Remote screens ─────────────────── */
.drawer-pair { display: flex; gap: 8px; }
.drawer-pair .drawer-button { flex: 1; }
.remote-status { display: flex; align-items: center; gap: 8px; margin: -12px 0 16px; font-size: 13px; color: var(--md-on-surface-variant); }
.remote-messages { display: flex; flex-direction: column; gap: 16px; }
.remote-assistant { display: flex; flex-direction: column; gap: 4px; }
.remote-activity { border-radius: 16px; background: var(--surface-1); }
.remote-activity-head { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 40px; padding: 0 12px; border: 0; background: transparent; color: var(--md-on-surface-variant); font: inherit; font-size: 13px; cursor: pointer; }
.remote-activity-head svg { width: 18px; height: 18px; fill: var(--md-primary); }
.remote-activity-body pre { margin: 0 12px 12px; padding: 10px; max-height: 240px; overflow: auto; border-radius: 10px; background: var(--md-surface-container); font-family: var(--mono-font); font-size: 12px; white-space: pre-wrap; }
.remote-hint { margin: 16px 0 8px; text-align: center; }
.remote-composer { position: sticky; bottom: 8px; display: flex; align-items: flex-end; gap: 8px; padding: 8px; border-radius: 28px; background: var(--tonal-2, var(--md-surface-container)); box-shadow: var(--shadow-8); }
.remote-composer textarea { flex: 1; min-height: 44px; max-height: 200px; padding: 10px 12px; border: 0; outline: 0; resize: vertical; background: transparent; color: var(--md-on-surface); font: inherit; font-size: 16px; }
.remote-composer .filled-button { width: 44px; height: 44px; padding: 0; border-radius: 50%; }
.usage-limit { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.usage-window { display: flex; flex-direction: column; gap: 4px; }
.usage-bar { height: 8px; border-radius: 4px; background: var(--md-surface-container-highest, var(--md-surface-variant)); overflow: hidden; }
.usage-bar span { display: block; height: 100%; background: var(--md-primary); }

/* ── Onboarding (WelcomeScreen) ────────────────────────────────────────── */
.onboarding { position: fixed; inset: 0; z-index: 40; display: flex; flex-direction: column; align-items: center; padding: 24px 24px calc(24px + env(safe-area-inset-bottom)); background: var(--md-background); color: var(--md-on-background); }
.onboarding-skip { position: absolute; top: 16px; right: 16px; }
.onboarding-body { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; width: min(560px, 100%); text-align: center; animation: page-enter 300ms cubic-bezier(0.2, 0, 0, 1); }
.onboarding-media { display: grid; place-items: center; width: 100%; min-height: 0; max-height: 52dvh; margin-bottom: 24px; overflow: auto; }
.onboarding-video { width: min(360px, 100%); max-height: 46dvh; border-radius: 28px; object-fit: cover; }
.onboarding-body h1 { margin: 0 0 12px; font-size: 28px; line-height: 36px; font-weight: 700; }
.onboarding-body p { margin: 0; max-width: 460px; font-size: 16px; line-height: 24px; color: var(--md-on-surface-variant); }
.onboarding-providers { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; width: 100%; }
.onboarding-provider { position: relative; display: flex; align-items: center; gap: 10px; min-height: 56px; padding: 0 14px; border: 1px solid var(--md-outline-variant); border-radius: 16px; background: var(--surface-1); color: var(--md-on-surface); font: inherit; font-size: 14px; cursor: pointer; text-align: start; }
.onboarding-provider.selected { border-color: var(--md-primary); background: var(--md-secondary-container); color: var(--md-on-secondary-container); }
.onboarding-provider img { width: 24px; height: 24px; }
.provider-letter { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--md-primary); color: var(--md-on-primary); font-size: 13px; font-weight: 700; }
.provider-check { position: absolute; top: 6px; right: 6px; }
.provider-check svg { width: 16px; height: 16px; fill: var(--md-primary); }
.onboarding-form { display: grid; gap: 16px; width: 100%; text-align: start; }
.onboarding-models { display: flex; flex-direction: column; width: 100%; max-height: 46dvh; overflow-y: auto; text-align: start; }
.onboarding-models .choice { margin: 0; }
.onboarding-dots { display: flex; gap: 8px; margin: 16px 0; }
.onboarding-dots .dot { width: 8px; height: 8px; padding: 0; border: 0; border-radius: 4px; background: var(--md-outline-variant); cursor: pointer; transition: width 200ms; }
.onboarding-dots .dot.active { width: 24px; background: var(--md-primary); }
.onboarding-next { width: min(360px, 100%); height: 52px; border-radius: 26px; font-size: 16px; }

.provider-logo { display: inline-block; flex: none; width: 24px; height: 24px; background: currentColor; -webkit-mask: var(--logo) center / contain no-repeat; mask: var(--logo) center / contain no-repeat; }
.settings-row-icon .provider-logo { color: var(--md-primary); }
.settings-row-icon .provider-letter { width: 24px; height: 24px; font-size: 12px; }
