/* The Automation page: rule cards, the three-block builder, and the run log.
   styles.css already carries .au-line, .au-key and .au-action from the old
   modal; those are reused rather than renamed so the two never disagree. */

/* icon() emits an SVG with no width or height and there is a global
   svg { width:16px; height:16px }. Everything below that wants a different
   size has to say so, or the arrows between blocks come out as 16px stubs. */

/* ---- Feature search in the top bar ----
   The markup reuses .search, .search-pop and .hit from styles.css so the two
   boxes behave identically; only the differences are here. It lives in this
   sheet rather than styles.css because styles.css is shared and off limits
   during a parallel batch, and this is the sheet this batch owns. */

/* Sizing only applies while the top bar is one row. styles.css already turns
   the bar into a wrapped stack at 860px and makes .search full width, and
   because the feature box carries the same .search class it inherits that: the
   two boxes end up on separate full-width rows, which is clearer separation
   than anything achievable side by side on a phone. Overriding the widths
   unconditionally broke exactly that, and left the two boxes 8px apart with
   the feature box wider than the lead box. */
@media (min-width: 861px) {
  /* The spacer is the separation the spec asked for, so it gets a floor
     rather than being the first thing flex gives up. */
  .topbar .spacer { min-width: 44px; }
  .topbar .search:not(.feature-search) { min-width: 190px; }
  .topbar .feature-search {
    flex: 0 1 240px;
    max-width: 260px;
    min-width: 118px;
  }
  /* The popup hangs off the right edge, since the box sits at the right end. */
  .topbar .feature-search .search-pop { left: auto; right: 0; min-width: 320px; }
}

/* Below that, its own full row under the lead search. `width: 100%` in
   styles.css does not do it on its own: .topbar .search is `flex: 1 1 0%`, so
   the two boxes just split one row between them and land 8px apart. The
   flex-basis is what actually claims the row. */
@media (max-width: 860px) {
  .topbar .search { flex: 1 0 100%; max-width: none; }
  .topbar .feature-search { order: 4; }
}
/* Visibly the quieter of the two: the lead search is the one people use all
   day, and a second box shouting for attention beside it is the confusion the
   spec asked to avoid. */
.topbar .feature-search input {
  background: transparent;
  border-style: dashed;
  font-size: 13px;
}
.topbar .feature-search input:focus { border-style: solid; background: #fff; }
.topbar .feature-search .search-pop svg { width: 13px; height: 13px; color: var(--muted); flex: none; }

.feat-where { display: block; }
.feat-hint { cursor: default; font-size: 12px; border-top: 1px solid var(--border); }
.feat-hint:hover { background: none; }

/* ---- Rule cards ---- */

.au-rules { display: grid; gap: 10px; }

.au-rule { transition: border-color .12s; }
.au-rule.off { opacity: .78; }
.au-rule.on { border-left: 3px solid var(--green); }
.au-rule .card-head { gap: 9px; align-items: center; flex-wrap: wrap; }
.au-flow { padding: 12px 16px; }
.au-flow .au-line span:last-child { min-width: 0; overflow-wrap: anywhere; }

.au-kind { background: #e0e7ff; color: #3730a3; }
.au-kind.live { background: #d1fae5; color: #065f46; }

/* The on/off switch. A checkbox reads as "select this row" on a card; a track
   and a knob reads as a power switch, which is what it is. */
.au-switch {
  width: 38px; height: 21px; border-radius: 999px; border: none;
  background: #cbd5e1; position: relative; cursor: pointer; flex: none; padding: 0;
  transition: background .14s;
}
.au-switch span {
  position: absolute; top: 2px; left: 2px; width: 17px; height: 17px;
  border-radius: 50%; background: #fff; transition: transform .14s;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .35);
}
.au-switch.on { background: var(--green); }
.au-switch.on span { transform: translateX(17px); }

.au-active-toggle {
  display: flex; gap: 7px; align-items: center; font-weight: 600; font-size: 13px;
  white-space: nowrap;
}

/* ---- Recipes ---- */

.au-recipes { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.au-recipe {
  display: grid; gap: 5px; text-align: left; padding: 12px 14px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 10px; background: #fff;
  min-width: 0; transition: border-color .12s, background .12s;
}
.au-recipe:hover { border-color: var(--blue); background: #f0f6ff; }
.au-recipe b { font-size: 13.5px; }
.au-recipe span { overflow-wrap: anywhere; }
.au-recipe-flow {
  font-size: 11.5px; color: #475569; background: #f1f5f9; border-radius: 6px;
  padding: 5px 8px; margin-top: 3px;
}

/* ---- The builder ---- */

.au-builder { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.au-canvas { display: grid; gap: 0; min-width: 0; }
.au-side { display: grid; gap: 14px; align-content: start; }

.au-name { margin-bottom: 14px; }
.au-name input { font-size: 15px; font-weight: 600; }

.au-block { background: var(--card); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.au-block.when { border-top: 3px solid var(--blue); }
.au-block.only { border-top: 3px solid #a855f7; }
.au-block.then { border-top: 3px solid var(--green); }
.au-block-head {
  display: flex; align-items: center; gap: 10px; padding: 11px 16px;
  border-bottom: 1px solid var(--border); background: #f8fafc;
}
.au-block-head h3 { font-size: 14px; margin: 0; }
.au-block-body { padding: 14px 16px; }

.au-step {
  width: 22px; height: 22px; border-radius: 50%; background: var(--text); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; flex: none;
}

/* The connector between blocks, so the rule reads top to bottom as one flow
   rather than three unrelated cards. */
.au-arrow { display: flex; justify-content: center; color: #94a3b8; padding: 4px 0; }
.au-arrow svg { width: 22px; height: 22px; }

.au-big-select { width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font-weight: 600; }
.au-tfields { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.au-help { margin-top: 9px; line-height: 1.5; }

.au-field { display: grid; gap: 4px; min-width: 0; flex: 1 1 190px; }
.au-field > span { font-size: 11.5px; font-weight: 700; color: var(--muted); }
.au-field input, .au-field select, .au-field textarea {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 7px; width: 100%;
  font-family: inherit; font-size: 13px;
}
.au-field textarea { resize: vertical; }

/* ---- Conditions ---- */

.au-cond {
  display: grid; grid-template-columns: minmax(120px, 200px) minmax(0, 1fr) auto;
  gap: 10px; align-items: center; padding: 9px 0; border-bottom: 1px dashed var(--border);
}
.au-cond:last-child { border-bottom: none; }
.au-cond-label { font-size: 12.5px; font-weight: 700; color: #334155; }
.au-cond-value { min-width: 0; }
.au-cond-value select, .au-cond-value input {
  width: 100%; padding: 7px 10px; border: 1px solid var(--border); border-radius: 7px; font-size: 13px;
}
.au-cond-value select[multiple] { padding: 4px; }
.au-condpick { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 7px; }
.au-condpick .btn { justify-content: flex-start; }

/* ---- Actions ---- */

.au-addaction { padding: 6px 10px; border: 1px solid var(--border); border-radius: 7px; font-weight: 600; font-size: 12.5px; }

#au-actions .au-action { background: #fff; padding: 12px 14px; margin-bottom: 10px; }
.au-action-head { display: flex; align-items: center; gap: 8px; }
.au-action-head svg { width: 15px; height: 15px; color: var(--muted); }
.au-action-n {
  width: 20px; height: 20px; border-radius: 6px; background: #eef2f7; color: #475569;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 800; flex: none;
}
.au-action-fields { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.au-action-fields .au-field input,
.au-action-fields .au-field select,
.au-action-fields .au-field textarea { margin-bottom: 0; }
.au-field.wide { flex-basis: 100%; }
.au-gated { background: #fef3c7; color: #92400e; }
.au-action .icon-btn[disabled] { opacity: .3; cursor: default; }

/* ---- Side panel ---- */

.au-warn {
  background: #fef3c7; color: #92400e; border-radius: 8px; padding: 8px 10px;
  font-size: 12.5px; line-height: 1.5;
}
.au-merge { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.au-merge code {
  background: #f1f5f9; border-radius: 5px; padding: 2px 6px; font-size: 11.5px; color: #334155;
}

.au-tryhead { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.au-tryrow { display: flex; gap: 8px; align-items: flex-start; padding: 7px 0; border-bottom: 1px dashed var(--border); }
.au-tryrow:last-child { border-bottom: none; }
.au-tryrow svg { width: 15px; height: 15px; flex: none; margin-top: 2px; }
.au-tryrow.ok svg { color: var(--green); }
.au-tryrow.no svg { color: var(--red); }
.au-tryrow > div { min-width: 0; overflow-wrap: anywhere; }
.au-trypreview {
  background: #f1f5f9; border-radius: 7px; padding: 6px 9px; margin-top: 5px;
  font-size: 12px; color: #334155; white-space: pre-wrap;
}

/* ---- Sequences ---- */

.au-seq { cursor: pointer; transition: border-color .12s; }
.au-seq:hover { border-color: var(--blue); }
.au-seq-row { display: flex; gap: 11px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--border); }
.au-seq-row:last-child { border-bottom: none; }

.au-note { padding: 14px 16px; margin-bottom: 14px; line-height: 1.55; }

/* ---- Run log ---- */

.au-log { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.au-log:last-child { border-bottom: none; }
.au-log-when { font-size: 12px; color: var(--muted); }
.au-log-what { min-width: 0; overflow-wrap: anywhere; }
.au-log-results { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; }
.au-log-res {
  display: inline-flex; align-items: center; gap: 4px; border-radius: 6px;
  padding: 2px 7px; font-size: 11.5px; font-weight: 600;
}
.au-log-res svg { width: 12px; height: 12px; }
.au-log-res.ok { background: #d1fae5; color: #065f46; }
.au-log-res.no { background: #fee2e2; color: #b91c1c; }

@media (max-width: 1100px) {
  .au-builder { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .au-cond { grid-template-columns: minmax(0, 1fr) auto; }
  .au-cond-label { grid-column: 1 / -1; }
  .au-log { grid-template-columns: minmax(0, 1fr); gap: 2px; }
}

/* ---- Who a rule belongs to ---- */

.au-scope { background: #eef2ff; color: #4338ca; }
.au-scope.office { background: #ecfdf5; color: #047857; }
.au-scope-field { max-width: 420px; }
.au-scope-field select { width: 100%; }
/* A rule somebody may only read is drawn in full and then locked, so it should
   look inert rather than broken. */
.au-readonly input:disabled,
.au-readonly select:disabled,
.au-readonly textarea:disabled { background: var(--bg); color: var(--text); opacity: 1; }
.au-readonly .au-action-head .icon-btn { display: none; }

/* ---- The smart list rail on People ----
   It lives here rather than in styles.css, which is shared and not ours to
   edit. The rail grew a resize handle, a drag grip, and a row of things you do
   to the list you are looking at. */

.rail-grip {
  flex: none;
  width: 7px;
  align-self: stretch;
  margin: 0 -6px 0 -9px;
  cursor: col-resize;
  border-radius: 4px;
  background: transparent;
  transition: background .12s;
}
.rail-grip:hover, .rail-grip:active { background: #cbd5e1; }

.filter-rail .sl-row { position: relative; }
.filter-rail .sl-grip {
  display: inline-flex;
  color: #cbd5e1;
  cursor: grab;
  margin-left: -6px;
}
.filter-rail .sl-grip svg { width: 13px; height: 13px; }
.filter-rail .sl-row:hover .sl-grip { color: var(--muted); }
.filter-rail .sl-row.dragging { opacity: .45; }
.filter-rail .sl-row.drop-target { box-shadow: inset 0 2px 0 var(--blue); }
.filter-rail .sl-edit { opacity: 0; transition: opacity .12s; }
.filter-rail .sl-row:hover .sl-edit, .filter-rail .sl-row.on .sl-edit { opacity: 1; }

.list-actions { padding: 7px 11px; background: var(--bg); border-radius: 9px; }
.list-actions .btn.danger[disabled] { opacity: .5; cursor: not-allowed; }

@media (max-width: 900px) {
  .rail-grip { display: none; }
  .list-actions { flex-wrap: wrap; }
}
