:root {
  --bg: #e8e4da;
  --panel: #ebe6dc;
  --ink: #1a1f1a;
  --muted: #6a736a;
  --line: #d0c8b4;
  --accent: #1b6b4a;
  --mine: #d4edd9;
  --theirs: #fff;
  --quote: #e8eef6;
  --font: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); }
.app { height: 100%; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 6px 10px; border-bottom: 1px solid var(--line); background: #f3efe6;
}
.icon-btn {
  display: inline-grid; place-items: center;
  width: 28px; height: 28px; padding: 0;
  border: 1px solid transparent; border-radius: 6px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: #fff; border-color: var(--line); color: var(--ink); }
.icon-btn.active {
  background: #fff; border-color: var(--line); color: var(--accent);
}

.offers-panel {
  position: absolute; inset: 41px 0 0 0; z-index: 20;
  display: flex; flex-direction: column;
  background: #f4f1ea;
  border-top: 1px solid var(--line);
}
.offers-panel.hidden { display: none !important; }
.app { position: relative; }
.offers-panel-head {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #faf7f1 0%, #f3efe6 100%);
}
.offers-head-copy {
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.offers-panel-head strong {
  font-size: 0.95rem; font-weight: 700; letter-spacing: -0.01em;
}
.offers-panel-head .muted {
  font-size: 0.72rem; color: var(--muted);
}
.offers-panel-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.offers-panel-actions input[type="search"] {
  width: 200px; height: 32px; border-radius: 999px;
  padding: 0 12px; background: #fff;
}
.offers-check {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 999px;
  background: #fff;
  font-size: 0.75rem; font-weight: 650; color: var(--ink);
  cursor: pointer; user-select: none;
}
.offers-check:has(input:checked) {
  background: #e6f5ec; border-color: #b7dfc6; color: #146043;
}
.offers-check input { accent-color: var(--accent); }
.offers-active-filters {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 16px; border-bottom: 1px solid var(--line);
  background: #efe9dc;
}
.offers-active-filters.hidden { display: none !important; }
.offers-filter-chip {
  display: inline-flex; align-items: center; gap: 6px;
  max-width: min(420px, 100%);
  height: 28px; padding: 0 4px 0 10px;
  border-radius: 999px; border: 1px solid #c8e2d2;
  background: #e6f5ec; color: #146043;
  font-size: 0.75rem;
}
.offers-filter-chip-label {
  font-weight: 650; color: #3d6b54; opacity: 0.85;
}
.offers-filter-chip strong {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-weight: 700;
}
.offers-filter-chip-clear {
  width: 22px; height: 22px; padding: 0;
  border: 0; border-radius: 999px;
  background: transparent; color: #146043;
  font-size: 1rem; line-height: 1; cursor: pointer;
}
.offers-filter-chip-clear:hover { background: rgba(20, 96, 67, 0.12); }
.status-pill {
  display: inline-block; font-size: 0.65rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.03em;
  padding: 2px 8px; border-radius: 999px;
  border: 0; font-family: inherit; line-height: inherit;
}
.status-pill.new { background: #e6f5ec; color: #146043; }
.status-pill.old { background: #eee9df; color: #6a736a; }
button.status-pill-link {
  cursor: pointer;
  text-decoration: none;
}
button.status-pill-link:hover {
  filter: brightness(0.97);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08);
}
.source-pill {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 650;
  padding: 2px 7px;
  border-radius: 6px;
  background: #efe9dc;
  color: #4a524a;
  white-space: nowrap;
}
.source-pill.source-chat { background: #e8f0ea; color: #146043; }
.source-pill.source-google-sheet { background: #e6f4ea; color: #137333; }
.source-pill.source-google-drive { background: #e8f0fe; color: #1967d2; }
.source-pill.source-excel { background: #e6f4ea; color: #0d652d; }
.source-pill.source-csv { background: #e6f4ea; color: #0d652d; }
.source-pill.source-pdf { background: #fce8e6; color: #c5221f; }
.source-pill.source-image { background: #fef7e0; color: #8a5a00; }
.source-pill.source-word { background: #e8f0fe; color: #185abc; }
.source-pill.source-file { background: #eee9df; color: #5f6368; }
a.source-pill.source-link {
  text-decoration: none;
  cursor: pointer;
}
a.source-pill.source-link:hover {
  filter: brightness(0.96);
  outline: 1px solid rgba(0,0,0,0.12);
}
.offers-table th.col-date,
.offers-table td.col-date {
  font-variant-numeric: tabular-nums; max-width: 100px;
}
.offers-table-wrap {
  flex: 1; min-height: 0; overflow: auto;
  background:
    radial-gradient(circle at 1px 1px, rgba(0,0,0,0.035) 1px, transparent 0) 0 0 / 18px 18px,
    #f7f4ee;
}
.offers-table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  font-size: 0.78rem; background: transparent;
}
.offers-table th, .offers-table td {
  border-bottom: 1px solid rgba(208, 200, 180, 0.7);
  padding: 9px 12px; text-align: left; vertical-align: middle;
  white-space: nowrap; max-width: 220px;
  overflow: hidden; text-overflow: ellipsis;
  background: rgba(255,255,255,0.92);
}
.offers-table th.col-num,
.offers-table td.col-num {
  width: 36px; max-width: 44px; text-align: right;
  color: var(--muted); font-variant-numeric: tabular-nums;
}

.offers-table th {
  position: sticky; top: 0; z-index: 1;
  background: #f3efe6; font-weight: 700; color: var(--muted);
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.04em;
  border-bottom: 1px solid var(--line);
}
.offers-table th.sortable {
  cursor: pointer; user-select: none;
  padding-right: 18px;
}
.offers-table th.sortable::after {
  content: "↕";
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.62rem;
  opacity: 0.35;
}
.offers-table th.sortable {
  position: sticky;
}
.offers-table th.sortable.sorted {
  color: var(--accent);
}
.offers-table th.sortable.sorted-asc::after { content: "↑"; opacity: 0.9; }
.offers-table th.sortable.sorted-desc::after { content: "↓"; opacity: 0.9; }
.offers-table th.sortable:hover {
  color: var(--ink);
  background: #efe9dc;
}
.offers-table tr.clickable { cursor: pointer; }
.offers-table tr:hover td { background: #f7fbf8; }
.offers-table td.wrap { white-space: normal; max-width: 280px; }
.offers-table .app-cell { font-weight: 650; color: var(--accent); cursor: pointer; }
.offers-table .src-sheet { color: #8a5a00; font-size: 0.68rem; margin-left: 4px; }
.adv-filter-btn {
  max-width: 100%;
  padding: 0;
  border: 0; background: transparent;
  color: var(--ink); font: inherit; font-weight: 650;
  text-align: left; cursor: pointer;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 2px;
}
.adv-filter-btn:hover {
  color: var(--accent);
  text-decoration-color: currentColor;
}
.adv-filter-btn.active {
  color: var(--accent);
  text-decoration-color: currentColor;
}
.followup-am-stats {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 8px 14px; border-bottom: 1px solid var(--line);
  background: #f3efe6;
}
.followup-am-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 9px; border-radius: 7px;
  background: #fff; border: 1px solid var(--line);
  font-size: 0.72rem; cursor: pointer;
}
.followup-am-chip:hover, .followup-am-chip.active {
  border-color: var(--accent); background: #e6f5ec;
}
.followup-am-chip .fu-need { color: #a33; font-weight: 700; }
.followup-am-chip .fu-chased { color: #8a5a00; font-weight: 650; }
.followup-am-chip .fu-ok { color: var(--accent); font-weight: 650; }
.followup-am-chip .fu-focus-metric {
  background: #fff;
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 0 6px;
}
.followup-am-chip .fu-chip-sub {
  font-size: 0.65rem;
  opacity: 0.85;
}
.followup-am-chip [data-status] { cursor: pointer; }
.followup-am-chip [data-status]:hover { text-decoration: underline; }
.fu-pill {
  display: inline-block; font-size: 0.65rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.03em;
  padding: 1px 6px; border-radius: 999px;
}
.fu-pill.needs_followup { background: #fde8e8; color: #a12626; }
.fu-pill.chased { background: #f8efd8; color: #8a5a00; }
.fu-pill.confirmed { background: #e6f5ec; color: #146043; }
.followup-table td.snip {
  white-space: normal; max-width: 220px; font-size: 0.72rem; color: var(--muted);
}
.followup-table th.sortable { cursor: pointer; user-select: none; }
.followup-table th.sortable:hover { color: var(--accent); }
.followup-table td.fu-miss { color: #a12626; font-weight: 650; }
.followup-table td.fu-silent { color: #8a5a00; font-style: italic; }
.followup-table th.col-pkgs,
.followup-table td.col-pkgs {
  min-width: 180px;
  max-width: 380px;
}
.fu-pkg-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  line-height: 1.35;
}
.fu-pkg-row,
.fu-pkg-rest {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
}
.fu-pkg-rest.hidden { display: none; }
.fu-pkg-count {
  font-weight: 700;
  color: var(--ink);
  font-size: 0.8rem;
}
.fu-pkg-chip {
  display: inline-block;
  margin: 0;
  padding: 1px 6px;
  border: 1px solid #c5ddd0;
  border-radius: 4px;
  background: #f3faf6;
  color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.68rem;
  font-weight: 650;
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fu-pkg-chip:hover { border-color: var(--accent); background: #e6f5ec; }
.fu-pkg-chip.fu-pkg-focus {
  outline: 2px solid #e89b2d;
  outline-offset: 1px;
  background: #fff4d6;
}
.fu-pkg-more {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 650;
  cursor: pointer;
  text-decoration: underline;
  padding: 0 2px;
}
.fu-pkg-more:hover { color: var(--ink); }
.brand-row { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; }
.brand-logo {
  display: inline-flex; align-items: center;
  margin-left: 2px; margin-right: 2px;
  text-decoration: none; line-height: 0;
}
.brand-logo img {
  display: block;
  height: 28px;
  width: auto;
}
.source-toggle {
  display: inline-flex; align-items: center;
  height: 28px; padding: 2px; margin-left: 4px;
  border: 1px solid var(--line); border-radius: 999px; background: #fff;
}
.source-toggle-btn {
  border: 0; background: transparent; border-radius: 999px;
  height: 22px; padding: 0 11px;
  font-size: 0.72rem; font-weight: 700; color: var(--muted);
  cursor: pointer;
}
.source-toggle-btn:hover { color: var(--ink); }
.source-toggle-btn.active {
  background: var(--accent); color: #fff;
}
/* Live = connector health LED (green ok / red fault). Works even when Old is selected. */
.source-toggle-btn#sourceLiveBtn.live-ok {
  color: #0d5c3d;
  box-shadow: 0 0 0 0 rgba(27, 107, 74, 0.35);
  animation: live-ok-pulse 2.4s ease-out infinite;
}
.source-toggle-btn#sourceLiveBtn.live-ok.active {
  background: #1b6b4a;
  color: #fff;
  box-shadow: 0 0 0 0 rgba(27, 107, 74, 0.5);
  animation: live-ok-pulse 2s ease-out infinite;
}
.source-toggle-btn#sourceLiveBtn.live-bad {
  color: #9b1c1c;
  box-shadow: 0 0 0 0 rgba(180, 35, 24, 0.35);
  animation: live-bad-pulse 1.6s ease-out infinite;
}
.source-toggle-btn#sourceLiveBtn.live-bad.active {
  background: #b42318;
  color: #fff;
  box-shadow: 0 0 0 0 rgba(180, 35, 24, 0.5);
  animation: live-bad-pulse 1.4s ease-out infinite;
}
@keyframes live-ok-pulse {
  0% { box-shadow: 0 0 0 0 rgba(27, 107, 74, 0.45), 0 0 10px rgba(27, 107, 74, 0.35); }
  70% { box-shadow: 0 0 0 7px rgba(27, 107, 74, 0), 0 0 0 rgba(27, 107, 74, 0); }
  100% { box-shadow: 0 0 0 0 rgba(27, 107, 74, 0), 0 0 0 rgba(27, 107, 74, 0); }
}
@keyframes live-bad-pulse {
  0% { box-shadow: 0 0 0 0 rgba(180, 35, 24, 0.5), 0 0 10px rgba(180, 35, 24, 0.4); }
  70% { box-shadow: 0 0 0 7px rgba(180, 35, 24, 0), 0 0 0 rgba(180, 35, 24, 0); }
  100% { box-shadow: 0 0 0 0 rgba(180, 35, 24, 0), 0 0 0 rgba(180, 35, 24, 0); }
}
.filters { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.filters select {
  min-width: 118px;
  cursor: pointer;
  color: var(--ink);
}
.filters select:disabled {
  opacity: 1;
  color: var(--ink);
  cursor: pointer;
  pointer-events: auto;
}
.date-picker { position: relative; }
.date-picker-btn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 32px; padding: 0 10px 0 8px;
  border: 1px solid var(--line); border-radius: 999px;
  background: #fff; color: var(--ink);
  font-size: 0.8rem; font-weight: 650; cursor: pointer;
  white-space: nowrap; max-width: 260px;
}
.date-picker-btn svg { flex-shrink: 0; color: var(--muted); }
.date-picker-btn span {
  overflow: hidden; text-overflow: ellipsis;
}
.date-picker-btn:hover { border-color: #c2bba8; }
.date-picker-btn.active {
  border-color: var(--accent); color: var(--accent);
  box-shadow: 0 0 0 3px rgba(27, 107, 74, 0.12);
}
.date-picker-btn.active svg { color: var(--accent); }
.date-picker-pop {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 40;
  width: 292px;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 10px 28px rgba(40, 36, 24, 0.16);
}
.date-picker-pop.hidden { display: none; }
.dp-presets {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-bottom: 10px;
}
.dp-chip {
  border: 1px solid var(--line); background: #f7f4ee;
  border-radius: 999px; padding: 3px 9px;
  font-size: 0.7rem; font-weight: 650; color: var(--ink);
  cursor: pointer;
}
.dp-chip:hover { background: #efe9dc; }
.dp-chip.active {
  background: #e6f5ec; border-color: var(--accent); color: #146043;
}
.dp-cal-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 2px 0 8px;
}
.dp-cal-head strong { font-size: 0.85rem; }
.dp-weekdays, .dp-grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 2px; text-align: center;
}
.dp-weekdays span {
  font-size: 0.65rem; font-weight: 700; color: var(--muted);
  padding: 2px 0 4px;
}
.dp-day {
  height: 32px; padding: 0; border: 0; background: transparent;
  border-radius: 8px; font-size: 0.78rem; font-weight: 600;
  color: var(--ink); cursor: pointer;
}
.dp-day:hover { background: #efe9dc; }
.dp-day.outside { color: #b3aa98; font-weight: 500; }
.dp-day.today { box-shadow: inset 0 0 0 1px var(--accent); }
.dp-day.disabled,
.dp-day:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}
.dp-day.in-range { background: #e6f5ec; border-radius: 0; }
.dp-day.start, .dp-day.end {
  background: var(--accent); color: #fff;
}
.dp-day.start { border-radius: 8px 0 0 8px; }
.dp-day.end { border-radius: 0 8px 8px 0; }
.dp-day.start.end, .dp-day.single {
  border-radius: 8px;
}
.dp-day.start:hover, .dp-day.end:hover { background: #165c40; color: #fff; }
.dp-foot {
  display: flex; align-items: center; gap: 6px;
  margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--line);
}
.dp-hint {
  flex: 1; font-size: 0.72rem; color: var(--muted); font-weight: 650;
}
.dp-foot .btn { padding: 4px 10px; font-size: 0.75rem; }
input, select, button {
  font: inherit; border: 1px solid var(--line); border-radius: 7px;
  padding: 5px 8px; background: #fff; font-size: 0.82rem;
}
input[type="search"] { width: 170px; }
.btn { cursor: pointer; background: #fff; }
.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 650;
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-toggle.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.hidden { display: none !important; }

.layout {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: 320px 1fr;
}

.sidebar {
  border-right: 1px solid var(--line); background: #f0ebe1;
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar-head {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 8px 12px 4px;
  font-size: 0.75rem; font-weight: 650; color: var(--muted);
}
.sidebar-tabs { display: flex; gap: 2px; }
.side-tab {
  border: 1px solid var(--line); background: #fff; cursor: pointer;
  font: inherit; font-size: 0.72rem; font-weight: 650;
  padding: 3px 8px; border-radius: 6px; color: var(--muted);
}
.side-tab.active {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
.sheet-detail {
  overflow: auto; padding: 12px 16px 24px;
  display: flex; flex-direction: column; gap: 14px;
  flex: 1; min-height: 0;
}
.sheet-card {
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px;
}
.sheet-card h3 {
  margin: 0 0 6px; font-size: 0.82rem; color: var(--muted); font-weight: 650;
}
.sheet-link {
  word-break: break-all; font-size: 0.82rem; color: #1a5fb4;
}
.sheet-msg {
  white-space: pre-wrap; word-break: break-word;
  font-size: 0.86rem; line-height: 1.35; margin: 0;
}
.pkg-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.pkg-list li {
  display: flex; justify-content: space-between; gap: 8px; align-items: baseline;
  font-size: 0.8rem; padding: 5px 8px; border-radius: 6px; background: #f7f4ee;
}
.pkg-list li.new {
  background: #e6f5ec; outline: 1px solid #b7dfc6;
}
.pkg-list .tag {
  flex-shrink: 0; font-size: 0.65rem; font-weight: 700;
  color: #146043; text-transform: uppercase;
}
.pkg-list .old { color: var(--muted); font-size: 0.65rem; }
.sidebar-tools {
  display: flex; flex-direction: column; gap: 5px;
  padding: 0 8px 8px;
}
.sidebar-tools input[type="search"],
.sidebar-tools select {
  width: 100%;
  font-size: 0.75rem;
  padding: 5px 7px;
  background: #fff;
}
.pill {
  background: #d6ebe0; color: var(--accent);
  border-radius: 999px; padding: 0 6px; font-size: 0.72rem;
}
.conv-list { overflow: auto; padding: 2px 6px 10px; flex: 1; min-height: 0; }
.conv-item {
  width: 100%; text-align: left; border: 0; background: transparent;
  padding: 9px 10px; border-radius: 8px; cursor: pointer;
  display: flex; flex-direction: column; gap: 3px;
}
.conv-item:hover { background: rgba(255,255,255,0.65); }
.conv-item.active { background: #fff; box-shadow: inset 2px 0 0 var(--accent); }
.conv-item.am-item .conv-title { font-weight: 650; }
.conv-row {
  display: flex;
  align-items: stretch;
  gap: 4px;
}
.conv-row .conv-item { flex: 1; min-width: 0; }
.conv-item.live-gone,
.conv-item.live-gone:hover,
.conv-item.live-gone.active {
  background: transparent;
  box-shadow: none;
}
.conv-item.live-gone.active { box-shadow: inset 2px 0 0 var(--accent); background: #fff; }
.conv-item.live-gone .conv-title { color: inherit; }
.conv-dot-out {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  margin-top: 5px;
  border-radius: 50%;
  background: #c45046;
}
.conv-del {
  flex-shrink: 0;
  align-self: center;
  border: 1px solid var(--line);
  background: #fff;
  color: #8f2f28;
  font-size: 0.68rem;
  font-weight: 650;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.conv-del:hover { background: #f6ddd9; border-color: #e8c0ba; }
.live-delete-btn {
  font-size: 0.72rem !important;
  padding: 4px 10px !important;
  white-space: nowrap;
  background: #fff;
  border: 1px solid #c45046;
  color: #8f2f28;
  font-weight: 650;
}
.live-delete-btn:hover { background: #f6ddd9; }
.live-delete-btn.hidden { display: none !important; }
.am-roster-summary {
  margin: 2px 4px 8px;
  padding: 7px 9px;
  font-size: 0.7rem;
  line-height: 1.35;
  color: var(--muted);
  background: rgba(255,255,255,0.55);
  border: 1px solid var(--line);
  border-radius: 7px;
}
.am-roster-summary strong { color: var(--accent); font-weight: 700; }
.am-back {
  width: 100%; text-align: left; border: 0; background: transparent;
  padding: 6px 10px 8px; margin-bottom: 2px;
  font-size: 0.72rem; font-weight: 650; color: var(--accent);
  cursor: pointer; border-radius: 6px;
}
.am-back:hover { background: rgba(255,255,255,0.65); }
.conv-top, .conv-sub {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
  min-width: 0;
}
.conv-title {
  font-weight: 600; font-size: 0.84rem; line-height: 1.3;
  white-space: normal; overflow: visible; word-break: break-word;
  flex: 1; min-width: 0;
}
.conv-time {
  flex-shrink: 0; color: var(--muted); font-size: 0.68rem;
  padding-top: 2px;
}
.conv-sub-text {
  color: var(--muted); font-size: 0.72rem; line-height: 1.3;
  white-space: normal; overflow: visible; word-break: break-word;
  flex: 1; min-width: 0;
}
.conv-count {
  flex-shrink: 0; color: var(--muted); font-size: 0.68rem; font-variant-numeric: tabular-nums;
}
.exchange {
  flex-shrink: 0; font-size: 0.68rem; font-weight: 700;
  font-variant-numeric: tabular-nums;
  background: rgba(0,0,0,0.05); border-radius: 999px; padding: 1px 6px;
  letter-spacing: 0.02em;
}
.exchange .ex-us { color: var(--accent); }
.exchange .ex-sep { color: var(--muted); margin: 0 1px; }
.exchange .ex-them { color: #8a4b12; }
.exchange.heavy {
  background: #fde8d8; outline: 1px solid #e8b48a;
}
.exchange.heavy .ex-them { color: #a03a00; }
.exchange.scoped {
  background: #e8f0fa;
  outline: 1px solid #b7c9e0;
}
.exchange-detail {
  display: inline-block; margin-top: 2px;
  font-size: 0.72rem; color: #8a4b12; font-weight: 600;
}

.thread {
  min-height: 0; display: flex; flex-direction: column; background: var(--panel);
}
.empty {
  margin: auto; color: var(--muted); font-size: 0.9rem;
}
.thread-panel { display: flex; flex-direction: column; min-height: 0; height: 100%; }
.thread-panel.hidden { display: none; }
.thread-head {
  border-bottom: 1px solid var(--line);
  background: #f7f3ec;
  flex-shrink: 0;
}
.thread-head-main {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  min-height: 56px;
}
.thread-head-main.hidden { display: none; }
.thread-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.thread-who {
  min-width: 0;
  flex: 1;
}
.thread-head h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 650;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.thread-sub {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.thread-head-actions {
  display: flex; align-items: center; gap: 6px; flex-shrink: 0;
  justify-content: flex-end;
}
.thread-search-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  min-height: 56px;
}
.thread-search-bar.hidden { display: none; }
.thread-search-bar input[type="search"] {
  flex: 1;
  width: auto;
  min-width: 0;
  height: 36px;
  border-radius: 18px;
  padding: 0 14px;
  background: #fff;
  font-size: 0.88rem;
}
.thread-search-bar .hit-nav {
  margin-top: 0;
}
.thread-context {
  padding: 6px 14px;
  font-size: 0.72rem;
  font-weight: 650;
  color: #5a4a28;
  background: #f3ead4;
  border-bottom: 1px solid #e4d6b4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.thread-context.hidden { display: none; }
.thread-context.live-gone {
  color: #7a2e28;
  background: #f6ddd9;
  border-bottom-color: #e8c0ba;
  white-space: normal;
}
.followup-back-btn {
  font-size: 0.72rem !important;
  padding: 4px 10px !important;
  white-space: nowrap;
  background: #fff;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-weight: 650;
}
.followup-back-btn:hover {
  background: #e6f5ec;
}
.followup-back-btn.hidden { display: none !important; }
.offers-back-btn {
  font-size: 0.72rem !important;
  padding: 4px 10px !important;
  white-space: nowrap;
  background: #fff;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-weight: 650;
}
.offers-back-btn:hover {
  background: #e6f5ec;
}
.offers-back-btn.hidden { display: none !important; }
.offers-table tr.offers-return-focus td {
  background: #fff4d6 !important;
  box-shadow: inset 3px 0 0 var(--accent);
}
.fu-origin-btn {
  font-size: 0.72rem !important;
  padding: 4px 10px !important;
  white-space: nowrap;
  background: #fff8e8;
  border: 1px solid #c48a1a;
  color: #8a5a00;
  font-weight: 700;
}
.fu-origin-btn:hover { background: #ffefcc; }
.fu-origin-btn.hidden { display: none !important; }
.row.focus-msg-origin .bubble {
  outline: 2px solid #c48a1a;
  box-shadow: 0 0 0 3px rgba(196, 138, 26, 0.2);
}
.row.focus-msg-follow .bubble {
  outline: 2px solid var(--accent);
  box-shadow: 0 0 0 3px rgba(27, 107, 74, 0.18);
}
.pkg-sheet tr.fu-pkg-row-hit td {
  background: #fff4d6;
}
.pkg-sheet tr.fu-pkg-row-hit.fu-pkg-clickable {
  cursor: pointer;
}
.pkg-sheet tr.fu-pkg-row-hit.fu-pkg-clickable:hover td {
  background: #ffecb8;
}
.pkg-sheet tr.fu-pkg-row-selected td {
  background: #ffd666 !important;
  box-shadow: inset 3px 0 0 #c48a1a;
}
.pkg-sheet tr.fu-pkg-row-selected td.pkg-p mark.hit {
  background: #ffbf1a;
  outline: 1px solid #8a5a00;
}
.pkg-sheet tr.fu-pkg-row-hit td.pkg-p mark.hit {
  background: #ffd666;
  outline: 1px solid #c48a1a;
}
.followup-table tr.fu-return-focus td {
  background: #fff4d6 !important;
  box-shadow: inset 3px 0 0 var(--accent);
}
.followup-table tr.fu-return-focus td.app-cell {
  outline: 2px solid #e89b2d;
  outline-offset: -2px;
}
.hit-nav {
  display: inline-flex; align-items: center; gap: 4px;
  flex-shrink: 0; margin-top: 1px;
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  padding: 1px 4px; font-size: 0.7rem; font-weight: 650; color: var(--muted);
}
.hit-nav.hidden { display: none !important; }
.hit-btn {
  width: 22px; height: 20px; padding: 0; line-height: 1;
  border: 0; background: transparent; cursor: pointer; color: var(--ink);
  border-radius: 5px; font-size: 0.65rem;
}
.hit-btn:hover { background: #efe9dc; }
.hit-btn:disabled { opacity: 0.35; cursor: default; }
.muted { margin: 0; color: var(--muted); font-size: 0.7rem; line-height: 1.25; }

.message-list {
  overflow: auto;
  padding: 10px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  background-color: #e5ddd5;
  background-image:
    radial-gradient(rgba(0,0,0,0.035) 1px, transparent 1px);
  background-size: 18px 18px;
}

.row { display: flex; width: 100%; }
.row.focus-msg .bubble { outline: 2px solid var(--accent); box-shadow: 0 0 0 3px rgba(27,107,74,0.18); }
.row.mine { justify-content: flex-end; }
.row.theirs, .row.unknown { justify-content: flex-start; }

.bubble {
  max-width: min(640px, 88%);
  min-width: 120px;
  padding: 6px 10px 4px;
  border-radius: 8px;
  box-shadow: 0 1px 0.5px rgba(0,0,0,0.08);
}
.bubble.wide-sheet {
  width: min(680px, 94%);
  max-width: min(720px, 96%);
}
.row.mine .bubble { background: var(--mine); border-bottom-right-radius: 2px; }
.row.theirs .bubble { background: var(--theirs); border-bottom-left-radius: 2px; }
.row.unknown .bubble { background: #f4f0e7; border: 1px dashed #cbb; }

.bubble-sender {
  display: block; font-size: 0.65rem; font-weight: 700; margin-bottom: 0;
  line-height: 1.2;
}
.row.mine .bubble-sender { color: #146043; }
.row.theirs .bubble-sender { color: #2a4570; }
.row.unknown .bubble-sender { color: #666; }

.quote {
  background: var(--quote);
  border-left: 3px solid #4a6fa5;
  border-radius: 4px;
  padding: 2px 5px;
  margin: 0 0 2px;
  font-size: 0.74rem;
  cursor: pointer;
}
.row.mine .quote { border-left-color: var(--accent); background: rgba(27,107,74,0.08); }
.quote-who { font-weight: 700; font-size: 0.65rem; color: #2a4570; }
.quote-when { font-weight: 500; color: var(--muted); margin-left: 4px; }
.quote-text {
  color: #333; white-space: pre-wrap; word-break: break-word;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  line-height: 1.25;
}
.quote-hint { display: none; }

.bubble-body {
  white-space: pre-wrap; word-break: break-word;
  font-size: 0.82rem; line-height: 1.35;
}
.bubble-body-empty { min-height: 0; }
.media-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
  white-space: normal;
}
.bubble-body:not(:empty) .media-stack:first-child { margin-top: 0; }
.media-thumb {
  display: block;
  max-width: min(360px, 100%);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(0,0,0,0.08);
  background: rgba(255,255,255,0.4);
  line-height: 0;
}
.media-thumb img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 420px;
  object-fit: contain;
  background: #f7f4ee;
}
.media-video {
  max-width: min(360px, 100%);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(0,0,0,0.08);
  background: #111;
}
.media-video video {
  display: block;
  width: 100%;
  max-height: 360px;
}
.media-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(0,0,0,0.1);
  background: rgba(255,255,255,0.7);
  color: var(--ink);
  text-decoration: none;
  font-size: 0.78rem;
  line-height: 1.3;
}
a.media-chip:hover { border-color: var(--accent); color: var(--accent); }
.media-chip-missing {
  color: var(--muted);
  background: rgba(0,0,0,0.03);
}
.media-chip-kind {
  flex: 0 0 auto;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
}
.media-chip-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.media-chip-note {
  flex: 0 0 auto;
  font-size: 0.65rem;
  color: var(--muted);
}
.bubble.wide-sheet .bubble-body,
.bubble-body:has(.pkg-sheet-wrap) {
  white-space: normal;
  max-width: none;
  width: 100%;
}
.pkg-intro {
  white-space: pre-wrap;
  margin-bottom: 8px;
  line-height: 1.35;
}
.pkg-tail {
  white-space: pre-wrap;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.78rem;
}
.pkg-sheet-wrap {
  overflow-x: auto;
  width: 100%;
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 8px;
  background: rgba(255,255,255,0.55);
}
.pkg-sheet {
  width: 100%;
  min-width: 320px;
  border-collapse: collapse;
  table-layout: auto;
  font-size: 0.76rem;
  line-height: 1.35;
}
.pkg-sheet th {
  text-align: left;
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  font-weight: 700;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,0.75);
  white-space: nowrap;
}
.pkg-sheet td {
  padding: 5px 8px;
  border-bottom: 1px solid rgba(0,0,0,0.05);
  vertical-align: top;
}
.pkg-sheet tr:last-child td { border-bottom: 0; }
.pkg-sheet tr:nth-child(even) td { background: rgba(0,0,0,0.02); }
.pkg-sheet .pkg-n {
  width: 32px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
  padding-right: 6px;
}
.pkg-sheet .pkg-a { font-weight: 600; min-width: 120px; max-width: 220px; }
.pkg-sheet .pkg-p {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.72rem;
  color: var(--accent);
  word-break: break-all;
  min-width: 140px;
}
.pkg-sheet .pkg-v { color: var(--muted); white-space: nowrap; }
.row.mine .pkg-sheet-wrap { background: rgba(255,255,255,0.4); }
.row.theirs .pkg-sheet-wrap, .row.unknown .pkg-sheet-wrap {
  background: rgba(255,255,255,0.9);
}
.mention {
  color: #1a5fb4;
  font-weight: 650;
  background: rgba(26, 95, 180, 0.08);
  border-radius: 4px;
  padding: 0 2px;
}
mark.hit {
  background: #ffe08a;
  color: inherit;
  padding: 0 2px;
  border-radius: 2px;
}
mark.hit.active-hit {
  outline: 2px solid #c47a00;
  background: #ffd24d;
}
mark.fu-done {
  background: #c8ead8;
  color: inherit;
  padding: 0 2px;
  border-radius: 2px;
}
mark.fu-done.active-hit {
  outline: 2px solid #2a7a4b;
  background: #9fd4b3;
}
.pkg-sheet tr.fu-pkg-row-chased td {
  background: #eef8f1;
}
.pkg-sheet tr.fu-pkg-row-chased.fu-pkg-clickable:hover td {
  background: #dcefe3;
}
.pkg-sheet tr.fu-pkg-row-chased.fu-pkg-row-selected td {
  background: #c8ead8 !important;
  box-shadow: inset 3px 0 0 #2a7a4b;
}
.bubble-foot {
  text-align: right; font-size: 0.6rem; color: var(--muted); margin-top: 0; line-height: 1.2;
}
.day-sep {
  align-self: center;
  margin: 4px 0 2px;
  padding: 1px 8px;
  font-size: 0.68rem;
  font-weight: 650;
  color: var(--muted);
  background: rgba(255,255,255,0.7);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.row.system {
  justify-content: center;
  margin: 6px 0;
}
.sys-event {
  max-width: 92%;
  text-align: center;
  padding: 6px 12px;
  border-radius: 10px;
  background: #f3efe6;
  border: 1px dashed #cfc6b4;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}
.sys-event-text { display: block; color: #4a534a; font-weight: 550; }
.sys-event-time {
  display: block;
  margin-top: 2px;
  font-size: 0.62rem;
  color: var(--muted);
}

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { max-height: 30vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .message-list { padding: 8px 10px; }
  .bubble { max-width: 94%; }
  .bubble.wide-sheet { width: 96%; max-width: 96%; }
}

.login-body {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: #f2f0e9;
}
.login-card {
  width: min(380px, 100%);
  padding: 28px 28px 22px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f7f4ed;
}
.login-logo {
  display: block;
  height: 36px;
  width: auto;
  margin: 0 auto 14px;
}
.login-card h1 {
  margin: 0;
  text-align: center;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.login-sub {
  margin: 4px 0 18px;
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
}
.login-card label {
  display: block;
  margin: 10px 0 4px;
  font-size: 0.75rem;
  font-weight: 650;
  color: #3d463d;
}
.login-card input {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  background: #fff;
}
.login-submit {
  width: 100%;
  height: 38px;
  margin-top: 16px;
  font-size: 0.88rem;
}
.login-err {
  min-height: 1.2em;
  margin: 10px 0 0;
  color: #9a2f2f;
  font-size: 0.78rem;
}
.login-forgot-row {
  margin: 12px 0 0;
  text-align: center;
}
.login-forgot {
  border: 0;
  background: none;
  padding: 0;
  color: var(--accent);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 650;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.login-forgot:hover { color: #146043; }
.login-forgot-msg {
  min-height: 1.2em;
  margin: 8px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
}
