:root {
  color-scheme: light;
  --bg: #f6f0e8;
  --panel: #fffaf3;
  --panel-strong: #fff4e3;
  --text: #2e241b;
  --muted: #7c6a5d;
  --line: #e6d8c8;
  --brand: #8d5524;
  --brand-dark: #613816;
  --danger: #b3261e;
  --warning: #9b6200;
  --success: #2f6d44;
  --shadow: 0 20px 60px rgba(67, 44, 24, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(190, 130, 67, 0.18), transparent 28rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 12px;
  padding: 0.75rem 1rem;
  background: var(--brand);
  color: white;
  cursor: pointer;
  font-weight: 700;
}

button:hover {
  background: var(--brand-dark);
}

button.secondary {
  background: var(--panel-strong);
  color: var(--brand-dark);
  border: 1px solid var(--line);
}

button.ghost {
  background: transparent;
  color: var(--muted);
}

button.small {
  padding: 0.5rem 0.7rem;
  border-radius: 10px;
  font-size: 0.86rem;
}

button.tiny {
  padding: 0.35rem 0.55rem;
  border-radius: 9px;
  font-size: 0.75rem;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
  background: white;
  color: var(--text);
}

label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

.hidden {
  display: none !important;
}

.eyebrow {
  margin-bottom: 0.35rem;
  color: var(--brand);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.muted {
  color: var(--muted);
}

.login-card {
  width: min(460px, calc(100vw - 2rem));
  margin: 10vh auto;
  padding: 2rem;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: rgba(255, 250, 243, 0.92);
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin-bottom: 0.5rem;
}

.login-form {
  display: grid;
  gap: 1rem;
  margin-top: 2rem;
}

.error {
  min-height: 1.2rem;
  color: var(--danger);
  font-weight: 700;
}

.dashboard {
  width: min(1480px, calc(100vw - 2rem));
  margin: 0 auto;
  padding: 1.5rem 0 2rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.topbar h1 {
  margin-bottom: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.45rem 0.7rem;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}

.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.stat-card {
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
}

.stat-card strong {
  display: block;
  font-size: 1.7rem;
}

.stat-card span {
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 800;
}

.filters {
  display: grid;
  grid-template-columns: 180px 160px 1fr;
  gap: 0.8rem;
  margin-bottom: 1rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 250, 243, 0.78);
}

.recent-messages-panel {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 250, 243, 0.78);
}

.section-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.section-title h2 {
  margin-bottom: 0.15rem;
  font-size: 1.05rem;
}

.section-title p {
  margin-bottom: 0;
}

.recent-messages {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.7rem;
  max-height: 280px;
  overflow: auto;
}

.message-card {
  display: grid;
  gap: 0.45rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0.8rem;
  background: white;
}

.message-card.clickable {
  cursor: pointer;
}

.message-card.clickable:hover {
  border-color: rgba(141, 85, 36, 0.55);
  box-shadow: 0 10px 24px rgba(67, 44, 24, 0.08);
}

.message-card.direcao-empresa {
  background: #f2fbf3;
}

.message-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.message-card-head span,
.message-card-meta {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
}

.message-card p {
  margin: 0;
  line-height: 1.35;
}

.empty-state.compact {
  min-height: 120px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(360px, 0.9fr) minmax(0, 1.5fr);
  gap: 1rem;
  align-items: start;
}

.ticket-list,
.ticket-detail {
  min-height: 64vh;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255, 250, 243, 0.82);
  box-shadow: var(--shadow);
}

.ticket-list {
  display: grid;
  align-content: start;
  gap: 0.75rem;
  max-height: 74vh;
  overflow: auto;
  padding: 0.8rem;
}

.list-heading {
  position: sticky;
  top: 0;
  z-index: 1;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0.85rem;
  background: rgba(255, 250, 243, 0.96);
  backdrop-filter: blur(8px);
}

.list-heading h2 {
  margin-bottom: 0.15rem;
  font-size: 1.02rem;
}

.list-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.ticket-card {
  display: grid;
  gap: 0.55rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0.9rem;
  background: white;
  cursor: pointer;
}

.ticket-card:hover,
.ticket-card.active {
  border-color: rgba(141, 85, 36, 0.55);
  box-shadow: 0 10px 30px rgba(67, 44, 24, 0.1);
}

.ticket-card-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 0.75rem;
}

.ticket-card h3 {
  margin: 0;
  font-size: 1rem;
}

.ticket-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.35;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.badge {
  border-radius: 999px;
  padding: 0.25rem 0.5rem;
  background: var(--panel-strong);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.badge.risco-alto,
.badge.prioridade-alta {
  background: #ffe8e5;
  color: var(--danger);
}

.badge.risco-medio,
.badge.prioridade-media {
  background: #fff1d3;
  color: var(--warning);
}

.badge.status-resolvido {
  background: #e7f5ea;
  color: var(--success);
}

.ticket-detail {
  padding: 1.1rem;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 60vh;
  text-align: center;
  color: var(--muted);
}

.detail-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.detail-header h2 {
  margin-bottom: 0.25rem;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
}

.section-card {
  margin-bottom: 0.9rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1rem;
  background: white;
}

.section-card h3 {
  margin-bottom: 0.6rem;
  font-size: 0.95rem;
}

.section-card p {
  white-space: pre-wrap;
  line-height: 1.45;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}

.message-list {
  display: grid;
  gap: 0.65rem;
  max-height: 340px;
  overflow: auto;
}

.message {
  display: grid;
  gap: 0.25rem;
  border-radius: 14px;
  padding: 0.7rem 0.8rem;
  background: var(--panel-strong);
}

.message.empresa {
  margin-left: 2rem;
  background: #edf6ef;
}

.message.cliente {
  margin-right: 2rem;
}

.message-meta {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  max-width: 360px;
  border-radius: 14px;
  padding: 0.9rem 1rem;
  background: var(--brand-dark);
  color: white;
  box-shadow: var(--shadow);
  font-weight: 800;
}

@media (max-width: 980px) {
  .stats,
  .filters,
  .recent-messages,
  .layout,
  .controls-grid {
    grid-template-columns: 1fr;
  }

  .ticket-list {
    max-height: none;
  }

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