/* admin-panel.css — P-admin-01 Consolidated Admin Panel
   CSS prefix: ap-
   Colors reference CSS variables from styles.css for theme consistency.
*/

/* -------------------------------------------------------------------------
   View container — mirrors .crm-view
------------------------------------------------------------------------- */

.admin-panel-view {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-height, 56px) - 4px);
  overflow: hidden;
}

/* -------------------------------------------------------------------------
   Root layout
------------------------------------------------------------------------- */

.ap-root {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  padding: 0;
}

.ap-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color, #475569);
  background: var(--bg-card, #334155);
  flex-shrink: 0;
}

.ap-heading {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0;
  color: var(--text-primary, #f8fafc);
}

.ap-scroll {
  flex: 1 1 0;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* -------------------------------------------------------------------------
   Cards
------------------------------------------------------------------------- */

.ap-card {
  background: var(--bg-card, #334155);
  border: 1px solid var(--border-color, #475569);
  border-radius: 6px;
  padding: 1rem 1.25rem;
}

.ap-card-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 0.75rem 0;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-color, #475569);
  color: var(--text-primary, #f8fafc);
}

.ap-card-desc {
  color: var(--text-muted, #9aa7b4);
  margin: 0 0 0.75rem 0;
  font-size: 0.9rem;
}

.ap-section-sublabel {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted, #9aa7b4);
  margin: 0.75rem 0 0.4rem 0;
}

/* -------------------------------------------------------------------------
   System section
------------------------------------------------------------------------- */

.ap-version {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 0.85rem;
  color: var(--text-muted, #9aa7b4);
  margin: 0 0 0.75rem 0;
}

.ap-counts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.ap-count-chip {
  background: var(--bg-light, #475569);
  border: 1px solid var(--border-color, #475569);
  border-radius: 4px;
  padding: 0.25rem 0.6rem;
  font-size: 0.85rem;
  color: var(--text-primary, #f8fafc);
}

.ap-count-label {
  color: var(--text-muted, #9aa7b4);
}

/* -------------------------------------------------------------------------
   Feature flags grid
------------------------------------------------------------------------- */

.ap-flags-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.ap-flag-chip {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 12px;
  font-size: 0.78rem;
  font-weight: 500;
  border: 1px solid transparent;
}

.ap-flag-on {
  background: rgba(34, 197, 94, 0.18);
  color: #86efac;
  border-color: rgba(34, 197, 94, 0.35);
}

.ap-flag-off {
  background: var(--bg-light, #475569);
  color: var(--text-muted, #9aa7b4);
  border-color: var(--border-color, #475569);
}

/* Operator finding 6: amber "token set but chat disabled" state for Telegram. */
.ap-flag-warn {
  background: rgba(245, 158, 11, 0.18);
  color: #fcd34d;
  border-color: rgba(245, 158, 11, 0.4);
}

.ap-flag-neutral {
  background: rgba(100, 116, 139, 0.3);
  color: var(--text-secondary, #94a3b8);
  border-color: var(--border-color, #475569);
}

.ap-flags-hint {
  font-size: 0.78rem;
  color: var(--text-muted, #9aa7b4);
  margin: 0.4rem 0 0 0;
  font-style: italic;
  width: 100%; /* ensure it wraps below chips */
}

/* -------------------------------------------------------------------------
   Tables (shared)
------------------------------------------------------------------------- */

.ap-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  color: var(--text-primary, #f8fafc);
}

.ap-table th,
.ap-table td {
  padding: 0.45rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color, #475569);
  vertical-align: middle;
}

.ap-table thead th {
  font-weight: 600;
  color: var(--text-muted, #9aa7b4);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--bg-light, #475569);
}

.ap-empty-cell {
  color: var(--text-muted, #9aa7b4);
  font-style: italic;
}

.ap-empty-message {
  color: var(--text-muted, #9aa7b4);
  font-size: 0.85rem;
  margin: 0.5rem 0;
}

/* -------------------------------------------------------------------------
   Toggle buttons
------------------------------------------------------------------------- */

.ap-toggle-on {
  background: rgba(34, 197, 94, 0.18);
  color: #86efac;
  border-color: rgba(34, 197, 94, 0.35);
}

.ap-toggle-on:hover {
  background: rgba(34, 197, 94, 0.28);
}

.ap-toggle-off {
  background: var(--bg-light, #475569);
  color: var(--text-muted, #9aa7b4);
  border-color: var(--border-color, #475569);
}

.ap-toggle-off:hover {
  background: var(--secondary, #64748b);
}

/* -------------------------------------------------------------------------
   Users section
------------------------------------------------------------------------- */

.ap-role-select {
  font-size: 0.85rem;
  padding: 0.2rem 0.4rem;
  border: 1px solid var(--border-color, #475569);
  border-radius: 4px;
  background: var(--bg-dark, #1e293b);
  color: var(--text-primary, #f8fafc);
}

/* -------------------------------------------------------------------------
   CalDAV section
------------------------------------------------------------------------- */

.ap-cal-url {
  font-size: 0.8rem;
  word-break: break-all;
  max-width: 280px;
  color: var(--text-secondary, #94a3b8);
}

.ap-cal-error {
  color: var(--danger, #ef4444);
  font-size: 0.8rem;
}

.ap-cal-add-form {
  margin-top: 1rem;
}

.ap-form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.5rem;
}

.ap-input {
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--border-color, #475569);
  border-radius: 4px;
  font-size: 0.875rem;
  background: var(--bg-dark, #1e293b);
  color: var(--text-primary, #f8fafc);
}

.ap-input:focus {
  outline: none;
  border-color: var(--primary, #3b82f6);
}

.ap-input[type='text'] {
  flex: 1 1 200px;
  min-width: 160px;
}

.ap-discover-results {
  margin-top: 0.4rem;
  font-size: 0.85rem;
  color: var(--text-muted, #9aa7b4);
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.ap-discover-label {
  font-weight: 600;
  color: var(--text-secondary, #94a3b8);
}

.ap-discover-btn {
  font-size: 0.78rem;
  padding: 0.15rem 0.45rem;
}

/* -------------------------------------------------------------------------
   Telegram section
------------------------------------------------------------------------- */

.ap-telegram-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.ap-telegram-info {
  font-size: 0.85rem;
  color: var(--text-muted, #9aa7b4);
}

/* -------------------------------------------------------------------------
   Error / hint lines
------------------------------------------------------------------------- */

.ap-error-line {
  color: var(--danger, #ef4444);
  font-size: 0.85rem;
  margin: 0 0 0.5rem 0;
  min-height: 0;
}

.ap-hint {
  font-size: 0.78rem;
  color: var(--text-secondary, #94a3b8);
  font-style: italic;
  margin: 0.5rem 0 0 0;
  padding: 0.4rem 0.6rem;
  background: rgba(245, 158, 11, 0.12);
  border-left: 3px solid var(--warning, #f59e0b);
  border-radius: 3px;
}

.ap-hint.hidden {
  display: none;
}

/* -------------------------------------------------------------------------
   Utilities
------------------------------------------------------------------------- */

.hidden {
  display: none !important;
}

/* -------------------------------------------------------------------------
   Table column-collapse helpers
   Priority-column collapsing: low-value columns are hidden behind a row
   expander on small screens.  The JS tables use standard <th>/<td> with no
   column-index knowledge, so we use structural nth-child selectors that map
   to the documented column order for each table.

   Users table   : Username · Email · Role · (actions)
     → phone keeps: Username (1) · Role (3) · actions (4); hides Email (2)
   CalDAV table  : User · Cal URL · Sync · Last sync · Last error · (actions)
     → phone keeps: User (1) · Sync (3) · actions (6); hides URL/dates/error
     → tablet keeps: User (1) · Cal URL (2) · Sync (3) · actions (6)
   Deck table    : Board · Write-back  (only 2 cols — no collapsing needed)
------------------------------------------------------------------------- */

/* Row-expander button: hidden by default; shown when collapse rules apply */
.ap-row-expand-btn {
  background: none;
  border: 1px solid var(--border-color, #475569);
  border-radius: var(--radius-sm, 0.25rem);
  color: var(--text-muted, #9aa7b4);
  cursor: pointer;
  font-size: var(--text-xs, 0.75rem);
  padding: 0.15rem 0.4rem;
  display: none;
}

.ap-row-expand-btn:hover {
  color: var(--text-primary, #f8fafc);
  border-color: var(--primary, #3b82f6);
}

/* Expandable overflow cells: hidden until row is expanded */
td.ap-col-overflow {
  display: none;
}

tr.ap-row-expanded td.ap-col-overflow {
  display: table-cell;
}

/* Sticky section headers in long scroll areas */
.ap-section-sublabel--sticky {
  position: sticky;
  top: 0;
  background: var(--bg-card, #334155);
  z-index: 1;
  padding-top: var(--space-2, 0.5rem);
  padding-bottom: var(--space-2, 0.5rem);
  margin-top: 0;
}

/* -------------------------------------------------------------------------
   Responsive — tablet (768–1023 px)
   Cards stay in single column (ap-scroll is already flex-col).
   CalDAV table: hide Last-sync, Last-error columns (cols 4, 5).
------------------------------------------------------------------------- */

@media (min-width: 768px) and (max-width: 1023px) {
  /* CalDAV table: hide Last sync (4) and Last error (5) */
  .ap-table.ap-table--caldav thead th:nth-child(4),
  .ap-table.ap-table--caldav thead th:nth-child(5),
  .ap-table.ap-table--caldav tbody td:nth-child(4),
  .ap-table.ap-table--caldav tbody td:nth-child(5) {
    display: none;
  }

  /* Users table: hide Email (col 2) */
  .ap-table.ap-table--users thead th:nth-child(2),
  .ap-table.ap-table--users tbody td:nth-child(2) {
    display: none;
  }

  /* Show row-expand button so hidden data is accessible */
  .ap-table.ap-table--caldav .ap-row-expand-btn,
  .ap-table.ap-table--users .ap-row-expand-btn {
    display: inline-block;
  }

  /* Forms stay horizontal on tablet */
  .ap-form-row {
    flex-wrap: wrap;
  }
}

/* -------------------------------------------------------------------------
   Responsive — phone (<768 px)
   Cards stack 1-col.  Tables collapse to priority columns.
   Flag grid → 2-col.  Forms → 1-col.  Touch targets ≥ 44px.
------------------------------------------------------------------------- */

@media (max-width: 767px) {
  .admin-panel-view {
    height: auto;
    min-height: calc(100vh - var(--header-height, 56px) - var(--bottom-nav-height, 56px) - 4px);
    overflow: visible;
  }

  .ap-root {
    height: auto;
    overflow: visible;
  }

  .ap-header {
    padding: var(--space-3) var(--space-4);
  }

  .ap-scroll {
    padding: var(--space-3) var(--space-3);
    /* Bottom clearance for fixed bottom-nav */
    padding-bottom: calc(var(--space-4) + var(--bottom-nav-height, 56px) + env(safe-area-inset-bottom));
    overflow-y: visible;
    height: auto;
    flex: none;
  }

  /* Cards already stack (flex-col on ap-scroll). Reduce horizontal padding. */
  .ap-card {
    padding: var(--space-4) var(--space-4);
  }

  /* Feature flags grid → 2 columns on phone */
  .ap-flags-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .ap-flag-chip {
    text-align: center;
  }

  /* Flag hint spans full width */
  .ap-flags-hint {
    grid-column: 1 / -1;
  }

  /* Count chips wrap freely */
  .ap-counts {
    flex-wrap: wrap;
  }

  /* Tables: scroll container on very small screens as fallback */
  .ap-card > .ap-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Users table: keep Username (1) · Role (3) · actions (4) */
  .ap-table.ap-table--users thead th:nth-child(2),
  .ap-table.ap-table--users tbody td:nth-child(2) {
    display: none;
  }

  /* CalDAV table: keep User (1) · Sync (3) · actions (6) */
  .ap-table.ap-table--caldav thead th:nth-child(2),
  .ap-table.ap-table--caldav thead th:nth-child(4),
  .ap-table.ap-table--caldav thead th:nth-child(5),
  .ap-table.ap-table--caldav tbody td:nth-child(2),
  .ap-table.ap-table--caldav tbody td:nth-child(4),
  .ap-table.ap-table--caldav tbody td:nth-child(5) {
    display: none;
  }

  /* Show row-expand buttons so hidden columns are accessible via a tap */
  .ap-table.ap-table--users .ap-row-expand-btn,
  .ap-table.ap-table--caldav .ap-row-expand-btn {
    display: inline-block;
    min-height: 36px;
    min-width: 44px;
  }

  /* Table cells: bigger touch targets */
  .ap-table th,
  .ap-table td {
    padding: var(--space-3) var(--space-2);
  }

  /* Form rows stack 1-col */
  .ap-form-row {
    flex-direction: column;
    align-items: stretch;
  }

  .ap-input[type='text'] {
    min-width: 0;
    flex: none;
    width: 100%;
  }

  /* Buttons full-width, min touch target */
  .ap-form-row .btn {
    min-height: 44px;
    width: 100%;
  }

  /* Sticky section sublabels for long scroll areas */
  .ap-section-sublabel {
    position: sticky;
    top: 0;
    background: var(--bg-card, #334155);
    z-index: 1;
    padding-top: var(--space-2, 0.5rem);
    padding-bottom: var(--space-2, 0.5rem);
    margin-top: 0;
  }

  /* Role select: full width, min touch target */
  .ap-role-select {
    min-height: 44px;
    width: 100%;
  }
}

/* O-01: editable runtime flags */
.ap-flags-edit-grid { display: flex; flex-direction: column; gap: var(--space-2); }
.ap-flag-row { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-3); background: var(--bg-light, #475569); border: 1px solid var(--border-color, #475569); border-radius: var(--radius-md); flex-wrap: wrap; }
.ap-flag-label { flex: 1 1 140px; color: var(--text-primary); font-size: var(--text-sm); }
.ap-flag-source { color: var(--text-muted); font-size: var(--text-xs); }
.ap-flag-pending { background: var(--warning); color: #1a1a1a; padding: 2px var(--space-2); border-radius: var(--radius-sm); font-size: var(--text-xs); }
.ap-restart-bar { display: flex; align-items: center; gap: var(--space-3); margin-top: var(--space-3); padding: var(--space-3); border: 1px solid var(--warning); border-radius: var(--radius-md); background: var(--bg-card, #334155); }
.ap-restart-bar.hidden { display: none; }
.ap-restart-msg { flex: 1; color: var(--text-primary); font-size: var(--text-sm); }
.ap-allowlist-editor { display: flex; flex-direction: column; gap: var(--space-2); }
.ap-allowlist-input { width: 100%; min-height: 80px; background: var(--bg-dark); color: var(--text-primary); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: var(--space-2); font-family: monospace; font-size: var(--text-sm); }
.ap-toast { position: fixed; bottom: calc(var(--bottom-nav-height, 56px) + var(--space-3)); left: 50%; transform: translateX(-50%); background: var(--bg-card); color: var(--text-primary); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: var(--space-2) var(--space-4); z-index: var(--z-toast); }

/* -------------------------------------------------------------------------
   B3: AI System Prompts
------------------------------------------------------------------------- */

.ap-prompts {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.ap-prompt-block {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--bg-light, #475569);
  border: 1px solid var(--border-color, #475569);
  border-radius: var(--radius-md, 6px);
}

.ap-prompt-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.ap-prompt-label {
  font-weight: 600;
  color: var(--text-primary, #f8fafc);
  font-size: 0.9rem;
}

.ap-prompt-input {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 0.82rem;
  line-height: 1.4;
}

.ap-prompt-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* -------------------------------------------------------------------------
   B4: Telegram access — DB-backed allow-list
------------------------------------------------------------------------- */

.ap-mono {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 0.82rem;
  color: var(--text-secondary, #94a3b8);
  word-break: break-all;
}

/* -------------------------------------------------------------------------
   B5: CalDAV passwords — per-user app password
------------------------------------------------------------------------- */

.ap-caldav-pw-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.ap-caldav-pw-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--bg-light, #475569);
  border: 1px solid var(--border-color, #475569);
  border-radius: var(--radius-md, 6px);
}

.ap-caldav-pw-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.ap-caldav-pw-name {
  font-weight: 600;
  color: var(--text-primary, #f8fafc);
  font-size: 0.9rem;
}

.ap-caldav-pw-email {
  color: var(--text-muted, #9aa7b4);
  font-size: 0.82rem;
}

/* CalDAV password row form: input flexes, buttons sit beside it */
.ap-caldav-pw-row .ap-form-row {
  margin-bottom: 0;
}

.ap-caldav-pw-row .ap-input[type='password'] {
  flex: 1 1 200px;
  min-width: 160px;
}

/* Telegram access table column-collapse — order:
   Chat ID (1) · Username (2) · Mapped user (3) · Approved (4) · actions (5)
   phone/tablet keep: Chat ID (1) · Username (2) · actions (5);
   hide Mapped user (3) + Approved (4) behind the row expander. */
@media (min-width: 768px) and (max-width: 1023px) {
  .ap-table.ap-table--telegram thead th:nth-child(4),
  .ap-table.ap-table--telegram tbody td:nth-child(4) {
    display: none;
  }

  .ap-table.ap-table--telegram .ap-row-expand-btn {
    display: inline-block;
  }
}

@media (max-width: 767px) {
  .ap-table.ap-table--telegram thead th:nth-child(3),
  .ap-table.ap-table--telegram thead th:nth-child(4),
  .ap-table.ap-table--telegram tbody td:nth-child(3),
  .ap-table.ap-table--telegram tbody td:nth-child(4) {
    display: none;
  }

  .ap-table.ap-table--telegram .ap-row-expand-btn {
    display: inline-block;
    min-height: 36px;
    min-width: 44px;
  }
}

/* ===========================================================================
   C1 — Ignored / spam senders blocklist section
   List + add card for the DB-backed ignore/spam sender lists. Badge colours
   distinguish the two lists at a glance; the table reuses the shared .ap-table.
   =========================================================================== */

.ap-blocklist-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  line-height: 1.4;
}

.ap-blocklist-badge--ignore {
  background: #e5e7eb;
  color: #374151;
}

.ap-blocklist-badge--spam {
  background: #fee2e2;
  color: #b91c1c;
}

/* Collapse the Note column on narrow screens to keep sender + action visible. */
@media (max-width: 767px) {
  .ap-table.ap-table--blocklist thead th:nth-child(3),
  .ap-table.ap-table--blocklist tbody td:nth-child(3) {
    display: none;
  }
}

/* ===========================================================================
   Tabs — group the admin sections into a small set of tabbed panels.
   The tab bar sits between the header and the scroll area. Tabs are real
   <button role="tab"> elements (keyboard + screen-reader friendly); panels
   are <section role="tabpanel"> toggled with .hidden.
   =========================================================================== */

.ap-tabbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  padding: 0.5rem 1rem 0 1rem;
  background: var(--bg-card, #334155);
  border-bottom: 1px solid var(--border-color, #475569);
  flex-shrink: 0;
}

.ap-tab {
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  border-top-left-radius: 6px;
  border-top-right-radius: 6px;
  color: var(--text-muted, #9aa7b4);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.6rem 1rem;
  /* 44px touch target (0.6rem*2 + ~1.25rem line-height ≈ 44px). */
  min-height: 44px;
  margin-bottom: -1px; /* overlap the bar's bottom border when active */
  white-space: nowrap;
}

.ap-tab:hover {
  color: var(--text-primary, #f8fafc);
  background: var(--bg-light, #475569);
}

.ap-tab:focus-visible {
  outline: 2px solid var(--primary, #3b82f6);
  outline-offset: -2px;
}

.ap-tab-active,
.ap-tab[aria-selected='true'] {
  color: var(--text-primary, #f8fafc);
  background: var(--bg-dark, #1e293b);
  border-color: var(--border-color, #475569);
  border-bottom-color: var(--bg-dark, #1e293b);
}

/* Tab panels: each holds its group's cards. Inherit the scroll-area's column
   flow so cards keep their 1rem gap. .hidden (display:none) toggles them. */
.ap-tabpanel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.ap-tabpanel:focus-visible {
  outline: none;
}

/* Narrow screens: let the tab bar scroll horizontally rather than wrap into a
   tall stack, so the cards stay above the fold. Touch targets stay ≥44px. */
@media (max-width: 767px) {
  .ap-tabbar {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0.5rem 0.75rem 0 0.75rem;
    gap: 0.2rem;
    scrollbar-width: thin;
  }

  .ap-tab {
    flex: 0 0 auto;
    padding: 0.65rem 0.85rem;
  }
}

/* ===========================================================================
   Pending Telegram requests — operator onboarding inbox.
   Each request is a row: identity + PII-safe preview + meta, plus Approve /
   Dismiss actions. Mirrors the .ap-caldav-pw-row card-list look.
   =========================================================================== */

.ap-pending-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.ap-pending-row {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem;
  background: var(--bg-light, #475569);
  border: 1px solid var(--border-color, #475569);
  border-radius: var(--radius-md, 6px);
  flex-wrap: wrap;
}

.ap-pending-main {
  flex: 1 1 220px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.ap-pending-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.ap-pending-name {
  font-weight: 600;
  color: var(--text-primary, #f8fafc);
  font-size: 0.92rem;
}

.ap-pending-chatid {
  font-size: 0.75rem;
}

.ap-pending-preview {
  margin: 0;
  color: var(--text-secondary, #94a3b8);
  font-size: 0.85rem;
  line-height: 1.4;
  /* Keep long previews from blowing out the row. */
  overflow-wrap: anywhere;
  word-break: break-word;
}

.ap-pending-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  color: var(--text-muted, #9aa7b4);
  font-size: 0.78rem;
}

.ap-pending-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
  align-items: flex-start;
}

/* Phone: stack the action buttons full-width with proper touch targets. */
@media (max-width: 767px) {
  .ap-pending-actions {
    width: 100%;
  }

  .ap-pending-actions .btn {
    flex: 1 1 0;
    min-height: 44px;
  }
}

/* Tools & settings shortcuts (relocated from the top nav into Integrations) */
.ap-tools-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.ap-tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.85rem;
  min-height: 44px;
  font: inherit;
  font-size: 0.85rem;
  color: var(--text-primary, #f8fafc);
  background: var(--bg-dark, #1e293b);
  border: 1px solid var(--border-color, #475569);
  border-radius: 8px;
  cursor: pointer;
}

.ap-tool-btn:hover {
  border-color: var(--accent, #38bdf8);
}
