    :root {
      --ink: #111;
      --line: #222;
      --red: #c81515;
      --paper: #fff;
    }

    * {
      box-sizing: border-box
    }

    body {
      margin: 0;
      background: #f3f3f3;
      font-family: Tahoma, Arial, sans-serif;
      color: var(--ink)
    }

    .wrapper {
      max-width: 980px;
      margin: 0 auto;
      padding: 12px;
      display: grid;
      gap: 14px
    }

    .sheet {
      background: var(--paper);
      border: 1px solid #d0d0d0;
      border-radius: 10px;
      box-shadow: 0 1px 2px rgba(0, 0, 0, .05);
      padding: 18px 18px 32px;
      position: relative;
      width: 100%;
    }

    @media (min-width:900px) {

      /* aproximar proporção A4 na tela */
      .sheet {
        padding: 28px 34px 44px
      }
    }

    @media print {
      body {
        background: #fff
      }

      @page {
        size: A5 portrait;
        margin: 8mm;
      }

      .wrapper {
        max-width: none;
        padding: 0;
        gap: 0
      }

      .controls {
        display: none !important
      }

      .sheet {
        width: 148mm;
        height: 210mm;
        page-break-after: always;
        border: none;
        border-radius: 0;
        box-shadow: none;
        padding: 6mm 6mm 6mm;
      }

      /* imprimir somente o que está marcado para impressão */
      .print-hide {
        display: none !important;
      }

      /* Ajustes para caber no A5 */
      .month-name {
        font-size: 20px;
        letter-spacing: .8px;
      }

      .r {
        grid-template-columns: 64px 1fr;
        min-height: 16px;
      }

      .left {
        padding: 2px 6px;
        font-size: 11px;
        gap: 6px;
      }

      .dw {
        font-size: 10px;
      }

      .right {
        padding: 2px 8px;
        font-size: 10px;
        gap: 1px;
      }

      .evt {
        line-height: 1.1;
      }

      .page-no {
        font-size: 10px;
        bottom: 3mm;
      }
    }

    /* page numbers */
    .page-no {
      position: absolute;
      left: 0;
      right: 0;
      bottom: 10px;
      text-align: center;
      font-size: 12px;
    }

    /* ===== YEAR PAGE ===== */
    .year-title {
      text-align: center;
      font-weight: 700;
      font-size: 26px;
      margin: 6px 0 18px;
    }

    .year-grid {
      display: grid;
      grid-template-columns: repeat(3, minmax(0, 1fr));
      gap: 14px 16px;
    }

    @media (max-width:780px) {
      .year-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
      }
    }

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

    .mini {
      border: 1px solid #999;
      padding: 8px;
      border-radius: 4px
    }

    .mini-head {
      display: flex;
      justify-content: space-between;
      align-items: baseline;
      margin-bottom: 6px;
      font-weight: 700
    }

    .mini-name {
      text-transform: capitalize;
      font-size: 14px
    }

    .mini-year {
      font-size: 12px
    }

    .mini-dow {
      display: grid;
      grid-template-columns: repeat(7, 1fr);
      border: 1px solid #999;
      border-bottom: none
    }

    .mini-dow .d {
      font-size: 10px;
      padding: 3px 0;
      text-align: center;
      border-right: 1px solid #999;
      font-weight: 700;
      background: #fafafa
    }

    .mini-dow .d:last-child {
      border-right: none
    }

    .mini-dow .d.sun {
      color: var(--red)
    }

    .mini-grid {
      display: grid;
      grid-template-columns: repeat(7, 1fr);
      border: 1px solid #999;
      border-top: none
    }

    .mday {
      height: 22px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 11px;
      border-right: 1px solid #999;
      border-top: 1px solid #999
    }

    .mday:nth-child(7n) {
      border-right: none
    }

    .mday.empty {
      color: transparent
    }

    .mday.sun {
      color: var(--red);
      font-weight: 700
    }

    .mday.has-event {
      background: var(--red);
      color: #fff;
      font-weight: 800
    }

    .mday.has-event {
      cursor: pointer
    }

    /* tooltip dos dias com evento */
    .day-tip {
      position: fixed;
      z-index: 9000;
      max-width: min(300px, calc(100vw - 16px));
      padding: 8px 10px;
      border-radius: 8px;
      background: #1f2937;
      color: #fff;
      font-size: 12px;
      line-height: 1.35;
      text-align: left;
      box-shadow: 0 6px 18px rgba(0, 0, 0, .25);
      pointer-events: none
    }

    .day-tip[hidden] {
      display: none
    }

    .day-tip-date {
      font-weight: 800;
      margin-bottom: 4px;
      color: #cbd5e1
    }

    .day-tip-ev+.day-tip-ev {
      margin-top: 8px
    }

    .day-tip-ev b {
      font-weight: 800
    }

    .day-tip-hr {
      color: #cbd5e1;
      font-size: 11px
    }

    .day-tip-ev.red .day-tip-hr {
      color: #fecaca
    }

    .day-tip-ev.red {
      color: #fca5a5;
      font-weight: 700
    }

    @media print {
      .day-tip {
        display: none !important
      }
    }

    .year-holidays {
      margin-top: 14px;
      font-size: 11px;
      font-weight: 700
    }

    /* ===== MONTH PAGES ===== */
    .month-head {
      border-top: 2px solid var(--line);
      padding-top: 6px;
      margin-top: 2px;
    }

    .month-name {
      text-align: right;
      font-size: 26px;
      font-weight: 800;
      letter-spacing: 1px;
    }

    .table {
      margin-top: 10px;
      border-top: 1px solid var(--line);
      border-bottom: 1px solid var(--line);
    }

    .r {
      display: grid;
      grid-template-columns: 92px 1fr;
      border-top: 1px solid var(--line);
      min-height: 24px;
    }

    .r:first-child {
      border-top: none
    }

    .left {
      border-right: 1px solid var(--line);
      padding: 3px 8px;
      display: flex;
      align-items: center;
      gap: 8px;
      font-size: 13px;
    }

    .left.sun {
      color: var(--red);
      font-weight: 800
    }

    .dd {
      min-width: 26px;
      text-align: right;
      font-weight: 700
    }

    .bar {
      opacity: .9
    }

    .dw {
      font-size: 12px;
      font-weight: 700
    }

    .right {
      padding: 3px 10px;
      display: flex;
      flex-direction: column;
      gap: 2px;
      font-size: 12px;
    }

    .evt {
      line-height: 1.15;
      white-space: pre-wrap
    }

    .evt.red {
      color: var(--red);
      font-weight: 800
    }

    /* separadores entre múltiplos eventos no mesmo dia */
    .right .evt+.evt {
      border-top: 1px solid var(--line);
      margin-top: 2px;
      padding-top: 2px;
    }

    /* ===== NOTES ===== */
    .notes-title {
      text-align: center;
      font-weight: 800;
      font-size: 22px;
      margin: 8px 0 14px;
    }

    .notes-lines {
      border-top: 1px solid var(--line)
    }

    .nline {
      height: 24px;
      border-bottom: 1px solid var(--line)
    }

    /* ===== CONTROLES ===== */
    .controls {
      position: sticky;
      top: 10px;
      z-index: 50;
      background: #fff;
      border: 1px solid #d0d0d0;
      border-radius: 12px;
      padding: 10px 14px;
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
      gap: 6px;
      width: fit-content;
      margin: 10px auto 14px;
    }

    .ctrl-row {
      display: flex;
      justify-content: center;
      align-items: center;
      gap: 14px;
    }

    .ctrl-stamp {
      text-align: center;
      font-size: 12px;
      color: #666;
    }

    .controls label {
      font-weight: 800;
      color: #333
    }

    .controls select {
      min-width: 160px
    }

    .controls label {
      font-weight: 700
    }

    .controls select,
    .controls button {
      font: inherit;
      border: 1px solid #c8c8c8;
      border-radius: 10px;
      padding: 8px 10px;
      background: #fff;
    }

    .controls button {
      font-weight: 800
    }

    .ctrl-left {
      display: flex;
      align-items: center;
      gap: 10px
    }

    .hidden {
      display: none !important
    }



    /* === PAGE MODEL: cada .sheet = 1 página A5 (frente/verso alinhado) === */
    .sheet {
      margin: 0 auto 18px auto;
    }

    @media print {
      .sheet {
        page-break-after: always;
        break-after: page;
      }

      .sheet:last-child {
        page-break-after: auto;
        break-after: auto;
      }
    }

    /* Controles nunca entram na impressão */
    @media print {

      .controls,
      .controles,
      .toolbar {
        display: none !important;
      }
    }


    /* === NOTES SHEETS (linhas para anotações) === */
    .notes-inner {
      padding: 14mm 10mm 12mm;
    }

    .cover-title {
      font-family: Tahoma, Arial, sans-serif;
      font-weight: 800;
      letter-spacing: .5px;
      text-align: center;
      margin-bottom: 6mm;
      font-size: 18px;
    }

    .notes-lines .line {
      height: 0;
      border-top: 1px solid #111;
      margin: 0 0 7.2mm 0;
      /* espaçamento das linhas (ajustado para caber em A5) */
    }

    /* === DUPLEX: garantir páginas em A5 e quebras exatas === */
    @media print {
      @page {
        size: A5;
        margin: 8mm;
      }

      .sheet {
        page-break-after: always;
        break-after: page;
      }

      .sheet:last-child {
        page-break-after: auto;
        break-after: auto;
      }

      /* sem sombras/fundos */
      body {
        background: #fff !important;
      }

      .sheet {
        box-shadow: none !important;
      }
    }

    /* ===== Controls (tela) ===== */
    .controls {
      display: flex;
      gap: 10px;
      align-items: center;
      justify-content: space-between;
      background: #fff;
      border: 1px solid #d0d0d0;
      border-radius: 10px;
      box-shadow: 0 1px 2px rgba(0, 0, 0, .05);
      padding: 10px 12px;
    }

    .ctrl-left {
      display: flex;
      align-items: center;
      gap: 8px;
      flex-wrap: wrap
    }

    .ctrl-right {
      display: flex;
      align-items: center;
      gap: 8px;
      flex-wrap: wrap
    }

    .controls label {
      font-size: 14px
    }

    .controls select {
      font-size: 14px;
      padding: 6px 8px;
      border: 1px solid #cfcfcf;
      border-radius: 8px;
      background: #fff;
    }

    .controls button {
      font-size: 14px;
      padding: 9px 10px;
      border-radius: 10px;
      border: 1px solid #bdbdbd;
      background: #fff;
      cursor: pointer;
    }

    .controls button:hover {
      filter: brightness(0.98)
    }

    .btn-secondary {
      background: #f6f6f6
    }

    .ml {
      margin-left: 6px
    }

    /* ===== Admin modal ===== */
    .modal-backdrop {
      position: fixed;
      inset: 0;
      background: rgba(0, 0, 0, .45);
      display: none;
      align-items: center;
      justify-content: center;
      padding: 14px;
      z-index: 50;
    }

    .modal {
      width: min(980px, 100%);
      background: #fff;
      border-radius: 14px;
      box-shadow: 0 12px 30px rgba(0, 0, 0, .25);
      border: 1px solid rgba(0, 0, 0, .08);
      overflow: hidden;
    }

    .modal-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 12px 14px;
      border-bottom: 1px solid #e5e5e5;
    }

    .modal-header h3 {
      margin: 0;
      font-size: 16px
    }

    .modal-body {
      padding: 12px 14px;
      display: grid;
      gap: 12px
    }

    .admin-grid {
      display: grid;
      gap: 10px
    }

    @media (min-width:820px) {
      .admin-grid {
        grid-template-columns: 360px 1fr;
        align-items: start
      }
    }

    .form {
      border: 1px solid #e5e5e5;
      border-radius: 12px;
      padding: 10px;
      display: grid;
      gap: 8px;
    }

    .form label {
      font-size: 13px
    }

    .form input,
    .form select,
    .form textarea {
      width: 100%;
      font-size: 14px;
      padding: 8px 10px;
      border: 1px solid #cfcfcf;
      border-radius: 10px;
    }

    .form textarea {
      min-height: 90px;
      resize: vertical
    }

    .form .row {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 8px
    }

    .form .actions {
      display: flex;
      gap: 8px;
      flex-wrap: wrap;
      margin-top: 2px
    }

    .form .actions button {
      flex: 1;
      min-width: 110px;
      padding: 9px 10px;
    }

    .list {
      border: 1px solid #e5e5e5;
      border-radius: 12px;
      overflow: hidden;
    }

    .list-head {
      padding: 10px;
      border-bottom: 1px solid #e5e5e5;
      display: flex;
      gap: 8px;
      align-items: center;
      justify-content: space-between;
      flex-wrap: wrap;
    }

    .list-head .hint {
      font-size: 12px;
      color: #444
    }

    .search-box {
      flex: 1;
      min-width: 200px;
      position: relative;
    }

    .search-box input {
      width: 100%;
      padding: 8px 12px;
      border: 1px solid #cfcfcf;
      border-radius: 8px;
      font-size: 14px;
    }

    .search-box input:focus {
      outline: none;
      border-color: #255ec8;
    }

    .list-items {
      max-height: 60vh;
      overflow: auto
    }

    .item {
      padding: 10px;
      border-bottom: 1px solid #f0f0f0;
      display: flex;
      gap: 10px;
      align-items: flex-start;
      justify-content: space-between;
    }

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

    .item .meta {
      font-size: 12px;
      color: #333;
      line-height: 1.25
    }

    .item .title {
      font-size: 14px;
      font-weight: 700
    }

    .item .badges {
      display: flex;
      gap: 6px;
      flex-wrap: wrap;
      margin-top: 4px
    }

    .badge {
      font-size: 11px;
      padding: 2px 8px;
      border-radius: 999px;
      border: 1px solid #ddd;
      background: #fafafa;
    }

    .badge.red {
      border-color: rgba(200, 21, 21, .4);
      color: var(--red);
      font-weight: 700
    }

    .item .btns {
      display: flex;
      gap: 8px
    }

    .item .btns button {
      padding: 6px 10px;
      border-radius: 10px
    }

    .muted {
      color: #666;
      font-size: 12px
    }

    .err {
      color: var(--red);
      font-weight: 700;
      font-size: 13px
    }

    .ok {
      color: #0a6;
      font-weight: 700;
      font-size: 13px
    }

    /* ===== Admin polish ===== */
    .modal-backdrop {
      background: rgba(10, 14, 23, .48);
      backdrop-filter: blur(3px);
    }

    .modal {
      border-radius: 18px;
      border: 1px solid rgba(17, 17, 17, .08);
      box-shadow: 0 20px 50px rgba(0, 0, 0, .25);
    }

    .modal-header {
      padding: 14px 16px;
      background: linear-gradient(180deg, #ffffff 0%, #fafafa 100%);
    }

    .modal-header h3 {
      font-size: 20px;
      font-weight: 800
    }

    .modal-body {
      padding: 14px 16px;
      background: #fcfcfd
    }

    .form,
    .list {
      border: 1px solid #e7e8eb;
      border-radius: 14px;
      background: #fff;
    }

    .form {
      box-shadow: 0 8px 22px rgba(0, 0, 0, .04);
    }

    .form input,
    .form select,
    .form textarea {
      border: 1px solid #d6d9df;
      border-radius: 12px;
      background: #fff;
    }

    .form input:focus,
    .form select:focus,
    .form textarea:focus {
      outline: none;
      border-color: #3c7ff0;
      box-shadow: 0 0 0 3px rgba(60, 127, 240, .15);
    }

    .form .actions button,
    .item .btns button,
    #btnSair,
    #btnRecarregar,
    #adminCloseBtn {
      border: 1px solid #d2d8e4;
      border-radius: 12px;
    }

    #btnSalvar {
      background: linear-gradient(180deg, #2f71e8 0%, #255ec8 100%);
      border-color: #255ec8;
      color: #fff;
      font-weight: 800;
    }

    #btnSalvar:hover {
      filter: brightness(1.03)
    }

    #btnExcluir {
      background: linear-gradient(180deg, #f05a5a 0%, #d73f3f 100%);
      border-color: #cb3535;
      color: #fff;
      font-weight: 800;
    }

    .item {
      border-bottom: 1px solid #eef0f4;
    }

    .item:hover {
      background: #f9fbff;
    }

    .swal2-popup {
      border-radius: 16px !important;
    }

    .swal2-confirm {
      border-radius: 10px !important;
      background: #255ec8 !important;
    }

    .swal2-cancel {
      border-radius: 10px !important;
    }

    /* ===== Mobile fit ===== */
    @media (max-width:640px) {
      body {
        overflow-x: hidden
      }

      .wrapper {
        max-width: 100%;
        padding: 8px;
        gap: 10px;
      }

      .sheet {
        width: 100%;
        max-width: 100%;
        margin: 0 auto 10px;
        padding: 12px 10px 24px;
        overflow-x: hidden;
      }

      .controls {
        position: static;
        width: 100%;
        margin: 6px 0 10px;
        padding: 10px;
        display: grid;
        grid-template-columns: 1fr;
        gap: 8px;
      }

      .ctrl-row {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr;
        gap: 8px;
      }

      .ctrl-left,
      .ctrl-right {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr;
        gap: 8px;
      }

      .controls select,
      .controls button {
        width: 100%;
        min-width: 0;
      }

      .year-grid {
        grid-template-columns: 1fr
      }

      .month-name {
        font-size: 22px
      }

      .r {
        grid-template-columns: 70px 1fr;
        min-height: 20px
      }

      .left {
        padding: 2px 6px;
        font-size: 11px;
        gap: 6px
      }

      .dw {
        font-size: 10px
      }

      .right {
        padding: 2px 6px;
        font-size: 10px
      }

      .right {
        padding: 2px 6px;
        font-size: 10px
      }

      /* Correção Modal Mobile */
      .form .row {
        grid-template-columns: 1fr;
        gap: 0
      }

      /* Ajuste crítico de scroll do modal */
      .modal {
        display: flex;
        flex-direction: column;
        max-height: 90vh;
        /* Limita altura */
        margin: 10px;
        /* Margem de respiro */
      }

      .modal-body {
        overflow-y: auto;
        /* Permite scroll no conteúdo (form + lista) */
        flex: 1;
        /* Ocupa espaço restante */
        display: block;
        /* Remove grid para evitar comportamento estranho */
      }

      .admin-grid {
        display: flex;
        flex-direction: column;
        gap: 12px;
      }

      /* Remove scroll interno da lista em mobile para unificar scroll no corpo */
      .list-items {
        max-height: none !important;
        overflow: visible !important;
      }
    }

    /* Botão Voltar ao Topo */
    #scrollTopBtn {
      position: fixed;
      bottom: 20px;
      right: 20px;
      z-index: 99;
      border: none;
      outline: none;
      /* Gradiente do tema (igual ao btnSalvar) */
      background: linear-gradient(180deg, #2f71e8 0%, #255ec8 100%);
      color: white;
      cursor: pointer;
      padding: 0;
      border-radius: 50%;
      box-shadow: 0 4px 12px rgba(37, 94, 200, 0.4);
      display: none;
      opacity: 0.9;
      transition: opacity 0.3s, transform 0.2s, filter 0.2s;
      width: 48px;
      height: 48px;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    #scrollTopBtn:hover {
      filter: brightness(1.1);
      transform: translateY(-2px);
      opacity: 1;
    }

    #scrollTopBtn svg {
      width: 24px;
      height: 24px;
      fill: #fff;
      stroke: #fff;
      stroke-width: 2px;
    }

    /* Ocultar inicialmente */
    .hidden-scroll {
      display: none !important;
    }

    /* convite de instalação (PWA) */
    .install-overlay{position:fixed;inset:0;z-index:10000;display:grid;place-items:center;padding:22px;background:rgba(15,23,42,.72);backdrop-filter:blur(5px)}
    .install-card{width:min(100%,390px);box-sizing:border-box;padding:28px 24px 22px;border-radius:24px;background:#fff;color:#183153;box-shadow:0 24px 70px rgba(0,0,0,.3);text-align:center;font-family:"Segoe UI",Tahoma,Geneva,Verdana,sans-serif}
    .install-icon{display:grid;place-items:center;width:76px;height:76px;margin:auto;border:1px solid #e2e8f0;border-radius:18px;background:#fff;box-shadow:0 5px 16px rgba(26,58,92,.16)}.install-icon svg{width:68px;height:68px}.install-eyebrow{margin:14px 0 5px;color:#1a3a5c;font-size:11px;font-weight:800;letter-spacing:.12em}.install-card h2{margin:0;font-size:24px;line-height:1.2}.install-description{margin:10px auto 16px;color:#64748b;line-height:1.45}.install-instructions{padding:13px;border-radius:13px;background:#eef4fb;color:#334155;font-size:14px;line-height:1.45}.install-actions{display:grid;gap:9px;margin-top:18px}.install-actions button{min-height:46px;border:0;border-radius:12px;font:inherit;font-weight:750;cursor:pointer}.install-primary{background:#1a3a5c;color:#fff}.install-secondary{background:transparent;color:#64748b}
    .install-icon{color:#075280;font-family:Georgia,serif;font-size:26px;font-weight:700}

    /* homologação (agenda-hml.): identidade amarela, para não confundir com a produção */
    [data-ambiente="hml"] body {
      background: linear-gradient(135deg, #f5c518 0%, #e0b00f 100%) fixed;
    }

    @media print {
      [data-ambiente="hml"] body {
        background: #fff;
      }
    }
