:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --font: system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.25rem;
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
  padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
}

.container.wide { max-width: 1100px; }

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.barra-relatorio {
  margin-bottom: 1rem;
}

.barra-relatorio-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}

.barra-relatorio-inner > div {
  flex: 1;
  min-width: 10rem;
}

.barra-relatorio-inner label {
  margin-bottom: 0.35rem;
}

.barra-relatorio-inner input[type="date"] {
  margin-bottom: 0;
}

.barra-relatorio-inner .btn {
  flex-shrink: 0;
}

@media (max-width: 520px) {
  .barra-relatorio-inner {
    flex-direction: column;
    align-items: stretch;
  }
  .barra-relatorio-inner .btn {
    width: 100%;
  }
}

h1 { font-size: 1.35rem; font-weight: 600; }
h2 { font-size: 1rem; color: var(--muted); margin-bottom: 0.75rem; font-weight: 500; }

.card {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

input, select, textarea {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--surface2);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 0.85rem;
}

textarea { min-height: 72px; resize: vertical; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1rem;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: var(--surface2); color: var(--text); }
.btn-ok { background: var(--ok); color: #fff; }
.btn-sm { padding: 0.4rem 0.65rem; font-size: 0.8rem; }
.btn-danger { background: var(--danger); color: #fff; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

@media (max-width: 520px) {
  .grid-2 { grid-template-columns: 1fr; }
}

.hidden { display: none !important; }

.task-list { list-style: none; }

.task-item {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--surface2);
}

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

.task-meta { font-size: 0.8rem; color: var(--muted); margin-top: 0.25rem; }

.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.badge-pendente { background: #422006; color: var(--warn); }
.badge-em_andamento { background: #1e3a5f; color: #93c5fd; }
.badge-concluida { background: #14532d; color: #86efac; }
.badge-cancelada { background: #450a0a; color: #fca5a5; }
.badge-estoque-ok { background: #14532d; color: #86efac; }
.badge-estoque-baixo { background: #422006; color: var(--warn); }

.estoque-row-acao {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.estoque-row-acao .input-qtd {
  width: 4.5rem;
  min-width: 4rem;
  margin-bottom: 0;
}

.estoque-row-nome {
  width: 100%;
}

.estoque-row-nome .input-inline {
  flex: 1 1 10rem;
  min-width: 8rem;
}

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

.user-name { color: var(--accent); font-weight: 500; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th, td {
  text-align: left;
  padding: 0.5rem;
  border-bottom: 1px solid var(--surface2);
}

th { color: var(--muted); font-weight: 500; }

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

.tab {
  padding: 0.5rem 0.85rem;
  border-radius: 8px;
  background: var(--surface2);
  border: none;
  color: var(--muted);
  cursor: pointer;
}

.tab.active { background: var(--accent); color: #fff; }

.empty { text-align: center; color: var(--muted); padding: 2rem; }

.link-mapa {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.8rem;
}
.link-mapa:hover { text-decoration: underline; }

.loc-cell { font-size: 0.75rem; max-width: 180px; line-height: 1.4; }

/* ——— Ponto ——— */
.barra-horas {
  width: 100%;
  height: 14px;
  background: var(--surface2);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

.barra-horas-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.3s ease;
}

.barra-horas-fill.barra-horas-extra {
  background: var(--ok);
}

.ponto-camera-bloco {
  margin-top: 1rem;
}

.ponto-camera-bloco video,
.ponto-camera-bloco img {
  width: 100%;
  max-width: 360px;
  border-radius: var(--radius);
  background: #000;
  display: block;
  margin: 0 auto;
}

.foto-ponto-thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  display: block;
}

.badge-ponto-entrada { background: #14532d; color: #86efac; }
.badge-ponto-volta_almoco { background: #14532d; color: #86efac; }
.badge-ponto-saida_almoco { background: #422006; color: var(--warn); }
.badge-ponto-saida { background: #1e3a5f; color: #93c5fd; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}

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

.modal-card {
  max-width: 420px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}

.input-inline {
  width: 100%;
  min-width: 5rem;
  margin-bottom: 0;
  padding: 0.4rem 0.55rem;
  font-size: 0.85rem;
}

.tabela-editavel td .input-inline {
  min-width: 7rem;
}

.task-item .input-inline {
  flex: 1;
  min-width: 8rem;
}

/* ——— Abas: texto curto no celular ——— */
.tab-short { display: none; }

.table-responsive {
  width: 100%;
  -webkit-overflow-scrolling: touch;
}

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

/* ——— Mobile: tabelas viram cards (tudo visível sem cortar) ——— */
@media (max-width: 768px) {
  .container {
    padding-top: max(0.85rem, env(safe-area-inset-top));
  }

  .card {
    padding: 1rem;
  }

  h1 {
    font-size: 1.15rem;
    line-height: 1.35;
    flex: 1;
    min-width: 0;
  }

  header {
    margin-bottom: 1rem;
  }

  .tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.45rem;
  }

  .tab {
    width: 100%;
    padding: 0.65rem 0.5rem;
    font-size: 0.8rem;
    text-align: center;
    min-height: 2.75rem;
  }

  .tab-long { display: none; }
  .tab-short { display: inline; }

  .btn {
    min-height: 2.75rem;
  }

  .btn-sm {
    min-height: 2.5rem;
  }

  .card > .btn-primary:not(.btn-sm),
  .card > .btn.btn-primary[id] {
    width: 100%;
  }

  .table-responsive tbody td select,
  .table-responsive tbody td input {
    margin-bottom: 0;
  }

  .task-item {
    flex-direction: column;
    align-items: stretch;
  }

  .task-item .actions {
    width: 100%;
  }

  .task-item .actions .btn {
    flex: 1 1 calc(50% - 0.25rem);
    min-width: 7rem;
  }

  .estoque-row-acao {
    width: 100%;
    justify-content: flex-end;
  }

  .estoque-row-acao .btn {
    flex: 1 1 auto;
  }

  .table-responsive:not(.table-responsive--scroll) table {
    display: block;
    width: 100%;
  }

  .table-responsive:not(.table-responsive--scroll) thead {
    display: none;
  }

  .table-responsive:not(.table-responsive--scroll) tbody {
    display: block;
  }

  .table-responsive:not(.table-responsive--scroll) tbody tr {
    display: block;
    margin-bottom: 0.85rem;
    padding: 0.85rem;
    background: var(--bg);
    border: 1px solid var(--surface2);
    border-radius: var(--radius);
  }

  .table-responsive:not(.table-responsive--scroll) tbody tr:last-child {
    margin-bottom: 0;
  }

  .table-responsive:not(.table-responsive--scroll) tbody td {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.55rem 0;
    border-bottom: 1px solid var(--surface2);
    text-align: right;
    font-size: 0.9rem;
  }

  .table-responsive:not(.table-responsive--scroll) tbody td:last-child {
    border-bottom: none;
    padding-bottom: 0;
  }

  .table-responsive:not(.table-responsive--scroll) tbody td:first-child {
    padding-top: 0;
  }

  .table-responsive:not(.table-responsive--scroll) tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--muted);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    flex: 0 0 auto;
    max-width: 42%;
    text-align: left;
    line-height: 1.3;
  }

  .table-responsive:not(.table-responsive--scroll) tbody td > *:not(.badge) {
    flex: 1 1 55%;
    min-width: 0;
    text-align: right;
  }

  .table-responsive:not(.table-responsive--scroll) tbody td .badge {
    margin-left: auto;
  }

  .table-responsive:not(.table-responsive--scroll) tbody td.actions-cell {
    flex-direction: column;
    align-items: stretch;
  }

  .table-responsive:not(.table-responsive--scroll) tbody td.actions-cell::before {
    max-width: 100%;
    margin-bottom: 0.15rem;
  }

  .table-responsive:not(.table-responsive--scroll) tbody td.actions-cell .actions,
  .table-responsive:not(.table-responsive--scroll) tbody td.actions-cell .estoque-row-acao {
    width: 100%;
    justify-content: stretch;
  }

  .table-responsive:not(.table-responsive--scroll) tbody td.actions-cell .actions .btn,
  .table-responsive:not(.table-responsive--scroll) tbody td.actions-cell .estoque-row-acao .btn {
    flex: 1 1 calc(50% - 0.2rem);
  }

  .table-responsive:not(.table-responsive--scroll) tbody td select,
  .table-responsive:not(.table-responsive--scroll) tbody td .input-inline,
  .table-responsive:not(.table-responsive--scroll) tbody td .sel-resp {
    width: 100%;
    max-width: 100%;
    flex: 1 1 100%;
    text-align: left;
  }

  .table-responsive:not(.table-responsive--scroll) tbody td.loc-cell {
    max-width: none;
    flex-direction: column;
    align-items: flex-start;
  }

  .table-responsive:not(.table-responsive--scroll) tbody td.loc-cell::before {
    max-width: 100%;
  }

  .table-responsive:not(.table-responsive--scroll) tbody td.loc-cell > * {
    text-align: left;
    width: 100%;
  }

  .tabela-editavel tbody td::before {
    max-width: 38%;
  }
}

@media (max-width: 380px) {
  .tabs {
    grid-template-columns: 1fr;
  }

  .task-item .actions .btn,
  .table-responsive:not(.table-responsive--scroll) tbody td.actions-cell .actions .btn {
    flex: 1 1 100%;
  }
}
