/* ============================================================
   AI Agent page (STEP 4.8)
   Ported from _design/zain-os/project/Automation - A.html
   ============================================================ */

.aa-hd { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.aa-hd h1 { font-size: 22px; font-weight: 500; letter-spacing: -0.01em; line-height: 1; margin: 0; color: var(--text); }
.aa-hd .sub { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }
.aa-hd-right { display: flex; align-items: center; gap: 10px; }

.aa-server-pill { display: inline-flex; align-items: center; gap: 8px; padding: 0 12px; height: 30px; background: var(--card); border: 1px solid var(--border); border-radius: var(--r-sm); font-size: 12px; color: var(--text); font-family: var(--font-mono); }
.aa-server-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: #6A8A70; box-shadow: 0 0 0 3px rgba(106,138,112,0.15); }
.aa-server-pill.off .dot { background: var(--danger); box-shadow: 0 0 0 3px rgba(161,63,40,0.15); }

/* Master switch */
.aa-master { display: flex; align-items: center; gap: 18px; padding: 16px 22px; background: var(--card); border: 1px solid var(--border-light); border-radius: var(--r-sm); margin-bottom: 22px; flex-wrap: wrap; }
.aa-master .label { font-size: 13px; color: var(--text-secondary); }
.aa-master .state { font-size: 16px; font-weight: 500; letter-spacing: -0.005em; }
.aa-master .state.on { color: #6A8A70; }
.aa-master .state.off { color: var(--danger); }
.aa-master .since { font-size: 11px; color: var(--text-tertiary); font-family: var(--font-mono); margin-left: 4px; }
.aa-master .spacer { flex: 1; min-width: 20px; }
.aa-master .today { font-size: 12px; color: var(--text-secondary); }
.aa-master .today strong { color: var(--text); font-variant-numeric: tabular-nums; }

.aa-switch { position: relative; width: 44px; height: 24px; border-radius: 12px; background: var(--brand); cursor: pointer; transition: background var(--dur-default) var(--ease); border: 0; padding: 0; flex-shrink: 0; }
.aa-switch::after { content: ''; position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: right var(--dur-default) var(--ease); }
.aa-switch.off { background: var(--border); }
.aa-switch.off::after { right: 22px; }

.aa-kill { height: 30px; padding: 0 14px; background: transparent; border: 1px solid var(--border); border-radius: var(--r-sm); color: var(--text); font-size: 12px; font-weight: 500; cursor: pointer; font-family: inherit; }
.aa-kill:hover { border-color: var(--brand-dim); }
.aa-kill.danger { color: var(--danger); border-color: var(--danger); }
.aa-kill.danger:hover { background: rgba(161,63,40,0.08); }

/* Grid layout */
.aa-grid { display: grid; grid-template-columns: 200px 1fr; gap: 24px; }
@media (max-width: 900px) { .aa-grid { grid-template-columns: 1fr; } }

.aa-rail-tabs { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; align-self: start; }
.aa-rail-tabs .tab { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--r-sm); color: var(--text-secondary); font-size: 13px; font-weight: 500; cursor: pointer; text-decoration: none; background: transparent; border: 0; font-family: inherit; text-align: left; width: 100%; }
.aa-rail-tabs .tab:hover { color: var(--text); background: var(--hover); }
.aa-rail-tabs .tab.is-active { background: var(--brand-soft); color: var(--brand); }
.aa-rail-tabs .tab svg { width: 14px; height: 14px; }
.aa-rail-tabs .tab .n { margin-left: auto; font-family: var(--font-mono); font-size: 10px; color: var(--text-tertiary); }
.aa-rail-tabs .tab.is-active .n { color: var(--brand); }
.aa-rail-sep { height: 1px; background: var(--border-light); margin: 8px 0; }

.aa-card { background: var(--card); border: 1px solid var(--border-light); border-radius: var(--r-sm); padding: 18px 20px; }
.aa-card-hd { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.aa-card-hd h3 { font-size: 13px; font-weight: 500; margin: 0; letter-spacing: -0.005em; color: var(--text); }
.aa-card-hd .sub { font-size: 11.5px; color: var(--text-tertiary); }
.aa-card-hd .spacer { flex: 1; }
.aa-card-hd a { font-size: 11.5px; color: var(--brand); text-decoration: none; cursor: pointer; }

.aa-ov-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; align-items: stretch; }
.aa-ov-grid > * { height: 100%; min-width: 0; }
@media (max-width: 900px) { .aa-ov-grid { grid-template-columns: 1fr; } }

.aa-health-list { display: flex; flex-direction: column; gap: 9px; }
.aa-health-row { display: grid; grid-template-columns: 10px 1fr auto; gap: 12px; align-items: center; font-size: 12.5px; }
.aa-health-row .dot { width: 8px; height: 8px; border-radius: 50%; background: #6A8A70; }
.aa-health-row .dot.warn { background: #C99A52; }
.aa-health-row .dot.dead { background: var(--danger); }
.aa-health-row .lbl { color: var(--text); }
.aa-health-row .det { color: var(--text-secondary); font-size: 11px; }
.aa-health-row .val { color: var(--text-secondary); font-family: var(--font-mono); font-size: 11px; }

.aa-stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.aa-stat { padding: 12px 0; }
.aa-stat .l { font-size: 10px; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.06em; font-family: var(--font-mono); margin-bottom: 6px; }
.aa-stat .v { font-size: 22px; font-weight: 500; color: var(--text); letter-spacing: -0.01em; font-variant-numeric: tabular-nums; line-height: 1; }
.aa-stat .d { font-size: 11px; color: var(--text-secondary); margin-top: 5px; }
.aa-stat .d.up { color: #6A8A70; }
.aa-stat .d.dn { color: var(--text-tertiary); }

.aa-alert-banner { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: rgba(201,154,82,0.08); border: 1px solid rgba(201,154,82,0.25); border-radius: var(--r-sm); margin-bottom: 16px; font-size: 12.5px; color: var(--text); }
.aa-alert-banner .ic { color: #C99A52; font-size: 16px; }
.aa-alert-banner strong { font-weight: 600; }
.aa-alert-banner .sp { flex: 1; }
.aa-alert-banner button { height: 26px; padding: 0 10px; background: transparent; border: 1px solid rgba(201,154,82,0.4); color: #C99A52; border-radius: var(--r-sm); font-size: 11.5px; font-weight: 500; cursor: pointer; font-family: inherit; }

.aa-toggle-list { display: flex; flex-direction: column; }
.aa-toggle-row { display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: center; padding: 12px 0; border-top: 1px solid var(--border-light); }
.aa-toggle-row:first-child { border-top: 0; padding-top: 0; }
.aa-toggle-row .t-name { font-size: 13px; font-weight: 500; color: var(--text); letter-spacing: -0.005em; }
.aa-toggle-row .t-desc { font-size: 11.5px; color: var(--text-secondary); margin-top: 2px; line-height: 1.45; max-width: 560px; }

/* Prompt editor */
.aa-section-title { font-size: 13px; font-weight: 500; margin: 28px 0 12px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.08em; font-family: var(--font-mono); }
.aa-prompt-grid { display: grid; grid-template-columns: 1fr 260px; gap: 16px; }
@media (max-width: 900px) { .aa-prompt-grid { grid-template-columns: 1fr; } }
.aa-prompt-editor { background: var(--card); border: 1px solid var(--border-light); border-radius: var(--r-sm); overflow: hidden; }
.aa-pe-hd { display: flex; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--border-light); gap: 10px; flex-wrap: wrap; }
.aa-pe-hd h3 { font-size: 13px; font-weight: 500; margin: 0; letter-spacing: -0.005em; color: var(--text); }
.aa-pe-hd .version { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-tertiary); background: var(--bg); padding: 2px 6px; border-radius: var(--r-sm); }
.aa-pe-hd .spacer { flex: 1; }
.aa-pe-hd button { height: 26px; padding: 0 10px; background: transparent; border: 1px solid var(--border); border-radius: var(--r-sm); color: var(--text-secondary); font-size: 11.5px; font-weight: 500; cursor: pointer; font-family: inherit; }
.aa-pe-hd button:hover { color: var(--text); border-color: var(--brand-dim); }
.aa-pe-hd .save { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.aa-pe-hd .save:hover { background: var(--brand-hover); }

.aa-pe-body { font-family: var(--font-mono); font-size: 12px; line-height: 1.65; color: var(--text); padding: 18px 20px; white-space: pre-wrap; min-height: 340px; outline: none; resize: vertical; width: 100%; background: var(--card); border: 0; box-sizing: border-box; }
.aa-pe-body:focus { outline: 0; }
.aa-pe-foot { display: flex; align-items: center; padding: 10px 18px; border-top: 1px solid var(--border-light); gap: 14px; font-size: 11px; color: var(--text-tertiary); font-family: var(--font-mono); }
.aa-pe-foot .right { margin-left: auto; }

.aa-pe-side { display: flex; flex-direction: column; gap: 14px; align-self: stretch; min-height: 0; }
.aa-pe-side .aa-card { padding: 14px 16px; }
.aa-var-list { display: flex; flex-direction: column; gap: 2px; }
.aa-var-item { display: flex; align-items: center; padding: 5px 8px; margin: 0 -8px; border-radius: 4px; cursor: pointer; font-size: 11.5px; color: var(--text); font-family: var(--font-mono); background: transparent; border: 0; width: calc(100% + 16px); text-align: left; }
.aa-var-item:hover { background: var(--hover); }
.aa-var-item .v { color: var(--brand); }
.aa-var-item .lbl { color: var(--text-secondary); margin-left: auto; font-family: var(--font-sans); font-size: 11px; }

.aa-test-panel { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.aa-test-panel textarea { width: 100%; min-height: 80px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 10px 12px; font-family: inherit; font-size: 12.5px; color: var(--text); resize: vertical; flex: 1 1 0; box-sizing: border-box; }
.aa-test-panel textarea:focus { outline: none; border-color: var(--brand); }
.aa-test-panel button { margin-top: 8px; width: 100%; height: 30px; background: var(--brand); border: 0; border-radius: var(--r-sm); color: #fff; font-size: 12px; font-weight: 600; cursor: pointer; font-family: inherit; }
.aa-test-panel button:hover { background: var(--brand-hover); }
.aa-test-out { margin-top: 10px; padding: 10px 12px; background: var(--bg); border: 1px solid var(--border-light); border-radius: var(--r-sm); font-size: 12px; color: var(--text); line-height: 1.5; max-height: 220px; overflow-y: auto; }
.aa-test-out .tag { font-size: 9px; color: var(--brand); text-transform: uppercase; letter-spacing: 0.06em; font-family: var(--font-mono); margin-bottom: 4px; display: block; }

/* Rules */
.aa-rule-row { display: grid; grid-template-columns: 260px 1fr; gap: 18px; align-items: center; padding: 14px 0; border-top: 1px solid var(--border-light); }
.aa-rule-row:first-child { border-top: 0; padding-top: 0; }
.aa-rule-row .r-label { font-size: 13px; font-weight: 500; color: var(--text); }
.aa-rule-row .r-label .desc { font-size: 11.5px; font-weight: 400; color: var(--text-secondary); margin-top: 2px; line-height: 1.45; }
.aa-rule-row .r-body { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.aa-rule-row input[type=number], .aa-rule-row input[type=text] { width: 80px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 6px 10px; color: var(--text); font-family: var(--font-mono); font-size: 12px; font-variant-numeric: tabular-nums; }
.aa-rule-row input:focus { outline: none; border-color: var(--brand); }
.aa-rule-row .unit { font-size: 11.5px; color: var(--text-secondary); }

.aa-tag-input { display: flex; flex-wrap: wrap; gap: 5px; padding: 6px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-sm); width: 100%; box-sizing: border-box; }
.aa-tag-input .tag { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; background: var(--brand-soft); color: var(--brand); border-radius: var(--r-pill); font-size: 11px; font-family: var(--font-mono); }
.aa-tag-input .tag .x { cursor: pointer; opacity: 0.7; }
.aa-tag-input .tag .x:hover { opacity: 1; }
.aa-tag-input input { border: 0; background: transparent; color: var(--text); font-size: 12px; font-family: inherit; min-width: 80px; padding: 3px 4px; outline: none; flex: 1; }

/* ───────── Voice tab (phrase editor) ───────── */

.aa-voice-intro { font-size: 12.5px; color: var(--text-secondary); margin: -4px 0 16px; line-height: 1.5; max-width: 720px; }

.aa-voice-group { padding: 18px 20px 8px; }
.aa-voice-group .aa-card-hd { margin-bottom: 8px; align-items: baseline; }
.aa-voice-group .aa-card-hd h3 { font-size: 13px; }
.aa-voice-group .aa-card-hd .sub { font-size: 11.5px; color: var(--text-tertiary); }
.aa-voice-group + .aa-voice-group { margin-top: 14px; }

.aa-voice-pair { padding: 12px 0 14px; border-top: 1px solid var(--border-light); }
.aa-voice-pair:first-of-type { border-top: 0; padding-top: 4px; }
.aa-voice-when { font-size: 11.5px; color: var(--text-tertiary); margin-bottom: 8px; letter-spacing: 0.01em; }

.aa-voice-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 720px) { .aa-voice-fields { grid-template-columns: 1fr; } }

.aa-voice-field { position: relative; display: block; }
.aa-voice-field .lang { position: absolute; top: 7px; left: 9px; font-size: 9.5px; font-family: var(--font-mono); font-weight: 600; letter-spacing: 0.10em; color: var(--text-tertiary); padding: 2px 6px; background: rgba(255,255,255,0.04); border-radius: 4px; pointer-events: none; z-index: 1; }
.aa-voice-field textarea {
  width: 100%;
  min-height: 36px;
  max-height: 160px;
  padding: 9px 12px 9px 44px;
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  line-height: 1.5;
  resize: none;
  outline: 0;
  box-sizing: border-box;
  transition: border-color 160ms, background 160ms;
  overflow: hidden;
}
.aa-voice-field textarea:focus {
  border-color: var(--brand);
  background: rgba(232, 97, 58, 0.04);
}
.aa-voice-field textarea::placeholder {
  color: var(--text-tertiary);
  opacity: 0.7;
}
/* Pre-filled defaults look identical to user-customized text — no faded
 * "you haven't touched this" tinting. The is-default class is still set
 * on the wrapper so the save logic can skip persisting unchanged values. */
/* RTL textareas: badge on the right, padding shifted accordingly */
.aa-voice-field textarea[dir="rtl"] { padding: 9px 44px 9px 12px; }
.aa-voice-field:has(textarea[dir="rtl"]) .lang { left: auto; right: 9px; }

/* ───────────────────────────────────────── Insights tab ───────────────── */
.aa-ins-windows { display: inline-flex; gap: 4px; }
.aa-ins-win { height: 24px; padding: 0 10px; background: transparent; border: 1px solid var(--border); border-radius: var(--r-sm); color: var(--text-secondary); font-size: 11px; font-family: var(--font-mono); cursor: pointer; }
.aa-ins-win:hover { color: var(--text); border-color: var(--brand-dim); }
.aa-ins-win.is-active { background: var(--brand-soft); color: var(--brand); border-color: var(--brand-soft); }

.aa-ins-health { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 700px) { .aa-ins-health { grid-template-columns: 1fr; } }
.aa-ins-tile { background: var(--hover); border: 1px solid var(--border-light); border-radius: var(--r-sm); padding: 14px 16px; }
.aa-ins-tile .l { font-size: 11.5px; color: var(--text-secondary); margin-bottom: 6px; }
.aa-ins-tile .v { font-size: 22px; font-weight: 500; color: var(--text); letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.aa-ins-tile .v .u { font-size: 13px; color: var(--text-tertiary); margin-left: 2px; font-weight: 400; }
.aa-ins-tile .d { font-size: 11px; color: var(--text-tertiary); margin-top: 4px; }
.aa-ins-pct.good { color: #6A8A70; }
.aa-ins-pct.warn { color: #B58A3F; }
.aa-ins-pct.bad { color: var(--danger); }

.aa-ins-patch { padding: 12px 0; border-top: 1px solid var(--border-light); }
.aa-ins-patch:first-child { border-top: 0; padding-top: 4px; }
.aa-ins-patch-meta { display: flex; gap: 12px; align-items: baseline; font-size: 10.5px; color: var(--text-tertiary); font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; }
.aa-ins-patch-meta .ts { color: var(--text-tertiary); }
.aa-ins-patch-meta .lat { color: var(--text-tertiary); }
.aa-ins-patch-meta .tools { color: var(--brand); flex: 1; text-transform: none; letter-spacing: 0; }
.aa-ins-patch-meta .link { color: var(--brand); cursor: pointer; text-decoration: none; text-transform: none; letter-spacing: 0; font-family: inherit; font-size: 11.5px; }
.aa-ins-patch-meta .link:hover { text-decoration: underline; }
.aa-ins-patch-text { font-size: 13px; color: var(--text); line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.aa-ins-patch-reply { font-size: 11px; color: var(--text-tertiary); margin-top: 4px; font-family: var(--font-mono); }

.aa-ins-rule-table { display: flex; flex-direction: column; }
.aa-ins-rule-row { display: grid; grid-template-columns: 1fr 80px 140px; gap: 12px; padding: 8px 0; border-top: 1px solid var(--border-light); font-size: 12px; align-items: baseline; }
.aa-ins-rule-row:first-child { border-top: 0; }
.aa-ins-rule-row.hd { font-size: 10.5px; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.04em; font-family: var(--font-mono); padding-bottom: 6px; }
.aa-ins-rule-row .rule { font-family: var(--font-mono); color: var(--text); font-size: 11.5px; word-break: break-all; }
.aa-ins-rule-row .num { font-variant-numeric: tabular-nums; color: var(--text); text-align: right; }
.aa-ins-rule-row .ts { color: var(--text-tertiary); font-size: 11px; }

/* ============================================================
   Responsive (additive only — desktop unchanged above)
   ============================================================ */

@media (max-width: 1024px) {
  /* Sidebar rail collapses above main; lose sticky so it doesn't pin */
  .aa-grid { grid-template-columns: 1fr; gap: 16px; }
  .aa-rail-tabs { position: static; flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .aa-rail-tabs .tab { width: auto; flex: 0 0 auto; }
  .aa-rail-sep { display: none; }

  /* Overview tiles + prompt grid collapse */
  .aa-ov-grid { grid-template-columns: 1fr; }
  .aa-prompt-grid { grid-template-columns: 1fr; }
  .aa-stat-grid { grid-template-columns: repeat(2, 1fr); }
  .aa-ins-health { grid-template-columns: repeat(2, 1fr); }

  /* Rule rows: stack label above body */
  .aa-rule-row { grid-template-columns: 1fr; gap: 8px; }

  /* Insights rule rows: horizontal scroll for tabular data */
  .aa-ins-rule-table { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .aa-ins-rule-row { min-width: 520px; }
}

@media (max-width: 640px) {
  /* Header wraps */
  .aa-hd { gap: 10px; }
  .aa-hd-right { width: 100%; justify-content: flex-start; flex-wrap: wrap; }

  /* Master switch: stack pieces */
  .aa-master { padding: 12px 14px; gap: 12px; }
  .aa-master .spacer { display: none; }
  .aa-master .today { width: 100%; }

  /* Cards: tighter padding */
  .aa-card { padding: 14px 14px; }
  .aa-pe-hd { padding: 10px 12px; }
  .aa-pe-body { padding: 14px 14px; min-height: 240px; }

  /* Stat / health grids collapse to single col */
  .aa-stat-grid { grid-template-columns: 1fr; }
  .aa-ins-health { grid-template-columns: 1fr; }

  /* Toggles + rules: stack & wrap controls */
  .aa-toggle-row { grid-template-columns: 1fr; gap: 8px; }
  .aa-rule-row { gap: 6px; }
  .aa-rule-row .r-body { width: 100%; }

  /* Voice fields already collapse at 720px */

  /* Prevent iOS zoom-on-focus */
  .aa-rule-row input[type=number],
  .aa-rule-row input[type=text],
  .aa-test-panel textarea,
  .aa-pe-body,
  .aa-voice-field textarea,
  .aa-tag-input input { font-size: 16px; }

  /* Insights window selector wraps */
  .aa-ins-windows { flex-wrap: wrap; }
}

@media (hover: none) and (pointer: coarse) {
  /* Touch tap targets */
  .aa-kill,
  .aa-pe-hd button,
  .aa-test-panel button,
  .aa-ins-win,
  .aa-alert-banner button { min-height: 36px; }
  .aa-rail-tabs .tab { min-height: 36px; }
  .aa-var-item { min-height: 36px; }
  /* Switches are pure tap targets — keep them at desktop size so they don't
     visually dominate, but ensure the click box is at least 36px wide. */
  .aa-switch { min-width: 44px; }
}

/* ============================================================
   Responsive — gap fixes (additive only)
   Targets long-form prompts, voice textareas, inline-styled
   followup templates, and insight rows so nothing overflows
   at 375px.
   ============================================================ */

@media (max-width: 1024px) {
  /* Card header on prompt editor may wrap with multiple buttons */
  .aa-pe-hd { row-gap: 6px; }
  .aa-pe-hd .version { margin-left: 0; }

  /* Toggle row description may overflow; let it use the full width */
  .aa-toggle-row .t-desc { max-width: 100%; }

  /* Voice intro / followup intro should never push the card wider */
  .aa-voice-intro { max-width: 100%; }

  /* Insights patch text — let long URLs/IDs wrap */
  .aa-ins-patch-text,
  .aa-ins-patch-reply,
  .aa-ins-patch-meta { word-break: break-word; }
  .aa-ins-patch-meta { flex-wrap: wrap; row-gap: 4px; }

  /* Master switch label cluster wraps cleanly */
  .aa-master .state { white-space: nowrap; }
  .aa-master .since { white-space: nowrap; }

  /* Server pill must remain readable; keep mono font but allow shrink */
  .aa-server-pill { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* Follow-up template textareas have inline min-width:280px; cap it so they
     fit a 360px viewport without horizontal overflow inside the card */
  textarea[id^="aa-fu-tpl-"] { min-width: 0 !important; width: 100% !important; }
}

@media (max-width: 640px) {
  /* Header: title can shrink slightly */
  .aa-hd h1 { font-size: 18px; }
  .aa-hd .sub { font-size: 12px; }

  /* Card body padding for prompt editor — already shrunk; ensure textarea
     resizable handle stays usable */
  .aa-pe-body { font-size: 16px; line-height: 1.6; min-height: 220px; }

  /* Test panel button stays full-width but make the textarea max-height
     reasonable so it doesn't dominate the viewport */
  .aa-test-panel textarea { max-height: 50vh; }
  .aa-test-out { max-height: 200px; word-break: break-word; }

  /* Variables list: scroll if too tall */
  .aa-var-list { max-height: 240px; overflow-y: auto; }

  /* Rule body wraps; ensure inputs share the row */
  .aa-rule-row .r-body { gap: 6px; }
  .aa-rule-row input[type=number],
  .aa-rule-row input[type=text] { width: auto; min-width: 80px; flex: 0 1 auto; }

  /* Tag input grows to full width and inputs are usable */
  .aa-tag-input { padding: 8px; }
  .aa-tag-input input { width: 100%; min-width: 120px; }

  /* Voice when label + textareas */
  .aa-voice-pair { padding: 10px 0 12px; }
  .aa-voice-field textarea { max-height: 50vh; }

  /* Health rows: shrink details to fit narrow widths */
  .aa-health-row { grid-template-columns: 10px 1fr auto; column-gap: 8px; }
  .aa-health-row .det { display: none; }

  /* Stat tiles: tighter padding */
  .aa-stat { padding: 8px 0; }
  .aa-stat .v { font-size: 18px; }

  /* Insights tile + window selector */
  .aa-ins-tile { padding: 12px 14px; }
  .aa-ins-tile .v { font-size: 18px; }

  /* Alert banner stacks the button below the message */
  .aa-alert-banner { flex-wrap: wrap; padding: 10px 12px; }
  .aa-alert-banner .sp { flex: 1 1 100%; }

  /* Followup card header buttons stack/wrap cleanly */
  .aa-card-hd { flex-wrap: wrap; row-gap: 6px; }

  /* Followup template textareas: cap height on phone */
  textarea[id^="aa-fu-tpl-"] { font-size: 16px !important; max-height: 40vh; }
}