:root {
  --bg: #ffffff; --ink: #111111; --muted: #6b6b6b; --rule: #d9d9d9; --strong: #111111;
  --tomato: #c8321f; --tomato-dark: #a42817; --ok: #2f7d4f; --ok-bg: #e4f2e9; --warn: #8a5a00; --warn-bg: #f7ecd2; --bad: #b3261e; --bad-bg: #f9dedc; --soft: #f5f5f3;
  --f-body: 'Inter', Helvetica, Arial, sans-serif; --f-mono: 'IBM Plex Mono', ui-monospace, monospace;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--f-body); overflow-x: hidden; }
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -.02em; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid #1a5fb4; outline-offset: 2px; }

.app { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; }
.sidebar, .app > * { min-width: 0; }
.sidebar { border-right: 1px solid var(--strong); padding: 26px 0; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; height: 100dvh; }
.brand { padding: 0 24px 26px; font-size: 1.35rem; font-weight: 800; letter-spacing: -.04em; }
.brand b { color: var(--tomato); }
.brand small { display: block; font-size: .72rem; font-weight: 500; letter-spacing: .04em; color: var(--muted); margin-top: 2px; }
.sidebar nav { display: flex; flex-direction: column; flex: 1; }
.sidebar nav button { background: none; border: 0; border-left: 3px solid transparent; text-align: left; padding: 11px 24px; cursor: pointer; min-height: 44px; color: var(--ink); }
.sidebar nav button:hover { background: var(--soft); }
.sidebar nav button[aria-current="page"] { border-left-color: var(--tomato); font-weight: 700; }
.who { padding: 14px 24px 0; font-size: .85rem; }
.who span { display: block; margin-bottom: 8px; color: var(--muted); }
.main { padding: clamp(20px, 3vw, 48px) clamp(16px, 3.5vw, 64px) 64px; width: 100%; }

.btn { border: 1px solid var(--strong); background: #fff; padding: 7px 14px; border-radius: 0; cursor: pointer; font-weight: 600; min-height: 44px; touch-action: manipulation; }
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--tomato); border-color: var(--tomato); color: #fff; }
.btn.primary:hover { background: var(--tomato-dark); }
.btn.danger { color: var(--bad); border-color: #d9a39f; }
.btn.sm { min-height: 36px; padding: 3px 12px; font-size: .85rem; }

.daybar { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.daybar > div { flex: 1; min-width: 200px; }
.daybar small, .eyebrow { display: block; text-transform: uppercase; letter-spacing: .14em; font-size: .72rem; color: var(--tomato); font-weight: 700; }
.daybar h2 { font-size: clamp(2rem, 3.2vw, 3.2rem); line-height: 1.05; letter-spacing: -.04em; }
.daybar h2::first-letter, .side h3::first-letter, .report-title::first-letter { text-transform: uppercase; }
input[type=date], input[type=month] { min-width: 150px; }

.stats { display: flex; flex-wrap: wrap; border-top: 2px solid var(--strong); border-bottom: 1px solid var(--strong); margin-bottom: 8px; }
.stats > div { padding: 12px 28px 12px 0; margin-right: 28px; border-right: 1px solid var(--rule); }
.stats > div:last-child { border-right: 0; }
.stats b { display: block; font-weight: 300; font-size: clamp(1.9rem, 2.6vw, 2.8rem); line-height: 1.15; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.stats span { font-size: .8rem; color: var(--muted); }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) clamp(240px, 22vw, 340px); gap: clamp(24px, 3vw, 48px); align-items: start; }
.agenda { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 520px), 1fr)); column-gap: clamp(24px, 3vw, 48px); align-content: start; }
.agenda > .empty { grid-column: 1 / -1; }
.visit { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 16px; border-bottom: 1px solid var(--strong); padding: 16px 0; }
.visit .time { font-family: var(--f-mono); font-weight: 500; line-height: 1.3; }
.visit .time span { display: block; font-size: .8rem; color: var(--muted); font-weight: 400; }
.visit h3 { font-size: 1.08rem; }
.visit p { margin: 2px 0 0; color: var(--muted); font-size: .92rem; }
.visit .row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.visit.cancelada h3 { text-decoration: line-through; color: var(--muted); }
.tag { display: inline-block; font-size: .7rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; margin-bottom: 4px; }
.tag.planificada { color: var(--ink); } .tag.realizada { color: var(--ok); } .tag.cancelada { color: var(--muted); }
.empty { padding: 36px 0; color: var(--muted); border-bottom: 1px solid var(--strong); }

.side { border-top: 2px solid var(--strong); padding-top: 12px; }
.side h3 { font-size: .95rem; }
.calnav { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.calnav button { background: none; border: 0; font-size: 1.2rem; cursor: pointer; min-width: 44px; min-height: 44px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; font-size: .82rem; }
.cal .dow { color: var(--muted); font-weight: 600; padding-bottom: 4px; }
.cal button { aspect-ratio: 1; border: 0; background: none; cursor: pointer; position: relative; min-width: 0; }
.cal button:hover { background: var(--soft); }
.cal button.today { font-weight: 800; color: var(--tomato); }
.cal button.sel { background: var(--ink); color: #fff; }
.cal button.has::after { content: ''; position: absolute; left: 50%; bottom: 3px; width: 4px; height: 4px; margin-left: -2px; background: var(--tomato); }

.panel { border-top: 2px solid var(--strong); padding: 14px 0 6px; margin-bottom: 28px; }
.panel h2 { font-size: 1.1rem; margin-bottom: 12px; }
.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; margin-bottom: 18px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .8rem; font-weight: 600; color: var(--muted); }
input, select, textarea { border: 1px solid var(--strong); border-radius: 0; padding: 8px 10px; background: #fff; min-height: 44px; font-size: 16px; color: var(--ink); font-weight: 400; }
textarea { min-height: 80px; resize: vertical; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--strong); padding: 8px; }
td { padding: 9px 8px; border-bottom: 1px solid var(--rule); vertical-align: top; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tablewrap { overflow-x: auto; }
.report-title { font-size: clamp(1.8rem, 2.8vw, 2.8rem); letter-spacing: -.04em; line-height: 1.05; margin-bottom: 18px; }

dialog { border: 2px solid var(--strong); border-radius: 0; background: #fff; padding: 24px; width: min(500px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(17,17,17,.55); }
dialog h2 { margin-bottom: 14px; font-size: 1.3rem; }
.form { display: grid; gap: 12px; }
.form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form .actions { display: flex; gap: 8px; justify-content: flex-end; }
.err { color: var(--bad); background: var(--bad-bg); padding: 8px 10px; font-size: .88rem; }

.loginwrap { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: 1fr 1fr; }
.loginside { border-right: 1px solid var(--strong); padding: 48px; display: flex; flex-direction: column; justify-content: flex-end; }
.loginside h1 { font-size: 3.4rem; letter-spacing: -.05em; line-height: 1; }
.loginside h1 b { color: var(--tomato); }
.loginside p { color: var(--muted); margin: 8px 0 0; }
.login { align-self: center; justify-self: center; width: min(340px, 90%); }
.login h2 { font-size: 1.3rem; }
@media (max-width: 760px) { .loginwrap { grid-template-columns: 1fr; } .loginside { padding: 28px; border-right: 0; border-bottom: 1px solid var(--strong); } .loginside h1 { font-size: 2rem; } .login { padding: 28px 0; } }

#toast { position: fixed; right: 20px; bottom: 20px; max-width: min(420px, calc(100vw - 40px)); transform: translateY(80px); background: var(--ink); color: #fff; padding: 10px 16px; transition: transform .2s, opacity .2s; z-index: 10; opacity: 0; visibility: hidden; }
#toast.show { transform: none; opacity: 1; visibility: visible; }

@media (max-width: 1180px) {
  .app { grid-template-columns: 196px minmax(0, 1fr); }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .layout .side { max-width: 380px; }
}
@media (min-width: 1700px) {
  html { font-size: 17px; }
  .app { grid-template-columns: 260px minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; padding: 14px 0 0; border-right: 0; border-bottom: 1px solid var(--strong); }
  .brand { padding: 0 16px 8px; }
  .sidebar nav { flex-direction: row; overflow-x: auto; scrollbar-width: thin; }
  .sidebar nav button { border-left: 0; border-bottom: 3px solid transparent; white-space: nowrap; padding: 10px 16px; }
  .sidebar nav button[aria-current="page"] { border-bottom-color: var(--tomato); }
  .who { display: flex; justify-content: space-between; align-items: center; padding: 8px 16px; border-top: 1px solid var(--rule); }
  .who span { margin: 0; }
  .main { padding: 20px 16px 48px; }
  .layout { grid-template-columns: minmax(0, 1fr); gap: 24px; }
  .daybar h2, .report-title { font-size: 1.9rem; }
  .stats > div { padding-right: 16px; margin-right: 16px; }
  .layout .side { max-width: none; }
}
@media (max-width: 480px) {
  .daybar > * { flex: 1 1 100%; }
  .daybar .btn, .daybar input[type=date] { width: 100%; }
  .stats > div { flex: 1 1 0; margin-right: 0; padding: 10px 10px 10px 0; }
  .stats b { font-size: 1.7rem; }
  .visit { grid-template-columns: 64px minmax(0, 1fr); gap: 12px; }
  .visit .row .btn { flex: 1 1 auto; }
  .filters > * { flex: 1 1 100%; }
  .filters .btn { width: 100%; }
  .form .two { grid-template-columns: 1fr; }
  dialog { padding: 18px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print {
  .sidebar, .filters, #toast { display: none !important; }
  .app { display: block; } .main { padding: 0; max-width: none; }
}
.tag.future { color: var(--tomato); }
.visit p.why { color: var(--ink); font-size: .88rem; margin-top: 6px; }
.hint { font-size: .85rem; color: var(--muted); }
#futurehint { color: var(--tomato); font-weight: 600; }
.daytitle::first-letter { text-transform: uppercase; }
dialog { max-height: calc(100vh - 24px); overflow-y: auto; }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 8px; background: var(--tomato); color: #fff; font-size: .75rem; font-weight: 700; text-align: center; line-height: 20px; }
.badge[hidden] { display: none; }
.reminder { border-left: 4px solid var(--tomato); background: var(--soft); padding: 10px 14px; margin-bottom: 16px; }
.notifs { list-style: none; margin: 0; padding: 0; border-top: 2px solid var(--strong); }
.notifs li { padding: 14px 12px 14px 16px; border-bottom: 1px solid var(--rule); border-left: 4px solid transparent; }
.notifs li.new { border-left-color: var(--tomato); background: var(--soft); }
.notifs p { margin: 0 0 2px; }
.notifs time { font-size: .8rem; color: var(--muted); }

/* revisión UI/UX */
.skip { position: absolute; left: 8px; top: -60px; background: var(--ink); color: #fff; padding: 10px 14px; z-index: 20; }
.skip:focus { top: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.main:focus { outline: none; }
label .req { color: var(--tomato); }
.req-note { font-size: .8rem; color: var(--muted); margin: 0; }
.err { border-left: 4px solid var(--bad); }
#toast.error { background: var(--bad); }
.btn.danger-solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger-solid:hover { background: #8f1f19; }
.visit .row .sep { flex: 1 1 auto; }
.visit .row .btn.danger { margin-left: auto; }
.cal button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.cal button.has::after { width: 6px; height: 6px; margin-left: -3px; }
.cal button.sel.has::after { background: #fff; }
.tablewrap:focus-visible { outline-offset: -3px; }
caption { text-align: left; font-weight: 700; padding: 0 8px 8px; }
.skeleton { color: var(--muted); padding: 20px 0; border-bottom: 1px solid var(--strong); }
.stats[aria-busy="true"] b { color: var(--rule); }
@media (max-width: 480px) {
  .btn.sm { min-height: 44px; }
  .visit .row .btn.danger { margin-left: 0; }
}

[hidden] { display: none !important; }

.whobtns { display: flex; flex-direction: column; gap: 8px; }
@media (max-width: 860px) { .whobtns { flex-direction: row; } }
@supports (padding: env(safe-area-inset-top)) {
  .main { padding-bottom: calc(48px + env(safe-area-inset-bottom)); }
  #toast { bottom: calc(20px + env(safe-area-inset-bottom)); }
}
@media (display-mode: standalone) { body { overscroll-behavior-y: none; } }
