:root {
  color-scheme: light;
  --ink: #14241c;
  --muted: #5d6f65;
  --soft: #eef4ef;
  --line: #d9e6dd;
  --line-soft: rgba(16, 70, 50, 0.08);
  --surface: #ffffff;
  --surface-2: #f4faf6;
  --glass: rgba(255, 255, 255, 0.72);

  --green: #0f7b56;
  --green-strong: #0a6446;
  --green-2: #dcf6e8;
  --coral: #e86d52;
  --coral-strong: #d9512f;
  --amber: #d69421;
  --blue: #315fca;

  --grad-brand: linear-gradient(135deg, #0f7b56 0%, #17a06d 55%, #2bc59a 100%);
  --grad-coral: linear-gradient(135deg, #f08368 0%, #e0512e 100%);
  --grad-page:
    radial-gradient(1200px 520px at 8% -8%, rgba(43, 197, 154, 0.16), transparent 60%),
    radial-gradient(1000px 480px at 100% 0%, rgba(232, 109, 82, 0.14), transparent 55%),
    radial-gradient(900px 600px at 50% 120%, rgba(15, 123, 86, 0.08), transparent 60%),
    #eef4f0;

  --shadow-color: rgba(13, 70, 50, 0.12);
  --shadow: 0 14px 40px var(--shadow-color);
  --shadow-lg: 0 26px 60px rgba(13, 70, 50, 0.18);
  --radius: 16px;
  --radius-sm: 11px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--grad-page);
  background-attachment: fixed;
  color: var(--ink);
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

button {
  cursor: pointer;
}

svg {
  display: block;
}

/* ===== Animações ===== */
@keyframes viewEnter {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.view-enter { animation: viewEnter 0.45s var(--ease) both; }

.view-enter .metric-card,
.view-enter > .surface,
.view-enter .workspace-grid > .surface {
  animation: rise 0.5s var(--ease) both;
}

.view-enter .metric-card:nth-child(1) { animation-delay: 0.04s; }
.view-enter .metric-card:nth-child(2) { animation-delay: 0.10s; }
.view-enter .metric-card:nth-child(3) { animation-delay: 0.16s; }
.view-enter .metric-card:nth-child(4) { animation-delay: 0.22s; }
.view-enter .workspace-grid > .surface:nth-child(2) { animation-delay: 0.12s; }

/* ===== Layout ===== */
.shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-width: 0;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 28px;
  min-width: 0;
  height: 100vh;
  padding: 26px 22px;
  border-right: 1px solid var(--line-soft);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.86), rgba(255, 255, 255, 0.66));
  backdrop-filter: blur(20px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--grad-brand);
  color: white;
  font-family: "Sora", sans-serif;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: 0.02em;
  box-shadow: 0 10px 24px rgba(15, 123, 86, 0.35);
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  font-family: "Sora", sans-serif;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.brand span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.nav {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  font-size: 14.5px;
  text-align: left;
  transition: background 0.2s var(--ease), color 0.2s var(--ease), transform 0.2s var(--ease);
}

.nav-item:hover {
  background: var(--green-2);
  color: var(--green-strong);
  transform: translateX(2px);
}

.nav-item.is-active {
  background: var(--grad-brand);
  color: white;
  box-shadow: 0 12px 26px rgba(15, 123, 86, 0.28);
}

.nav-item.is-active::before {
  content: "";
  position: absolute;
  left: -22px;
  top: 50%;
  width: 4px;
  height: 22px;
  transform: translateY(-50%);
  border-radius: 0 4px 4px 0;
  background: var(--coral);
}

.nav-icon {
  width: 20px;
  height: 20px;
  min-width: 20px;
}

.sidebar-panel {
  margin-top: auto;
  padding: 18px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: linear-gradient(160deg, rgba(220, 246, 232, 0.9), rgba(255, 255, 255, 0.7));
}

.panel-kicker,
.eyebrow {
  color: var(--coral-strong);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.sidebar-panel strong {
  display: block;
  margin-top: 8px;
  font-family: "Sora", sans-serif;
}

.sidebar-panel p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.app {
  min-width: 0;
  padding: 30px 30px 40px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 26px;
}

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

h1 {
  margin-bottom: 0;
  font-family: "Sora", sans-serif;
  font-weight: 800;
  font-size: clamp(28px, 3vw, 40px);
  line-height: 1.04;
  letter-spacing: -0.02em;
}

h2 {
  margin-bottom: 0;
  font-family: "Sora", sans-serif;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.01em;
}

.eyebrow {
  display: inline-block;
  margin-bottom: 6px;
}

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

.search {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 320px;
  height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--muted);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.search svg {
  width: 18px;
  height: 18px;
}

.search:focus-within {
  border-color: var(--green);
  box-shadow: 0 0 0 4px rgba(15, 123, 86, 0.12);
}

.search input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.primary-button,
.ghost-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  border-radius: var(--radius-sm);
  font-weight: 800;
  font-size: 14.5px;
  transition: transform 0.18s var(--ease), box-shadow 0.18s var(--ease), filter 0.18s var(--ease), background 0.18s var(--ease);
}

.primary-button svg {
  width: 18px;
  height: 18px;
}

.primary-button {
  border: 0;
  padding: 0 18px;
  background: var(--grad-brand);
  color: white;
  white-space: nowrap;
  box-shadow: 0 14px 30px rgba(15, 123, 86, 0.32);
}

.primary-button:hover {
  transform: translateY(-2px);
  filter: brightness(1.05);
  box-shadow: 0 18px 38px rgba(15, 123, 86, 0.4);
}

.primary-button:active {
  transform: translateY(0) scale(0.98);
}

.ghost-button {
  border: 1px solid var(--line);
  padding: 0 16px;
  background: var(--surface);
  color: var(--ink);
}

.ghost-button:hover {
  border-color: var(--green);
  color: var(--green-strong);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.icon-button svg {
  width: 20px;
  height: 20px;
}

.icon-button:hover {
  border-color: var(--coral);
  color: var(--coral-strong);
  background: #fff3ef;
}

:focus-visible {
  outline: 3px solid rgba(15, 123, 86, 0.45);
  outline-offset: 2px;
}

.view {
  display: none;
}

.view.is-visible {
  display: block;
}

/* ===== Métricas ===== */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.metric-card,
.surface {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--glass);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}

.metric-card {
  position: relative;
  overflow: hidden;
  min-height: 132px;
  padding: 20px;
  transition: transform 0.25s var(--ease), box-shadow 0.25s var(--ease);
}

.metric-card::after {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: var(--grad-brand);
  opacity: 0.85;
}

.metric-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.metric-card span,
.metric-card small {
  display: block;
  color: var(--muted);
  font-weight: 600;
}

.metric-card span {
  font-size: 13.5px;
}

.metric-card strong {
  display: block;
  margin: 12px 0 4px;
  font-family: "Sora", sans-serif;
  font-size: 34px;
  line-height: 1;
  letter-spacing: -0.02em;
}

.metric-card small {
  font-size: 12.5px;
}

.metric-card.accent {
  background: linear-gradient(140deg, #16a06d 0%, #0f7b56 55%, #0c6749 100%);
  color: white;
  border-color: transparent;
  box-shadow: 0 20px 46px rgba(15, 123, 86, 0.45);
}

.metric-card.accent::after {
  background: var(--grad-coral);
  opacity: 1;
}

.metric-card.accent span,
.metric-card.accent small {
  color: rgba(255, 255, 255, 0.78);
}

/* ===== Superfícies ===== */
.workspace-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.span-2 {
  grid-column: span 2;
}

.surface {
  padding: 22px;
}

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

.priority-list,
.return-board,
.template-list,
.status-chart {
  display: grid;
  gap: 12px;
}

.priority-item,
.return-card,
.template-card,
.status-row {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  transition: transform 0.22s var(--ease), box-shadow 0.22s var(--ease), border-color 0.22s var(--ease);
}

.priority-item:hover,
.return-card:hover,
.template-card:hover {
  transform: translateY(-3px);
  border-color: rgba(15, 123, 86, 0.35);
  box-shadow: var(--shadow);
}

.priority-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 16px;
}

.client-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.client-title strong {
  font-size: 16px;
  font-weight: 700;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 0 10px;
  border-radius: 999px;
  background: white;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  border: 1px solid var(--line-soft);
}

.chip.due {
  background: #ffe7df;
  color: #9c321d;
  border-color: transparent;
}

.chip.ok {
  background: var(--green-2);
  color: var(--green-strong);
  border-color: transparent;
}

.client-meta {
  color: var(--muted);
  font-size: 13px;
}

.action-stack {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mini-button {
  min-height: 36px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: white;
  color: var(--ink);
  font-weight: 800;
  font-size: 13px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: transform 0.16s var(--ease), box-shadow 0.16s var(--ease), background 0.16s var(--ease), border-color 0.16s var(--ease);
}

.mini-button:hover {
  transform: translateY(-1px);
  border-color: var(--green);
  color: var(--green-strong);
  box-shadow: var(--shadow);
}

.mini-button:active {
  transform: translateY(0) scale(0.97);
}

.mini-button.whatsapp {
  border-color: transparent;
  background: var(--grad-brand);
  color: white;
  box-shadow: 0 10px 22px rgba(15, 123, 86, 0.28);
}

.mini-button.whatsapp:hover {
  color: white;
  filter: brightness(1.06);
  box-shadow: 0 14px 28px rgba(15, 123, 86, 0.38);
}

/* ===== Tabela ===== */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 840px;
}

th,
td {
  padding: 15px 12px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

tbody tr {
  transition: background 0.18s var(--ease);
}

tbody tr:hover {
  background: var(--green-2);
}

td {
  color: var(--ink);
  font-size: 14px;
}

td strong {
  font-weight: 700;
}

/* ===== Gráfico de status ===== */
.status-row {
  padding: 14px;
}

.status-line {
  display: flex;
  justify-content: space-between;
  margin-bottom: 9px;
  font-weight: 800;
  font-size: 14px;
}

.bar {
  height: 11px;
  overflow: hidden;
  border-radius: 999px;
  background: #e1ece5;
}

.bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--grad-brand);
  transition: width 0.9s var(--ease);
}

/* ===== Retornos / Templates ===== */
.return-board {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: start;
}

.return-card,
.template-card {
  padding: 15px;
}

.return-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}

.template-card p,
.generated-message {
  color: var(--muted);
  line-height: 1.55;
}

/* ===== Formulários ===== */
.message-lab,
.settings-grid,
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: white;
  color: var(--ink);
  outline: 0;
  padding: 11px 13px;
  font-weight: 600;
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 4px rgba(15, 123, 86, 0.12);
}

textarea {
  resize: vertical;
}

.generated-message {
  margin-top: 16px;
  padding: 18px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.settings p {
  max-width: 680px;
  color: var(--muted);
  line-height: 1.55;
}

.settings > div:first-child {
  margin-bottom: 20px;
}

/* ===== Modal ===== */
.modal {
  width: min(760px, calc(100vw - 32px));
  padding: 24px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  box-shadow: 0 40px 100px rgba(13, 70, 50, 0.32);
  animation: rise 0.3s var(--ease) both;
}

.modal::backdrop {
  background: rgba(13, 35, 27, 0.42);
  backdrop-filter: blur(5px);
}

.modal-head,
.modal-actions {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.modal-head {
  margin-bottom: 20px;
}

.modal-actions {
  justify-content: flex-end;
  margin-top: 20px;
}

.full {
  grid-column: 1 / -1;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: min(420px, calc(100vw - 44px));
  padding: 15px 18px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #14241c, #0a5c40);
  color: white;
  font-weight: 700;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(14px);
  transition: 240ms var(--ease);
  pointer-events: none;
  z-index: 50;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* ===== Responsivo ===== */
@media (max-width: 1120px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 16px;
  }

  .nav {
    display: flex;
    max-width: 100%;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .nav-item {
    width: auto;
    min-width: max-content;
  }

  .nav-item.is-active::before {
    display: none;
  }

  /* No celular a barra vira menu de topo — mantém o botão Sair acessível (compacto). */
  .sidebar-panel {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
    padding: 10px 14px;
  }
  .sidebar-panel .panel-kicker,
  .sidebar-panel strong {
    display: none;
  }
  .sidebar-panel p {
    margin: 0;
    flex: 1;
  }
  .sidebar-panel #logoutBtn {
    width: auto !important;
    margin: 0 !important;
    padding: 8px 18px;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .return-board {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .app {
    padding: 20px 14px 30px;
    /* Evita que um item largo (tabela/grade) estique a página e deixe tudo minúsculo. */
    overflow-x: hidden;
  }

  /* Filhos de grid precisam poder encolher (senão empurram a largura da página). */
  .metric-grid > *,
  .workspace-grid > *,
  .form-grid > * {
    min-width: 0;
  }

  .topbar,
  .topbar-actions,
  .section-head,
  .priority-item,
  .return-card {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions,
  .search {
    width: 100%;
    min-width: 0;
  }

  .workspace-grid,
  .message-lab,
  .settings-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .span-2,
  .full {
    grid-column: auto;
  }

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

  .action-stack {
    flex-wrap: wrap;
  }
}

/* ===== Acessibilidade: menos animação ===== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
