:root {
  --navy: #1e3a8a; --navy2: #2563eb; --bg: #f5f7fc; --card: #ffffff; --text: #0f172a;
  --muted: #64748b; --line: #e2e8f0; --warn: #b45309; --warnbg: #fef3c7; --red: #dc2626;
  --redbg: #fee2e2; --green: #15803d; --greenbg: #dcfce7; --accent: #2563eb;
  --radius: 14px; --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 14px rgba(15, 23, 42, .05);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; background: linear-gradient(120deg, var(--navy), var(--navy2)); color: #fff; }
.brand, .logo { font-weight: 800; letter-spacing: -.02em; font-size: 20px; }
.brand span, .logo span { color: #93c5fd; margin: 0 1px; }
.sync { font-size: 12px; opacity: .9; text-align: right; }
.sync.stale { color: #fde68a; }

main { max-width: 760px; margin: 0 auto; padding: 14px 16px calc(90px + env(safe-area-inset-bottom)); }
.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
.tabs a { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px;
  text-decoration: none; color: var(--muted); font-size: 11px; padding: 2px 0; }
.tabs a i { font-style: normal; font-size: 18px; line-height: 22px; }
.tabs a.on { color: var(--accent); font-weight: 600; }
.tabs b { position: absolute; top: 0; right: calc(50% - 20px); background: var(--red); color: #fff; font-size: 10px;
  border-radius: 9px; padding: 0 5px; line-height: 16px; }

h2 { font-size: 22px; margin: 6px 0 2px; letter-spacing: -.02em; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 8px; }
.sub { color: var(--muted); margin: 0 0 12px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line);
  padding: 14px; margin-bottom: 10px; }

.ev { display: flex; gap: 12px; align-items: stretch; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; margin-bottom: 8px; cursor: pointer; }
.ev .bar { width: 4px; border-radius: 3px; flex: none; }
.ev .time { flex: none; width: 50px; font-variant-numeric: tabular-nums; font-weight: 700; font-size: 14px; }
.ev .time small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }
.ev .body { flex: 1; min-width: 0; }
.ev .title { font-weight: 600; }
.ev .meta { color: var(--muted); font-size: 13px; margin-top: 2px; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.ev.past { opacity: .55; }
.ev.now { outline: 2px solid var(--accent); }
.ev.cancel .title { text-decoration: line-through; color: var(--muted); }
.tag { display: inline-block; font-size: 11px; font-weight: 600; border-radius: 6px; padding: 1px 7px; }
.tag.warn { background: var(--warnbg); color: var(--warn); }
.tag.red { background: var(--redbg); color: var(--red); }
.tag.green { background: var(--greenbg); color: var(--green); }
.tag.blue { background: rgba(37, 99, 235, .12); color: var(--accent); }
.tag.gray { background: rgba(100, 116, 139, .14); color: var(--muted); }
.was { font-size: 12px; color: var(--warn); margin-top: 3px; }
.note { font-size: 12px; color: var(--muted); margin-top: 3px; font-style: italic; }

.hero { background: linear-gradient(130deg, var(--navy), var(--navy2)); color: #fff; border-radius: 18px; padding: 16px 18px;
  margin-bottom: 14px; }
.hero .d { font-size: 13px; opacity: .85; }
.hero .big { font-size: 24px; font-weight: 800; letter-spacing: -.02em; margin-top: 2px; }
.hero .s { font-size: 14px; opacity: .9; margin-top: 4px; }
.empty { text-align: center; color: var(--muted); padding: 22px 10px; }

.daylabel { font-weight: 700; margin: 18px 0 8px; display: flex; align-items: baseline; gap: 8px; }
.daylabel small { color: var(--muted); font-weight: 500; text-transform: none; }
.weeklabel { margin: 26px 0 4px; font-size: 13px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .05em; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }

.month { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.month .h { text-align: center; font-size: 11px; color: var(--muted); font-weight: 600; padding: 4px 0; }
.month .c { min-height: 58px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 4px;
  font-size: 12px; cursor: pointer; overflow: hidden; }
.month .c.out { opacity: .35; }
.month .c.today { outline: 2px solid var(--accent); }
.month .c.sel { background: rgba(37, 99, 235, .1); }
.month .n { font-weight: 700; font-size: 12px; }
.dots { display: flex; flex-wrap: wrap; gap: 2px; margin-top: 3px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; display: block; }
.dots i.x { outline: 2px solid var(--red); outline-offset: 1px; }
.month .lbl { font-size: 10px; font-weight: 700; color: var(--red); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.btn { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 9px 14px; cursor: pointer;
  font-weight: 600; font-size: 14px; }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn.danger { color: var(--red); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; font-weight: 600; }
input, select, textarea { width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 10px; }
textarea { min-height: 110px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.err { color: var(--red); font-size: 13px; margin-top: 8px; min-height: 1em; }
.warnbox { background: var(--warnbg); color: var(--warn); border-radius: 10px; padding: 10px 12px; font-size: 13px; margin: 10px 0; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
pre { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; overflow: auto; max-height: 220px; white-space: pre-wrap; word-break: break-all; }
ol.steps { padding-left: 20px; margin: 6px 0; }
ol.steps li { margin: 4px 0; }

.chg { border-left: 4px solid var(--line); }
.chg.aplicado { border-left-color: var(--green); }
.chg.pendiente { border-left-color: var(--warn); }
.chg .head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.chg .subj { font-weight: 600; }
.chg .from { font-size: 12px; color: var(--muted); }
.chg .what { font-size: 13px; margin-top: 6px; }
.chg details { margin-top: 6px; font-size: 12px; color: var(--muted); }
.chg .actions { margin-top: 8px; }

.login { position: fixed; inset: 0; display: grid; place-items: center; background: linear-gradient(140deg, var(--navy), var(--navy2)); padding: 16px; }
.login-card { width: 100%; max-width: 340px; background: var(--card); border-radius: 18px; padding: 24px; text-align: center; }
.login-card .logo { font-size: 30px; color: var(--navy); }
.login-card p { color: var(--muted); margin: 4px 0 18px; }
.login-card .btn { width: 100%; margin-top: 10px; }

dialog { border: none; border-radius: 18px; padding: 0; width: min(440px, calc(100% - 24px)); background: var(--card); color: var(--text); }
dialog::backdrop { background: rgba(2, 6, 23, .5); }
dialog form { padding: 18px; }
dialog h4 { margin: 0 0 4px; font-size: 18px; }
.toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; transition: .25s; pointer-events: none; z-index: 20; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(-50%); }
@media (max-width: 420px) { .tabs a span { font-size: 10px; } .ev .time { width: 44px; } }

/* ---------- v3: mes detallado, días pasados en gris, entregas destacadas ---------- */
body[data-view="mes"] main { max-width: 1280px; }
.month { gap: 5px; }
.month .h { font-size: 12px; }
.month .c { min-height: 108px; padding: 5px; display: flex; flex-direction: column; gap: 2px; }
.month .n { margin-bottom: 2px; }
.month .n small { font-weight: 700; color: var(--accent); font-size: 10px; text-transform: uppercase; }
.month .c.today { outline: 2px solid var(--accent); outline-offset: -1px; }
.month .c.past { background: var(--past-bg); border-color: var(--past-line); }
.month .c.past .n { color: var(--muted); }
.month .c.past .it { filter: grayscale(1); opacity: .55; }
.month .c.has-ent { box-shadow: inset 0 0 0 2px var(--ent); }
.month .c.has-ex { box-shadow: inset 0 0 0 2px var(--red); }
.month .c.has-ent.has-ex { box-shadow: inset 0 0 0 2px var(--red), inset 0 0 0 4px var(--ent); }
.it { font-size: 11px; line-height: 1.25; border-left: 3px solid var(--c); padding: 1px 4px; border-radius: 3px;
  background: color-mix(in srgb, var(--c) 12%, transparent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.it b { font-weight: 700; font-variant-numeric: tabular-nums; }
.it em { font-style: normal; color: var(--muted); font-size: 10px; }
.it.ent { background: var(--ent-bg); border-left-color: var(--ent); color: var(--ent-text); font-weight: 700; }
.it.ex { background: var(--redbg); border-left-color: var(--red); color: var(--red); font-weight: 700; }
.it.chg { background: var(--warnbg); }
.it.x { text-decoration: line-through; opacity: .6; border-left-color: var(--red); background: transparent; }
.month .more { font-size: 10px; color: var(--muted); padding-left: 4px; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); margin: 0 0 10px; }
.legend span { display: flex; align-items: center; gap: 5px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.lg-ent { background: var(--ent); } .lg-ex { background: var(--red); } .lg-ch { background: var(--warn); }
.lg-x { border: 2px solid var(--red); } .lg-past { background: var(--past-bg); border: 1px solid var(--past-line); }

.ev.past { opacity: 1; filter: grayscale(1); background: var(--past-bg); color: var(--muted); }
.ev.past .title { color: var(--muted); }
.ev.deadline { align-items: center; border-width: 1px 1px 1px 1px; }
.ev.deadline .count { flex: none; font-weight: 800; font-size: 13px; padding: 6px 10px; border-radius: 10px; white-space: nowrap; }
.ev.deadline.red { border-color: var(--red); } .ev.deadline.red .count { background: var(--redbg); color: var(--red); }
.ev.deadline.warn { border-color: var(--ent); } .ev.deadline.warn .count { background: var(--ent-bg); color: var(--ent-text); }
.ev.deadline.blue .count { background: rgba(37, 99, 235, .12); color: var(--accent); }

:root { --ent: #f59e0b; --ent-bg: #fef3c7; --ent-text: #92400e; --past-bg: #e5e7eb; --past-line: #d1d5db; }

@media (max-width: 700px) {
  .month { gap: 2px; }
  .month .c { min-height: 74px; padding: 3px 2px; border-radius: 6px; }
  .it { font-size: 9px; padding: 0 2px; border-left-width: 2px; }
  .it b, .it em { display: none; }
  .month .h { font-size: 10px; }
  .legend { gap: 8px; font-size: 11px; }
}

/* ---------- v4: tema claro, entregas enviadas, alertas ---------- */
.top { background: #ffffff; color: var(--text); border-bottom: 1px solid var(--line); }
.brand { color: var(--navy); }
.brand span { color: var(--navy2); }
.sync { color: var(--muted); opacity: 1; }
.sync.stale { color: var(--warn); }
.hero { background: linear-gradient(130deg, #eff4ff, #dbe7ff); color: var(--text); border: 1px solid #c7d7fb; }
.hero .d { color: var(--navy2); opacity: 1; font-weight: 600; }
.hero .big { color: var(--navy); }
.hero .s { color: #334155; opacity: 1; }
.login { background: linear-gradient(140deg, #eff4ff, #dbe7ff); }
.login-card { box-shadow: 0 10px 40px rgba(30, 58, 138, .15); }
.tabs { box-shadow: 0 -2px 10px rgba(15, 23, 42, .04); }
.btn.ok { background: #16a34a; color: #fff; border-color: transparent; }
.btn.ok.big { width: 100%; padding: 12px; font-size: 15px; margin: 6px 0 4px; }
.okbox { background: var(--greenbg); color: var(--green); border-radius: 10px; padding: 10px 12px; font-size: 13px; margin: 10px 0; }
.alertbox { background: #fff1f2; border: 1px solid #fecdd3; color: #9f1239; border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; font-size: 14px; }
.alertbox b { display: block; margin-bottom: 4px; }
.ev.deadline .btn.ok { flex: none; padding: 6px 10px; font-size: 12px; }
.ev.deadline.done { opacity: .75; }
.ev.deadline.done .title { text-decoration: line-through; color: var(--muted); }
.ev.deadline.done .count { background: var(--greenbg); color: var(--green); }
details.sent { margin: 8px 0 4px; }
details.sent summary { cursor: pointer; color: var(--green); font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.it.ent.done { background: var(--greenbg); border-left-color: #16a34a; color: var(--green); font-weight: 600; text-decoration: line-through; }
.tabs b { right: calc(50% - 22px); }
@media (max-width: 520px) { .ev.deadline { flex-wrap: wrap; } .ev.deadline .count { margin-left: auto; } }

/* ---------- v5: mes con detalle completo, tareas ---------- */
.it { white-space: normal; overflow: visible; text-overflow: clip; word-break: break-word; cursor: pointer; padding: 2px 4px; }
.it:hover { filter: brightness(.95); box-shadow: 0 0 0 1px var(--c); }
.it.ent:hover { box-shadow: 0 0 0 1px var(--ent); }
.it b { display: block; font-size: 10px; }
.it em { display: block; }
.month .c { min-height: 120px; height: auto; }
.ev.deadline .acts, .trow .acts { display: flex; gap: 6px; flex: none; }
.tstats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 6px 0 4px; }
.tstats div { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; text-align: center; }
.tstats b { display: block; font-size: 22px; } .tstats span { font-size: 12px; color: var(--muted); }
.tstats .hot { border-color: var(--red); } .tstats .hot b { color: var(--red); }
.trow { display: flex; gap: 12px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 10px 12px; margin-bottom: 8px; cursor: pointer; }
.trow .tdate { flex: none; width: 46px; text-align: center; border-radius: 10px; background: var(--bg); padding: 4px 0; }
.trow .tdate b { display: block; font-size: 20px; line-height: 1.1; } .trow .tdate small { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.trow .tbody { flex: 1; min-width: 0; } .trow .title { font-weight: 700; }
.trow .meta { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.trow .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.trow .tside { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex: none; }
.trow .count { font-weight: 800; font-size: 12px; padding: 4px 9px; border-radius: 9px; white-space: nowrap; }
.trow.red { border-color: var(--red); } .trow.red .count { background: var(--redbg); color: var(--red); }
.trow.warn { border-color: var(--ent); } .trow.warn .count { background: var(--ent-bg); color: var(--ent-text); }
.trow.blue .count { background: rgba(37, 99, 235, .12); color: var(--accent); }
.trow.late { opacity: .8; } .trow.late .count { background: var(--past-bg); color: var(--muted); }
.trow.done { opacity: .75; } .trow.done .title { text-decoration: line-through; color: var(--muted); }
.trow.done .count { background: var(--greenbg); color: var(--green); }
@media (max-width: 700px) {
  .it { font-size: 9px; padding: 1px 2px; line-height: 1.2; }
  .it b { font-size: 8.5px; } .it em { display: none; }
  .month .c { min-height: 80px; }
  .tstats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 520px) { .trow { flex-wrap: wrap; } .trow .tside { flex-direction: row; width: 100%; justify-content: space-between; align-items: center; } }
