:root {
  --wa-green: #128c7e;
  --wa-green-light: #25d366;
  --wa-green-dark: #075e54;
  --wa-teal: #dcf8c6;
  --surface: #ffffff;
  --surface-muted: #f4f7f6;
  --border: #e8eeec;
  --text: #1a2e28;
  --text-muted: #5f736c;
  --shadow-sm: 0 1px 3px rgba(7, 94, 84, 0.06);
  --shadow-md: 0 8px 30px rgba(7, 94, 84, 0.1);
  --radius: 14px;
  --radius-lg: 20px;
  --font: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--surface-muted);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9375rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* —— App shell —— */
.app-page {
  min-height: 100vh;
}

.app-header {
  background: linear-gradient(135deg, var(--wa-green-dark) 0%, var(--wa-green) 55%, #159a8a 100%);
  color: #fff;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.app-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  color: var(--wa-green-light);
  flex-shrink: 0;
}

.app-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  color: #fff;
  text-decoration: none;
  transition: background 0.15s;
  flex-shrink: 0;
}

.app-back:hover {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}

.app-brand-label {
  margin: 0;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.75;
  font-weight: 500;
}

.app-brand-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(420px, 55vw);
}

.app-header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.app-user {
  font-size: 0.8rem;
  opacity: 0.8;
}

.btn-app-ghost {
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: transparent;
  border-radius: 10px;
  font-weight: 600;
  padding: 0.35rem 0.85rem;
}

.btn-app-ghost:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.5);
  color: #fff;
}

.app-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.app-main--detail {
  max-width: 1280px;
  padding-bottom: 1.5rem;
}

/* —— Buttons —— */
.btn-wa {
  background: var(--wa-green);
  border: none;
  color: #fff;
  font-weight: 600;
  border-radius: 10px;
  padding: 0.55rem 1.1rem;
  transition: background 0.15s, transform 0.1s;
}

.btn-wa:hover {
  background: var(--wa-green-dark);
  color: #fff;
}

.btn-wa:active {
  transform: scale(0.98);
}

.btn-wa-outline {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--wa-green-dark);
  font-weight: 600;
  border-radius: 10px;
}

.btn-wa-outline:hover {
  background: var(--surface-muted);
  border-color: #c5d5d0;
  color: var(--wa-green-dark);
}

/* —— Dashboard —— */
.page-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-intro h2 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.page-intro p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow-sm);
}

.stat-card .stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--wa-green-dark);
  line-height: 1.1;
}

.stat-card .stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 0.2rem;
}

.inbox-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.inbox-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.inbox-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
  transition: background 0.12s;
}

.inbox-item:last-child {
  border-bottom: none;
}

.inbox-item:hover {
  background: #f9fbfa;
}

.inbox-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--wa-green) 0%, var(--wa-green-light) 100%);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.inbox-body {
  min-width: 0;
}

.inbox-name {
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 0.15rem;
  color: var(--text);
}

.inbox-preview {
  color: var(--text-muted);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.inbox-meta {
  text-align: right;
  flex-shrink: 0;
}

.inbox-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.inbox-empty {
  text-align: center;
  padding: 3.5rem 1.5rem;
}

.inbox-empty-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 1rem;
  background: #e8f5f0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--wa-green);
}

.inbox-empty h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.inbox-empty p {
  color: var(--text-muted);
  font-size: 0.9rem;
  max-width: 320px;
  margin: 0 auto 1.25rem;
}

/* —— Badges —— */
.badge-status {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.25em 0.65em;
  border-radius: 999px;
  text-transform: capitalize;
}

.badge-done {
  background: #d1fae5;
  color: #065f46;
}

.badge-progress {
  background: #fef3c7;
  color: #92400e;
}

.badge-failed {
  background: #fee2e2;
  color: #991b1b;
}

.badge-default {
  background: #e8eeec;
  color: #334155;
}

/* —— Conversation detail —— */
.detail-layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}

.detail-sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: sticky;
  top: 5.5rem;
}

.detail-transcript {
  min-width: 0;
  min-height: calc(100vh - 7.5rem);
  display: flex;
  flex-direction: column;
}

.detail-hero {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
  text-align: center;
}

.detail-hero .detail-info {
  width: 100%;
}

.detail-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--wa-green-dark), var(--wa-green-light));
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.detail-info h2 {
  margin: 0 0 0.75rem;
  font-size: 1.2rem;
  font-weight: 700;
  word-break: break-word;
}

.detail-facts {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  text-align: left;
}

.detail-fact {
  display: grid;
  grid-template-columns: 6.5rem 1fr;
  gap: 0.5rem;
  font-size: 0.85rem;
  align-items: baseline;
}

.detail-fact dt {
  margin: 0;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.detail-fact dd {
  margin: 0;
  color: var(--text);
}

.detail-note {
  font-size: 0.8rem;
  color: #b45309;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  margin-top: 0.75rem;
}

.summary-card {
  background: linear-gradient(135deg, #f0fdf4 0%, #ecfdf5 100%);
  border: 1px solid #bbf7d0;
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 0;
}

.summary-card h3 {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--wa-green-dark);
  font-weight: 700;
}

.summary-card p {
  margin: 0;
  color: var(--text);
  font-size: 0.95rem;
}

.transcript-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.transcript-card--fill {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 7.5rem);
  margin-bottom: 0;
}

.transcript-header {
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: #fafcfb;
}

.chat-panel {
  min-height: 280px;
  overflow-y: auto;
  padding: 1.25rem;
  background: #e5ddd5 url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23d4cdc4' fill-opacity='0.35'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.chat-panel--fill {
  flex: 1;
  min-height: 0;
  max-height: none;
}

.chat-row {
  display: flex;
  margin-bottom: 10px;
}

.chat-row-user {
  justify-content: flex-start;
}

.chat-row-agent {
  justify-content: flex-end;
}

.chat-bubble {
  max-width: 78%;
  padding: 8px 12px 10px;
  border-radius: 12px;
  font-size: 0.92rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.chat-bubble-user {
  background: var(--surface);
  border-bottom-left-radius: 4px;
}

.chat-bubble-agent {
  background: var(--wa-teal);
  border-bottom-right-radius: 4px;
}

.chat-meta {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 3px;
  color: var(--wa-green-dark);
  opacity: 0.75;
}

.chat-bubble-agent .chat-meta {
  color: #2d6a4f;
}

.chat-text {
  line-height: 1.45;
  word-break: break-word;
}

.detail-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.detail-actions .btn-outline-danger {
  border-radius: 10px;
  font-weight: 600;
}

@media (max-width: 991px) {
  .detail-layout {
    grid-template-columns: 1fr;
  }

  .detail-sidebar {
    position: static;
  }

  .detail-transcript,
  .transcript-card--fill {
    min-height: 420px;
  }

  .transcript-card--fill {
    min-height: 480px;
  }
}

/* —— Login —— */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: linear-gradient(160deg, var(--wa-green-dark) 0%, var(--wa-green) 40%, #1a9d8a 100%);
}

.login-shell {
  width: 100%;
  max-width: 400px;
}

.login-brand {
  text-align: center;
  color: #fff;
  margin-bottom: 1.5rem;
}

.login-brand-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 0.75rem;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--wa-green-light);
}

.login-brand h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 0.25rem;
  letter-spacing: -0.02em;
}

.login-brand p {
  margin: 0;
  opacity: 0.85;
  font-size: 0.9rem;
}

.login-card {
  background: var(--surface);
  border: none;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 0.25rem;
}

.login-card .card-body {
  padding: 1.75rem !important;
}

.login-card .form-label {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text);
}

.login-card .form-control {
  border-radius: 10px;
  border-color: var(--border);
  padding: 0.6rem 0.85rem;
}

.login-card .form-control:focus {
  border-color: var(--wa-green);
  box-shadow: 0 0 0 3px rgba(18, 140, 126, 0.15);
}

/* —— Alerts —— */
.app-alert {
  border-radius: var(--radius);
  border: none;
  font-size: 0.9rem;
}

@media (max-width: 576px) {
  .app-brand-title {
    font-size: 1rem;
    max-width: 50vw;
  }

  .inbox-item {
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
  }

  .inbox-meta {
    grid-column: 2;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  .inbox-time {
    margin-bottom: 0;
  }
}
