/* ──────────────────────────────────────────────────────────────────
   Commands page
   ────────────────────────────────────────────────────────────────── */

.cmd-wrap {
  max-width: 980px;
  margin: 0 auto;
  padding: var(--sp-6) var(--sp-6) var(--sp-10);
}

/* Header */
.cmd-hd {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: var(--sp-4);
  margin-bottom: var(--sp-6);
}
.cmd-hd h1 {
  margin: 0;
  font-size: var(--fs-h1);
  letter-spacing: -0.015em;
  font-weight: 600;
}
.cmd-hd .sub {
  color: var(--text-secondary);
  font-size: var(--fs-body);
  margin-top: 4px;
  max-width: 540px;
}
.cmd-new-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.cmd-new-btn svg { width: 14px; height: 14px; }

/* Sections */
.cmd-section {
  margin-top: var(--sp-7);
  padding-top: var(--sp-5);
  border-top: 1px solid var(--border-light);
}
.cmd-section-hd { margin-bottom: var(--sp-4); }
.cmd-section-hd h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.005em;
}
.cmd-section-sub {
  margin-top: 4px;
  color: var(--text-secondary);
  font-size: 13px;
}

/* Custom command list */
.cmd-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.cmd-empty {
  padding: var(--sp-6) var(--sp-4);
  background: var(--bg);
  border: 1px dashed var(--border-light);
  border-radius: var(--r-md);
  text-align: center;
}
.cmd-empty-title {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
}
.cmd-empty-sub {
  color: var(--text-secondary);
  font-size: 12.5px;
}

.cmd-card {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--border-light);
  border-radius: var(--r-md);
  transition: border-color 120ms, box-shadow 120ms;
}
.cmd-card:hover {
  border-color: var(--border);
  box-shadow: 0 4px 12px rgba(0,0,0,0.18);
}
.cmd-card.disabled { opacity: 0.55; }
.cmd-card-l { flex: 1; min-width: 0; }
.cmd-card-r { display: flex; gap: 6px; flex-shrink: 0; align-items: center; }

.cmd-card-trigger {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--brand);
  letter-spacing: -0.01em;
}
.cmd-card-aliases {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 5px;
}
.cmd-alias-chip {
  display: inline-block;
  padding: 1px 7px;
  background: rgba(232,97,58,0.08);
  border: 1px solid rgba(232,97,58,0.18);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--brand);
}
.cmd-card-action {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  color: var(--text-secondary);
  font-size: 12px;
}
.cmd-card-action-icon {
  width: 13px; height: 13px;
  opacity: 0.8;
}
.cmd-card-pill {
  display: inline-block;
  padding: 1px 7px;
  background: var(--hover);
  color: var(--text-tertiary);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  margin-left: 4px;
}
.cmd-card-pill-off {
  background: rgba(200,85,61,0.10);
  color: #d77;
}
.cmd-card-desc {
  margin-top: 6px;
  color: var(--text-secondary);
  font-size: 12.5px;
  line-height: 1.45;
}
.cmd-card-preview {
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-tertiary);
  line-height: 1.45;
  font-style: italic;
}

.cmd-icon-btn {
  width: 30px; height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border-light);
  border-radius: var(--r-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 120ms;
}
.cmd-icon-btn:hover { color: var(--text); border-color: var(--border); background: var(--hover); }
.cmd-icon-btn svg { width: 13px; height: 13px; }
.cmd-icon-btn-danger:hover { color: #C8553D; border-color: rgba(200,85,61,0.4); background: rgba(200,85,61,0.06); }

/* Unit slashes grid */
.cmd-units-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px;
}
.cmd-unit-tile {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: var(--r-md);
  transition: border-color 120ms;
}
.cmd-unit-tile:hover { border-color: var(--border); }
.cmd-unit-tile.is-unavailable { opacity: 0.7; }
.cmd-unit-l { flex: 1; min-width: 0; }
.cmd-unit-r { flex-shrink: 0; align-self: center; }

.cmd-unit-trigger {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--brand);
  display: flex;
  align-items: center;
  gap: 6px;
}
.cmd-unit-override {
  display: inline-block;
  padding: 0 6px;
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--brand);
  background: rgba(232,97,58,0.10);
  border-radius: 3px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.cmd-unit-name {
  margin-top: 3px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.cmd-unit-sub {
  margin-top: 2px;
  font-size: 11.5px;
  color: var(--text-tertiary);
}
.cmd-unit-alt code {
  font-family: var(--font-mono);
  color: var(--text-secondary);
  background: var(--hover);
  padding: 0 4px;
  border-radius: 3px;
  font-size: 10.5px;
}

/* Trigger chips on a unit tile (override aliases + unit_code shortcut). */
.cmd-unit-aliases {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 5px;
}
.cmd-unit-alias-chip {
  display: inline-block;
  padding: 1px 7px;
  background: rgba(232,97,58,0.08);
  border: 1px solid rgba(232,97,58,0.18);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--brand);
}
.cmd-unit-pills {
  margin-top: 6px;
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.cmd-customize-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text-secondary);
  font-size: 11.5px;
  font-family: inherit;
  cursor: pointer;
  transition: all 120ms;
}
.cmd-customize-btn:hover {
  color: var(--brand);
  border-color: var(--brand-dim);
}
.cmd-customize-btn svg { width: 11px; height: 11px; }

/* Built-ins */
.cmd-builtins {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 6px;
}
.cmd-builtin {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: var(--r-sm);
  font-size: 12.5px;
  color: var(--text-secondary);
}
.cmd-builtin code {
  display: inline-block;
  padding: 1px 6px;
  background: var(--hover);
  color: var(--brand);
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 12px;
  flex-shrink: 0;
}

/* ──────────────────────────────────────────────────────────────────
   Editor form
   ────────────────────────────────────────────────────────────────── */

/* Action picker — 4 visual cards */
.cmd-action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
  margin-bottom: 4px;
}
.cmd-action-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: var(--r-sm);
  color: var(--text);
  text-align: left;
  font-family: inherit;
  cursor: pointer;
  transition: all 140ms;
}
.cmd-action-card:hover {
  border-color: var(--border);
  background: var(--hover);
}
.cmd-action-card.is-on {
  border-color: var(--brand);
  background: rgba(232,97,58,0.06);
  box-shadow: 0 0 0 1px var(--brand) inset;
}
.cmd-action-icon {
  width: 28px; height: 28px;
  border-radius: 6px;
  background: var(--hover);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  flex-shrink: 0;
}
.cmd-action-card.is-on .cmd-action-icon {
  background: var(--brand);
  color: #fff;
}
.cmd-action-icon svg { width: 13px; height: 13px; }
.cmd-action-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.cmd-action-title {
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: -0.005em;
}
.cmd-action-desc {
  font-size: 11px;
  color: var(--text-tertiary);
  line-height: 1.35;
}

/* ───── Generic prefix-wrapped input (anchored to the input itself
   so the prefix doesn't drift over labels/hints when the field has
   extra content above or below it) ───── */
.cmd-input-prefix {
  position: relative;
  display: block;
}
.cmd-input-prefix .cmd-prefix {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-tertiary);
  pointer-events: none;
  line-height: 1;
}
.cmd-input-prefix input {
  padding-left: 26px !important;
  width: 100%;
}

/* Alias input + chips inside the editor */
.cmd-alias-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 6px;
  min-height: 24px;
}
.cmd-alias-empty {
  color: var(--text-tertiary);
  font-size: 11.5px;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}
.cmd-alias-chip-edit {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px 2px 9px;
  background: rgba(232,97,58,0.08);
  border: 1px solid rgba(232,97,58,0.20);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--brand);
}
.cmd-alias-x {
  width: 18px; height: 18px;
  border: none;
  background: transparent;
  color: var(--brand);
  opacity: 0.7;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.cmd-alias-x:hover {
  opacity: 1;
  background: rgba(232,97,58,0.16);
}
.cmd-alias-input {
  position: relative;
}

/* ───── Multi-unit picker (in the editor form, for send_unit action) ───── */
.cmd-unit-picker-selected {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 6px;
  min-height: 24px;
}
.cmd-unit-picker-empty {
  color: var(--text-tertiary);
  font-size: 11.5px;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}
.cmd-unit-pick-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px 3px 10px;
  background: rgba(232,97,58,0.08);
  border: 1px solid rgba(232,97,58,0.20);
  border-radius: 999px;
  font-size: 12px;
  color: var(--text);
}
.cmd-unit-pick-chip.is-sold {
  background: rgba(200,85,61,0.10);
  border-color: rgba(200,85,61,0.30);
}
.cmd-unit-pick-name {
  font-weight: 500;
}
.cmd-unit-pick-warn {
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: #d77;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 1px 5px;
  background: rgba(200,85,61,0.16);
  border-radius: 3px;
}
.cmd-unit-pick-x {
  width: 20px; height: 20px;
  border: none;
  background: transparent;
  color: var(--brand);
  opacity: 0.7;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.cmd-unit-pick-x:hover {
  opacity: 1;
  background: rgba(232,97,58,0.16);
}

/* ───── Dropzone (custom — we own the layout so it works on a <div>
   without inheriting <label>-default inline rules) ───── */
.cmd-dz {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 28px 18px;
  background: var(--bg);
  border: 1.5px dashed var(--border);
  border-radius: var(--r-md);
  text-align: center;
  cursor: pointer;
  transition: border-color 160ms, background 160ms;
}
.cmd-dz:hover, .cmd-dz.cmd-dz-hot {
  border-color: var(--brand);
  background: rgba(232,97,58,0.06);
}
.cmd-dz input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
  /* Keep it hidden but inside the layout so accept= works */
}
.cmd-dz-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--brand-soft, rgba(232,97,58,0.10));
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--brand);
}
.cmd-dz-icon svg { width: 16px; height: 16px; }
.cmd-dz-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.cmd-dz-title em {
  color: var(--brand);
  font-style: normal;
  text-decoration: underline;
}
.cmd-dz-sub {
  font-size: 11.5px;
  color: var(--text-tertiary);
}

/* Attachments list inside the editor */
.cmd-attach-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}
.cmd-att-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 6px 6px;
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: var(--r-sm);
  transition: border-color 120ms;
}
.cmd-att-row.is-uploading {
  border-style: dashed;
  opacity: 0.7;
}
.cmd-att-thumb {
  width: 36px; height: 36px;
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--card);
}
.cmd-att-thumb-doc {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
  background: var(--card);
}
.cmd-att-meta {
  flex: 1;
  min-width: 0;
}
.cmd-att-name {
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cmd-att-status {
  font-size: 10.5px;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
}
.cmd-att-x {
  width: 24px; height: 24px;
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.cmd-att-x:hover {
  color: #C8553D;
  background: rgba(200,85,61,0.10);
}
.cmd-att-x svg { width: 11px; height: 11px; }

/* Tighten the toggle-row label color in our usage */
.mk-toggle-row .tg-title { color: var(--text); }

/* ============================================================
   Responsive (additive only — desktop unchanged above).
   The Commands page is a settings-style list of custom slash
   commands plus an auto-generated unit grid. The editor for a
   command opens inside an mk-modal (handled by page-modal-kit
   responsive rules), so here we only tune the LIST page itself.
   ============================================================ */

@media (max-width: 1024px) {
  .cmd-wrap { padding: var(--sp-5) var(--sp-4) var(--sp-8); }

  .cmd-hd { gap: var(--sp-3); }
  .cmd-hd .sub { max-width: none; }

  /* Auto-fit grids already collapse via minmax — nudge minimums
     so 2 cols fit comfortably on iPad portrait. */
  .cmd-units-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
  .cmd-builtins   { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
  .cmd-action-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}

@media (max-width: 640px) {
  .cmd-wrap { padding: var(--sp-4) var(--sp-3) var(--sp-8); }

  /* Stack title and "New command" button on phone */
  .cmd-hd {
    flex-direction: column;
    align-items: stretch;
    gap: var(--sp-3);
  }
  .cmd-hd .h-l { width: 100%; }
  .cmd-new-btn {
    width: 100%;
    justify-content: center;
    min-height: 44px;
    font-size: var(--fs-14);
  }

  /* Section spacing tightens */
  .cmd-section { margin-top: var(--sp-5); padding-top: var(--sp-4); }
  .cmd-section-hd h2 { font-size: var(--fs-15); }

  /* All multi-col grids collapse to one column */
  .cmd-units-grid,
  .cmd-builtins,
  .cmd-action-grid {
    grid-template-columns: 1fr;
  }

  /* Custom command rows: more tap-friendly padding, larger trigger text */
  .cmd-card {
    padding: 14px 14px;
    gap: 10px;
    min-height: 44px;
  }
  .cmd-card-trigger { font-size: var(--fs-15); }
  .cmd-card-desc, .cmd-card-preview { font-size: var(--fs-13); }

  /* Edit/Delete icon buttons grow to 44px tap targets */
  .cmd-icon-btn {
    width: 38px;
    height: 38px;
    min-width: 38px;
  }
  .cmd-icon-btn svg { width: 14px; height: 14px; }

  /* Unit tiles: tap-friendly, full-width override badge wraps cleanly */
  .cmd-unit-tile {
    padding: 12px 12px;
    gap: 10px;
  }
  .cmd-unit-trigger { font-size: var(--fs-14); flex-wrap: wrap; }
  .cmd-unit-name { font-size: var(--fs-14); }

  .cmd-customize-btn {
    min-height: 38px;
    padding: 6px 12px;
    font-size: var(--fs-12);
  }
  .cmd-customize-btn svg { width: 12px; height: 12px; }

  /* Built-in command rows: bigger code chip + readable text */
  .cmd-builtin {
    padding: 12px 12px;
    font-size: var(--fs-13);
    min-height: 44px;
  }
  .cmd-builtin code { font-size: var(--fs-13); padding: 2px 7px; }

  /* Editor form atoms (used inside an mk-modal opened from this page).
     The trigger input uses a custom .cmd-input-prefix wrapper, so we
     need to bump its font-size to 16px to avoid iOS zoom-on-focus. */
  .cmd-input-prefix input {
    font-size: 16px !important;
    min-height: 40px;
  }
  .cmd-input-prefix .cmd-prefix {
    font-size: 14px;
  }

  /* Action picker cards stack one-per-row, comfortable padding */
  .cmd-action-card {
    padding: 14px 14px;
    min-height: 56px;
  }
  .cmd-action-title { font-size: var(--fs-13); }
  .cmd-action-desc  { font-size: var(--fs-12); }

  /* Alias / unit-pick chips: bigger remove buttons for fingertips */
  .cmd-alias-x,
  .cmd-unit-pick-x {
    width: 24px;
    height: 24px;
    font-size: 16px;
  }
  .cmd-alias-chip-edit,
  .cmd-unit-pick-chip {
    font-size: var(--fs-12);
    padding-top: 4px;
    padding-bottom: 4px;
  }

  /* Dropzone — taller drop area, larger touch surface */
  .cmd-dz {
    padding: 32px 16px;
    gap: 10px;
  }
  .cmd-dz-icon { width: 40px; height: 40px; }
  .cmd-dz-icon svg { width: 18px; height: 18px; }
  .cmd-dz-title { font-size: var(--fs-14); }

  /* Attachment rows: bigger thumb, comfortable delete button */
  .cmd-att-row {
    padding: 8px 8px 8px 8px;
    gap: 10px;
  }
  .cmd-att-thumb { width: 40px; height: 40px; }
  .cmd-att-name { font-size: var(--fs-13); }
  .cmd-att-x {
    width: 32px;
    height: 32px;
  }
  .cmd-att-x svg { width: 13px; height: 13px; }
}

/* ===== Touch (hover-less) device polish =====
   These run regardless of viewport width — covers iPads in landscape
   that still benefit from larger tap targets. */
@media (hover: none) and (pointer: coarse) {
  .cmd-icon-btn { min-width: 36px; min-height: 36px; }
  .cmd-customize-btn { min-height: 36px; }
  .cmd-action-card { min-height: 52px; }
  .cmd-att-x { min-width: 32px; min-height: 32px; }
  .cmd-alias-x,
  .cmd-unit-pick-x { min-width: 24px; min-height: 24px; }
  /* Drop hover-only shadow effect since it never resolves on touch */
  .cmd-card:hover { box-shadow: none; }
}
