:root {
  /* Paleta Vale (ferrovia): verde-azulado + amarelo/dourado, fundo branco */
  --teal-dark: #00786f;
  --teal: #009e93;
  --teal-light: #e0f4f2;
  --gold: #f2b705;
  --green: #f2b705;
  --green-bg: #fdf1c4;
  --gray-border: #d7dde1;
  --text: #1f2937;
  --text-muted: #6b7280;
  --bg: #00786f;
  --frota-astra: #3f3f46;
  --frota-crrc: #b9c2bc;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  background: var(--teal-dark);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.topbar-logo {
  height: 32px;
  width: auto;
  background: white;
  border-radius: 6px;
  padding: 3px 8px;
}

.topbar-title h1 {
  font-size: 1.1rem;
  margin: 0;
}

.topbar-title span {
  font-size: 0.8rem;
  opacity: 0.8;
}

.painel-hero {
  background: var(--teal-dark);
  margin: -1.25rem -1.25rem 0.4rem;
  padding: 0.5rem 1.25rem 0.6rem;
  border-radius: 0 0 14px 14px;
}

.painel-hero img {
  width: 100%;
  height: 140px;
  object-fit: cover;
  display: block;
  border-radius: 10px;
}

.tabs {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.tab-btn {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.4);
  color: white;
  padding: 0.4rem 0.9rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}

.tab-btn.active, .tab-btn:hover {
  background: white;
  color: var(--teal-dark);
  border-color: white;
}

.tabs-sep {
  width: 1px;
  align-self: stretch;
  background: rgba(255,255,255,0.35);
  margin: 0 0.25rem;
}

.tabs-sep.hidden { display: none; }

.tab-select-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.tab-select-wrap.hidden { display: none; }

.tab-select {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.4);
  color: white;
  padding: 0.4rem 0.7rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}

.tab-select option {
  color: var(--text);
}

.tab-select-ano {
  width: 5.5rem;
}

.tab-select:hover, .tab-select:focus {
  background: white;
  color: var(--teal-dark);
  border-color: white;
}

.tab-btn-static {
  cursor: default;
  font-weight: 600;
  white-space: nowrap;
}

.tab-btn-static:hover {
  background: transparent;
  color: white;
  border-color: rgba(255,255,255,0.4);
}

#app {
  padding: 1.25rem;
  max-width: 1800px;
  margin: 0 auto;
}

.view { display: none; }
.view.active { display: block; }

.card {
  background: white;
  border: 1px solid var(--gray-border);
  border-radius: 10px;
  padding: 1.1rem 1.25rem;
  margin-bottom: 1.25rem;
}

.card h2 {
  margin-top: 0;
  font-size: 1rem;
  color: var(--teal-dark);
}

/* Painel */
.form-grid select, .form-grid input, .form-inline input, .form-inline select {
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--gray-border);
  border-radius: 6px;
  font-size: 0.9rem;
}

.mapa-container {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.mapa-titlebar {
  color: white;
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: 0.02em;
  text-align: center;
  padding: 0.25rem 0.65rem 0.4rem;
}

.table-scroll {
  overflow-x: auto;
  border-radius: 10px;
  border: 1px solid var(--bg);
}

.mapa-grid {
  display: grid;
  background: var(--bg);
}

.mapa-cell {
  border-right: 1px solid var(--bg);
  border-top: 1px solid var(--bg);
}

.mapa-head {
  background: #3f3f46;
  color: white;
  font-size: 0.62rem;
  line-height: 1.25;
  text-transform: uppercase;
  padding: 0.5rem 0.25rem;
  border-right: 1px solid rgba(255,255,255,0.2);
  border-top: none;
  text-align: center;
  white-space: normal;
  overflow-wrap: break-word;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mapa-body {
  vertical-align: top;
  padding: 0.35rem;
  min-width: 0;
}

.chip-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.chip {
  display: block;
  text-align: center;
  padding: 0.45rem 0.3rem;
  border-radius: 5px;
  border: 1px solid #6b7280;
  background: #6b7280;
  font-size: 0.78rem;
  cursor: pointer;
  font-weight: 600;
  width: 100%;
  min-width: 0;
  transition: background 0.25s ease;
  overflow-wrap: break-word;
}

.chip:hover { background: #f0f0f0; }

.chip.executado {
  font-weight: 700;
}

.chip[data-frota="CRRC"] { color: #ffffff; }
.chip[data-frota="Astra"] { color: #000000; }

.mapa-legenda {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  align-items: center;
  padding: 0.75rem 0.25rem 0.25rem;
  font-size: 0.78rem;
  color: #d1d5db;
}

.mapa-legenda-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.mapa-legenda-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: inline-block;
}

.frota-grupo {
  margin-bottom: 1rem;
}

.frota-grupo h4 {
  margin: 0 0 0.4rem 0;
  font-size: 0.8rem;
  text-transform: uppercase;
  color: var(--teal-dark);
  letter-spacing: 0.02em;
}

.frota-count {
  color: var(--text-muted);
  font-weight: 400;
  text-transform: none;
}

.cadastro-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.4rem;
}

.cadastro-actions {
  display: flex;
  gap: 0.4rem;
}

.cadastro-editando {
  grid-column: 1 / -1;
}

.cadastro-editando .edit-codigo,
.cadastro-editando .edit-nome,
.cadastro-editando .edit-frota {
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--gray-border);
  border-radius: 6px;
  font-size: 0.85rem;
}

.cadastro-editando .edit-nome { flex: 1; }

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.9rem;
  align-items: end;
}

.form-grid label, .form-inline label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

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

.prog-carro-field { grid-column: 1 / 3; }

.checkbox-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  border: 1px solid var(--gray-border);
  border-radius: 8px;
  padding: 0.7rem;
  max-height: 220px;
  overflow-y: auto;
}

.tipo-toggle {
  background: #fbfbfb;
  border: 1px solid var(--gray-border);
  color: var(--text);
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  font-size: 0.8rem;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.tipo-toggle:hover { border-color: var(--teal); }

.tipo-toggle.active {
  background: var(--teal);
  border-color: var(--teal);
  color: white;
}

.btn-primary {
  background: var(--teal);
  color: white;
  border: none;
  padding: 0.5rem 1.1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  height: fit-content;
}

.btn-primary:hover { background: var(--teal-dark); }

.btn-secondary {
  background: white;
  border: 1px solid var(--gray-border);
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.78rem;
}

.btn-danger {
  background: #fdecec;
  border: 1px solid #f3b4b4;
  color: #b42318;
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.75rem;
}

.btn-icon-danger {
  background: #fdecec;
  border: 1px solid #f3b4b4;
  border-radius: 6px;
  cursor: pointer;
  padding: 0.3rem 0.55rem;
  font-size: 0.9rem;
  line-height: 1;
}

.btn-icon-danger:hover { background: #fbd5d5; }

.prog-carro-row {
  display: flex;
  gap: 0.5rem;
}

.prog-carro-row input { flex: 0 1 140px; }

.carros-selecionados {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.carro-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--teal-light);
  color: var(--teal-dark);
  padding: 0.25rem 0.4rem 0.25rem 0.7rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.carro-chip button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--teal-dark);
  font-size: 0.95rem;
  line-height: 1;
  padding: 0 0.2rem;
}

.form-inline {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.form-inline input { flex: 1; }

.prog-lista, .lista-cadastro {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.prog-item, .cadastro-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--gray-border);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.prog-item .tags {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}

.tag {
  background: var(--teal-light);
  color: var(--teal-dark);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--text-muted);
  margin-right: 0.35rem;
}

.status-dot.on { background: var(--green); }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 50;
}

.modal-overlay.hidden { display: none; }

.modal {
  background: white;
  border-radius: 12px;
  padding: 1.75rem;
  max-width: 700px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.9rem;
  border: none;
  background: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--text-muted);
}

.ordem-header h2 { margin: 0 0 0.2rem 0; color: var(--teal-dark); }
.ordem-header .sub { color: var(--text-muted); font-size: 0.85rem; }

.ordem-dates {
  display: flex;
  gap: 1.25rem;
  margin: 0.9rem 0;
  flex-wrap: wrap;
}

.ordem-dates label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.ordem-dates input {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--gray-border);
  border-radius: 6px;
}

.ordem-status {
  display: inline-block;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.ordem-status.aberto { background: #e2e8e4; color: var(--text-muted); }
.ordem-status.concluido { background: var(--green-bg); color: #7a5b00; }

.ordem-progress-track {
  background: #eef1f2;
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
  margin: 0.6rem 0 1.1rem;
}

.ordem-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #4ade80, #16a34a);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.ordem-progress-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: -0.85rem;
  margin-bottom: 1rem;
  text-align: right;
}

.checklist-categoria {
  margin-top: 0.9rem;
  border: 1px solid var(--gray-border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}

.checklist-categoria h3 {
  background: var(--teal-light);
  margin: 0;
  padding: 0.5rem 0.85rem;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--teal-dark);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.excel-toggle-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.85rem;
  background: #f0fdf4;
  border-top: 1px solid #f0f0f0;
  cursor: pointer;
  user-select: none;
  font-size: 0.8rem;
  color: #166534;
  font-weight: 600;
}

.excel-toggle-row:hover {
  background: #dcfce7;
}

.cat-plus {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  background: #16a34a;
  color: white;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.cat-count {
  margin-left: auto;
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
  color: var(--text-muted);
  font-size: 0.72rem;
}

.cat-body.hidden {
  display: none;
}

.cat-body:not(.hidden) {
  max-height: 360px;
  overflow-y: auto;
  border-top: 1px solid var(--gray-border);
}

.checklist-item {
  padding: 0.55rem 0.85rem;
  border-top: 1px solid #f0f0f0;
  transition: background 0.15s ease;
}

.checklist-item:hover { background: #fafbfb; }

.checklist-item-main {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.85rem;
}

.checklist-item input[type=checkbox] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--teal);
  flex-shrink: 0;
}

.checklist-item-main label { flex: 1; }

.checklist-item.done .checklist-item-main label {
  text-decoration: line-through;
  color: var(--text-muted);
}

.checklist-responsaveis {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin: 0.4rem 0 0 1.65rem;
}

.checklist-responsavel {
  width: 82px;
  padding: 0.25rem 0.4rem;
  border: 1px solid var(--gray-border);
  border-radius: 5px;
  font-size: 0.72rem;
  color: var(--text);
  background: #fbfbfb;
}

.checklist-anotacao {
  display: block;
  width: calc(100% - 1.65rem);
  margin: 0.4rem 0 0 1.65rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--gray-border);
  border-radius: 6px;
  font-size: 0.76rem;
  font-family: inherit;
  color: var(--text);
  background: #fbfbfb;
  resize: vertical;
  min-height: 32px;
}

.checklist-anotacao:focus {
  outline: none;
  border-color: var(--teal);
  background: white;
}

.checklist-responsavel:focus {
  border-color: var(--teal);
  background: white;
  outline: none;
}

.checklist-responsavel::placeholder { color: #b0b8bf; }

.btn-subchecklist {
  background: var(--teal-light);
  color: var(--teal-dark);
  border: 1px solid var(--teal);
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.btn-subchecklist:hover { background: var(--teal); color: white; }

.subchecklist {
  margin: 0.5rem 0 0 1.65rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--gray-border);
  border-radius: 8px;
  background: #f7f8f9;
}

.subchecklist.hidden { display: none; }

.subchecklist-item {
  padding: 0.4rem 0;
  border-bottom: 1px solid #e8ebed;
}

.subchecklist-item:last-child { border-bottom: none; }

.subchecklist-item-main {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.subchecklist-item-main input[type=checkbox] {
  margin-top: 0.2rem;
  width: 15px;
  height: 15px;
  cursor: pointer;
}

.subchecklist-item-main label {
  font-size: 0.8rem;
  line-height: 1.35;
}

.subchecklist-item.done .subchecklist-item-main label {
  text-decoration: line-through;
  color: var(--text-muted);
}

.subchecklist-como {
  margin: 0.3rem 0 0 1.7rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: pre-line;
  line-height: 1.5;
}

.add-item-row {
  display: flex;
  gap: 0.4rem;
  padding: 0.5rem 0.85rem;
  border-top: 1px solid #f0f0f0;
  background: #fbfcfc;
}

.add-item-row input {
  flex: 1;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--gray-border);
  border-radius: 6px;
  font-size: 0.8rem;
}

.categoria-anotacao {
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: 0.5rem 0.7rem;
  border: none;
  border-top: 1px solid var(--gray-border);
  font-size: 0.8rem;
  font-family: inherit;
  color: var(--text);
  background: #fffbea;
  resize: vertical;
  min-height: 36px;
}

.categoria-anotacao:focus {
  outline: none;
  background: #fff6d1;
}

.add-categoria-row {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.9rem;
}

.add-categoria-row input {
  flex: 1;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--gray-border);
  border-radius: 6px;
}

.empty-msg {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
}

.mapa-body .empty-msg {
  color: #cbd5e1;
}

.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--teal-dark);
  color: white;
  padding: 0.6rem 1.1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  z-index: 100;
}

.toast.error { background: #b42318; }
.toast.hidden { display: none; }

.historico-carro-titulo {
  color: var(--teal-dark);
  margin: 0.5rem 0 1rem;
}

.historico-bloco {
  border: 1px solid var(--gray-border);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 1.1rem;
}

.historico-bloco-header {
  background: var(--teal-light);
  padding: 0.6rem 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  color: var(--teal-dark);
}

.historico-datas {
  margin-left: auto;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.historico-table-scroll {
  overflow-x: auto;
}

.historico-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.historico-table th {
  text-align: left;
  background: #f4f6f7;
  padding: 0.5rem 0.7rem;
  color: var(--text-muted);
  font-weight: 600;
  border-top: 1px solid var(--gray-border);
}

.historico-table td {
  padding: 0.45rem 0.7rem;
  border-top: 1px solid #f0f0f0;
}

.historico-anotacoes {
  padding: 0.6rem 0.9rem;
  background: #fffbea;
  border-top: 1px solid var(--gray-border);
  font-size: 0.8rem;
}

.historico-anotacao-item {
  margin-top: 0.3rem;
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
}

@media (max-width: 720px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-inline { flex-wrap: wrap; }
  .form-inline input, .form-inline select { flex: 1 1 100%; }
  .prog-carro-row { flex-wrap: wrap; }
  .prog-carro-row input { flex: 1 1 100%; }
  .topbar { padding: 0.6rem 0.9rem; }
  .painel-hero img { height: 110px; }
  .painel-hero { padding: 0.6rem 0.75rem 0.9rem; }
  .checklist-responsavel { width: 70px; }
  .modal { padding: 1rem; }
}

@media print {
  .topbar, .painel-hero, .modal-overlay, .toast {
    display: none !important;
  }
  body, #app {
    background: white;
    padding: 0;
  }
  .mapa-cell, .table-scroll {
    border-color: #999 !important;
  }
  .chip {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
