:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-2: #f0efea;
  --line: #e3e1da;
  --text: #1f2a2a;
  --muted: #68736f;
  --primary: #1f6f6b;
  --primary-ink: #ffffff;
  --primary-soft: #dcefec;
  --danger: #b3372f;
  --danger-soft: #fbe6e3;
  --ok: #2c7a4b;
  --ok-soft: #dff1e5;
  --warn: #99610a;
  --warn-soft: #fbedcf;
  --info: #2b5f93;
  --info-soft: #dfeaf6;
  --note: #6d4fa3;
  --note-soft: #ebe4f6;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(0 0 0 / 5%), 0 4px 16px rgb(0 0 0 / 4%);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131817;
    --surface: #1b2221;
    --surface-2: #232c2a;
    --line: #2f3a38;
    --text: #e6ecea;
    --muted: #97a39f;
    --primary: #58b7b0;
    --primary-ink: #0d1f1e;
    --primary-soft: #1d3a38;
    --danger: #ef8a80;
    --danger-soft: #40211e;
    --ok: #7fcf9d;
    --ok-soft: #1c3526;
    --warn: #e6b65a;
    --warn-soft: #3b2e12;
    --info: #8ab8e6;
    --info-soft: #1b2e42;
    --note: #b9a2e6;
    --note-soft: #2c2440;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
h1, h2, p { margin: 0; }
h1 { font-size: 1.35rem; line-height: 1.2; }
h2 { font-size: 1rem; }
a { color: var(--primary); }
h1 a { color: inherit; text-decoration: none; }
h1 a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.boot { padding: 40px; text-align: center; color: var(--muted); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- Estrutura ---------- */
.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); height: 100dvh; }
.side { display: flex; flex-direction: column; gap: 20px; padding: 20px 14px; background: var(--surface); border-right: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; padding: 0 6px; }
.brand-mark { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--primary); color: var(--primary-ink); font-size: 1.2rem; font-weight: 700; }
.side-nav { display: flex; flex-direction: column; gap: 4px; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; color: var(--muted); text-decoration: none; font-weight: 600; }
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.nav-on { background: var(--primary-soft); color: var(--primary); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 0 6px; }
.side-foot small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.content { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.main { flex: 1; min-height: 0; overflow: auto; }
.banner { padding: 8px 16px; background: var(--warn-soft); color: var(--warn); font-size: .88rem; text-align: center; }
.tabbar { display: none; }
.view { max-width: 980px; margin: 0 auto; padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.view-full { max-width: none; height: 100%; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back { color: var(--muted); text-decoration: none; font-size: .9rem; align-self: flex-start; }
.back:hover { color: var(--text); }
.toolbar { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.search { flex: 1; min-width: 200px; }

/* ---------- Controles ---------- */
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=tel], input[type=email], input[type=date], input[type=time], input[type=number],
input[type=password], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); min-height: 40px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--primary); flex: none; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 7px 14px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary); filter: brightness(1.08); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); filter: brightness(1.08); }
.btn-danger-ghost { color: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); justify-content: flex-start; padding-left: 6px; }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border: 1px solid transparent; border-radius: 9px; background: transparent; cursor: pointer; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.link { border: 0; background: none; padding: 4px; color: var(--primary); cursor: pointer; text-decoration: underline; }

.form { display: flex; flex-direction: column; gap: 14px; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-label { font-size: .85rem; font-weight: 600; color: var(--muted); }
.field-hint { font-size: .8rem; color: var(--muted); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }

.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { padding: 6px 13px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; font-size: .88rem; color: var(--muted); }
.pill:hover { background: var(--surface-2); }
.pill-on, .pill-on:hover { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }

.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .76rem; font-weight: 700; white-space: nowrap; vertical-align: middle; background: var(--surface-2); color: var(--muted); }
.chip-agendada { background: var(--info-soft); color: var(--info); }
.chip-realizada, .chip-pago { background: var(--ok-soft); color: var(--ok); }
.chip-faltou, .chip-parcial { background: var(--warn-soft); color: var(--warn); }
.chip-pendente { background: var(--danger-soft); color: var(--danger); }
.chip-forma { background: var(--primary-soft); color: var(--primary); }

/* ---------- Cartões e listas ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.card.list { padding: 6px; gap: 0; }
.list { display: flex; flex-direction: column; }
.card > .list { margin: 0 -8px; }
.list-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 9px; text-decoration: none; color: inherit; border: 0; background: none; text-align: left; width: 100%; flex-wrap: wrap; }
a.list-row, button.list-row { cursor: pointer; }
a.list-row:hover, button.list-row:hover { background: var(--surface-2); }
.list-row + .list-row { box-shadow: 0 -1px 0 var(--line); }
.list-main { flex: 1; min-width: 160px; display: flex; flex-direction: column; gap: 1px; color: inherit; text-decoration: none; }
.list-main small { color: var(--muted); }
.avatar { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-weight: 700; flex: none; }
.amount { font-variant-numeric: tabular-nums; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); display: flex; flex-direction: column; gap: 12px; align-items: center; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow); }
.stat span, .stat small { color: var(--muted); font-size: .84rem; }
.stat strong { font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.stat-warn strong { color: var(--danger); }
.stat-main strong { color: var(--ok); }

.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px 20px; margin: 0; }
.info dt { font-size: .8rem; color: var(--muted); font-weight: 600; }
.info dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }

.formas { display: flex; flex-direction: column; gap: 10px; }
.forma-row { display: grid; grid-template-columns: 110px 1fr auto; gap: 12px; align-items: center; }
.forma-row strong { font-variant-numeric: tabular-nums; min-width: 96px; text-align: right; }
.forma-bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.forma-bar span { display: block; height: 100%; background: var(--primary); border-radius: 4px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tab { padding: 9px 14px; border: 0; background: none; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab-on { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- Agenda ---------- */
.cal-nav { display: flex; align-items: center; gap: 6px; }
.cal-title { margin-left: 8px; font-size: 1.15rem; }
.cal-title::first-letter { text-transform: uppercase; }
.cal { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.cal-head, .cal-body { display: grid; }
.cal-head { border-bottom: 1px solid var(--line); scrollbar-gutter: stable; overflow: hidden; }
.cal-dayhead { padding: 8px 4px; text-align: center; display: flex; flex-direction: column; color: var(--muted); font-size: .8rem; text-transform: uppercase; border-left: 1px solid var(--line); }
.cal-dayhead strong { font-size: 1.1rem; color: var(--text); }
.cal-dayhead.is-today strong { color: var(--primary); }
.cal-scroll { flex: 1; min-height: 0; overflow-y: auto; scrollbar-gutter: stable; }
.cal-time { font-size: .74rem; color: var(--muted); text-align: right; padding: 2px 6px 0 0; }
.cal-time-sub { font-size: .66rem; opacity: .7; }
.cal-col { position: relative; border-left: 1px solid var(--line); cursor: cell;
  /* linha forte a cada hora e linha fraca a cada intervalo; os tamanhos vêm do JS */
  background-image: linear-gradient(to bottom, var(--line) 1px, transparent 1px), linear-gradient(to bottom, color-mix(in srgb, var(--line) 45%, transparent) 1px, transparent 1px); }
.zoom { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
.zoom .icon-btn:disabled { opacity: .35; cursor: default; }
.zoom-label { min-width: 52px; text-align: center; font-weight: 600; font-size: .88rem; font-variant-numeric: tabular-nums; }
.cal-tip { margin-left: auto; }
.cal-col.is-today { background-color: color-mix(in srgb, var(--primary-soft) 35%, transparent); }
.cal-now { position: absolute; left: 0; right: 0; height: 2px; background: var(--danger); pointer-events: none; z-index: 2; }
.ev { position: absolute; display: flex; flex-direction: column; padding: 3px 7px; border-radius: 7px; overflow: hidden; text-decoration: none; text-align: left; font: inherit; font-size: .8rem; line-height: 1.25; border: 0; border-left: 3px solid var(--info); background: var(--info-soft); color: var(--text); cursor: pointer; }
.ev { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.ev-compromisso { border-left-color: var(--note); background: var(--note-soft); }
/* Item "pego" para arrastar: treme uma vez e fica destacado até ser solto. */
.ev.ev-grab { z-index: 10; cursor: grabbing; outline: 2px solid var(--primary); box-shadow: 0 10px 26px rgb(0 0 0 / 28%); filter: none; animation: ev-shake .32s ease; }
@keyframes ev-shake {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-2.5deg); }
  40% { transform: rotate(2.5deg); }
  60% { transform: rotate(-1.5deg); }
  80% { transform: rotate(1.5deg); }
}
@media (prefers-reduced-motion: reduce) { .ev.ev-grab { animation: none; } }
.ev-swatch { width: 12px; height: 9px; border-radius: 3px; border-left: 3px solid var(--note); margin-left: 10px; flex: none; }
.ev:hover { filter: brightness(.97); z-index: 3; }
.ev-time { font-size: .72rem; color: var(--muted); white-space: nowrap; overflow: hidden; padding-right: 10px; }
.ev-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-realizada { border-color: var(--ok); background: var(--ok-soft); }
.ev-faltou { border-color: var(--warn); background: var(--warn-soft); }
.ev-cancelada { border-color: var(--muted); background: var(--surface-2); opacity: .7; }
.ev-cancelada .ev-name { text-decoration: line-through; }
.ev-pay { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.ev .ev-pay { position: absolute; top: 5px; right: 5px; }
.ev-paid { background: var(--ok); }
.ev-owes { background: var(--danger); }
.cal-legend { display: flex; align-items: center; gap: 6px; font-size: .8rem; }
.cal-legend .ev-pay:not(:first-child) { margin-left: 10px; }
.day-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.day-pick { display: flex; flex-direction: column; align-items: center; padding: 6px 0; border-radius: 10px; border: 1px solid transparent; background: none; cursor: pointer; color: var(--muted); font-size: .72rem; text-transform: uppercase; }
.day-pick strong { font-size: 1rem; color: var(--text); }
.day-pick.day-today strong { color: var(--primary); }
.day-pick.day-on { background: var(--primary); color: var(--primary-ink); }
.day-pick.day-on strong { color: var(--primary-ink); }

/* ---------- Sessão ---------- */
.notes { min-height: 220px; line-height: 1.55; }
.save-state { font-size: .82rem; }
.files { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; align-items: start; }
.file { border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.file img, .file video { width: 100%; max-height: 220px; object-fit: contain; border-radius: 6px; background: var(--surface-2); }
.file audio { width: 100%; }
.file-meta { display: flex; align-items: center; gap: 8px; font-size: .82rem; flex-wrap: wrap; }
.file-meta span { flex: 1; min-width: 120px; color: var(--muted); }
.rec-preview { width: 100%; max-height: 320px; border-radius: 10px; background: #000; }
.rec-audio { width: 100%; }
.rec-clock { font-size: 2rem; font-variant-numeric: tabular-nums; text-align: center; margin: 12px 0; }
.rec-clock.rec-on { color: var(--danger); }

/* ---------- Recebimento ---------- */
.link-list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 9px; max-height: 240px; overflow: auto; }
.link-list > p { padding: 12px; }
.link-row { display: flex; align-items: center; gap: 10px; padding: 9px 12px; cursor: pointer; flex-wrap: wrap; }
.link-row + .link-row { border-top: 1px solid var(--line); }
.link-main { flex: 1; min-width: 180px; }
.link-amount { color: var(--muted); font-size: .86rem; font-variant-numeric: tabular-nums; }
.link-summary { font-size: .88rem; font-weight: 600; }

/* ---------- Modal e avisos ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgb(0 0 0 / 45%); display: grid; place-items: center; padding: 16px; overflow: auto; }
.modal { width: min(520px, 100%); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; background: var(--surface); border-radius: 14px; box-shadow: 0 20px 60px rgb(0 0 0 / 30%); }
.modal-wide { width: min(640px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 10px 20px; }
.modal-head h2 { font-size: 1.1rem; }
.modal-body { padding: 4px 20px 20px; overflow: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.spacer { flex: 1; }
.toasts { position: fixed; z-index: 60; left: 50%; bottom: 84px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; width: min(420px, calc(100% - 32px)); pointer-events: none; }
.toast { padding: 11px 14px; border-radius: 10px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); font-weight: 600; font-size: .9rem; }
.toast-error { background: var(--danger); color: #fff; }

/* ---------- Login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); }
.login-card .brand-mark { width: 44px; height: 44px; font-size: 1.5rem; }
.login-links { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }

/* ---------- Celular ---------- */
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .side { display: none; }
  .tabbar { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .tabbar .nav-link { flex-direction: column; gap: 2px; padding: 8px 4px; font-size: .74rem; border-radius: 0; }
  .tabbar .nav-link.nav-on { background: none; }
  .view { padding: 14px; gap: 12px; }
  .cal-title { font-size: 1rem; margin-left: 2px; }
  .card { padding: 14px; }
  .forma-row { grid-template-columns: 96px 1fr auto; }
  input, select, textarea { font-size: 16px; } /* evita o zoom automático do iOS ao focar */
}
