/*
  STYLE.REV.CSS
  — Revisão focada em hierarquia visual, contraste, acessibilidade e coerência de marca (azul Office)
  — Compatível com o HTML atual (sem trocar classes/IDs)
  — Dark mode automático (prefers-color-scheme) + foco visível
  — Melhor responsividade (dashboard, chart, filtros e tabela)
*/

/* ==========================
   Design Tokens
========================== */
:root {
  /* Brand */
  --brand: #0d5bd7;
  --brand-600: #0b4dbc;
  /* hover */
  --brand-700: #083b8e;
  /* pressed */
  --brand-soft: #e7f0ff;

  /* Surfaces */
  --bg: #eef3f9;
  /* app background */
  --panel: #ffffff;
  /* cards, panels */
  --panel-2: #f8fbff;
  /* subtle panel */
  --panel-border: #e1e8f2;
  /* borders */

  /* Text */
  --text: #0e1b2b;
  /* primary text */
  --text-dim: #475569;
  /* secondary */
  --text-inv: #ffffff;
  /* inverse */

  /* Semantic */
  --red: #ef4444;
  --orange: #f59e0b;
  --blue: #3b82f6;
  --green: #10b981;
  --gray: #94a3b8;
  --yellow: #fffb00;
  --pink: #ec4899;

  /* Elevation */
  --shadow-1: 0 1px 2px rgba(14, 27, 43, .06), 0 1px 1px rgba(14, 27, 43, .04);
  --shadow-2: 0 6px 20px rgba(14, 27, 43, .08);
  --shadow-3: 0 24px 60px rgba(14, 27, 43, .14);

  /* Radius */
  --r-xs: 8px;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-pill: 999px;

  /* Spacing scale */
  --sp-1: 6px;
  --sp-2: 8px;
  --sp-3: 10px;
  --sp-4: 12px;
  --sp-5: 14px;
  --sp-6: 16px;
  --sp-7: 18px;
  --sp-8: 20px;
  --sp-9: 24px;
}

/* Dark mode automático (sem mudar HTML) */
/* Tema claro por padrão em :root. Overrides manuais abaixo. */

/* Tema escuro – ativo quando html[data-theme="dark"] */
html[data-theme="dark"] {
  --bg: #0b1220;
  --panel: #0f172a;
  --panel-2: #0b1326;
  --panel-border: #1f2937;
  --text: #e5e7eb;
  --text-dim: #94a3b8;
  --text-inv: #0b1220;
  --brand-soft: #0a1a3a;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .35), 0 1px 1px rgba(0, 0, 0, .25);
  --shadow-2: 0 10px 30px rgba(0, 0, 0, .35);
  --shadow-3: 0 30px 80px rgba(0, 0, 0, .55);
}

/* Tema claro forçado – html[data-theme="light"] */
html[data-theme="light"] {
  /* mantém os tokens definidos no :root (já é o claro), mas garante color-scheme */
  color-scheme: light;
}

/* Preferência do SO continua valendo quando não há override manual */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    /* só aplica se usuário não escolheu manualmente */
    --bg: #0b1220;
    --panel: #0f172a;
    --panel-2: #0b1326;
    --panel-border: #1f2937;
    --text: #e5e7eb;
    --text-dim: #94a3b8;
    --text-inv: #0b1220;
    --brand-soft: #0a1a3a;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .35), 0 1px 1px rgba(0, 0, 0, .25);
    --shadow-2: 0 10px 30px rgba(0, 0, 0, .35);
    --shadow-3: 0 30px 80px rgba(0, 0, 0, .55);
  }
}


/* ==========================
   Base & Accessibility
========================== */
* {
  box-sizing: border-box
}

html,
body {
  height: 100%
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, Segoe UI, Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

:focus {
  outline: none
}

:focus-visible {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 35%, transparent), 0 0 0 6px color-mix(in srgb, var(--brand) 18%, transparent);
}

::placeholder {
  color: color-mix(in srgb, var(--text) 50%, transparent)
}

/* Scrollbar sutil */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--brand-600) transparent
}

*::-webkit-scrollbar {
  height: 10px;
  width: 10px
}

*::-webkit-scrollbar-thumb {
  border-radius: var(--r-xs);
  background: color-mix(in srgb, var(--brand) 60%, #8892a6);
}

*::-webkit-scrollbar-track {
  background: transparent
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important
  }
}

/* ==========================
   Topbar & Actions
========================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-5) var(--sp-6);
  background: linear-gradient(180deg, var(--panel), color-mix(in srgb, var(--panel) 80%, #eef));
  border-bottom: 1px solid var(--panel-border);
  backdrop-filter: saturate(140%) blur(6px);
}

.topbar img {
  max-height: 42px;
  height: auto
}

.actions {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap
}

/* Buttons */
.btn {
  --btn-bg: var(--brand);
  --btn-fg: var(--text-inv);
  --btn-bdr: transparent;
  background: var(--btn-bg);
  color: var(--btn-fg);
  border: 1px solid var(--btn-bdr);
  font-weight: 700;
  padding: 10px 14px;
  border-radius: var(--r-md);
  cursor: pointer;
  box-shadow: var(--shadow-1);
  transition: .18s transform, .18s background, .18s box-shadow
}

.btn:hover {
  background: var(--brand-600);
  box-shadow: var(--shadow-2)
}

.btn:active {
  transform: translateY(1px);
  background: var(--brand-700)
}

.btn:disabled {
  opacity: .55;
  cursor: not-allowed;
  box-shadow: none
}

.btn-outline {
  --btn-bg: var(--panel);
  --btn-fg: var(--brand);
  --btn-bdr: var(--brand);
  border-radius: var(--r-xl);
  box-shadow: none
}

.btn-outline:hover {
  background: color-mix(in srgb, var(--brand) 6%, var(--panel))
}

.btn-danger {
  --btn-bg: var(--red);
  --btn-fg: #fff;
  border-radius: var(--r-md)
}

.btn-danger:hover {
  filter: saturate(115%)
}

.icon-btn {
  background: transparent;
  border: 1px solid color-mix(in srgb, var(--red) 30%, var(--panel-border));
  color: var(--red);
  font-size: 20px;
  cursor: pointer;
  border-radius: var(--r-pill);
  padding: 4px 10px;
  transition: .18s
}

.icon-btn:hover {
  background: color-mix(in srgb, var(--red) 10%, transparent)
}

/* ==========================
   Dashboard & Chart
========================== */
.dashboard {
  display: grid;
  grid-template-columns: repeat(5, minmax(160px, 1fr));
  gap: var(--sp-3);
  padding: var(--sp-4)
}

.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--r-md);
  padding: var(--sp-5);
  box-shadow: var(--shadow-2);
  cursor: pointer;
  transition: .18s transform, .18s box-shadow
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-3)
}

.kpi-title {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .04em
}

.kpi-value {
  font-size: 28px;
  font-weight: 800;
  margin-top: 4px
}

.chart-wrap {
  padding: 0 var(--sp-4) var(--sp-4)
}

#chartResp {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-2);
  padding: var(--sp-2);
  width: 100%;
  height: auto;
  max-height: 260px;
}

/* ==========================
   Filtros
========================== */
.filters {
  display: grid;
  grid-template-columns: 1fr repeat(4, 220px) 160px;
  gap: var(--sp-2);
  padding: var(--sp-4);
  border-bottom: 1px solid var(--panel-border);
  background: var(--panel-2);
}

.filters input,
.filters select {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--r-sm);
  padding: 10px;
  color: var(--text);
  box-shadow: var(--shadow-1);
  transition: .15s border-color, .15s box-shadow
}

.filters input:focus,
.filters select:focus {
  border-color: color-mix(in srgb, var(--brand) 50%, var(--panel-border));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent)
}

/* ==========================
   Groups & Table
========================== */
.wrap {
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-7)
}

.group {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
  margin: 0px 40px 0px 40px;
}

.group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--panel-border);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border-radius: var(--r-lg) var(--r-lg) 0 0
}

.group-header h2 {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 800;
  color: var(--text)
}

.badge {
  background: var(--brand-soft);
  color: var(--brand-700);
  border-radius: var(--r-pill);
  padding: 3px 10px;
  font-size: 12px;
  border: 1px solid color-mix(in srgb, var(--brand) 25%, var(--panel-border))
}

.table-wrapper {
  overflow: auto
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px
}

thead th {
  position: sticky;
  top: 0;
  background: var(--panel-2);
  border-bottom: 1px solid var(--panel-border);
  text-align: left;
  padding: 12px 10px;
  color: var(--text-dim);
  font-weight: 700;
  cursor: pointer
}

thead th.sort-asc::after {
  content: " ▲";
  font-size: 11px
}

thead th.sort-desc::after {
  content: " ▼";
  font-size: 11px
}

tbody tr:nth-child(even) {
  background: color-mix(in srgb, var(--panel) 85%, var(--panel-2))
}

tbody td {
  padding: 12px 10px;
  border-bottom: 1px solid #eef2f7;
  color: var(--text);
  white-space: normal;
  max-width: 200px;
}

tr.row {
  cursor: grab
}

tr.row.dragging {
  opacity: .55
}

tr.row:hover {
  background: color-mix(in srgb, var(--panel-2) 65%, var(--panel))
}

/* Status dot */
.dot {
  width: 10px;
  height: 10px;
  border-radius: var(--r-pill);
  display: inline-block;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12)
}

.dot.red {
  background: var(--red)
}

.dot.pink {
  background: var(--pink)
}

.dot.green {
  background: var(--green)
}

.dot.blue {
  background: var(--blue)
}

.dot.orange {
  background: var(--orange)
}

.dot.gray {
  background: var(--gray)
}

.dot.yellow {
  background: var(--yellow)
}

/* Chips */
.tag {
  padding: 4px 8px;
  border-radius: var(--r-pill);
  font-size: 12px;
  display: inline-block;
  border: 1px solid #e5ecf7
}

.tag.prio-URGENTE {
  background: color-mix(in srgb, var(--red) 12%, transparent);
  color: #b91c1c
}

.tag.prio-ALTA {
  background: color-mix(in srgb, var(--orange) 18%, transparent);
  color: #9a5a07
}

.tag.prio-NORMAL {
  background: color-mix(in srgb, var(--blue) 16%, transparent);
  color: #1d4ed8
}

.tag.prio-BAIXA {
  background: color-mix(in srgb, var(--gray) 18%, transparent);
  color: #334155
}

.tag.sit-EM_ANDAMENTO {
  background: color-mix(in srgb, #fb923c 18%, transparent);
  color: #b45309
}

.tag.sit-FINALIZADA {
  background: color-mix(in srgb, #38bdf8 18%, transparent);
  color: #0369a1
}

/* Vencimento */
.due-overdue {
  color: #b91c1c;
  font-weight: 700
}

.due-today {
  color: #b45309;
  font-weight: 700
}

.due-future {
  color: #0f172a
}

.due-none {
  color: #64748b
}

/* Inline edit */
.inline-select {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--r-md);
  padding: 6px 8px
}

/* ==========================
   Modal & Comments
========================== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(14, 27, 43, .45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000
}

.overlay.show {
  display: flex
}

.modal {
  width: min(980px, 95vw);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--r-lg);
  max-height: 80vh;
  box-shadow: var(--shadow-3);
  overflow: auto
}

.modal-header,
.modal-footer {
  padding: 10px 14px;
  border-bottom: 1px solid var(--panel-border)
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(180deg, var(--panel-2), var(--panel))
}

.modal-footer {
  border-top: 1px solid var(--panel-border);
  display: flex;
  justify-content: space-between
}

.grid-form {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-3);
  padding: 12px 14px
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px
}

.grid-form input,
.grid-form select,
.comment-form textarea,
.comment-form input {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: var(--r-md);
  padding: 10px;
  box-shadow: var(--shadow-1)
}

.readonly input {
  opacity: .85
}

.comments {
  padding: 6px 14px 12px;
  border-top: 1px dashed var(--panel-border)
}

.comments-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 4px 0
}

.muted {
  color: var(--text-dim)
}

.comment-drop {
  border: 2px dashed color-mix(in srgb, var(--brand) 30%, var(--panel-border));
  border-radius: var(--r-md);
  padding: 12px;
  text-align: center;
  color: var(--text-dim);
  background: var(--panel-2);
  margin-bottom: 8px;
  transition: .15s;
  max-width: 560px
}

.comment-drop.dragover {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand-700)
}

.comment-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px
}

.comment-form textarea {
  grid-column: 1/-1;
  min-height: 92px
}

#commentText {
  max-width: 560px
}

.comment-actions {
  display: flex;
  justify-content: flex-end;
  grid-column: 1/-1
}

.comments-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 260px;
  overflow: auto
}

.comment-item {
  background: var(--panel-2);
  border: 1px solid var(--panel-border);
  border-radius: var(--r-sm);
  padding: 8px 10px
}

.comment-head {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 4px
}

.mention-badge {
  background: #0ea5e9;
  color: #fff;
  border-radius: var(--r-pill);
  padding: 2px 8px;
  font-size: 11px;
  margin-left: 8px
}

.attachments {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px
}

.att-row {
  display: flex;
  align-items: center;
  gap: 8px
}

.att-thumb {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--panel)
}

.att-thumb img {
  max-width: 100%;
  max-height: 100%
}

.att-thumb .pdf-badge {
  font-size: 12px;
  font-weight: 800;
  color: #b91c1c
}

.attachment {
  font-size: 12px;
  color: var(--text);
  text-decoration: none
}

.attachment:hover {
  text-decoration: underline
}

.attachment-remove {
  color: var(--red);
  cursor: pointer;
  text-decoration: underline;
  font-size: 12px
}

/* ==========================
   FAB
========================== */
.fab {
  position: fixed;
  right: 22px;
  bottom: 22px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  line-height: 58px;
  cursor: pointer;
  box-shadow: 0 12px 28px color-mix(in srgb, var(--brand) 35%, transparent);
  pointer-events: auto;
  z-index: 9999;
  transition: .18s transform, .18s box-shadow
}

.fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 34px color-mix(in srgb, var(--brand) 45%, transparent)
}

.fab:active {
  transform: translateY(0)
}

/* ==========================
   Responsive
========================== */
@media (max-width:1200px) {
  .dashboard {
    grid-template-columns: repeat(3, minmax(160px, 1fr))
  }
}

@media (max-width:980px) {
  .filters {
    grid-template-columns: 1fr 1fr 1fr 1fr 1fr 160px
  }
}

@media (max-width:800px) {
  .dashboard {
    grid-template-columns: 1fr 1fr
  }

  .filters {
    grid-template-columns: 1fr 1fr;
    grid-auto-rows: 1fr
  }

  thead th,
  tbody td {
    white-space: nowrap
  }
}

@media (max-width:520px) {
  .actions {
    gap: 6px
  }

  .btn,
  .btn-outline {
    padding: 8px 12px
  }

  .kpi-value {
    font-size: 24px
  }
}


/* ==========================
   HOTFIX – Legibilidade no modo escuro
   (força cores de texto/inputs/tabela e remove pretos fixos)
========================== */
html {
  color-scheme: light dark
}

/* Texto padrão em todos os containers principais */
body,
.card,
.group,
.group-header,
.filters,
.table-wrapper,
table,
thead th,
tbody td,
.modal {
  color: var(--text)
}

/* Inputs/selects – garante texto claro no dark */
.filters input,
.filters select,
.grid-form input,
.grid-form select,
.comment-form textarea,
.comment-form input,
.inline-select {
  color: var(--text);
  background: var(--panel-2)
}

/* Opções do <select> (alguns navegadores mantêm #000) */
select,
option {
  background: var(--panel);
  color: var(--text)
}

/* Títulos e badges */
.group-header h2,
.badge,
.kpi-title {
  color: var(--text)
}

/* Tabela – bordas mais visíveis no dark */
tbody td {
  border-bottom: 1px solid color-mix(in srgb, var(--panel-border) 80%, transparent)
}

/* Chips: evitar textos escuros no dark */
.tag {
  color: var(--text)
}

.tag.prio-URGENTE {
  background: color-mix(in srgb, var(--red) 18%, var(--panel));
  border-color: color-mix(in srgb, var(--red) 55%, var(--panel-border))
}

.tag.prio-ALTA {
  background: color-mix(in srgb, var(--orange) 16%, var(--panel));
  border-color: color-mix(in srgb, var(--orange) 55%, var(--panel-border))
}

.tag.prio-NORMAL {
  background: color-mix(in srgb, var(--blue) 16%, var(--panel));
  border-color: color-mix(in srgb, var(--blue) 55%, var(--panel-border))
}

.tag.prio-BAIXA {
  background: color-mix(in srgb, var(--gray) 18%, var(--panel));
  border-color: color-mix(in srgb, var(--gray) 55%, var(--panel-border))
}

.tag.sit-EM_ANDAMENTO {
  background: color-mix(in srgb, #fb923c 18%, var(--panel));
  border-color: color-mix(in srgb, #fb923c 55%, var(--panel-border))
}

.tag.sit-FINALIZADA {
  background: color-mix(in srgb, #38bdf8 18%, var(--panel));
  border-color: color-mix(in srgb, #38bdf8 55%, var(--panel-border))
}

/* Datas de vencimento – sem hex fixo escuro */
.due-overdue {
  color: color-mix(in srgb, var(--red) 75%, var(--text));
  font-weight: 700
}

.due-today {
  color: color-mix(in srgb, var(--orange) 70%, var(--text));
  font-weight: 700
}

.due-future {
  color: var(--text)
}

.due-none {
  color: var(--text-dim)
}

/* Botões outline em painéis escuros */
.btn-outline {
  color: var(--brand)
}

.btn-outline:hover {
  color: var(--brand);
  border-color: var(--brand)
}

/* Placeholders mais claros no dark */
::placeholder {
  color: color-mix(in srgb, var(--text) 65%, transparent)
}


/* ==========================
   Toggle de Tema (estilo do botão)
========================== */
.theme-toggle {
  --size: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: var(--r-pill);
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text);
  height: var(--size);
  padding: 0 12px;
  box-shadow: var(--shadow-1);
  cursor: pointer;
  transition: .18s backgroun, .18s box-shadow, .18s border-color
}

.theme-toggle:hover {
  box-shadow: var(--shadow-2)
}

.theme-toggle .icon {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center
}

.theme-toggle[data-mode="dark"] .label::after {
  content: "Escuro"
}

.theme-toggle[data-mode="light"] .label::after {
  content: "Claro"
}

/* ====== Compact Mode (oculta gráfico + filtros) ====== */
.is-insights-hidden .chart-wrap,
.is-insights-hidden .filters {
  display: none !important;
}

/* Opcional: compactar o espaçamento quando oculto */
.is-insights-hidden .dashboard {
  margin-bottom: 8px;
}


