/*
  Cores da marca (logo): bege #fdfcdd, azul-marinho #1f3c5a, laranja #f97725.
  Os estados usam tons pastel (fundo) com uma versão mais escura (texto/contorno).
*/
:root {
  color-scheme: light;

  /* base bege */
  --bg: #fdfcdd;
  --surface: #fffef2;
  --surface-2: #f6f3d2;
  --border: #e8e3bb;
  --text: #1f3c5a;
  --muted: #6b7a87;

  /* marca */
  --primary: #1f3c5a;
  --primary-soft: #dbe5ef;
  --primary-ink: #fdfcdd;
  --accent: #f97725;
  --accent-soft: #fde0c8;
  --accent-ink: #b4501a;
  --chart: #8fadcb;
  --track: #f1eecd;

  --topbar: #fdfcdd;
  --topbar-ink: #1f3c5a;
  --topbar-muted: #6b7a87;

  /* estados em pastel */
  --in: #3f7a4a;
  /* verde-salva */
  --in-soft: #d7ead2;
  --in-line: #a6cfa0;
  --out: #b2493a;
  /* coral */
  --out-soft: #f8d8cf;
  --out-line: #eaa898;
  --warn: #93671a;
  /* manteiga */
  --warn-soft: #f7e7b4;
  --warn-line: #e6c977;
  --off: #66568f;
  /* lavanda */
  --off-soft: #e4ddf1;

  --radius: 14px;
  --shadow: 0 1px 2px rgba(31, 60, 90, .05), 0 4px 14px rgba(31, 60, 90, .06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}

h1,
h2,
h3 {
  margin: 0;
}

h1 {
  font-size: 1.5rem;
}

h3 {
  font-size: 1rem;
  margin-bottom: 12px;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: .85rem;
}

.hidden {
  display: none !important;
}

body.role-geral .admin-only {
  display: none !important;
}

/* ---------- Login ---------- */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.auth-card {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.auth-card h2 {
  font-size: 1.15rem;
  margin: 8px 0 4px;
}

.auth-card p {
  margin: 4px 0 18px;
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 10px 20px;
  background: var(--topbar);
  color: var(--topbar-ink);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.1rem;
}

.brand.big {
  font-size: 1.5rem;
  color: var(--primary);
  margin-bottom: 4px;
}

.logo {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: block;
}

.brand.big .logo {
  width: 64px;
  height: 64px;
  border-radius: 14px;
}

.clock {
  font-variant-numeric: tabular-nums;
  color: var(--topbar-muted);
  font-weight: 600;
}

/* separadores: a ativa fica com a palavra sublinhada a laranja */
.tabs {
  margin-left: auto;
  display: flex;
  gap: 2px;
  overflow-x: auto;
}

.tab {
  border: 0;
  background: transparent;
  color: var(--topbar-muted);
  white-space: nowrap;
  padding: 8px 12px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline 2px transparent;
  text-underline-offset: 6px;
  transition: color .15s ease, text-decoration-color .15s ease;
}

.tab:hover {
  color: var(--topbar-ink);
  text-decoration-color: var(--accent-soft);
}

.tab.active {
  color: var(--topbar-ink);
  text-decoration-color: var(--accent);
}

.topbar .btn.ghost {
  color: var(--topbar-ink);
}

.user-menu {
  position: relative;
}

.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 220px;
  z-index: 20;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(31, 60, 90, .15);
  padding: 6px;
}

.menu-head {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  font-size: .9rem;
}

.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.menu-item:hover {
  background: var(--surface-2);
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 16px 60px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.section-head {
  margin-bottom: 20px;
}

.section-head p {
  margin: 4px 0 0;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.row.wrap {
  flex-wrap: wrap;
}

.gap {
  gap: 8px;
  justify-content: flex-start;
  flex-wrap: wrap;
}

.center {
  justify-content: center;
}

.end {
  justify-content: flex-end;
}

.spacer {
  flex: 1;
}

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 10px;
  text-decoration: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover {
  filter: brightness(.97);
}

.btn:disabled {
  opacity: .5;
  cursor: default;
}

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-ink);
}

.btn.danger {
  color: var(--out);
  border-color: var(--out-line);
  background: var(--surface);
}

.btn.danger:hover {
  background: var(--out-soft);
}

.btn.ghost {
  border-color: transparent;
  background: transparent;
}

.btn.block {
  width: 100%;
}

.btn.small {
  padding: 5px 10px;
  font-size: .85rem;
}

.btn.in {
  background: var(--in-soft);
  border: 2px solid var(--in-line);
  color: var(--in);
}

.btn.out {
  background: var(--out-soft);
  border: 2px solid var(--out-line);
  color: var(--out);
}

.btn.brk {
  background: var(--warn-soft);
  border: 2px solid var(--warn-line);
  color: var(--warn);
}

.link {
  border: 0;
  background: none;
  color: var(--primary);
  font: inherit;
  cursor: pointer;
  padding: 0;
}

#sch-manage-codes.link {
  flex: 1;
  display: flex;
  justify-self: flex-end;
  justify-content: flex-end;
  align-items: center;
}

input,
select {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  min-width: 0;
}

input:focus-visible,
select:focus-visible,
.btn:focus-visible,
.emp-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
  font-weight: 600;
  font-size: .9rem;
}

.field input,
.field select {
  font-weight: 400;
}

.hint {
  font-weight: 400;
  font-size: .8rem;
  color: var(--muted);
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

/* Interruptor (substitui a checkbox nativa) */
.check input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex-shrink: 0;
  margin: 0;
  padding: 0;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background .2s ease, border-color .2s ease;
}

.check input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(31, 60, 90, .25);
  transition: transform .2s ease, background .2s ease;
}

.check input[type="checkbox"]:checked {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.check input[type="checkbox"]:checked::after {
  transform: translateX(16px);
  background: var(--accent);
}

.check:hover input[type="checkbox"]:not(:checked) {
  border-color: var(--muted);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 12px;
}

.form-grid .span2 {
  grid-column: span 2;
}

.secret {
  -webkit-text-security: disc;
}

.form-error {
  color: var(--out);
  font-size: .9rem;
  min-height: 1.2em;
  margin: 0 0 10px;
}

.search {
  width: 100%;
  max-width: 360px;
  margin-bottom: 16px;
}

.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------- Ponto grid ---------- */
.kiosk-summary {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
}

.emp-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  padding: 18px 12px 14px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: transform .1s ease, border-color .15s ease;
}

.emp-card:hover {
  transform: translateY(-2px);
}

.emp-card:active {
  transform: scale(.98);
}

.emp-card.is-work {
  border-color: var(--in-line);
  background: linear-gradient(var(--surface) 60%, var(--in-soft));
}

.emp-card.is-break {
  border-color: var(--warn-line);
  background: linear-gradient(var(--surface) 60%, var(--warn-soft));
}

.emp-card .name {
  font-weight: 700;
}

.emp-card .role {
  color: var(--muted);
  font-size: .85rem;
}

.emp-card .times {
  font-size: .8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* estado sempre no fundo do cartão, mesmo com nomes/categorias de alturas diferentes */
.emp-card .card-foot {
  margin-top: auto;
  padding-top: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.emp-card.archived {
  opacity: .55;
}

.emp-card .name .color-dot {
  margin-right: 6px;
}

/* aniversário: chapéu de festa por cima do avatar */
.avatar-wrap {
  position: relative;
  display: inline-block;
  flex-shrink: 0;
}

.avatar-wrap .avatar {
  margin: 0;
}

.avatar-wrap.lg {
  display: block;
  width: fit-content;
  margin: 34px auto 12px;
}

.party-hat {
  position: absolute;
  width: 58%;
  top: -40%;
  right: -12%;
  transform: rotate(24deg);
  pointer-events: none;
  filter: drop-shadow(0 2px 2px rgba(31, 60, 90, .2));
  animation: hat-wiggle 2.4s ease-in-out infinite;
}

@keyframes hat-wiggle {

  0%,
  100% {
    transform: rotate(24deg);
  }

  50% {
    transform: rotate(16deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .party-hat {
    animation: none;
  }
}

.badge.bday {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.emp-card .lock {
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: .8rem;
  opacity: .6;
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}

.badge.in {
  background: var(--in-soft);
  color: var(--in);
}

.badge.out {
  background: var(--out-soft);
  color: var(--out);
}

.badge.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge.off {
  background: var(--off-soft);
  color: var(--off);
}

.badge.blue {
  background: var(--primary-soft);
  color: var(--primary);
}

.avatar {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--primary-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.6rem;
  color: var(--primary);
  flex-shrink: 0;
}

.avatar.sm {
  width: 44px;
  height: 44px;
  font-size: 1rem;
}

.avatar.lg {
  width: 120px;
  height: 120px;
  font-size: 2.2rem;
  margin: 0 auto 12px;
}

.empty {
  padding: 40px;
  text-align: center;
  color: var(--muted);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
}

/* ---------- Funcionários list ---------- */
.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.list-item.archived {
  opacity: .55;
}

.list-item .info {
  flex: 1;
  min-width: 0;
}

.list-item .name {
  font-weight: 700;
}

.list-item .role {
  color: var(--muted);
  font-size: .9rem;
}

.list-item .meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-top: 16px;
  box-shadow: var(--shadow);
}

.card .row {
  margin-bottom: 8px;
  align-items: flex-start;
}

.card .row h3 {
  margin-bottom: 4px;
}

.card p.small {
  margin: 0 0 8px;
}

/* ---------- Dialogs ---------- */
.dialog {
  border: 0;
  border-radius: 18px;
  padding: 24px;
  width: min(440px, calc(100vw - 32px));
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(31, 60, 90, .25);
}

.dialog.wide {
  width: min(560px, calc(100vw - 32px));
}

.dialog::backdrop {
  background: rgba(31, 60, 90, .35);
}

.dialog h2 {
  margin-bottom: 16px;
}

.punch {
  text-align: center;
}

.punch img.avatar {
  width: 120px;
  height: 120px;
  margin: 0 auto 12px;
}

.punch .avatar-wrap .avatar {
  margin: 0;
}

.punch h2 {
  margin-bottom: 2px;
}

.punch .muted {
  margin: 0;
}

.punch-time {
  font-size: 2.6rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  margin: 14px 0 6px;
}

.punch-today {
  margin: 10px 0 14px;
  font-size: .9rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.pin-wrap input {
  width: 160px;
  text-align: center;
  font-size: 1.4rem;
  letter-spacing: .3em;
  margin-bottom: 8px;
}

.punch-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.punch-actions .btn {
  padding: 14px 22px;
  font-size: 1.05rem;
  min-width: 150px;
}

.photo-pick {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.photo-pick .avatar {
  width: 72px;
  height: 72px;
  font-size: 1.4rem;
}

/* ---------- Recorte da foto ---------- */
.crop-dialog {
  width: min(360px, calc(100vw - 32px));
}

.crop-stage {
  position: relative;
  width: 280px;
  height: 280px;
  margin: 0 auto;
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface-2);
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.crop-stage:active {
  cursor: grabbing;
}

.crop-stage canvas {
  display: block;
  width: 280px;
  height: 280px;
}

/* escurece fora do círculo, como o avatar final */
.crop-mask {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 50%;
  box-shadow: 0 0 0 200px rgba(253, 252, 221, .72);
  outline: 2px solid rgba(31, 60, 90, .35);
  outline-offset: -1px;
}

.crop-tools {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 14px 0 4px;
}

.crop-tools input[type="range"] {
  flex: 1;
  max-width: 170px;
  accent-color: var(--accent);
  padding: 0;
  border: 0;
  background: none;
}

.crop-tools .ghost {
  font-size: 1.3rem;
  padding: 2px 10px;
}

.crop-zoom-icon {
  font-weight: 700;
  color: var(--muted);
  width: 12px;
  text-align: center;
}

.center-text {
  text-align: center;
  display: block;
  margin: 0 0 14px;
}

/* ---------- Cores dos funcionários ---------- */
.color-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 7px;
  vertical-align: 1px;
  box-shadow: inset 0 0 0 1px rgba(31, 60, 90, .15);
}

.swatches {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  font-weight: 400;
}

.swatch {
  position: relative;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--border);
  transition: transform .1s ease;
}

.swatch:hover {
  transform: scale(1.08);
}

.swatch.selected {
  box-shadow: 0 0 0 2px var(--primary);
}

.swatch.custom {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: conic-gradient(#f6b98e, #f2d27a, #b5d6a7, #9fd3c7, #a9c7e3, #c9b6e4, #e8b4cf, #f6b98e);
}

.swatch.custom input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

/* cabeçalho de impressão (definições) */
textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-weight: 400;
}

.logo-preview {
  min-height: 48px;
  display: flex;
  align-items: center;
}

.logo-preview img {
  max-height: 64px;
  max-width: 280px;
  display: block;
}

.print-header {
  display: none;
}

@media print {
  body.print-sched {
    background: #fff;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  body.print-sched .topbar,
  body.print-sched .toast,
  body.print-sched dialog,
  body.print-sched #view-horarios>.section-head,
  body.print-sched .sch-toolbar,
  body.print-sched .fair-card,
  body.print-sched .drag-handle {
    display: none !important;
  }

  body.print-sched main {
    max-width: none;
    padding: 0;
  }

  body.print-sched .print-header {
    display: block;
    color: #000;
    font-family: "Times New Roman", Georgia, serif;
  }

  body.print-sched .ph-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10mm;
  }

  body.print-sched .ph-left p {
    margin: 1.2mm 0;
    font-size: 9.5pt;
  }

  body.print-sched .ph-logo {
    max-height: 16mm;
    max-width: 70mm;
    display: block;
    margin-bottom: 3mm;
  }

  body.print-sched .ph-box {
    border: 1.5px solid #000;
    padding: 3mm 5mm;
    text-align: center;
    font-size: 9.5pt;
    line-height: 1.35;
    max-width: 125mm;
    flex-shrink: 0;
  }

  body.print-sched .ph-title {
    font-size: 13pt;
    margin: 5mm 0 3mm;
    color: #000;
    font-family: system-ui, sans-serif;
  }

  body.print-sched .sch-card {
    box-shadow: none;
    border: 1px solid #999;
    border-radius: 0;
    margin: 0;
  }

  body.print-sched .table-wrap {
    overflow: visible;
  }

  body.print-sched table.sched {
    width: 100%;
    min-width: 0;
    font-size: 7.5pt;
  }

  body.print-sched table.sched .emp-col {
    position: static;
    min-width: 0;
    width: 34mm;
    padding: 1.5mm 2mm;
    font-size: 8pt;
    box-shadow: none;
  }

  /* coluna "Categoria" antes do nome (só na impressão) */
  body.print-sched table.sched .cat-col {
    display: table-cell;
    width: 24mm;
    padding: 1mm 1.5mm;
    text-align: left;
    font-size: 6pt;
    line-height: 1.2;
    font-weight: 600;
    color: var(--muted);
    background: var(--surface);
    white-space: normal;
  }

  body.print-sched table.sched thead .cat-col {
    background: var(--surface-2);
    font-size: 6pt;
    text-transform: uppercase;
  }

  body.print-sched table.sched th.day {
    min-width: 0;
    padding: 1mm 0;
    font-size: 7pt;
  }

  body.print-sched table.sched td.c {
    min-width: 0;
    height: 6.5mm;
    font-size: 7pt;
  }

  body.print-sched table.sched th,
  body.print-sched table.sched td {
    border-color: #bbb;
  }

  body.print-sched table.sched tr {
    break-inside: avoid;
  }

  /* no papel, os valores por omissão aparecem iguais aos restantes e não há destaque de "hoje" */
  body.print-sched table.sched td.c.filled.auto {
    background: var(--c);
    color: var(--text);
    font-weight: 800;
  }

  body.print-sched table.sched th.day.today {
    box-shadow: none;
  }

  body.print-sched .sch-legend {
    margin-top: 3mm;
    font-size: 7.5pt;
    gap: 1.5mm;
  }

  body.print-sched .legend-row {
    gap: 1mm 5mm;
  }

  body.print-sched .code-chip {
    min-width: 0;
    padding: 0 1.5mm;
  }
}

@media print {
  @page {
    size: A4 landscape;
    margin: 9mm;
  }
}

/* formulário de códigos de horário */
.periods {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 400;
}

.period-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.period-row input[type="time"] {
  width: 120px;
}

#code-shift-fields {
  margin-bottom: 4px;
}

/* ---------- Calendário de férias ---------- */
.month-nav {
  display: flex;
  align-items: center;
  gap: 6px;
}

.month-nav h1 {
  min-width: 200px;
  text-align: center;
}

.month-nav .ghost {
  font-size: 1.4rem;
  line-height: 1;
  padding: 4px 12px;
}

.cal-card {
  padding: 0;
  overflow: hidden;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.cal-head {
  padding: 10px 8px;
  text-align: center;
  font-size: .78rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.cal-day {
  min-height: 112px;
  padding: 6px 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  min-width: 0;
}

.cal-day:nth-child(7n) {
  border-right: 0;
}

.cal-day.weekend {
  background: color-mix(in srgb, var(--surface-2) 55%, var(--surface));
}

.cal-day.other {
  background: var(--bg);
}

.cal-day.other .cal-num {
  opacity: .4;
}

.cal-day.holiday {
  background: var(--accent-soft);
}

body:not(.role-geral) .cal-day {
  cursor: pointer;
}

body:not(.role-geral) .cal-day:hover {
  box-shadow: inset 0 0 0 2px var(--accent-soft);
}

.cal-num {
  font-size: .85rem;
  font-weight: 700;
  color: var(--muted);
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.cal-day.today .cal-num {
  background: var(--accent);
  color: #fff;
}

.cal-top {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  margin-bottom: 2px;
}

.cal-holiday {
  flex: 1;
  min-width: 0;
  font-size: .72rem;
  font-weight: 700;
  color: var(--accent-ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip-gap {
  height: 20px;
}

/* barras de férias: segmentos que se unem de um dia para o outro */
.chip {
  height: 20px;
  margin: 0 -7px;
  padding: 0 7px;
  background: var(--c);
  font-size: .74rem;
  font-weight: 700;
  color: var(--text);
  line-height: 20px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.chip-start {
  margin-left: 0;
  border-top-left-radius: 6px;
  border-bottom-left-radius: 6px;
}

.chip-end {
  margin-right: 0;
  border-top-right-radius: 6px;
  border-bottom-right-radius: 6px;
}

.chip span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  font-size: .88rem;
  font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.legend-item .muted {
  font-weight: 400;
  margin-left: 4px;
}

.legend-item.none {
  opacity: .6;
}

/* ---------- Horários mensais ---------- */
.sch-toolbar {
  position: sticky;
  top: 64px;
  z-index: 5;
}

.sch-toolbar p {
  margin: 10px 0 0;
}

.sch-brushes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.sch-brushes #sch-manage-codes {
  align-self: center;
  margin-left: 8px;
  font-weight: 600;
}

.brush {
  min-width: 46px;
  padding: 7px 10px;
  border-radius: 9px;
  font: inherit;
  font-weight: 800;
  font-size: .85rem;
  color: var(--text);
  background: var(--c);
  border: 2px solid transparent;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(31, 60, 90, .12);
}

.brush:hover {
  transform: translateY(-1px);
}

.brush.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.sch-card {
  padding: 0;
  overflow: hidden;
}

.sch-wrap {
  max-width: 100%;
}

table.sched {
  border-collapse: separate;
  border-spacing: 0;
  font-size: .8rem;
  width: auto;
  min-width: 100%;
}

table.sched th,
table.sched td {
  padding: 0;
  text-align: center;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

/* coluna "Categoria": escondida no ecrã, aparece só na impressão */
table.sched .cat-col {
  display: none;
}

table.sched .emp-col {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface);
  text-align: left;
  padding: 8px 12px;
  min-width: 170px;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: .88rem;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  font-weight: 700;
  box-shadow: 1px 0 0 var(--border);
}

table.sched thead th {
  background: var(--surface-2);
}

table.sched thead .emp-col {
  background: var(--surface-2);
  color: var(--muted);
  font-size: .75rem;
  text-transform: uppercase;
}

table.sched th.day {
  min-width: 36px;
  padding: 6px 2px;
  line-height: 1.15;
  font-size: .78rem;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
}

table.sched th.day span {
  display: block;
  font-size: .65rem;
  color: var(--muted);
  font-weight: 700;
}

table.sched td.c {
  height: 34px;
  min-width: 36px;
  font-weight: 800;
  color: var(--text);
  user-select: none;
  background: var(--surface);
}

body:not(.role-geral) table.sched.brush-on td.c {
  cursor: cell;
}

body:not(.role-geral) table.sched.brush-on td.c:hover {
  box-shadow: inset 0 0 0 2px var(--primary);
}

/* domingo bloqueado (sempre FO) */
body:not(.role-geral) table.sched.brush-on td.c.sun {
  cursor: not-allowed;
}

body:not(.role-geral) table.sched.brush-on td.c.sun:hover {
  box-shadow: none;
}

table.sched td.c.filled {
  background: var(--c);
}

/* valor por omissão (horário fixo / feriado): mais suave até ser alterado */
table.sched td.c.filled.auto {
  background: color-mix(in srgb, var(--c) 45%, var(--surface));
  color: var(--muted);
  font-weight: 700;
}

main:has(#view-horarios.active) {
  max-width: none;
}

table.sched .sat,
table.sched td.c.sat:not(.filled) {
  background: color-mix(in srgb, var(--accent-soft) 45%, var(--surface));
}

table.sched th.day.sat {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

table.sched .sun,
table.sched td.c.sun:not(.filled) {
  background: color-mix(in srgb, var(--surface-2) 70%, var(--surface));
}

table.sched th.day.holiday {
  background: var(--off-soft);
  color: var(--off);
}

table.sched td.c.holiday:not(.filled) {
  background: color-mix(in srgb, var(--off-soft) 50%, var(--surface));
}

table.sched th.day.today {
  box-shadow: inset 0 -3px 0 var(--accent);
}

table.sched .tot {
  padding: 6px 10px;
  font-weight: 700;
  color: var(--muted);
  background: var(--surface-2);
  font-variant-numeric: tabular-nums;
}

/* conta geral: ao passar o rato numa linha, os dias com horário de trabalho ficam na cor do funcionário
   (folgas, ausências e dias vazios mantêm a cor original) */
/* as restantes linhas ficam esbatidas (mais transparentes e um pouco cinzentas) */
body.role-geral table.sched tbody > tr > * {
  transition: opacity .15s ease, filter .15s ease;
}

body.role-geral table.sched tbody:has(tr[data-row]:hover) > tr:not(:hover) > * {
  opacity: .35;
  filter: grayscale(.7);
}

body.role-geral table.sched tbody tr[data-row]:hover td.c.shift,
body.role-geral table.sched tbody tr[data-row]:hover .emp-col {
  background: var(--emp);
  color: var(--text);
}

table.sched tr.coverage td {
  height: 28px;
  font-weight: 700;
  color: var(--muted);
}

/* reordenar linhas */
.drag-handle {
  display: inline-block;
  width: 16px;
  margin: 0 6px 0 -4px;
  color: var(--muted);
  cursor: grab;
  font-size: 1rem;
  line-height: 1;
  user-select: none;
  opacity: .55;
}

table.sched tr:hover .drag-handle {
  opacity: 1;
}

.drag-handle:active {
  cursor: grabbing;
}

table.sched tr.dragging th,
table.sched tr.dragging td {
  opacity: .45;
}

table.sched tr.drop-before>* {
  box-shadow: inset 0 3px 0 var(--accent);
}

table.sched tr.drop-after>* {
  box-shadow: inset 0 -3px 0 var(--accent);
}

table.sched tr.coverage .emp-col {
  color: var(--muted);
  font-weight: 600;
  font-size: .8rem;
}

.sch-legend {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
  font-size: .85rem;
}

.legend-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
}

.legend-code {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.code-chip {
  display: inline-block;
  min-width: 38px;
  padding: 3px 8px;
  border-radius: 7px;
  text-align: center;
  font-weight: 800;
  background: var(--c);
  box-shadow: inset 0 0 0 1px rgba(31, 60, 90, .12);
}

.fair-card {
  padding: 0;
}

.fair-card>summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.fair-card>summary::-webkit-details-marker {
  display: none;
}

.fair-card>summary::before {
  content: '▸';
  color: var(--accent);
  font-size: 1rem;
  transition: transform .15s ease;
}

.fair-card[open]>summary::before {
  transform: rotate(90deg);
}

.fair-card>summary:hover {
  color: var(--accent-ink);
}

.fair-card>p,
.fair-card>.table-wrap {
  margin: 0 18px 16px;
}

td.fair-low {
  background: var(--in-soft);
  color: var(--in);
  font-weight: 800;
}

td.fair-high {
  background: var(--out-soft);
  color: var(--out);
  font-weight: 800;
}

.fair-chip {
  padding: 1px 7px;
  border-radius: 6px;
  font-weight: 700;
}

.fair-chip.low {
  background: var(--in-soft);
  color: var(--in);
}

.fair-chip.high {
  background: var(--out-soft);
  color: var(--out);
}

td.zero {
  color: var(--muted);
  opacity: .5;
}

td.extra-pos {
  color: var(--accent-ink);
  font-weight: 800;
}

/* ---------- Relatórios ---------- */
.subtabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  overflow-x: auto;
}

.subtab {
  border: 0;
  background: none;
  font: inherit;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  padding: 10px 14px;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  margin-bottom: -1px;
}

.subtab.active {
  color: var(--primary);
  border-bottom-color: var(--accent);
}

.report {
  display: none;
}

.report.active {
  display: block;
}

.stats {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  margin-top: 16px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.stat .label {
  color: var(--muted);
  font-size: .85rem;
  font-weight: 600;
}

.stat .value {
  font-size: 1.6rem;
  font-weight: 800;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 16px;
}

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

.bar-row {
  display: grid;
  grid-template-columns: 130px 1fr 64px;
  align-items: center;
  gap: 10px;
  font-size: .9rem;
}

.bar-row .lbl {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.bar-track {
  position: relative;
  height: 14px;
  background: var(--track);
  border-radius: 999px;
}

.bar-fill {
  height: 100%;
  background: var(--chart);
  border-radius: 999px;
}

.bar-row .val {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.columns {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 200px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.col {
  flex: 1 0 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
  gap: 4px;
}

.col .col-bar {
  width: 100%;
  max-width: 40px;
  background: var(--chart);
  border-radius: 6px 6px 0 0;
  min-height: 2px;
}

.col .col-val {
  font-size: .7rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.col .col-lbl {
  font-size: .7rem;
  color: var(--muted);
  white-space: nowrap;
}

.col.weekend .col-lbl {
  opacity: .55;
}

.table-wrap {
  overflow-x: auto;
}

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

th,
td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .03em;
}

td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

td.wrap {
  white-space: normal;
  min-width: 200px;
}

tr.total td {
  font-weight: 700;
  border-top: 2px solid var(--border);
}

table.sheet td.num,
table.sheet th.num {
  min-width: 58px;
}

table.sheet td.zero {
  color: var(--muted);
  opacity: .5;
}

table.sheet td.offcell {
  color: var(--off);
  font-size: .8rem;
}

.who {
  display: flex;
  align-items: center;
  gap: 8px;
}

.who .avatar {
  width: 28px;
  height: 28px;
  font-size: .75rem;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(120px);
  background: var(--text);
  color: var(--bg);
  padding: 12px 20px;
  border-radius: 12px;
  font-weight: 600;
  transition: transform .25s ease;
  z-index: 100;
  max-width: calc(100vw - 32px);
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

.toast.error {
  background: var(--out-soft);
  color: var(--out);
  border: 1px solid var(--out-line);
}

@media (max-width: 860px) {
  .two-col {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 10px 16px;
  }

  .tabs {
    margin-left: 0;
    width: 100%;
    order: 3;
  }

  .user-menu {
    margin-left: auto;
  }

  .tab {
    padding: 8px 10px;
  }

  .grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }

  .bar-row {
    grid-template-columns: 90px 1fr 56px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-grid .span2 {
    grid-column: auto;
  }

  .month-nav h1 {
    min-width: 0;
    font-size: 1.2rem;
  }

  .cal-day {
    min-height: 76px;
    padding: 4px 3px 6px;
  }

  .cal-head {
    padding: 8px 2px;
    font-size: .7rem;
  }

  .chip,
  .chip-gap {
    height: 8px;
  }

  .chip {
    margin: 0 -3px;
    padding: 0;
    font-size: 0;
  }

  .cal-holiday {
    display: none;
  }

  .chip-start,
  .chip-end {
    border-radius: 4px;
  }

  .chip-start {
    margin-left: 0;
  }

  .chip-end {
    margin-right: 0;
  }

  .cal-holiday {
    font-size: .6rem;
  }
}