:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1c2434;
  --muted: #6b7280;
  --line: #dfe3ec;
  --accent: #2f5bd7;
  --accent-soft: #e8eefc;
  --danger: #c0392b;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
}

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px 24px; background: #fff;
  border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 26px; }
.brand-text h1 { margin: 0; font-size: 18px; }
.brand-text p { margin: 0; font-size: 12.5px; color: var(--muted); }

.tabs { display: flex; gap: 4px; background: #eef1f7; padding: 4px; border-radius: 10px; }
.tabs button {
  border: 0; background: transparent; padding: 8px 18px;
  border-radius: 8px; font: inherit; font-weight: 600;
  color: var(--muted); cursor: pointer;
}
.tabs button:hover { color: var(--ink); }
.tabs button.active { background: #fff; color: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

main { padding: 22px 24px 60px; max-width: 1180px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }
.lead { color: var(--muted); margin-top: 0; }

.toolbar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar-right { margin-left: auto; display: flex; gap: 10px; }
.field { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; }
.field input[type="month"] { font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }

.btn {
  font: inherit; font-weight: 600; padding: 9px 16px;
  border-radius: 9px; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; cursor: pointer;
}
.btn:hover { filter: brightness(1.07); }
.btn.ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: #f7f9fd; }
.btn.small { padding: 6px 12px; font-size: 13.5px; }
.btn.tiny { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn.danger { background: #fff; color: var(--danger); border-color: #f0c9c4; }
.btn.danger:hover { background: #fdf1ef; }
.icon-btn { border: 0; background: transparent; font-size: 18px; cursor: pointer; color: var(--muted); padding: 4px 8px; }

.sections { display: grid; gap: 18px; }
.section-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.section-card > header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--line); background: #fbfcff;
}
.section-card h2 { margin: 0; font-size: 15.5px; }
.section-card h2 .badge {
  font-size: 11.5px; font-weight: 700; color: var(--accent);
  background: var(--accent-soft); border-radius: 999px; padding: 3px 9px; margin-left: 8px;
}

.row-item {
  display: grid; grid-template-columns: 140px 1fr 1fr 150px;
  gap: 12px; align-items: center; padding: 11px 16px; border-top: 1px solid #eef1f6;
}
.row-item:first-of-type { border-top: 0; }
.row-item:hover { background: #fafbff; }
.row-date { font-weight: 700; }
.row-date small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-block; padding: 3px 10px; border-radius: 999px; background: #eef2fa; color: #2a3550; font-size: 13px; }
.chip.kids { background: #fdf1e3; color: #7a4b12; }
.chip.empty { background: transparent; color: #a6adbb; font-style: italic; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.people-grid, .config-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card h2 { margin: 0 0 14px; font-size: 16px; }

.cfg-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 8px 0; border-top: 1px solid #eef1f6; font-size: 14px;
}
.cfg-row:first-of-type { border-top: 0; }
.cfg-row input[type="number"] { width: 92px; font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; text-align: right; }
.cfg-row input[type="color"] { width: 54px; height: 32px; border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 2px; cursor: pointer; }

.add-form { display: flex; gap: 8px; margin-bottom: 14px; }
.add-form input, .quick-add input { flex: 1; font: inherit; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; }
.people-list { list-style: none; margin: 0; padding: 0; }
.people-list li { display: flex; align-items: center; justify-content: space-between; padding: 8px 4px; border-top: 1px solid #eef1f6; }

.notes-editor { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 16px; margin-bottom: 18px; }
.notes-editor summary { cursor: pointer; font-weight: 600; }
.notes-editor textarea { width: 100%; margin-top: 10px; font: inherit; padding: 10px; border: 1px solid var(--line); border-radius: 8px; }

.sheet-wrap { overflow-x: auto; padding-bottom: 20px; }
.sheet {
  width: 210mm; min-height: 297mm; margin: 0 auto;
  padding: 10mm; background: #fff; border: 1px solid var(--line); box-shadow: var(--shadow);
  color: var(--text-color, #000);
}
.sheet .doc-title {
  text-align: center; font-size: var(--title-font, 15pt); font-weight: 700;
  color: var(--title-color, #0070c0); margin: 0 0 10px;
}
.sheet table { width: 100%; border-collapse: collapse; table-layout: fixed; margin-bottom: 3mm; }
.sheet th, .sheet td {
  border: 1px solid #000; padding: var(--row-pad, 4px) 6px;
  font-size: var(--sheet-font, 9.5pt); font-weight: 700; vertical-align: middle;
}
.sheet th {
  background: var(--header-bg, #d9d9d9);
  color: var(--header-text-color, #000000);
  text-align: center;
}
.sheet td { color: var(--text-color, #000000); }
.sheet td.col-data { color: var(--color-data, #000000); }
.sheet td.col-dia { color: var(--color-dia, #000000); }
.sheet td.col-recep { color: var(--color-recep, #000000); text-align: left; }
.sheet td.col-kids { color: var(--color-kids, #000000); text-align: center; }
.sheet td.center { text-align: center; white-space: nowrap; }
.sheet .section-title { background: var(--header-bg, #d9d9d9); font-weight: 700; text-align: center; }
.sheet .section-title.ceia { color: #ff0000; }
.sheet .notes { margin-top: 4mm; font-size: var(--notes-font, 9pt); line-height: 1.6; }
.sheet .notes p { margin: 0; }
.sheet .notes .note-line { text-transform: uppercase; font-weight: 700; color: var(--notes-color, #e00000); }

.modal {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.modal.hidden { display: none; }
.modal-box { background: #fff; border-radius: 16px; width: min(760px, 100%); max-height: 85vh; display: flex; flex-direction: column; overflow: hidden; }
.modal-head { display: flex; justify-content: space-between; padding: 16px 20px 12px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-head p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.modal-body { padding: 16px 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 20px; overflow-y: auto; flex: 1; }
.pick-col h3 { margin: 0 0 10px; font-size: 14px; }
.pick-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px;
  border-radius: 999px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 13.5px;
}
.pick-chip input { display: none; }
.pick-chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.quick-add { display: flex; gap: 8px; margin-top: 8px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 20px; border-top: 1px solid var(--line); background: #fbfcff; flex-wrap: wrap; }

.share-box { width: min(620px, 100%); }
.share-body { display: grid; grid-template-columns: 1fr; gap: 14px; padding: 16px 20px; overflow-y: auto; }
.share-body img {
  width: 100%; max-height: 46vh; object-fit: contain; object-position: top;
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
}
.share-steps { margin: 0; padding-left: 20px; font-size: 13.5px; color: #475569; }
.share-steps li { margin-bottom: 4px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: #1c2434; color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; z-index: 80;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.hint { color: var(--muted); font-size: 12.5px; margin: 0 0 18px; }

.color-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; margin-bottom: 14px; font-size: 13.5px; color: var(--muted);
}
.color-bar input[type="color"] { width: 46px; height: 30px; border: 1px solid var(--line); border-radius: 7px; background: #fff; padding: 2px; cursor: pointer; }
.color-bar #colorBarLabel { flex: 1; min-width: 180px; }
#report [data-ckey] { cursor: pointer; }
#report [data-ckey]:hover { background: rgba(47, 91, 215, .07); }
#report .color-target { outline: 2px dashed var(--accent); outline-offset: 1px; }

@media print {
  body { background: #fff; }
  .topbar, .no-print { display: none !important; }
  main { padding: 0; max-width: none; }
  .view { display: none !important; }
  #view-relatorio { display: block !important; }
  .sheet { width: 100% !important; border: 0; box-shadow: none; padding: 0; }
  .sheet table { page-break-inside: avoid; }
  .sheet tr { page-break-inside: avoid; }
}

@media (max-width: 760px) {
  main { padding: 12px 10px 60px; }
  .topbar { padding: 10px 12px; flex-direction: column; align-items: stretch; gap: 10px; }
  .tabs { overflow-x: auto; }
  .tabs button { padding: 7px 12px; font-size: 13px; white-space: nowrap; }
  .row-item { grid-template-columns: 1fr; gap: 6px; }
  .row-actions { justify-content: flex-start; }
  .people-grid, .config-grid, .modal-body { grid-template-columns: 1fr; }
  .sheet-wrap { margin: 0 -10px; padding: 0 10px 16px; }
  .sheet { width: 210mm !important; padding: 10mm !important; }
}
