/* ── Control Center ── */
.control-body { min-height: 100vh; }
.control-topbar { flex-wrap: wrap; }
.control-search-wrap { flex: 1; min-width: 220px; max-width: 480px; }
.control-search {
  width: 100%; height: 42px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 10px;
  font: inherit; background: #f8fafc;
}
.control-search:focus { outline: 2px solid rgba(15,118,110,.25); border-color: var(--teal); }

.control-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
  width: min(1280px, calc(100vw - 32px));
  margin: 20px auto 60px;
  align-items: start;
}
.control-sidebar { padding: 16px; position: sticky; top: 12px; }
.control-sidebar-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.device-list { display: flex; flex-direction: column; gap: 8px; max-height: calc(100vh - 180px); overflow: auto; }

.device-card {
  border: 1px solid var(--line); border-radius: 12px; padding: 12px;
  background: #f8fafc; cursor: pointer; text-align: left; width: 100%;
  font: inherit; color: inherit;
}
.device-card:hover { border-color: var(--teal); background: #ecfdf5; }
.device-card.active { border-color: var(--teal); background: #e6f4f1; box-shadow: 0 0 0 2px rgba(15,118,110,.12); }
.device-card strong { display: block; font-size: 15px; }
.device-card .owner { color: var(--muted); font-size: 13px; margin-top: 2px; }
.device-card .meta { color: var(--muted); font-size: 12px; margin-top: 6px; line-height: 1.4; }
.device-card .online { color: var(--green); font-weight: 700; font-size: 11px; }

.control-main { min-width: 0; }
.time-tabs {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px;
}
.time-tab {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px;
  padding: 7px 14px; font-size: 13px; font-weight: 600; cursor: pointer; color: #475569;
}
.time-tab:hover { border-color: var(--teal); }
.time-tab.active { background: var(--teal); border-color: var(--teal); color: #fff; }
.time-tab[data-win="live"].active { background: #dc2626; border-color: #dc2626; }

.live-pill {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  padding: 2px 8px; border-radius: 999px; background: #fef2f2; color: #dc2626;
  animation: live-pulse 2s ease-in-out infinite;
}
@keyframes live-pulse { 50% { opacity: .65; } }

.activity-card.is-live { border-color: #fecaca; box-shadow: 0 0 0 1px rgba(220,38,38,.08); }
.activity-stats { margin: 0 0 4px; font-size: 13px; font-weight: 600; color: var(--teal-dark); }
.activity-topic { margin: 0 0 6px; font-size: 13px; color: #7c3aed; font-style: italic; }

.detail-tabs {
  display: flex; gap: 4px; padding: 0 20px; border-bottom: 1px solid var(--line);
  background: #f8fafc; flex-wrap: wrap;
}
.detail-tab {
  border: 0; background: transparent; padding: 10px 14px; font-size: 13px; font-weight: 700;
  color: #64748b; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.detail-tab.active { color: var(--teal-dark); border-bottom-color: var(--teal); }
.detail-overview .detail-stat { font-weight: 700; color: var(--teal-dark); }
.detail-overview .detail-topic { color: #7c3aed; font-weight: 600; }
.bubble-src {
  display: inline-block; font-size: 10px; font-weight: 700; text-transform: uppercase;
  color: #64748b; margin-left: 6px;
}
.source-list { margin: 0; padding-left: 18px; }
.raw-pre {
  font-size: 11px; overflow: auto; max-height: 320px;
  background: #f1f5f9; padding: 12px; border-radius: 8px;
}

.journey-list { margin: 12px 0 0; padding-left: 20px; color: #334155; }
.journey-list li { margin-bottom: 8px; line-height: 1.45; }
.return-note { color: var(--teal-dark); font-weight: 600; margin: 8px 0; }
.journey-map-links { display: flex; flex-direction: column; gap: 10px; }
.journey-map-head { margin: 16px 0 8px; font-size: 13px; color: var(--muted); text-transform: uppercase; }
.journey-stop, .journey-trip {
  display: block; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  text-decoration: none; color: inherit; background: #f8fafc;
}
.journey-stop:hover, .journey-trip:hover { border-color: var(--teal); background: #ecfdf5; }

.control-toolbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 12px;
}

.category-tabs {
  display: flex; flex-wrap: wrap; gap: 6px; flex: 1; min-width: 200px;
}
.cat-tab {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px;
  padding: 6px 12px; font-size: 12px; font-weight: 600; cursor: pointer; color: #475569;
}
.cat-tab:hover { border-color: var(--teal); }
.cat-tab.active { background: var(--teal); border-color: var(--teal); color: #fff; }

.view-toggle {
  display: flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden;
}
.view-btn {
  border: 0; background: var(--panel); padding: 8px 12px; font-size: 12px; font-weight: 700;
  cursor: pointer; color: #64748b;
}
.view-btn.active { background: #e6f4f1; color: var(--teal-dark); }

.activity-feed { display: flex; flex-direction: column; gap: 10px; }
.activity-card {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 14px;
  align-items: start;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.activity-icon { font-size: 26px; line-height: 1; padding-top: 2px; }
.activity-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 4px; }
.activity-head strong { font-size: 15px; color: #0f172a; }
.activity-participants { margin: 0 0 6px; color: var(--teal-dark); font-size: 13px; font-weight: 600; }
.activity-summary { margin: 0 0 8px; color: #334155; font-size: 14px; line-height: 1.45; }
.activity-summary.story-snippet { font-size: 14px; line-height: 1.55; color: #1e293b; margin-top: 4px; }

.story-prose { color: #334155; line-height: 1.6; }
.story-section { margin-bottom: 20px; }
.story-section h3 {
  margin: 0 0 10px; font-size: 12px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted);
}
.story-section p { margin: 0 0 10px; white-space: pre-wrap; }
.story-bullets { margin: 0; padding-left: 20px; }
.story-bullets li { margin-bottom: 6px; }
.story-lead { color: #475569; font-size: 15px; line-height: 1.5; margin: 0 0 16px; }
.story-card-lead { font-size: 15px; line-height: 1.5; color: #0f172a; margin: 0 0 8px; font-weight: 500; }

.activity-meta {
  display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; color: var(--muted);
}
.activity-meta time { margin-left: auto; white-space: nowrap; }

.cat-pill, .count-pill, .typing-pill {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  padding: 2px 8px; border-radius: 999px; background: #e2e8f0; color: #475569;
}
.typing-pill { background: #fef3c7; color: #92400e; }

.activity-detail-btn {
  align-self: center;
  border: 1px solid var(--teal);
  background: #ecfdf5;
  color: var(--teal-dark);
  border-radius: 9px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.activity-detail-btn:hover { background: var(--teal); color: #fff; }

/* Detail modal */
body.modal-open { overflow: hidden; }
.detail-modal {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.detail-modal[hidden] { display: none !important; }
.detail-backdrop {
  position: absolute; inset: 0; background: rgba(15, 23, 42, .45);
}
.detail-panel {
  position: relative; width: min(720px, 100%); max-height: min(88vh, 900px);
  overflow: auto; padding: 0; z-index: 1;
}
.detail-head {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 18px 20px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--panel); z-index: 2;
}
.detail-head h2 { margin: 4px 0 0; font-size: 18px; }
.detail-sub { margin: 4px 0 0; color: var(--teal-dark); font-weight: 600; font-size: 14px; }
.detail-icon { font-size: 28px; }
.detail-close {
  border: 0; background: transparent; font-size: 28px; line-height: 1;
  cursor: pointer; color: #64748b; padding: 0 4px;
}
.detail-summary { padding: 16px 20px; border-bottom: 1px solid var(--line); background: #f8fafc; }
.detail-summary p { margin: 0 0 8px; }
.detail-body { padding: 16px 20px 24px; }
.detail-body h3 { margin: 0 0 12px; font-size: 14px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }

.conv-thread { display: flex; flex-direction: column; gap: 8px; }
.bubble {
  max-width: 85%; padding: 10px 12px; border-radius: 12px; font-size: 14px;
}
.bubble.sent { align-self: flex-end; background: #dcf8c6; border-bottom-right-radius: 4px; }
.bubble.recv { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble.unk { align-self: center; background: #f1f5f9; }
.bubble p { margin: 0; overflow-wrap: anywhere; }
.bubble time { display: block; margin-top: 4px; font-size: 11px; color: var(--muted); }
.bubble-who { display: block; font-size: 11px; font-weight: 700; color: var(--teal-dark); margin-bottom: 2px; }

.detail-timeline { list-style: none; margin: 0; padding: 0; }
.detail-timeline li {
  padding: 10px 0; border-bottom: 1px solid var(--line);
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px;
}
.detail-timeline time { grid-column: 2; font-size: 12px; color: var(--muted); white-space: nowrap; }

.typing-badge { color: #92400e; font-weight: 700; }

.health-banner {
  margin-bottom: 14px;
  border: 1px solid #fcd34d;
  background: #fffbeb;
  border-radius: 12px;
  padding: 14px 16px;
}
.health-inner { display: flex; gap: 12px; align-items: flex-start; }
.health-icon { font-size: 22px; line-height: 1.2; }
.health-block { margin-bottom: 10px; }
.health-block strong { color: #92400e; }
.health-block ul { margin: 6px 0 0 18px; padding: 0; color: #78350f; font-size: 14px; }
.health-block li { margin-bottom: 4px; }
.health-foot { margin: 8px 0 0; font-size: 13px; color: #92400e; }

.control-select {
  height: 38px; padding: 0 12px; border: 1px solid var(--line);
  border-radius: 9px; background: var(--panel); font: inherit;
}

.event-table { display: flex; flex-direction: column; gap: 6px; }
.event-row {
  display: grid;
  grid-template-columns: 140px 1fr 120px;
  gap: 12px;
  align-items: start;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}
.event-row .who { font-weight: 700; font-size: 13px; color: var(--teal-dark); }
.event-row .who small { display: block; color: var(--muted); font-weight: 500; }
.event-row .what strong { font-size: 14px; }
.event-row .what p { margin: 4px 0 0; color: #334155; font-size: 14px; overflow-wrap: anywhere; }
.event-row .when { text-align: right; color: var(--muted); font-size: 12px; white-space: nowrap; }
.event-type {
  display: inline-block; font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; padding: 2px 7px; border-radius: 999px;
  background: #e2e8f0; color: #475569; margin-top: 4px;
}

.device-edit-btn {
  margin-top: 8px; font-size: 12px; padding: 4px 10px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--panel);
  cursor: pointer;
}
.device-edit-btn:hover { border-color: var(--teal); }
.device-card-actions { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.device-card-actions a.device-edit-btn { text-decoration: none; color: inherit; display: inline-block; }

/* ── Fleet management (many devices) ── */
.fleet-bar {
  display: flex; flex-wrap: wrap; gap: 10px 20px; align-items: center;
  width: min(1280px, calc(100vw - 32px));
  margin: 0 auto 12px; padding: 12px 18px;
}
.fleet-stat { display: flex; flex-direction: column; min-width: 72px; }
.fleet-stat strong { font-size: 22px; line-height: 1.1; color: #0f172a; }
.fleet-stat span { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.fleet-stat.online-stat strong { color: var(--green); }
.fleet-stat.live-stat strong { color: #dc2626; }

.fleet-badge {
  display: inline-block; margin-left: 6px; padding: 1px 7px;
  border-radius: 999px; background: #e2e8f0; font-size: 11px; font-weight: 700; color: #475569;
}

.device-toolbar { display: flex; gap: 6px; margin-bottom: 8px; }
.device-search {
  flex: 1; min-width: 0; height: 34px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 8px; font: inherit; font-size: 13px; background: #f8fafc;
}
.device-search:focus { outline: 2px solid rgba(15,118,110,.2); border-color: var(--teal); }
.device-sort {
  height: 34px; padding: 0 8px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--panel); font: inherit; font-size: 12px; max-width: 110px;
}

.device-view-toggle {
  display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-bottom: 8px;
}
.dv-btn {
  flex: 1; border: 0; background: var(--panel); padding: 6px 8px;
  font-size: 11px; font-weight: 700; cursor: pointer; color: #64748b;
}
.dv-btn.active { background: #e6f4f1; color: var(--teal-dark); }

.device-list.compact { gap: 2px; }
.device-row {
  display: grid; grid-template-columns: 32px 1fr auto; gap: 8px; align-items: center;
  padding: 7px 8px; border-radius: 8px; cursor: pointer; border: 1px solid transparent;
}
.device-row:hover { background: #f1f5f9; border-color: var(--line); }
.device-row.active { background: #e6f4f1; border-color: var(--teal); box-shadow: 0 0 0 1px rgba(15,118,110,.1); }
.device-row.is-online .device-row-name { color: var(--teal-dark); }

.device-avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 8px; background: #e2e8f0;
  font-size: 12px; font-weight: 800; color: #475569; flex-shrink: 0;
}
.device-avatar.sm { width: 24px; height: 24px; font-size: 11px; border-radius: 6px; }
.device-avatar.lg { width: 36px; height: 36px; font-size: 14px; }

.device-row-main { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.device-row-name {
  font-size: 13px; font-weight: 700; color: #0f172a;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.device-row-sub {
  font-size: 11px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.device-row-badges { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }

.mini-pill {
  font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 999px;
  background: #e2e8f0; color: #475569;
}
.mini-pill.live { background: #fef2f2; color: #dc2626; }

.status-dot {
  width: 8px; height: 8px; border-radius: 50%; background: #cbd5e1; flex-shrink: 0;
}
.status-dot.on { background: var(--green); box-shadow: 0 0 0 2px rgba(22,163,74,.2); }

.device-card-top { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.device-card-top > div { flex: 1; min-width: 0; }

.device-pager {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line);
}
.pager-btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 7px;
  padding: 5px 10px; font-size: 11px; font-weight: 700; cursor: pointer; color: #475569;
}
.pager-btn:hover:not(:disabled) { border-color: var(--teal); color: var(--teal-dark); }
.pager-btn:disabled { opacity: .4; cursor: default; }
.pager-label { font-size: 11px; color: var(--muted); text-align: center; flex: 1; }

.selected-device-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 14px; margin-bottom: 12px; border-radius: 10px;
  background: #ecfdf5; border: 1px solid #a7f3d0; font-size: 14px; font-weight: 600; color: var(--teal-dark);
}

.group-toggle {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: #475569;
  cursor: pointer; white-space: nowrap;
}
.group-toggle input { accent-color: var(--teal); }

.device-activity-group {
  border: 1px solid var(--line); border-radius: 14px; overflow: hidden; margin-bottom: 4px;
}
.device-group-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; background: #f8fafc; border-bottom: 1px solid var(--line);
}
.device-group-head > div { flex: 1; min-width: 120px; }
.device-group-head strong { font-size: 14px; }
.device-group-head .owner { display: block; font-size: 12px; color: var(--muted); font-weight: 500; }
.group-count { font-size: 12px; color: var(--muted); font-weight: 600; }
.group-focus { margin-left: auto; }
.device-group-feed { display: flex; flex-direction: column; gap: 0; }
.device-group-feed .activity-card { border: 0; border-radius: 0; box-shadow: none; border-bottom: 1px solid var(--line); }
.device-group-feed .activity-card:last-child { border-bottom: 0; }

.device-pill {
  font-size: 10px; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  background: #e6f4f1; color: var(--teal-dark);
}

.sidebar-toggle { display: none; }

.overview-panel {
  margin-bottom: 14px;
  padding: 16px 18px;
}
.overview-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.overview-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.overview-stat .label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}
.overview-stat strong { display: block; font-size: 15px; }
.overview-apps {
  margin: 8px 0 0;
  padding-left: 18px;
  font-size: 13px;
  color: var(--muted);
}
.overview-link {
  display: inline-block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--teal-dark);
  font-weight: 600;
}
.perm-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.perm-chip {
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #f1f5f9;
  color: #64748b;
}
.perm-chip.ok { background: #dcfce7; color: #166534; }
.perm-chip.bad { background: #fef3c7; color: #92400e; }

@media (max-width: 900px) {
  .overview-grid { grid-template-columns: 1fr; }
  .control-layout { grid-template-columns: 1fr; }
  .control-sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 900; width: min(320px, 88vw);
    max-height: 100vh; overflow: auto; transform: translateX(-105%);
    transition: transform .2s ease; margin: 0; border-radius: 0;
    box-shadow: 4px 0 24px rgba(15,23,42,.15);
  }
  .control-layout.sidebar-open .control-sidebar { transform: translateX(0); }
  .sidebar-toggle { display: inline-flex; }
  .device-list { max-height: calc(100vh - 220px); }
  .event-row { grid-template-columns: 1fr; }
  .event-row .when { text-align: left; }
  .activity-card { grid-template-columns: 36px 1fr; }
  .activity-detail-btn { grid-column: 1 / -1; width: 100%; }
  .activity-meta time { margin-left: 0; width: 100%; }
}
