:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #0f766e;
  --brand-dark: #0b5750;
  --am: #f59e0b;     /* mañana */
  --pm: #6366f1;     /* tarde */
  --full: #0f766e;   /* completo */
  --danger: #dc2626;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.4;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#app { max-width: 520px; margin: 0 auto; padding: 16px 16px 120px; }

.hidden { display: none !important; }

/* ---------- header ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.hello { font-size: 14px; color: var(--muted); }
.hello b { color: var(--ink); font-size: 17px; display: block; }
.top-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: none;
  background: var(--card); box-shadow: var(--shadow); font-size: 18px;
  display: grid; place-items: center; cursor: pointer; color: var(--ink);
}

/* ---------- cards ---------- */
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}

.month-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.month-name { font-size: 20px; font-weight: 700; display: flex; align-items: center; gap: 8px; cursor: pointer; }
.chev { color: var(--muted); font-size: 14px; }
.badge { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; }
.badge.open { background: #ecfdf5; color: #047857; }
.badge.closed { background: #fef2f2; color: #b91c1c; }

.rate-row { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; gap: 10px; }
.rate-row label { color: var(--muted); font-size: 14px; }
.rate-input { display: flex; align-items: center; gap: 6px; }
.rate-input input {
  width: 130px; text-align: right; font-size: 17px; font-weight: 700;
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
  font-family: inherit; color: var(--ink);
}
.rate-input input:disabled { background: #f9fafb; color: var(--muted); }

/* ---------- calendar ---------- */
.weekdays, .grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.weekdays { margin: 6px 0; }
.weekdays span { text-align: center; font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; }
.cell {
  aspect-ratio: 1 / 1; border-radius: 12px; border: 1px solid var(--line);
  background: #fff; position: relative; display: flex; flex-direction: column;
  align-items: center; justify-content: center; cursor: pointer; overflow: hidden;
  font-size: 15px; font-weight: 600;
}
.cell.empty { border: none; background: transparent; cursor: default; }
.cell.weekend { background: #fbfbfc; }
.cell.today { outline: 2px solid var(--brand); outline-offset: -2px; }
.cell .num { z-index: 2; }
.cell .frac { z-index: 2; font-size: 10px; font-weight: 700; color: #fff; margin-top: 1px; }
.cell.disabled { cursor: default; opacity: .85; }

/* fills */
.cell .fill { position: absolute; inset: 0; z-index: 1; }
.cell.full  .fill { background: var(--full); }
.cell.am    .fill { background: linear-gradient(135deg, var(--am) 50%, transparent 50%); }
.cell.pm    .fill { background: linear-gradient(315deg, var(--pm) 50%, transparent 50%); }
.cell.full .num, .cell.full .frac { color: #fff; }
.cell.am .num, .cell.pm .num { color: var(--ink); }

.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 12px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 4px; margin-right: 5px; vertical-align: -1px; }
.legend .l-full { background: var(--full); }
.legend .l-am { background: var(--am); }
.legend .l-pm { background: var(--pm); }

/* ---------- totals sticky ---------- */
.totals {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: var(--card); border-top: 1px solid var(--line);
  box-shadow: 0 -2px 10px rgba(0,0,0,.05);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
}
.totals-inner { max-width: 520px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.totals .big { flex: 1; }
.totals .big .d { font-size: 13px; color: var(--muted); }
.totals .big .v { font-size: 20px; font-weight: 800; }
.totals .pay { text-align: right; }
.totals .pay .d { font-size: 13px; color: var(--muted); }
.totals .pay .v { font-size: 20px; font-weight: 800; color: var(--brand); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; border: none; border-radius: 12px; padding: 14px 16px;
  font-size: 16px; font-weight: 700; font-family: inherit; cursor: pointer;
  background: var(--brand); color: #fff;
}
.btn:active { transform: translateY(1px); }
.btn.secondary { background: #eef2f7; color: var(--ink); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; color: var(--brand); box-shadow: none; }
.btn[disabled] { opacity: .5; cursor: default; }
.btn-row { display: flex; gap: 10px; margin-top: 10px; }

/* ---------- login / setup ---------- */
.auth-wrap { min-height: 70vh; display: flex; flex-direction: column; justify-content: center; }
.brand-logo { text-align: center; margin-bottom: 18px; }
.brand-logo .mark { font-size: 44px; }
.brand-logo h1 { margin: 6px 0 2px; font-size: 24px; }
.brand-logo p { margin: 0; color: var(--muted); font-size: 14px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 13px 14px; border: 1px solid var(--line);
  border-radius: 12px; font-size: 16px; font-family: inherit;
}
.error { color: var(--danger); font-size: 14px; margin: 8px 0; min-height: 18px; }

/* ---------- list (months / users) ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--card); width: 100%; max-width: 520px;
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-height: 85vh; overflow-y: auto;
}
.modal h2 { margin: 0 0 14px; font-size: 18px; }
.list-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 13px 12px; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px;
  cursor: pointer; background: #fff;
}
.list-item .lead .t { font-weight: 700; }
.list-item .lead .s { font-size: 13px; color: var(--muted); }
.list-item.active { border-color: var(--brand); background: #f0fdfa; }

/* ---------- bottom sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--card); width: 100%; max-width: 520px;
  border-radius: 20px 20px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}
.sheet-title { text-align: center; font-weight: 700; margin-bottom: 12px; }
.opt {
  width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 12px;
  padding: 15px 16px; font-size: 16px; font-weight: 600; font-family: inherit;
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; cursor: pointer;
}
.opt span { font-weight: 800; }
.opt-full { border-color: var(--full); color: var(--full); }
.opt-am { border-color: var(--am); color: #b45309; }
.opt-pm { border-color: var(--pm); color: #4338ca; }
.opt-clear { color: var(--muted); }
.opt-cancel { justify-content: center; color: var(--muted); border-style: dashed; }

/* ---------- nota en la hoja del día ---------- */
.note-field { margin: 6px 0 4px; }
.note-field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.note-field .opt-hint { color: #9ca3af; font-weight: 400; }
.note-field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
  font-size: 16px; font-family: inherit; resize: vertical; min-height: 52px; color: var(--ink);
}
.opt-note { justify-content: center; border-color: var(--brand); color: var(--brand); margin-top: 8px; }

/* ---------- puntito de nota en la celda ---------- */
.note-dot {
  position: absolute; top: 0; right: 0; z-index: 3;
  width: 20px; height: 20px; display: grid; place-items: center; cursor: pointer;
}
.note-dot::after {
  content: ""; width: 8px; height: 8px; border-radius: 50%;
  background: #fde047; border: 1.5px solid #ca8a04; box-shadow: 0 0 0 1.5px #fff;
}
.cell.full .note-dot::after { box-shadow: 0 0 0 1.5px var(--full); }

/* ---------- globito flotante (tooltip de nota) ---------- */
.note-tip {
  position: fixed; z-index: 60; max-width: 220px;
  background: #111827; color: #fff; font-size: 13px; line-height: 1.35;
  padding: 9px 11px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.25);
  white-space: pre-wrap; word-break: break-word; pointer-events: none;
}
.note-tip::after {
  content: ""; position: absolute; left: var(--arrow-x, 50%); transform: translateX(-50%);
  border: 6px solid transparent;
}
.note-tip.below::after { top: -12px; border-bottom-color: #111827; }
.note-tip.above::after { bottom: -12px; border-top-color: #111827; }

.resumen-box {
  background: #f0fdfa; border: 1px solid #99f6e4; border-radius: 12px;
  padding: 16px; text-align: center; margin: 6px 0 14px; font-size: 16px;
}
.resumen-box b { color: var(--brand-dark); }
.muted-note { font-size: 13px; color: var(--muted); text-align: center; margin-top: 8px; }
