/* ext_contact_folders.css — agent contact folders for the Inbox.
 *
 * Scope: the folder rail inside the conversation column, the folder modals, and the
 * "Save as contact" affordances. Uses the inbox's own CSS variables where they exist
 * so this never looks bolted on; falls back to the v9 dark palette when they are not
 * defined (the module can load before the inbox has injected its style block).
 */

/* v9.303 — THEME FIX (Adeel: "in the light theme it's showing dark with dark text,
 * unreadable"). Two separate causes, both here:
 *
 * 1. The dark backgrounds were HARDCODED hexes (#1b1f28 menu, #262c38 hover, #191d25
 *    footer, #1c2029 field fill). ext_theme.js only remaps the exact hexes in its
 *    HC_MAP, and none of these five are in it — so in light mode the menu kept its
 *    near-black paint. Every colour below now derives from the live theme tokens
 *    (--bg-*, --text*, --line*), which flip with data-theme=light.
 *
 * 2. --v9-text was taken from the inbox's own --v9-text, which ext_chat_inbox.js
 *    pins to #e7eaf0 unconditionally (it is not theme-aware). That near-white ink was
 *    then painted on the light menu = invisible text. The v9f-* ink now comes from
 *    --text / --text-2 / --text-3 instead.
 *
 * Fallbacks mirror the dark tokens so the module still renders correctly if it loads
 * before the shell has defined them (same contract the old file documented). */
:root,
.v9-page {
  --v9f-border: var(--line, #2a2f3a);
  --v9f-surface: var(--bg-2, #171a21);
  --v9f-surface2: var(--bg-3, #1c2029);
  --v9f-hover: var(--bg-3, #262c38);
  --v9f-menu: var(--bg-2, #1b1f28);
  --v9f-text: var(--text, #e6e9ef);
  --v9f-text2: var(--text-3, #94a3b8);
  --v9f-accent: #3b82f6;
  --v9f-danger: #dc2626;
}

/* Light mode: the theme's own surfaces/ink are already correct, but the selected-row
 * wash and hover fill need to stay legible on paper (a dark translucent blue over white
 * reads as a grey smear). Only these two are restated; everything else follows the tokens. */
[data-theme="light"] {
  --v9f-hover: #eef0f4;
  --v9f-menu: #ffffff;
  --v9f-surface2: #f2f4f7;
}

/* ── folder FILTER (compact dropdown, one row when closed) ───────────────── */
/* Replaces an earlier always-expanded tree that ate ~20% of the conversation
 * column. A folder is a FILTER, so it lives inline next to the search box:
 * 0 extra height closed, one line open. */

.v9f-rail {
  flex-shrink: 0;
  position: relative;
  padding: 0;
  background: transparent;
}

.v9f-filter { position: relative; }

.v9f-select {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  box-sizing: border-box;
  background: var(--v9f-surface2);
  border: 1px solid var(--v9f-border);
  border-radius: 7px;
  color: var(--v9f-text);
  font: inherit;
  font-size: 12.5px;
  padding: 6px 9px;
  cursor: pointer;
  text-align: left;
  min-width: 0;
  transition: border-color .12s, background .12s;
}
.v9f-select:hover { background: var(--v9f-hover); }
.v9f-select[aria-expanded="true"] {
  border-color: var(--v9f-accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, .16);
}
.v9f-select-ico { flex: 0 0 auto; font-size: 12px; opacity: .85; }
.v9f-select-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.v9f-caret { flex: 0 0 auto; font-size: 9px; opacity: .65; }

/* Overlays the list instead of pushing it down - opening the menu must not reflow
 * the conversation column. */
.v9f-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 500;
  background: var(--v9f-menu);
  border: 1px solid var(--v9f-border);
  border-radius: 8px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, .28);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 320px;
}

.v9f-menu-scroll { overflow-y: auto; padding: 4px; }

.v9f-opt-wrap { display: flex; align-items: center; position: relative; }

.v9f-opt-row {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  box-sizing: border-box;
  background: none;
  border: 0;
  border-radius: 5px;
  color: var(--v9f-text);
  font: inherit;
  font-size: 12.5px;
  /* Vertical padding only: the inline padding-left that encodes nesting depth must not
   * be overridden by a padding shorthand. */
  padding-top: 6px;
  padding-bottom: 6px;
  padding-right: 8px;
  padding-left: 8px;
  cursor: pointer;
  text-align: left;
  min-width: 0;
}
.v9f-opt-row:hover { background: var(--v9f-hover); }
.v9f-opt-row.sel { background: rgba(59, 130, 246, .18); }
[data-theme="light"] .v9f-opt-row.sel { background: rgba(59, 130, 246, .14); }
.v9f-opt-ico { flex: 0 0 auto; font-size: 11px; opacity: .85; }
.v9f-opt-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.v9f-opt-empty {
  font-size: 11.5px;
  color: var(--v9f-text2);
  padding: 8px 10px;
  font-style: italic;
}

/* Per-folder tools sit on top of the row and appear on hover only. */
.v9f-opt-tools {
  position: absolute;
  right: 5px;
  display: none;
  gap: 1px;
  background: linear-gradient(90deg, transparent, var(--v9f-hover) 22%);
  padding-left: 12px;
}
.v9f-opt-wrap:hover .v9f-opt-tools { display: flex; }
.v9f-opt-wrap:hover .v9f-opt-row .v9f-count { visibility: hidden; }

.v9f-act {
  width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px;
  font-size: 10px;
  color: var(--v9f-text2);
  cursor: pointer;
}
.v9f-act:hover { background: var(--v9f-border); color: var(--v9f-text); }
.v9f-act.danger:hover { background: var(--v9f-danger); color: #fff; }

.v9f-count {
  font-size: 10px;
  color: var(--v9f-text2);
  background: var(--v9f-surface2);
  border: 1px solid var(--v9f-border);
  border-radius: 9px;
  padding: 0 5px;
  min-width: 16px;
  text-align: center;
  flex-shrink: 0;
  line-height: 16px;
}

.v9f-menu-foot {
  border-top: 1px solid var(--v9f-border);
  padding: 5px;
  background: var(--v9f-surface2);
  flex-shrink: 0;
}
.v9f-newfolder {
  width: 100%;
  background: none;
  border: 0;
  color: var(--v9f-text2);
  font: inherit;
  font-size: 12px;
  padding: 6px 8px;
  border-radius: 5px;
  cursor: pointer;
  text-align: left;
}
.v9f-newfolder:hover { background: var(--v9f-hover); color: var(--v9f-text); }

/* Manual "Sync now": pulls folders + chats from Telegram immediately. */
.v9f-syncnow {
  width: 100%;
  background: none;
  border: 0;
  border-top: 1px solid var(--v9f-border);
  margin-top: 3px;
  padding: 6px 8px 2px;
  color: var(--v9f-text2);
  font: inherit;
  font-size: 12px;
  border-radius: 0 0 5px 5px;
  cursor: pointer;
  text-align: left;
}
.v9f-syncnow:hover:not(:disabled) { background: var(--v9f-hover); color: var(--v9f-text); }
.v9f-syncnow:disabled { opacity: .6; cursor: default; }

/* ── modals ──────────────────────────────────────────────────────────────── */
.v9f-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 6, 12, .62);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100000;
  padding: 20px;
}

.v9f-dialog {
  width: 100%;
  max-width: 430px;
  background: var(--v9f-surface);
  border: 1px solid var(--v9f-border);
  border-radius: 10px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
  color: var(--v9f-text);
  display: flex;
  flex-direction: column;
  max-height: 88vh;
  overflow: hidden;
}

.v9f-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  border-bottom: 1px solid var(--v9f-border);
  font-size: 14px;
}

.v9f-x {
  background: none; border: 0; color: var(--v9f-text2);
  cursor: pointer; font-size: 14px; padding: 2px 6px; border-radius: 5px;
}
.v9f-x:hover { background: var(--v9f-surface2); color: var(--v9f-text); }

.v9f-dialog-body { padding: 16px; overflow-y: auto; }

.v9f-label {
  display: block;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--v9f-text2);
  margin-bottom: 6px;
  letter-spacing: .02em;
}
.v9f-opt { font-weight: 400; text-transform: none; opacity: .8; }

.v9f-input {
  width: 100%;
  box-sizing: border-box;
  background: var(--v9f-surface2);
  border: 1px solid var(--v9f-border);
  border-radius: 7px;
  color: var(--v9f-text);
  font: inherit;
  font-size: 13px;
  padding: 8px 10px;
  outline: none;
}
.v9f-input:focus {
  border-color: var(--v9f-accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, .18);
}
.v9f-input.sm { padding: 6px 9px; font-size: 12.5px; }

.v9f-hint {
  font-size: 11.5px;
  color: var(--v9f-text2);
  margin-top: 10px;
  line-height: 1.5;
}

.v9f-warn {
  font-size: 13px;
  line-height: 1.55;
  color: var(--v9f-text);
}

.v9f-checks {
  max-height: 190px;
  overflow-y: auto;
  border: 1px solid var(--v9f-border);
  border-radius: 7px;
  background: var(--v9f-surface2);
  padding: 4px;
}

.v9f-check {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 5px;
  font-size: 12.5px;
  cursor: pointer;
}
.v9f-check:hover { background: var(--v9f-hover); }
.v9f-check input { accent-color: var(--v9f-accent); flex: 0 0 auto; }
.v9f-check span:first-of-type {
  flex: 1 1 auto; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.v9f-newrow { display: flex; gap: 6px; margin-top: 8px; }
.v9f-newrow .v9f-input { flex: 1 1 auto; }

.v9f-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.v9f-btn {
  background: var(--v9f-surface2);
  border: 1px solid var(--v9f-border);
  color: var(--v9f-text);
  border-radius: 7px;
  padding: 7px 14px;
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.v9f-btn:hover { background: var(--v9f-hover); }
.v9f-btn.primary {
  background: var(--v9f-accent);
  border-color: var(--v9f-accent);
  color: #fff;
  font-weight: 600;
}
.v9f-btn.primary:hover { background: #2f6fd0; }
.v9f-btn.primary:disabled { opacity: .6; cursor: default; }
.v9f-btn.danger {
  background: var(--v9f-danger);
  border-color: var(--v9f-danger);
  color: #fff;
  font-weight: 600;
}
.v9f-btn.danger:hover { background: #b91c1c; }

/* ── thread action "Save as contact" ─────────────────────────────────────── */
.v9f-saved-chip {
  font-size: 10.5px;
  color: #4ade80;
  background: rgba(34, 197, 94, .12);
  border: 1px solid rgba(34, 197, 94, .35);
  border-radius: 5px;
  padding: 2px 7px;
  white-space: nowrap;
}
/* On paper, light-green ink on a 12% green wash measures ~1.7:1. Use a dark green. */
[data-theme="light"] .v9f-saved-chip { color: #15803d; background: rgba(34, 197, 94, .14); }

/* ── mobile ──────────────────────────────────────────────────────────────── */
@media (max-width: 720px) {
  .v9f-menu { max-height: 46vh; }
  .v9f-dialog { max-width: none; }
  .v9f-actions { margin-top: 14px; }
}

/* ── filter bar: search + folder dropdown share ONE row ──────────────────── */
/* The point of this file's rewrite: the folder control must not add vertical
 * space. Search flexes, the dropdown takes a fixed 150px. */
.v9-filterbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.v9-filterbar .v9-search-group { flex: 1 1 auto; min-width: 0; }
.v9-filterbar .v9f-rail {
  flex: 0 0 auto;
  width: 150px;
  padding: 0;
}
.v9-filterbar .v9f-select { width: 150px; }

@media (max-width: 720px) {
  .v9-filterbar .v9f-rail,
  .v9-filterbar .v9f-select { width: 118px; }
}

/* Read-only mode (Ben 2026-11-13: folder sync is one-way, Telegram -> CRM).
   The create/rename/delete controls are not rendered at all when this is shown, so this
   note is the only hint the operator gets about WHY the rail looks bare. */
.v9f-readonly {
  margin-top: 6px;
  padding: 6px 8px;
  font-size: 11px;
  color: var(--v9f-text2);
  border-top: 1px solid var(--v9f-border);
  display: flex;
  align-items: center;
  gap: 5px;
}
