:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-soft: #f8faf9;
  --border: #dde5e2;
  --text: #17211d;
  --muted: #66736d;
  --sidebar: #111c18;
  --sidebar-soft: #1a2a24;
  --accent: #128c52;
  --accent-strong: #0f7a48;
  --shadow: 0 14px 36px rgba(18, 33, 29, 0.08);
}

* {
  letter-spacing: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.login-bg {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at top left, #e4f4eb, transparent 34%), var(--bg);
}

.login-panel {
  width: min(420px, 92vw);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 32px;
  box-shadow: var(--shadow);
}

.btn-success {
  --bs-btn-bg: var(--accent);
  --bs-btn-border-color: var(--accent);
  --bs-btn-hover-bg: var(--accent-strong);
  --bs-btn-hover-border-color: var(--accent-strong);
}

.app-body {
  min-height: 100vh;
}

.app-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 280px;
  background: var(--sidebar);
  color: #e9f1ee;
  z-index: 1040;
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-header,
.sidebar-footer {
  padding: 20px;
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #fff;
  text-decoration: none;
}

.brand-icon {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  font-size: 1.25rem;
}

.brand-mark small,
.admin-chip span {
  display: block;
  color: #a9b8b2;
  font-size: 0.82rem;
}

.login-brand {
  color: var(--text);
}

.login-brand small {
  color: var(--muted);
}

.sidebar-nav {
  padding: 8px 12px;
  flex: 1;
}

.sidebar-link {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  color: #cbd8d3;
  text-decoration: none;
  border: 0;
  border-radius: 8px;
  background: transparent;
  padding: 11px 12px;
  margin: 3px 0;
  font-weight: 600;
  text-align: left;
}

.sidebar-link:hover,
.sidebar-link.active {
  color: #fff;
  background: var(--sidebar-soft);
}

.logout-link:hover {
  background: rgba(220, 53, 69, 0.18);
}

.admin-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  margin-bottom: 10px;
}

.app-main {
  margin-left: 280px;
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 1020;
  min-height: 74px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 28px;
}

.eyebrow {
  color: var(--accent);
  text-transform: uppercase;
  font-size: 0.72rem;
  font-weight: 800;
}

.page-title {
  font-size: 1.35rem;
  font-weight: 800;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-content {
  padding: 28px;
}

.content-card,
.metric-card,
.inbox-list-panel,
.thread-panel,
.customer-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.content-card {
  padding: 20px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.metric-card {
  padding: 18px;
}

.metric-card span,
.metric-card small,
.section-heading p,
.conversation-meta,
.conversation-card p,
.detail-list dt,
.reply-state,
.settings-list span,
.audit-item span {
  color: var(--muted);
}

.metric-card strong {
  display: block;
  font-size: 2rem;
  line-height: 1.1;
  margin: 6px 0;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.section-heading h2 {
  font-size: 1rem;
  font-weight: 800;
  margin: 0;
}

.section-heading p {
  margin: 3px 0 0;
  font-size: 0.9rem;
}

.data-table {
  min-width: 860px;
}

.data-table th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  font-weight: 800;
}

.data-table td {
  font-size: 0.92rem;
}

.empty-state {
  display: grid;
  place-items: center;
  text-align: center;
  gap: 6px;
  padding: 36px 16px;
  color: var(--muted);
}

.empty-state i {
  color: var(--accent);
  font-size: 2rem;
}

.empty-state strong {
  color: var(--text);
}

.stack-list,
.activity-list,
.settings-list,
.audit-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.progress-row,
.analytics-row,
.settings-list div,
.audit-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.progress-row > div:first-child {
  min-width: 128px;
}

.progress-row span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.progress {
  height: 8px;
  background: #e9efed;
}

.status-pill-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.status-pill {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.activity-item {
  display: flex;
  gap: 12px;
  align-items: center;
}

.activity-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #eef4f1;
  color: var(--accent);
}

.activity-icon.outgoing {
  background: #e7f5ed;
}

.activity-item span:last-child {
  display: block;
  color: var(--muted);
  font-size: 0.84rem;
}

.inbox-shell {
  display: grid;
  grid-template-columns: 340px minmax(420px, 1fr) 340px;
  gap: 16px;
  height: calc(100vh - 130px);
  min-height: 680px;
}

.inbox-list-panel,
.thread-panel,
.customer-panel {
  min-height: 0;
  overflow: hidden;
}

.inbox-list-panel,
.customer-panel {
  padding: 16px;
}

.inbox-filters {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.conversation-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: calc(100% - 220px);
  overflow-y: auto;
}

.conversation-card {
  position: relative;
  display: block;
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface);
}

.conversation-delete-form {
  position: absolute;
  top: 9px;
  right: 9px;
  z-index: 2;
}

.conversation-delete {
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  padding: 0;
  appearance: none;
  border: 0 !important;
  border-radius: 3px;
  color: #f15b62;
  background: #ffe8e9;
  box-shadow: none !important;
  cursor: pointer;
}

.conversation-delete:hover,
.conversation-delete:focus-visible {
  color: #c93642;
  background: #ffd1d5;
}

.conversation-delete i {
  font-size: 11px;
  line-height: 1;
}

.conversation-card:hover,
.conversation-card.active {
  border-color: rgba(18, 140, 82, 0.45);
  background: #f6fbf8;
}

.conversation-top,
.conversation-meta,
.badge-row,
.thread-header,
.detail-header,
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.conversation-top time,
.conversation-meta {
  font-size: 0.8rem;
}

.conversation-card p {
  margin: 8px 0;
  font-size: 0.88rem;
}

.badge-row {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.unread-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--accent);
}

.thread-panel {
  display: flex;
  flex-direction: column;
}

.thread-header,
.reply-box {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.thread-header h2 {
  font-size: 1.05rem;
  margin: 0;
}

.thread-header span {
  color: var(--muted);
  font-size: 0.88rem;
}

.thread-body,
.conversation {
  flex: 1;
  padding: 18px;
  overflow-y: auto;
  background: #f7faf8;
}

.reply-box {
  border-top: 1px solid var(--border);
  border-bottom: 0;
  background: var(--surface);
}

.message-row {
  display: flex;
  margin-bottom: 12px;
}

.message-row.outgoing {
  justify-content: flex-end;
}

.message-bubble {
  max-width: 78%;
  padding: 11px 13px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--border);
}

.message-row.outgoing .message-bubble {
  background: #ddf3e6;
  border-color: #c7ead6;
}

.message-bubble.sender-user {
  background: #fff;
}

.message-bubble.sender-bot {
  background: #eef4f1;
}

.message-bubble.sender-ai {
  background: #fff8df;
  border-color: #f0df9c;
}

.message-bubble.sender-admin {
  background: #ddf3e6;
  border-color: #c7ead6;
}

.message-bubble p {
  margin: 5px 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.message-bubble small,
.message-type {
  color: var(--muted);
  font-size: 0.78rem;
}

.message-type {
  display: flex;
  gap: 5px;
  align-items: center;
  text-transform: uppercase;
  font-weight: 800;
}

.message-ticks {
  color: #229ed9;
  font-size: 0.82rem;
  vertical-align: -1px;
}

.customer-panel {
  overflow-y: auto;
}

.detail-list {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 10px 14px;
  margin: 0;
}

.detail-list.compact {
  grid-template-columns: 120px minmax(0, 1fr);
}

.detail-list dd {
  margin: 0;
  word-break: break-word;
}

.status-control,
.notes-box {
  border-top: 1px solid var(--border);
  margin-top: 18px;
  padding-top: 18px;
}

.notes-box h3 {
  font-size: 0.92rem;
  font-weight: 800;
}

.notes-box p,
.empty-note {
  color: var(--muted);
  margin: 0;
}

.back-link {
  color: var(--muted);
  text-decoration: none;
  font-weight: 700;
}

.back-link:hover {
  color: var(--accent);
}

.path-stack {
  display: grid;
  gap: 10px;
}

.path-stack span,
.empty-note {
  display: flex;
  align-items: center;
  gap: 10px;
}

.path-stack i,
.empty-note i {
  color: var(--accent);
}

.requirement-text {
  white-space: pre-wrap;
}

.ai-summary-text {
  border-top: 1px solid var(--border);
  margin: 14px 0 0;
  padding-top: 12px;
  color: var(--muted);
}

.retention-input {
  max-width: 120px;
}

.icon-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
}

@media (max-width: 1199.98px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .inbox-shell {
    grid-template-columns: 300px minmax(360px, 1fr);
    height: auto;
    min-height: 0;
  }

  .customer-panel {
    grid-column: 1 / -1;
  }

  .thread-panel {
    min-height: 680px;
  }
}

@media (max-width: 991.98px) {
  .app-sidebar {
    position: fixed;
  }

  .app-main {
    margin-left: 0;
  }

  .app-content,
  .topbar {
    padding-left: 18px;
    padding-right: 18px;
  }

  .topbar-actions {
    display: none;
  }

  .inbox-shell {
    grid-template-columns: 1fr;
  }

  .conversation-list {
    max-height: 420px;
    height: auto;
  }

  .thread-panel {
    min-height: 620px;
  }
}

@media (max-width: 575.98px) {
  .metric-grid,
  .status-pill-grid {
    grid-template-columns: 1fr;
  }

  .detail-list,
  .detail-list.compact {
    grid-template-columns: 1fr;
  }

  .page-title {
    font-size: 1.1rem;
  }
}
