:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --ink: #172026;
  --muted: #64717d;
  --line: #dde5eb;
  --accent: #126a5b;
  --accent-strong: #0b4b40;
  --danger: #a5372f;
  --warning: #8a5a00;
  --shadow: 0 10px 28px rgba(23, 32, 38, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select, textarea { font: inherit; }
h1, h2, p { margin: 0; }
h1 { font-size: 28px; line-height: 1.15; }
h2 { font-size: 18px; }
p { color: var(--muted); margin-top: 6px; }
.error-text { color: var(--danger); }

.hidden { display: none !important; }
.login-gate { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-box { width: min(430px, 100%); display: grid; gap: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 28px; }
.login-mark { width: 42px; height: 42px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 272px minmax(0, 1fr); }
.sidebar {
  align-self: start;
  background: #101820;
  color: #f8fbff;
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-height: 100vh;
  padding: 20px;
  position: sticky;
  top: 0;
}
.brand { display: flex; align-items: center; gap: 12px; min-height: 44px; }
.brand-mark { width: 34px; height: 34px; }
.brand span { display: block; color: #aeb9c4; font-size: 13px; margin-top: 2px; }
.business-switcher { display: grid; gap: 6px; color: #c8d2dc; font-size: 13px; }
.business-switcher select { color: var(--ink); }
.nav { display: grid; gap: 6px; }
.nav-item {
  align-items: center;
  border: 0;
  background: transparent;
  color: #c8d2dc;
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  text-align: left;
  padding: 10px 12px;
  cursor: pointer;
}
.nav-item:hover { background: #1d2a35; color: #fff; }
.nav-item.active {
  background: #dff4ec;
  box-shadow: inset 3px 0 0 var(--accent), 0 8px 18px rgba(18, 106, 91, 0.12);
  color: var(--accent-strong);
  font-weight: 850;
}
.nav-count {
  align-items: center;
  background: var(--accent);
  border-radius: 999px;
  color: #fff;
  display: inline-flex;
  font-size: 12px;
  font-weight: 850;
  justify-content: center;
  margin-left: 8px;
  min-height: 22px;
  min-width: 24px;
  padding: 2px 7px;
}
.nav-item.active .nav-count {
  background: var(--accent);
  color: #fff;
}
.sidebar::after { content: ""; margin-top: auto; }

.content { min-width: 0; padding: 28px; }
.mobile-appbar { display: none; }
.topbar, .split-header, .toolbar { display: flex; align-items: center; gap: 12px; }
.topbar { justify-content: space-between; margin-bottom: 18px; }
.split-header { justify-content: space-between; margin-bottom: 14px; }
.toolbar.right { justify-content: flex-end; }
.filter-row { display: flex; align-items: end; gap: 10px; }
.filter-row label { min-width: 150px; }

.primary-button, .secondary-button, .icon-button {
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 8px 12px;
  cursor: pointer;
}
.primary-button { background: var(--accent); color: #fff; }
.primary-button:hover { background: var(--accent-strong); }
.secondary-button { background: #fff; border-color: var(--line); color: var(--ink); }
.icon-button { width: 38px; padding: 0; background: #fff; border-color: var(--line); }
.danger-icon-button {
  border-color: #f3c8c2;
  color: var(--danger);
}
.danger-icon-button:hover {
  background: #fff2f0;
}
.refresh-button {
  width: 40px;
  padding: 8px 0;
  font-size: 20px;
  line-height: 1;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 9px 10px;
}
textarea { resize: vertical; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }

.review-metrics { display: grid; grid-template-columns: repeat(4, minmax(140px, 1fr)); gap: 12px; margin-bottom: 18px; }
.review-metrics div, .view, .timeline-item, .card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.review-metrics div { padding: 14px; }
.review-metrics span { display: block; font-size: 24px; font-weight: 750; }
.review-metrics small { color: var(--muted); }
.view { box-shadow: var(--shadow); padding: 16px; }
.timeline, .cards { display: grid; gap: 10px; }
.feed-filter-bar {
  border-bottom: 1px solid var(--line);
  justify-content: flex-end;
  margin: -2px 0 14px;
  padding-bottom: 14px;
}
.timeline-item, .card { padding: 13px; display: grid; gap: 6px; }
.thread-card { gap: 10px; }
.item-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.muted { color: var(--muted); }
.conversation-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  color: var(--muted);
}
.message-preview {
  background: #f6f8f9;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #26343d;
  padding: 9px 10px;
}
.signal-analysis {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.signal-analysis div {
  background: #f6f8f9;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
}
.signal-analysis small {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-bottom: 3px;
}
.signal-analysis strong {
  display: block;
  font-size: 14px;
  overflow-wrap: anywhere;
}
.thread-messages { display: grid; gap: 8px; }
.latest-exchange {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  padding: 10px;
}
.latest-exchange > small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}
.compact-thread { gap: 6px; }
.thread-transcript {
  border-top: 1px solid var(--line);
  margin-top: 2px;
  padding-top: 8px;
}
.thread-transcript summary {
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
}
.thread-transcript .thread-messages { margin-top: 8px; }
.message-bubble {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}
.message-bubble span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 4px;
  text-transform: uppercase;
}
.message-bubble p { color: var(--ink); margin: 0; }
.message-bubble.customer { background: #f6f8f9; }
.message-bubble.closeful { background: #eef7f4; border-color: #cfe4dd; }
.action-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.action-detail-grid div {
  background: #f6f8f9;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
}
.action-detail-grid small {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-bottom: 3px;
}
.action-detail-grid strong { font-size: 14px; }
.source-value {
  align-items: center;
  display: inline-flex;
  gap: 7px;
}
.recommendation {
  background: #fff9eb;
  border: 1px solid #f4dfaa;
  border-radius: 8px;
  color: #4f3b08;
  padding: 10px;
}
.group-count {
  background: #eef3f4;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #40515d;
  font-size: 13px;
  font-weight: 700;
  padding: 8px 10px;
}
.action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.card-controls {
  align-items: center;
  display: flex;
  gap: 8px;
}
.signal-focus {
  animation: signalFocus 1.8s ease-out;
}
@keyframes signalFocus {
  0% { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(18, 106, 91, 0.18); }
  100% { border-color: var(--line); box-shadow: none; }
}
.status-pill, .priority-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  background: #eef3f4;
  color: #40515d;
  font-size: 12px;
  font-weight: 700;
}
.review-title-row {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.review-card { gap: 10px; }
.review-link {
  align-items: center;
  display: inline-flex;
  min-height: 34px;
  text-decoration: none;
}
.draft-reply {
  background: #f6f8f9;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  padding: 10px;
}
.draft-reply small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}
.draft-reply p {
  color: var(--ink);
  margin: 0;
}
.save-status { color: var(--muted); font-size: 13px; min-width: 52px; text-align: right; }
.priority-high, .priority-critical { background: #ffe7df; color: #8d2d1f; }
.priority-medium { background: #fff2d6; color: var(--warning); }
.priority-low { background: #e8f4ec; color: #1f6b42; }
.raw-details {
  border-top: 1px solid var(--line);
  margin-top: 4px;
  padding-top: 8px;
}
.raw-details summary {
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}
.raw-details pre {
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  background: #f6f8f9;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #26343d;
  font-size: 12px;
  line-height: 1.5;
  margin: 8px 0 0;
  padding: 10px;
}

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.settings-grid .full { grid-column: 1 / -1; }
.grid-two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
dialog { width: min(680px, calc(100vw - 24px)); border: 0; border-radius: 10px; padding: 0; box-shadow: 0 18px 60px rgba(23, 32, 38, 0.28); }
dialog::backdrop { background: rgba(16, 24, 32, 0.45); }
.dialog-form { padding: 18px; display: grid; gap: 12px; }
.back-to-top {
  align-items: center;
  background: var(--accent);
  border: 1px solid var(--accent-strong);
  border-radius: 999px;
  bottom: 22px;
  box-shadow: 0 10px 24px rgba(23, 32, 38, 0.2);
  color: #fff;
  cursor: pointer;
  display: flex;
  font-size: 22px;
  font-weight: 800;
  height: 44px;
  justify-content: center;
  line-height: 1;
  position: fixed;
  right: 22px;
  width: 44px;
  z-index: 20;
}
.back-to-top:hover { background: var(--accent-strong); }

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    align-self: stretch;
    background: var(--bg);
    color: var(--ink);
    gap: 0;
    min-height: 0;
    padding: 0 20px 12px;
    position: static;
  }
  .brand, .business-switcher, .desktop-settings { display: none !important; }
  .nav {
    background: rgba(223, 244, 236, 0.92);
    backdrop-filter: blur(14px) saturate(1.15);
    border: 1px solid rgba(18, 106, 91, 0.22);
    border-radius: 8px;
    bottom: 12px;
    box-shadow: 0 16px 34px rgba(18, 106, 91, 0.22), 0 4px 12px rgba(23, 32, 38, 0.12);
    grid-template-columns: repeat(3, 1fr);
    left: 12px;
    padding: 4px;
    position: fixed;
    right: 12px;
    z-index: 30;
  }
  .nav-item {
    display: flex;
    justify-content: center;
    color: #2f4f49;
    font-weight: 750;
    text-align: center;
    padding: 9px 10px;
  }
  .nav-item[data-view="inbox"] { order: 1; }
  .nav-item[data-view="actions"] { order: 2; }
  .nav-item[data-view="reviews"] { order: 3; }
  .nav-item.active, .nav-item:hover {
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 6px 16px rgba(18, 106, 91, 0.18);
    color: var(--accent-strong);
  }
  .nav-item.active .nav-count {
    background: var(--accent);
    color: #fff;
  }
  .content { padding: 14px 20px 86px; }
  .mobile-appbar {
    align-items: center;
    display: flex;
    justify-content: space-between;
    padding: 14px 20px 8px;
    position: relative;
  }
  .mobile-brand { align-items: center; display: flex; gap: 10px; min-height: 42px; }
  .mobile-controls { align-items: center; display: flex; gap: 8px; }
  .menu-button { font-size: 20px; line-height: 1; }
  .mobile-menu {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    display: grid;
    gap: 4px;
    min-width: 210px;
    padding: 8px;
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    z-index: 40;
  }
  .mobile-menu-label {
    color: var(--muted);
    font-size: 13px;
    padding: 8px 10px 6px;
  }
  .mobile-menu-item {
    background: transparent;
    border: 0;
    border-radius: 8px;
    color: var(--ink);
    min-height: 38px;
    padding: 9px 10px;
    text-align: left;
  }
  .mobile-menu-item:hover { background: #f2f5f7; }
  .topbar {
    align-items: center;
    flex-direction: row;
    margin-bottom: 14px;
  }
  .topbar h1 { font-size: 28px; }
  .topbar .toolbar { display: none; }
  #businessSubtitle { display: none; }
  .review-metrics { grid-template-columns: repeat(2, 1fr); }
  .settings-grid, .grid-two, .action-detail-grid { grid-template-columns: 1fr; }
  .signal-analysis {
    gap: 8px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .signal-analysis div {
    min-height: 86px;
    padding: 8px;
  }
  .signal-analysis strong {
    font-size: 13px;
    line-height: 1.25;
  }
  .filter-row { align-items: stretch; flex-direction: column; width: 100%; }
  .filter-row label { min-width: 0; }
  .feed-filter-bar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .item-row { align-items: flex-start; }
  .card-controls { flex-shrink: 0; }
  .back-to-top {
    bottom: 16px;
    height: 42px;
    right: 16px;
    width: 42px;
  }
}
