/* Spark Sessions Dashboard — mobile-first
 * Design influences: Linear mobile (snappy transitions, structured chips),
 * iMessage / Slack mobile (chat-list pattern, dock composer).
 *
 * Key choices:
 *  - Single source CSS, no preprocessor.
 *  - Uses CSS variables for color groups so server can set --group-color.
 *  - Hardware-accelerated transforms only.
 *  - Dark theme matches the broader Spark internal site.
 */

:root {
  --bg: #0A0A0A;
  --bg-card: #141414;
  --bg-card-hover: #1A1A1A;
  --bg-elev: #1F1F1F;
  --border: #262626;
  --border-strong: #383838;
  --text: #F5F5F5;
  --text-dim: #A0A0A0;
  --text-faint: #707070;
  --accent: #3B82F6;

  --group-red:    #EF4444;
  --group-orange: #F59E0B;
  --group-purple: #A78BFA;
  --group-blue:   #3B82F6;
  --group-green:  #10B981;
  --group-gray:   #6B7280;

  --safe-bottom: env(safe-area-inset-bottom, 0);
  --safe-top: env(safe-area-inset-top, 0);

  --t-fast: 160ms cubic-bezier(0.25, 0.1, 0.25, 1);
  --t-med: 240ms cubic-bezier(0.25, 0.1, 0.25, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-feature-settings: 'cv11', 'ss01';
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  height: 100dvh;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }

/* ─── Topbar ─── */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(var(--safe-top) + 12px) 12px 12px;
  background: rgba(10,10,10,0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-title {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.topbar-eyebrow {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  line-height: 1;
}
.topbar h1 {
  font-size: 18px;
  font-weight: 600;
  margin: 2px 0 0;
  letter-spacing: -0.01em;
}
.detail-title h1 { font-size: 16px; }
.icon-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
  color: var(--text-dim);
  transition: background var(--t-fast), color var(--t-fast);
}
.icon-btn:active { background: var(--bg-elev); color: var(--text); transform: scale(0.96); }
.icon-btn:hover { color: var(--text); }

/* ─── Search ─── */
.search-row {
  display: flex;
  gap: 8px;
  padding: 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
#search {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
  transition: border-color var(--t-fast);
}
#search:focus { outline: none; border-color: var(--accent); }
#search::placeholder { color: var(--text-faint); }

/* ─── Session list ─── */
.session-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 0 calc(72px + var(--safe-bottom));
}
.loading {
  text-align: center;
  color: var(--text-faint);
  padding: 40px 16px;
  font-size: 14px;
}

.group-header {
  display: flex; align-items: center; gap: 8px;
  padding: 18px 16px 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.group-header .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--group-color, var(--text-faint));
}

.session-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: transparent;
  border: 0;
  width: 100%;
  text-align: left;
  cursor: pointer;
  transition: background var(--t-fast), transform var(--t-fast);
  position: relative;
}
.session-row:active {
  background: var(--bg-card-hover);
  transform: scale(0.99);
}
.session-row + .session-row {
  border-top: 1px solid var(--border);
}
.session-row.has-pending::after {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--group-color, var(--accent));
}
.session-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--group-color, var(--accent)) 18%, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
  position: relative;
}
.session-icon .heartbeat {
  position: absolute;
  bottom: -2px; right: -2px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--text-faint);
  border: 2px solid var(--bg);
}
.session-icon.live .heartbeat { background: var(--group-green); }
.session-icon.recent .heartbeat { background: var(--group-orange); }
.session-icon.idle .heartbeat { background: var(--text-faint); }
.session-icon.pulse .heartbeat {
  background: var(--group-green);
  animation: heartbeat-pulse 1.4s ease-in-out infinite;
}
@keyframes heartbeat-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(16,185,129,0.5); }
  50%      { box-shadow: 0 0 0 6px rgba(16,185,129,0); }
}

.session-body {
  flex: 1;
  min-width: 0;
}
.session-row-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.session-name {
  font-weight: 600;
  font-size: 16px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session-time {
  font-size: 11px;
  color: var(--text-faint);
  flex-shrink: 0;
}
.session-subtitle {
  font-size: 13px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}
.session-pending {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  background: var(--group-color, var(--accent));
  color: white;
  font-size: 11px;
  font-weight: 700;
  border-radius: 10px;
  margin-left: 6px;
}

/* ─── Bottom nav ─── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: rgba(10,10,10,0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  z-index: 5;
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px 6px;
  color: var(--text-faint);
  text-decoration: none;
  font-size: 10px;
  font-weight: 500;
  transition: color var(--t-fast);
}
.nav-item.active { color: var(--text); }

/* ─── Detail view ─── */
.view-detail {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  z-index: 20;
  transform: translateX(100%);
  transition: transform var(--t-med);
}
body[data-view="detail"] .view-detail { transform: translateX(0); }
body[data-view="detail"] .view-list { transform: translateX(-15%); opacity: 0.5; }
.view-list { transition: transform var(--t-med), opacity var(--t-med); }

.session-meta {
  padding: 8px 16px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 11px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 500;
}
.chip .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--chip-dot, var(--text-faint));
}

/* ─── Inbox feed ─── */
.inbox-feed {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.empty-state {
  margin: auto;
  text-align: center;
  color: var(--text-faint);
}
.empty-icon { font-size: 40px; opacity: 0.5; margin-bottom: 8px; }
.empty-state .hint { font-size: 12px; margin-top: 4px; }

.msg {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 14px;
  max-width: 88%;
  align-self: flex-end;
  font-size: 14px;
  line-height: 1.4;
  animation: msgIn var(--t-med) ease-out;
}
.msg.own { background: var(--accent); color: white; border-color: transparent; }
.msg.processed { opacity: 0.55; align-self: flex-start; }
.msg .msg-meta {
  font-size: 10px;
  color: var(--text-faint);
  margin-top: 4px;
}
.msg.own .msg-meta { color: rgba(255,255,255,0.7); }
.msg .audio-tag, .msg .image-tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; opacity: 0.8;
  background: rgba(255,255,255,0.1);
  padding: 2px 6px; border-radius: 4px;
  margin-bottom: 4px;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ─── Composer ─── */
.composer {
  border-top: 1px solid var(--border);
  background: var(--bg);
  padding: 8px 8px calc(8px + var(--safe-bottom));
  flex-shrink: 0;
}
.attachments {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 0 4px 6px;
}
.attachments:empty { display: none; }
.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-dim);
}
.attachment-chip img {
  width: 24px; height: 24px;
  border-radius: 50%;
  object-fit: cover;
}
.attachment-chip .x {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--bg-elev);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
}
.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 4px 4px 4px 6px;
  transition: border-color var(--t-fast);
}
.composer-row:focus-within { border-color: var(--border-strong); }
#composer-text {
  flex: 1;
  background: transparent;
  border: 0;
  outline: 0;
  resize: none;
  font-size: 15px;
  line-height: 1.35;
  padding: 9px 6px;
  max-height: 120px;
  color: var(--text);
}
#composer-text::placeholder { color: var(--text-faint); }
.composer-mic.recording {
  background: var(--group-red);
  color: white;
  animation: pulse 1.2s ease-in-out infinite;
}
.composer-send.has-content {
  background: var(--accent);
  color: white;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.6); }
  50% { box-shadow: 0 0 0 8px rgba(239,68,68,0); }
}
.composer-status {
  font-size: 11px;
  color: var(--text-faint);
  padding: 4px 10px 0;
  min-height: 14px;
}
.composer-status.error { color: var(--group-red); }
.composer-status.success { color: var(--group-green); }

/* ─── Toast ─── */
.toast {
  position: fixed;
  bottom: calc(80px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  z-index: 100;
  transition: transform var(--t-med), opacity var(--t-med);
  opacity: 0;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ─── Tablet / desktop ─── */
@media (min-width: 768px) {
  body { display: grid; grid-template-columns: 360px 1fr; }
  .view-list {
    border-right: 1px solid var(--border);
    height: 100dvh;
  }
  .view-detail {
    position: relative;
    transform: none !important;
    z-index: auto;
  }
  body[data-view="detail"] .view-list { transform: none; opacity: 1; }
  body[data-view="list"] .view-detail { display: flex; }
  .bottom-nav { grid-column: 1 / -1; }
  .topbar-back { display: none; }
  #back-to-list { display: flex; }
}
@media (min-width: 1100px) {
  body { grid-template-columns: 380px 1fr; }
}
