:root {
  --bg: #eef3f5;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --surface-3: #edf5f2;
  --text: #17202a;
  --muted: #657382;
  --line: #dbe4ea;
  --primary: #12805c;
  --primary-2: #0f6f82;
  --primary-soft: #e4f5ee;
  --accent: #3657d8;
  --amber: #b7791f;
  --danger: #bc3f27;
  --nav: #18231f;
  --nav-2: #22332d;
  --chat-bg: #e9ded2;
  --bubble-in: #ffffff;
  --bubble-out: #d8f8cf;
  --radius: 8px;
  --shadow: 0 14px 38px rgba(23, 32, 42, .08);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

a {
  color: inherit;
}

.login-page {
  background:
    linear-gradient(130deg, rgba(18, 128, 92, .92), rgba(24, 35, 31, .96)),
    #18231f;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(100%, 430px);
  padding: 32px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .26);
}

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

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

.login-panel h1 {
  font-size: 1.55rem;
  font-weight: 850;
  margin: 0 0 4px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
}

.app-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px 14px;
  background: var(--nav);
  color: #f5f7f8;
  display: flex;
  flex-direction: column;
  gap: 20px;
  z-index: 10;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  font-weight: 850;
  letter-spacing: 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .22);
}

.brand strong,
.sidebar-user strong {
  display: block;
  line-height: 1.12;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand small,
.sidebar-user small {
  display: block;
  margin-top: 3px;
  color: #b8c5ce;
  font-size: .78rem;
}

.side-nav {
  display: grid;
  gap: 5px;
}

.side-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 10px 12px;
  color: #d2dce2;
  text-decoration: none;
  border-radius: var(--radius);
  font-weight: 700;
  transition: background .18s ease, color .18s ease;
}

.side-nav a:hover,
.side-nav a.active {
  color: #fff;
  background: var(--nav-2);
}

.side-nav a.active {
  box-shadow: inset 3px 0 0 var(--primary);
}

.side-nav i {
  width: 20px;
  text-align: center;
  font-size: 1.05rem;
}

.sidebar-user {
  margin-top: auto;
  padding: 12px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .07);
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.avatar,
.contact-avatar {
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 850;
}

.avatar {
  width: 38px;
  height: 38px;
  background: #e6f6ef;
  color: var(--primary);
}

.app-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

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

.topbar h1 {
  margin: 0;
  font-size: 1.24rem;
  font-weight: 850;
}

.eyebrow {
  display: block;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.content-wrap {
  width: 100%;
  max-width: none;
  margin: 0 auto;
  padding: 22px 28px 38px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.page-head h1,
.page-head h2 {
  margin: 0;
  font-size: 1.42rem;
  font-weight: 850;
}

.page-head p {
  margin: 4px 0 0;
  color: var(--muted);
}

.card,
.table-panel,
.soft-panel,
.metric {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card,
.metric,
.table-panel {
  background: var(--surface);
}

.card {
  overflow: hidden;
}

.card-header {
  border-bottom-color: var(--line);
}

.btn,
.form-control,
.form-select {
  border-radius: var(--radius);
}

.btn {
  font-weight: 750;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
}

.btn-primary:hover,
.btn-primary:focus {
  background: #0d6d4e;
  border-color: #0d6d4e;
}

.btn-outline-secondary {
  border-color: #cbd5dc;
}

.badge {
  border-radius: 999px;
  font-weight: 800;
}

.table {
  margin-bottom: 0;
  vertical-align: middle;
}

.table-panel {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-panel .table {
  min-width: 720px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}

.metric {
  padding: 20px;
}

.metric span {
  color: var(--muted);
  font-weight: 800;
  font-size: .84rem;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(1.7rem, 4vw, 2.15rem);
  line-height: 1;
}

.chat-shell {
  height: calc(100dvh - 116px);
  min-height: 610px;
  display: grid;
  grid-template-columns: 360px minmax(520px, 1fr) 330px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  font-size: .96rem;
}

.chat-list {
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  background: var(--surface-2);
}

.chat-list-head {
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.chat-list-head h2,
.customer-panel h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 850;
}

.chat-search {
  margin-top: 12px;
  position: relative;
}

.chat-search i {
  position: absolute;
  top: 50%;
  left: 12px;
  transform: translateY(-50%);
  color: var(--muted);
}

.chat-search input {
  height: 40px;
  padding-left: 38px;
  background: #f7faf9;
  border-color: #d9e3e8;
}

.chat-items {
  min-height: 0;
  overflow-y: auto;
}

.chat-item {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 10px;
  padding: 12px 14px;
  text-decoration: none;
  border-bottom: 1px solid #e7eef2;
  color: var(--text);
  transition: background .15s ease;
}

.chat-item:hover,
.chat-item.active {
  background: var(--primary-soft);
}

.contact-avatar {
  width: 44px;
  height: 44px;
  background: #e6eefc;
  color: #2845b8;
}

.chat-item-main {
  min-width: 0;
}

.chat-item-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.chat-item-name,
.chat-item-time {
  white-space: nowrap;
}

.chat-item-name {
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 850;
}

.chat-item-time {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: .75rem;
}

.chat-item-preview {
  margin: 3px 0 0;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: .88rem;
}

.chat-window {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--chat-bg);
}

.chat-window-head {
  min-height: 66px;
  padding: 11px 16px;
  background: #f7faf9;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.chat-window-title {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-window-title strong,
.chat-window-title small {
  display: block;
}

.chat-window-title strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 850;
}

.chat-window-title small {
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mobile-chat-back {
  display: none;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border: 1px solid var(--line);
  border-radius: 50%;
  place-items: center;
  text-decoration: none;
  background: #fff;
}

.chat-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.chat-actions form {
  margin: 0;
}

.chat-actions .form-select {
  min-width: 138px;
}

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 22px;
  background:
    linear-gradient(rgba(255, 255, 255, .16), rgba(255, 255, 255, .16)),
    var(--chat-bg);
}

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

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

.message-bubble {
  max-width: min(74%, 720px);
  padding: 8px 10px 6px;
  border-radius: var(--radius);
  background: var(--bubble-in);
  box-shadow: 0 1px 2px rgba(23, 32, 42, .13);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message-row.out .message-bubble {
  background: var(--bubble-out);
}

.message-meta {
  margin-top: 4px;
  color: #657382;
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  font-size: .72rem;
}

.composer {
  padding: 12px;
  background: #f6f7f8;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: 46px 46px minmax(0, 1fr) 46px;
  gap: 10px;
  align-items: center;
}

.composer input[type="text"] {
  min-width: 0;
  height: 44px;
  border-radius: 999px;
}

.composer .btn,
.composer label.btn {
  width: 46px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
}

.composer-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: #f6f7f8;
  border-top: 1px dashed var(--line);
  font-size: .85rem;
}

.media-imagem {
  max-width: 260px;
  max-height: 260px;
  border-radius: 10px;
  display: block;
  margin-bottom: 4px;
  object-fit: cover;
}

.media-audio,
.media-video {
  max-width: 260px;
  display: block;
  margin-bottom: 4px;
}

.media-video {
  max-width: 320px;
  border-radius: 10px;
}

.media-doc {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  color: inherit;
  text-decoration: underline;
}

.customer-panel {
  min-width: 0;
  border-left: 1px solid var(--line);
  background: var(--surface-2);
  overflow-y: auto;
  padding: 18px;
}

.customer-card {
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
}

.customer-card .contact-avatar {
  width: 64px;
  height: 64px;
  margin-bottom: 10px;
  font-size: 1.2rem;
}

.detail-list {
  display: grid;
  gap: 12px;
}

.detail {
  display: grid;
  gap: 2px;
}

.detail span {
  color: var(--muted);
  font-size: .78rem;
  font-weight: 800;
}

.detail strong {
  overflow-wrap: anywhere;
}

.empty-state {
  height: 100%;
  min-height: 220px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 30px;
  color: var(--muted);
}

.empty-state i {
  display: block;
  font-size: 2rem;
  margin-bottom: 10px;
  color: var(--primary);
}

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

.queue-checks {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
}

.queue-check {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

@media (max-width: 1240px) {
  .chat-shell {
    grid-template-columns: 310px minmax(0, 1fr);
  }

  .customer-panel {
    display: none;
  }
}

@media (max-width: 980px) {
  .app-shell {
    display: block;
    padding-bottom: 74px;
  }

  .app-sidebar {
    position: fixed;
    inset: auto 0 0 0;
    height: 68px;
    padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
    border-top: 1px solid rgba(255, 255, 255, .12);
    box-shadow: 0 -10px 30px rgba(23, 32, 42, .18);
  }

  .app-sidebar .brand,
  .sidebar-user {
    display: none;
  }

  .side-nav {
    height: 100%;
    display: flex;
    gap: 4px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .side-nav::-webkit-scrollbar {
    display: none;
  }

  .side-nav a {
    min-width: 62px;
    flex: 0 0 62px;
    min-height: 54px;
    padding: 6px 4px;
    justify-content: center;
    flex-direction: column;
    gap: 2px;
    font-size: .68rem;
    line-height: 1.05;
    text-align: center;
  }

  .side-nav a.active {
    box-shadow: inset 0 3px 0 var(--primary);
  }

  .side-nav i {
    width: auto;
    font-size: 1.12rem;
  }

  .topbar {
    top: 0;
    min-height: 62px;
    padding: 12px 16px;
  }

  .topbar h1 {
    font-size: 1.08rem;
  }

  .topbar .btn {
    padding-inline: 10px;
  }

  .content-wrap {
    padding: 16px 14px 24px;
  }

  .page-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .page-head > .d-flex {
    width: 100%;
  }

  .page-head .btn {
    white-space: nowrap;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .chat-shell {
    height: calc(100dvh - 152px);
    min-height: 520px;
    grid-template-columns: minmax(0, 1fr);
    border-radius: 0;
    margin-inline: -14px;
    border-left: 0;
    border-right: 0;
  }

  .chat-shell.has-active .chat-list {
    display: none;
  }

  .chat-shell.is-listing .chat-window {
    display: none;
  }

  .chat-list {
    border-right: 0;
  }

  .chat-list-head {
    padding: 14px;
  }

  .chat-items {
    overflow-y: auto;
  }

  .chat-item {
    padding: 13px 14px;
  }

  .chat-window {
    min-height: 0;
  }

  .chat-window-head {
    min-height: auto;
    align-items: flex-start;
    padding: 10px 12px;
    gap: 8px;
  }

  .chat-window-title {
    flex: 1;
  }

  .mobile-chat-back {
    display: grid;
  }

  .chat-window-title .contact-avatar {
    width: 38px;
    height: 38px;
  }

  .chat-actions {
    width: 100%;
    justify-content: flex-start;
    padding-left: 48px;
  }

  .chat-actions .form-select {
    min-width: 120px;
    max-width: 160px;
  }

  .chat-messages {
    padding: 16px 12px;
  }

  .message-bubble {
    max-width: 88%;
  }

  .composer {
    padding: 10px;
  }

  .table-panel {
    margin-inline: -2px;
  }
}

@media (max-width: 480px) {
  .login-shell {
    padding: 14px;
  }

  .login-panel {
    padding: 24px;
  }

  .eyebrow {
    display: none;
  }

  .topbar {
    gap: 10px;
  }

  .topbar .btn {
    font-size: 0;
    width: 38px;
    height: 38px;
    padding: 0;
    display: grid;
    place-items: center;
  }

  .topbar .btn i {
    font-size: 1rem;
    margin: 0;
  }

  .metric {
    padding: 16px;
  }

  .chat-shell {
    height: calc(100dvh - 144px);
  }

  .side-nav a span {
    max-width: 58px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .chat-actions {
    padding-left: 0;
  }
}

/* Atendimento: ocupa a tela como uma central de conversas, sem cara de card pequeno. */
.is-conversation-page {
  background: #e7eef1;
}

.is-conversation-page .topbar {
  min-height: 58px;
  padding: 10px 24px;
  background: #ffffff;
}

.is-conversation-page .topbar h1 {
  font-size: 1.1rem;
}

.is-conversation-page .content-wrap {
  max-width: none;
  padding: 14px 16px 16px;
}

.is-conversation-page .chat-shell {
  height: calc(100dvh - 88px);
  min-height: 0;
  width: 100%;
  border-radius: 8px;
  box-shadow: 0 18px 48px rgba(23, 32, 42, .11);
}

.is-conversation-page .chat-shell.is-listing {
  grid-template-columns: 380px minmax(0, 1fr);
}

.is-conversation-page .chat-shell.is-listing .customer-panel {
  display: none;
}

.is-conversation-page .chat-list-head {
  padding: 18px;
}

.is-conversation-page .chat-list-head h2 {
  font-size: 1.08rem;
}

.is-conversation-page .chat-search input {
  height: 44px;
  font-size: .96rem;
}

.is-conversation-page .chat-item {
  min-height: 74px;
  padding: 14px 16px;
}

.is-conversation-page .chat-window {
  background: #efeae2;
}

.is-conversation-page .chat-messages,
.is-conversation-page .chat-window > .empty-state {
  background:
    radial-gradient(circle at 1px 1px, rgba(18, 128, 92, .09) 1px, transparent 0),
    #efeae2;
  background-size: 18px 18px;
}

.is-conversation-page .chat-window > .empty-state {
  min-height: 100%;
}

.is-conversation-page .chat-window > .empty-state i {
  width: 74px;
  height: 74px;
  margin: 0 auto 16px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(18, 128, 92, .12);
  font-size: 2.1rem;
}

.is-conversation-page .chat-window > .empty-state strong {
  font-size: 1.18rem;
  color: #344054;
}

.is-conversation-page .chat-window > .empty-state p,
.is-conversation-page .customer-panel > .empty-state p {
  display: none;
}

.is-conversation-page .customer-panel {
  background: #ffffff;
}

@media (min-width: 1500px) {
  .is-conversation-page .chat-shell {
    grid-template-columns: 390px minmax(0, 1fr) 350px;
  }

  .is-conversation-page .chat-shell.is-listing {
    grid-template-columns: 390px minmax(0, 1fr);
  }
}

@media (max-width: 1240px) {
  .is-conversation-page .chat-shell,
  .is-conversation-page .chat-shell.is-listing {
    grid-template-columns: 340px minmax(0, 1fr);
  }
}

@media (max-width: 980px) {
  .is-conversation-page .app-main,
  .is-conversation-page .content-wrap {
    height: calc(100dvh - 74px);
  }

  .is-conversation-page .chat-shell,
  .is-conversation-page .chat-shell.is-listing {
    height: calc(100dvh - 74px);
  }
}

@media (max-width: 760px) {
  .is-conversation-page .chat-shell,
  .is-conversation-page .chat-shell.is-listing {
    grid-template-columns: minmax(0, 1fr);
  }

  .is-conversation-page .chat-list-head {
    min-height: 86px;
    padding: 14px;
  }

  .is-conversation-page .chat-item {
    min-height: 76px;
    padding: 14px;
  }
}
