:root {
  --bg: #f4f6f8; --surface: #fff; --ink: #18212b; --muted: #5d6b79; --line: #dfe5eb;
  --brand: #0f766e; --brand-ink: #fff; --brand-soft: #e3f4f2;
  --danger: #b42318; --warn: #b54708; --ok: #027a48; --info: #175cd3;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419; --surface: #182029; --ink: #e6edf3; --muted: #93a1af; --line: #2a3644;
    --brand: #2dd4bf; --brand-ink: #062a27; --brand-soft: #123a37;
    --danger: #f97066; --warn: #fdb022; --ok: #32d583; --info: #84adff;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 1.5rem; margin: 0; } h2 { font-size: 1.15rem; margin: 0 0 .5rem; } h3 { font-size: 1rem; margin: 0 0 .6rem; } h4 { margin: .8rem 0 .2rem; font-size: .9rem; }
a { color: var(--brand); }
.boot { padding: 3rem; text-align: center; color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: .85rem; } .warn { color: var(--warn); } .cap::first-letter { text-transform: uppercase; }
.pre { white-space: pre-wrap; } .error { color: var(--danger); margin: .3rem 0; }
.strike td:first-child strong { text-decoration: line-through; }

button, .button { font: inherit; border-radius: 8px; padding: .5rem .9rem; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: .3rem; }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
button.ghost, .button.ghost { background: transparent; }
button.danger { color: var(--danger); }
button.small { padding: .25rem .6rem; font-size: .85rem; }
button.link { border: 0; background: none; padding: 0; color: var(--brand); text-decoration: underline; }
button.icon { padding: .2rem .5rem; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .5rem .6rem; width: 100%; min-width: 0; }
textarea { resize: vertical; }
input[type=checkbox] { width: auto; }
input[type=color] { padding: .1rem; height: 2.4rem; }
.field { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; }
.field > span { color: var(--muted); font-weight: 500; }
.field small { color: var(--muted); }
.check { display: flex; gap: .5rem; align-items: center; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .8rem; }
.grid > .full, .grid > footer, .grid > h3 { grid-column: 1 / -1; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
footer { display: flex; gap: .5rem; justify-content: flex-end; }
.row { display: flex; gap: .5rem; align-items: center; } .row.wrap { flex-wrap: wrap; } .row.spread { justify-content: space-between; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
.cols { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 1rem; align-items: start; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.card-head h3 { margin: 0; }
details.card summary { cursor: pointer; }
.empty { color: var(--muted); padding: .6rem 0; margin: 0; }
.alert { background: #fef3f2; color: var(--danger); border: 1px solid #fecdca; border-radius: 8px; padding: .6rem .8rem; font-weight: 600; }
.note { background: var(--brand-soft); border-radius: 8px; padding: .6rem .8rem; }
@media (prefers-color-scheme: dark) { .alert { background: #3a1513; border-color: #6b2420; } }

.pill { display: inline-block; font-size: .75rem; font-weight: 600; padding: .1rem .5rem; border-radius: 99px; background: var(--line); color: var(--ink); white-space: nowrap; }
.pill.accepted, .pill.confirmed, .pill.done { background: #d1fadf; color: #05603a; }
.pill.presented, .pill.in_progress, .pill.arrived { background: #d1e9ff; color: #1849a9; }
.pill.requested, .pill.portal { background: #fef0c7; color: #93370d; }
.pill.rejected, .pill.cancelled, .pill.no_show { background: #fee4e2; color: #912018; }
@media (prefers-color-scheme: dark) { .pill { filter: brightness(.9) saturate(.9); } }

.list { list-style: none; margin: 0; padding: 0; }
.list li { border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: .6rem; }
.list li:first-child { border-top: 0; }
.list li > a, .list li > span { display: flex; flex-direction: column; padding: .6rem 0; text-decoration: none; color: inherit; flex: 1; min-width: 0; }
.list li > a:hover strong { color: var(--brand); }
.list.compact li > a, .list.compact li > span { padding: .4rem 0; }
.list li > span.row { flex-direction: row; flex: 0 0 auto; padding: 0; }
.dot { display: inline-block; width: .7rem; height: .7rem; border-radius: 50%; vertical-align: middle; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 0; }
.facts dt { color: var(--muted); } .facts dd { margin: 0; }

.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--line); padding: .4rem; }
.table td { border-bottom: 1px solid var(--line); padding: .5rem .4rem; vertical-align: top; }
.table .num { text-align: right; white-space: nowrap; }
.table tfoot td { border: 0; } .table tr.total td { font-weight: 700; font-size: 1.05rem; border-top: 2px solid var(--ink); }
.table .actions { display: flex; gap: .3rem; flex-wrap: wrap; justify-content: flex-end; }
.table tr.clickable { cursor: pointer; } .table tr.clickable:hover { background: var(--brand-soft); }
.card:has(.table) { overflow-x: auto; }

/* Estructura del equipo */
.shell { display: grid; grid-template-columns: 210px minmax(0, 1fr); min-height: 100vh; }
.nav { background: var(--surface); border-right: 1px solid var(--line); padding: 1rem .8rem; display: flex; flex-direction: column; gap: 1rem; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; flex-direction: column; } .brand small { color: var(--muted); }
.nav nav { display: flex; flex-direction: column; gap: .2rem; flex: 1; }
.nav nav a { display: flex; gap: .6rem; padding: .55rem .7rem; border-radius: 8px; color: var(--ink); text-decoration: none; }
.nav nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.content { padding: 1.2rem 1.5rem 3rem; min-width: 0; max-width: 1400px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head p { margin: .2rem 0 0; }
.back { font-size: .85rem; text-decoration: none; }
.toolbar { display: flex; gap: 1rem; align-items: center; margin-bottom: 1rem; }
.toolbar input[type=search] { max-width: 520px; }
@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .nav { position: sticky; top: 0; z-index: 5; height: auto; flex-direction: row; align-items: center; padding: .5rem 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { display: none; }
  .nav nav { flex-direction: row; justify-content: space-around; }
  .nav nav a { flex-direction: column; align-items: center; gap: 0; font-size: .75rem; padding: .3rem .4rem; }
  .content { padding: 1rem 16px 3rem; }
  .cols { grid-template-columns: 1fr; }
  .toolbar { flex-direction: column; align-items: stretch; }
}

/* Modal */
.modal { border: 0; border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); background: var(--surface); color: var(--ink); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { width: min(820px, calc(100vw - 32px)); }
.modal::backdrop { background: rgba(15,20,25,.5); }
.modal > header { display: flex; justify-content: space-between; align-items: center; padding: .9rem 1rem; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal > header h2 { margin: 0; }
.modal-body { padding: 1rem; display: flex; flex-direction: column; gap: .8rem; }
.modal-body > p { margin: 0; }
.code { font: 700 1.9rem/1.2 ui-monospace, Menlo, monospace; letter-spacing: .08em; text-align: center; background: var(--brand-soft); border-radius: 10px; padding: 1rem; margin: 0; word-break: break-all; }
.picker { list-style: none; margin: .2rem 0 0; padding: 0; border: 1px solid var(--line); border-radius: 8px; max-height: 240px; overflow: auto; }
.picker button { width: 100%; border: 0; border-radius: 0; text-align: left; justify-content: flex-start; }
.picker button:hover { background: var(--brand-soft); }

#toast { position: fixed; left: 50%; bottom: 1.2rem; transform: translate(-50%, 150%); background: var(--ink); color: var(--bg); padding: .7rem 1.1rem; border-radius: 10px; transition: transform .2s; z-index: 1000; max-width: calc(100vw - 32px); }
#toast:not(.show) { visibility: hidden; } #toast.show { transform: translate(-50%, 0); } #toast.error { background: var(--danger); color: #fff; }

/* Agenda */
.grid-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.day-grid { display: grid; position: relative; }
.corner, .col-head { position: sticky; top: 0; background: var(--surface); z-index: 2; border-bottom: 1px solid var(--line); }
.col-head { padding: .5rem; font-weight: 600; border-top: 3px solid; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.times { position: relative; border-right: 1px solid var(--line); }
.times span { position: absolute; right: 6px; transform: translateY(-50%); font-size: .75rem; color: var(--muted); }
.times span:first-child { transform: none; }
.col { position: relative; border-right: 1px solid var(--line); }
.cell { position: absolute; left: 0; right: 0; border: 0; border-radius: 0; padding: 0; border-top: 1px dashed transparent; background: transparent; }
.cell.hour { border-top-color: var(--line); }
.cell.off { background: repeating-linear-gradient(45deg, transparent 0 6px, color-mix(in srgb, var(--line) 55%, transparent) 6px 8px); }
.cell:hover { background: var(--brand-soft); }
.appt { position: absolute; left: 3px; right: 3px; z-index: 1; border-radius: 6px; border: 1px solid var(--line); border-left: 4px solid; background: var(--brand-soft); color: var(--ink); padding: .15rem .4rem; flex-direction: column; align-items: flex-start; gap: 0; overflow: hidden; text-align: left; font-size: .8rem; line-height: 1.25; }
.appt span { color: var(--muted); }
.appt.requested { background: #fef0c7; color: #93370d; border-style: dashed; }
.appt.arrived { background: #d1e9ff; } .appt.done { opacity: .6; } .appt.no_show { opacity: .5; text-decoration: line-through; }
@media (prefers-color-scheme: dark) { .appt.requested { background: #4a2d0b; color: #fec84b; } .appt.arrived { background: #102a56; } }
.booking { border-color: var(--brand); }
.booking p { margin: 0; }
.slot-days { display: flex; flex-direction: column; gap: .5rem; margin-top: .6rem; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .3rem; }
.chip { padding: .3rem .7rem; border-radius: 99px; font-size: .85rem; }
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.chips.days { flex-wrap: nowrap; overflow-x: auto; padding-bottom: .3rem; }
.chips.days .chip { white-space: nowrap; }
.requests { border-color: #fec84b; }

/* Acceso */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: min(400px, 100%); display: flex; flex-direction: column; gap: .9rem; }
.auth .links { display: flex; flex-direction: column; gap: .4rem; align-items: flex-start; }

/* Portal paciente */
.portal { max-width: 720px; margin: 0 auto; padding: 1rem 16px 3rem; }
.portal-head { display: flex; justify-content: space-between; align-items: flex-start; margin: .5rem 0 1rem; }
.portal-head p { margin: .2rem 0 0; }
.portal .list li { flex-wrap: wrap; }
.portal .total { text-align: right; font-weight: 700; margin: .6rem 0 0; }
.portal-foot { text-align: center; }

/* Impresión */
.print-only { display: none; }
@media print {
  .nav, .no-print, #toast { display: none !important; }
  .shell { display: block; } .content { padding: 0; }
  .print-only { display: block; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; border: 0; padding: 0; }
  .print-head h1 { margin: 1rem 0 .3rem; }
}
