* { box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.card {
  background: #1e293b;
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
h1 {
  font-size: 20px;
  margin: 0 0 4px;
}
.subtitle {
  color: #94a3b8;
  font-size: 13px;
  margin: 0 0 24px;
}
label {
  display: block;
  font-size: 13px;
  margin: 16px 0 6px;
  color: #cbd5e1;
}
input, textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #334155;
  background: #0f172a;
  color: #e2e8f0;
  font-size: 14px;
}
input:focus, textarea:focus {
  outline: none;
  border-color: #6366f1;
}
button {
  margin-top: 20px;
  width: 100%;
  padding: 11px;
  border-radius: 8px;
  border: none;
  background: #6366f1;
  color: white;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
button:hover { background: #4f46e5; }
button.secondary {
  background: transparent;
  border: 1px solid #334155;
  color: #cbd5e1;
}
button.secondary:hover { background: #334155; }
.msg {
  margin-top: 16px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  display: none;
}
.msg.ok { display: block; background: rgba(34,197,94,0.15); color: #4ade80; }
.msg.err { display: block; background: rgba(239,68,68,0.15); color: #f87171; }
.msg.warn { display: block; background: rgba(245,158,11,0.15); color: #fbbf24; }
.divider {
  margin: 24px 0;
  border-top: 1px solid #334155;
  text-align: center;
}
.divider span {
  background: #1e293b;
  padding: 0 10px;
  color: #64748b;
  font-size: 12px;
  position: relative;
  top: -10px;
}
.wide { max-width: 640px; }
.table-scroll {
  margin-top: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid #334155;
}
th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
th.sortable:hover { color: #e2e8f0; }
th.sortable::after {
  content: "↕";
  color: #475569;
  margin-left: 4px;
  font-size: 11px;
}
th.sortable.sort-asc::after { content: "↑"; color: #818cf8; }
th.sortable.sort-desc::after { content: "↓"; color: #818cf8; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.pill {
  font-size: 12px;
  color: #94a3b8;
}
.linklike {
  background: none;
  border: none;
  color: #818cf8;
  font-size: 13px;
  padding: 0;
  margin-top: 12px;
  cursor: pointer;
  width: auto;
}

/* Layout com menu lateral, usado nas telas autenticadas (apontamentos, recursos) */
body.shell {
  display: block;
  padding: 0;
}
.app-shell {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: #111827;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #1f2937;
  /* Sem isso, o flex stretch padrão faz a sidebar esticar até a altura do
     main-content (ex: tabela do Forecast, lista de Recursos) — em páginas
     com conteúdo mais alto que a tela, "Sair" no rodapé ficava empurrado
     pra fora da área visível, exigindo rolar a página inteira (não só o
     conteúdo) pra alcançar. position: sticky prende a sidebar na altura
     da viewport, com rolagem própria só nela quando o menu não couber. */
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar-brand {
  font-weight: 700;
  font-size: 15px;
  color: #e2e8f0;
  margin-bottom: 28px;
}
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}
.sidebar-nav a {
  color: #94a3b8;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
}
.sidebar-nav a:hover { background: #1e293b; color: #e2e8f0; }
.sidebar-nav a.active { background: #6366f1; color: #fff; }
.sidebar-footer {
  border-top: 1px solid #1f2937;
  padding-top: 16px;
}
.sidebar-user {
  font-size: 13px;
  color: #cbd5e1;
  margin-bottom: 8px;
}
.main-content {
  flex: 1;
  min-width: 0; /* sem isso, um filho largo (ex: grade de alocação) impede o encolhimento e força scroll na página inteira em vez de só dentro do card */
  padding: 40px 24px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.badge.on { background: rgba(34,197,94,0.15); color: #4ade80; }
.badge.off { background: rgba(148,163,184,0.15); color: #94a3b8; }
.linklike.small {
  font-size: 12px;
  margin-top: 0;
}
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: #1e293b;
  border-radius: 12px;
  padding: 28px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
.modal-box h2 {
  font-size: 17px;
  margin: 0 0 16px;
}
.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid #334155;
  font-size: 13px;
}
.detail-row span:first-child {
  color: #94a3b8;
}
.detail-row span:last-child {
  text-align: right;
}
.modal-box button.secondary {
  margin-top: 20px;
}
@media (max-width: 700px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: auto;
    height: auto;
    overflow-y: visible;
    flex-direction: row;
    align-items: center;
    border-right: none;
    border-bottom: 1px solid #1f2937;
    padding: 12px 16px;
  }
  .sidebar-brand { margin-bottom: 0; margin-right: 16px; }
  .sidebar-nav { flex-direction: row; flex: 1; }
  .sidebar-footer {
    border-top: none;
    padding-top: 0;
    display: flex;
    align-items: center;
    gap: 12px;
  }
  .sidebar-user { margin-bottom: 0; }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Tela de Recursos (responsiva: mobile-first) ---------- */

.main-content:has(.page-recursos) {
  align-items: stretch;
  justify-content: stretch;
}

.page-recursos {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
}

.page-recursos .header {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 20px;
}

.page-recursos .header h1 {
  margin: 0 0 4px;
}

.header-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.search-box {
  width: 100%;
  padding: 11px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-color, #334155);
  background: var(--bg-secondary, #0f172a);
  color: var(--text-primary, #e0e7ff);
  font-size: 14px;
}

.search-box:focus {
  outline: none;
  border-color: var(--accent-color, #6366f1);
}

.btn-sync {
  width: 100%;
  min-height: 48px;
  padding: 11px;
  border-radius: 8px;
  border: none;
  background: var(--accent-color, #6366f1);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.btn-sync:hover { background: #4f46e5; }
.btn-sync:active { transform: scale(0.98); }
.btn-sync:disabled { opacity: 0.7; cursor: default; }
.btn-sync.loading { position: relative; }

/* Tabela: escondida por padrão (mobile-first), tabela real só no desktop */
.resources-table { display: none; }

/* Cards: visíveis por padrão em mobile */
.resources-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.resource-card {
  background: var(--bg-primary, #1e293b);
  border: 1px solid var(--border-color, #334155);
  border-radius: 12px;
  padding: 14px;
  transition: border-color 0.15s ease;
}

.resource-card:active { border-color: var(--accent-color, #6366f1); }

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.card-nome {
  font-weight: 600;
  font-size: 15px;
  color: var(--text-primary, #e0e7ff);
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.card-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 13px;
}

.card-field span:first-child { color: var(--text-secondary, #94a3b8); font-size: 12px; }
.card-field span:last-child { overflow-wrap: anywhere; }

.card-footer {
  display: flex;
  justify-content: flex-end;
  border-top: 1px solid var(--border-color, #334155);
  padding-top: 10px;
}

.card-footer .btn-view {
  min-height: 44px;
  padding: 0 14px;
}

.btn-view {
  background: none;
  border: 1px solid var(--border-color, #334155);
  color: var(--accent-color, #818cf8);
  font-size: 13px;
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-view:hover { background: rgba(99,102,241,0.12); border-color: var(--accent-color, #6366f1); }
.btn-view:active { transform: scale(0.98); }

.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.status-badge.status-ativo { background: rgba(34,197,94,0.15); color: var(--status-ativo, #22c55e); }
.status-badge.status-inativo { background: rgba(239,68,68,0.15); color: var(--status-inativo, #ef4444); }
.status-badge.status-pendente { background: rgba(245,158,11,0.15); color: #fbbf24; cursor: help; }
.status-badge.status-falha { background: rgba(239,68,68,0.15); color: #f87171; cursor: help; }

/* Banner de apontamentos pendentes de sincronização (sync-monitor.js) */
.sync-banner {
  display: none;
  flex-direction: column;
  position: sticky;
  top: 0;
  z-index: 60;
  gap: 6px;
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 600;
  color: #78350f;
  background: #fbbf24;
  text-align: center;
}
.sync-banner.show { display: flex; }
.sync-banner.critico { background: #f87171; color: #7f1d1d; }
.sync-banner-linha {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
}
.sync-banner button {
  width: auto;
  margin-top: 0;
  padding: 6px 12px;
  font-size: 12px;
  background: rgba(0,0,0,0.15);
  color: inherit;
}
.sync-banner button:hover { background: rgba(0,0,0,0.25); }
.sync-banner button:disabled { opacity: 0.6; cursor: default; }
/* Detalhe do motivo real de cada apontamento pendente (ultimo_erro) —
   linhas menores e mais claras que o resumo acima, sem negrito. */
.sync-banner-detalhes {
  display: none;
  font-size: 12px;
  font-weight: 400;
  opacity: 0.9;
}
.sync-banner-detalhes.show { display: block; }

.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-secondary, #94a3b8);
  font-size: 14px;
}

/* Tablet: 768px+ — cards em grade de 2 colunas */
@media (min-width: 768px) {
  .header-actions {
    flex-direction: row;
    align-items: center;
  }
  .search-box { flex: 1; min-width: 240px; }
  .btn-sync { width: auto; white-space: nowrap; padding-left: 20px; padding-right: 20px; }

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

/* Desktop: 1024px+ — tabela substitui os cards */
@media (min-width: 1024px) {
  .page-recursos .header {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }

  /* Em mobile/tablet o btn-sync é o CTA principal da tela (full-width,
     alvo de toque de 48px). No desktop, ao lado da busca e por cima de uma
     tabela com botões pequenos ("Ver cadastro"), esse mesmo tamanho fica
     desproporcional — reduz para a mesma escala do resto da UI aqui,
     igual já é feito para o btn-sync de alocacao.html. */
  .page-recursos .btn-sync {
    min-height: auto;
    margin-top: 0;
    padding: 8px 16px;
    font-size: 13px;
  }

  .resources-table { display: table; }
  .resources-cards { display: none; }

  .resources-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
  }
  .resources-table th,
  .resources-table td {
    text-align: left;
    padding: 10px 8px;
    border-bottom: 1px solid var(--border-color, #334155);
  }
  .resources-table th.sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
  }
  .resources-table th.sortable:hover { color: var(--text-primary, #e0e7ff); }
  .resources-table th.sortable::after {
    content: "↕";
    color: #475569;
    margin-left: 4px;
    font-size: 11px;
  }
  .resources-table th.sortable.sort-asc::after { content: "↑"; color: var(--accent-color, #818cf8); }
  .resources-table th.sortable.sort-desc::after { content: "↓"; color: var(--accent-color, #818cf8); }
  .resources-table tbody tr:hover { background: rgba(99,102,241,0.06); }

  .resources-table .btn-view { min-height: auto; }
}
