/* Nelli — Painel. Fontes: Fraunces (display) + Karla (corpo), self-hosted. */

@font-face {
  font-family: "Fraunces";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/static/fonts/fraunces-variable-latin.woff2") format("woff2");
}

@font-face {
  font-family: "Karla";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/static/fonts/karla-variable-latin.woff2") format("woff2");
}

:root {
  --brand-green-dark: #163f2c;
  --brand-green: #1b5e3a;
  --brand-green-bright: #6bcb4d;

  --surface-1: #fbfaf7;
  --surface-2: #ffffff;
  --page-plane: #f4f2ec;
  --text-primary: #17211b;
  --text-secondary: #5a5f57;
  --text-muted: #8b8f85;
  --border-hairline: rgba(23, 33, 27, 0.1);
  --gridline: #e6e3da;

  /* categorical (validada — ordem fixa, não trocar) */
  --cat-1: #6b4e9e; /* pergunta */
  --cat-2: #1f7a4d; /* atividade */
  --cat-3: #2678a6; /* comunicacao */
  --cat-4: #d98f1e; /* anotacao */

  /* status (fixo, nunca reusar em categórico) */
  --status-good: #0ca30c;
  --status-warning: #d98f1e;
  --status-critical: #d03b3b;

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --shadow-card: 0 1px 2px rgba(23, 33, 27, 0.04), 0 8px 24px -12px rgba(23, 33, 27, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface-1: #16211c;
    --surface-2: #1c2a22;
    --page-plane: #0f1712;
    --text-primary: #f3f5f1;
    --text-secondary: #b9c0b4;
    --text-muted: #7f8a7a;
    --border-hairline: rgba(255, 255, 255, 0.08);
    --gridline: #2a352c;

    --cat-1: #a58fd8;
    --cat-2: #4caf6d;
    --cat-3: #5fa8c9;
    --cat-4: #e0a83a;

    --status-good: #4caf50;
    --status-warning: #e0a83a;
    --status-critical: #e0685f;

    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.2), 0 8px 24px -12px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: "Karla", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

h1, h2, h3, .display {
  font-family: "Fraunces", Georgia, serif;
  font-optical-sizing: auto;
  letter-spacing: -0.01em;
}

/* ---------- Header ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px calc(14px + env(safe-area-inset-top)) 16px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: linear-gradient(160deg, var(--brand-green-dark), var(--brand-green) 70%);
  color: #fff;
  box-shadow: 0 4px 18px -8px rgba(0, 0, 0, 0.35);
}

.topbar .avatar {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.35);
  flex-shrink: 0;
}

.topbar .titles { min-width: 0; }
.topbar h1 { font-size: 19px; margin: 0; font-weight: 600; color: #fff; }
.topbar p { margin: 1px 0 0; font-size: 12.5px; color: rgba(255, 255, 255, 0.78); }
.topbar .status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--brand-green-bright);
  display: inline-block;
  margin-right: 6px;
  box-shadow: 0 0 0 3px rgba(107, 203, 77, 0.25);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ---------- Layout ---------- */

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px 14px 8px;
}

.section-title {
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 700;
  margin: 26px 4px 10px;
}
.section-title:first-child { margin-top: 6px; }

/* ---------- Stat tiles ---------- */

.stat-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.stat-tile {
  background: var(--surface-2);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
}
.stat-tile .k {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 700;
}
.stat-tile .v {
  font-family: "Fraunces", Georgia, serif;
  font-size: 32px;
  font-weight: 600;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.stat-tile .accent {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}
.stat-tile.c-1 .accent { background: var(--cat-2); }
.stat-tile.c-2 .accent { background: var(--status-warning); }
.stat-tile.c-3 .accent { background: var(--status-good); }
.stat-tile.c-4 .accent { background: var(--cat-1); }

/* ---------- Cards / charts ---------- */

.card {
  background: var(--surface-2);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-card);
  margin-bottom: 14px;
}
.card h2 {
  font-size: 16px;
  margin: 0 0 4px;
  font-weight: 600;
}
.card .sub {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 0 0 16px;
}

.charts-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-top: 14px;
  font-size: 12.5px;
  color: var(--text-secondary);
}
.legend .dot {
  width: 9px; height: 9px; border-radius: 50%;
  display: inline-block; margin-right: 6px;
}

.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.bar-row .label { width: 92px; flex-shrink: 0; font-size: 12.5px; color: var(--text-secondary); }
.bar-row .track { flex: 1; height: 10px; background: var(--gridline); border-radius: 6px; overflow: hidden; }
.bar-row .fill { height: 100%; border-radius: 6px; }
.bar-row .count { width: 28px; text-align: right; font-size: 12.5px; font-variant-numeric: tabular-nums; color: var(--text-secondary); }

.sparkline-wrap { width: 100%; overflow-x: auto; }

/* ---------- Empty state ---------- */

.empty {
  color: var(--text-muted);
  font-size: 13.5px;
  padding: 18px 4px;
  text-align: center;
}

/* ---------- Activity list (mobile: cards) ---------- */

.activity-list { display: flex; flex-direction: column; gap: 10px; }

.activity-card {
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  padding: 13px 14px;
  background: var(--surface-1);
}
.activity-card .row-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.activity-card .titulo { font-weight: 600; font-size: 14.5px; }
.activity-card .descricao { font-size: 13px; color: var(--text-secondary); margin-top: 3px; }
.activity-card .meta {
  display: flex; flex-wrap: wrap; gap: 6px 14px;
  margin-top: 9px; font-size: 12px; color: var(--text-muted);
}
.activity-card .meta span strong { color: var(--text-secondary); font-weight: 600; }

.pill {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.pendente { background: color-mix(in srgb, var(--status-warning) 16%, transparent); color: var(--status-warning); }
.pill.concluida { background: color-mix(in srgb, var(--status-good) 16%, transparent); color: var(--status-good); }
.pill.atrasada { background: color-mix(in srgb, var(--status-critical) 16%, transparent); color: var(--status-critical); }

.tag {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 8px;
  border-radius: 6px;
  white-space: nowrap;
}
.tag.atividade { background: color-mix(in srgb, var(--cat-2) 16%, transparent); color: var(--cat-2); }
.tag.anotacao { background: color-mix(in srgb, var(--cat-4) 18%, transparent); color: var(--cat-4); }
.tag.comunicacao { background: color-mix(in srgb, var(--cat-3) 16%, transparent); color: var(--cat-3); }
.tag.pergunta { background: color-mix(in srgb, var(--cat-1) 16%, transparent); color: var(--cat-1); }
.tag.audio { background: rgba(107, 78, 158, 0.12); color: #6b4e9e; }
.tag.texto { background: rgba(90, 95, 87, 0.12); color: var(--text-secondary); }

.evidence-thumbs { display: flex; gap: 6px; margin-top: 9px; }
.evidence-thumbs img {
  width: 42px; height: 42px; object-fit: cover; border-radius: 8px;
  border: 1px solid var(--border-hairline);
}

/* ---------- Messages feed ---------- */

.feed-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--border-hairline);
  font-size: 13px;
}
.feed-item:last-child { border-bottom: none; }
.feed-item .text { margin-top: 5px; color: var(--text-secondary); }
.feed-item time { color: var(--text-muted); font-size: 11.5px; }

/* ---------- Table (desktop only) ---------- */

.table-wrap { display: none; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border-hairline); vertical-align: middle; }
th { color: var(--text-muted); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }

/* ---------- Responsive: tablet/desktop ---------- */

@media (min-width: 720px) {
  .stat-row { grid-template-columns: repeat(4, 1fr); }
  .charts-grid { grid-template-columns: 1.2fr 1fr; }
  .two-col { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; align-items: start; }
  .activity-list { display: none; }
  .table-wrap { display: block; }
}

/* ---------- Install hint ---------- */

.install-hint {
  display: none;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--text-secondary);
  box-shadow: var(--shadow-card);
}
.install-hint.visible { display: flex; }
.install-hint button {
  background: var(--brand-green);
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  margin-left: auto;
  flex-shrink: 0;
}

/* ---------- Header install button ---------- */

.topbar .header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.28);
  color: #fff;
  padding: 8px 12px;
  border-radius: 999px;
  font-family: "Karla", sans-serif;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:active { background: rgba(255, 255, 255, 0.24); }
.icon-btn svg { width: 15px; height: 15px; flex-shrink: 0; }

/* ---------- Modal overlay (compartilhado: instalação + chat) ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 18, 0.5);
  backdrop-filter: blur(2px);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 0;
}
.modal-overlay.open { display: flex; }

.modal-sheet {
  width: 100%;
  max-width: 480px;
  background: var(--surface-2);
  border-radius: 22px 22px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.25);
  animation: sheet-up 0.28s cubic-bezier(.2,.8,.2,1);
  max-height: 88vh;
  overflow-y: auto;
}
@keyframes sheet-up {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
@media (min-width: 640px) {
  .modal-overlay { align-items: center; }
  .modal-sheet { border-radius: 22px; }
}

.modal-sheet .modal-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.modal-sheet .modal-head h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  flex: 1;
}
.modal-sheet .modal-head p {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
}
.modal-close {
  background: var(--gridline);
  border: none;
  width: 30px; height: 30px;
  border-radius: 50%;
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}

.install-steps {
  font-size: 13.5px;
  color: var(--text-secondary);
  line-height: 1.6;
  background: var(--surface-1);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  padding: 14px 16px;
}

/* ---------- Chat FAB ---------- */

.chat-fab {
  position: fixed;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: linear-gradient(160deg, var(--brand-green), var(--brand-green-dark));
  border: none;
  box-shadow: 0 10px 24px -6px rgba(22, 63, 44, 0.55);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 90;
  -webkit-tap-highlight-color: transparent;
}
.chat-fab svg { width: 26px; height: 26px; }
.chat-fab:active { transform: scale(0.94); }

/* ---------- Chat modal (pergunta / resposta em voz, sem histórico) ---------- */

.chat-avatar-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 6px 0 20px;
}
.chat-avatar-row img {
  width: 84px; height: 84px;
  border-radius: 26px;
  object-fit: cover;
  box-shadow: var(--shadow-card);
}

.chat-state {
  font-size: 13.5px;
  color: var(--text-secondary);
  text-align: center;
  min-height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.voice-orb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--brand-green-bright);
  display: none;
}
.voice-orb.active {
  display: inline-block;
  animation: orb-pulse 1s ease-in-out infinite;
}
@keyframes orb-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.5); opacity: 0.5; }
}

.chat-form {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.chat-form input {
  flex: 1;
  border: 1px solid var(--border-hairline);
  background: var(--surface-1);
  border-radius: 999px;
  padding: 12px 16px;
  font-family: "Karla", sans-serif;
  font-size: 14.5px;
  color: var(--text-primary);
  outline: none;
}
.chat-form input:focus { border-color: var(--brand-green); }
.chat-form button {
  width: 46px; height: 46px;
  border-radius: 50%;
  border: none;
  background: var(--brand-green);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.chat-form button:disabled { opacity: 0.5; cursor: default; }
.chat-form button svg { width: 18px; height: 18px; }

.chat-hint {
  font-size: 11.5px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 12px;
}
