:root {
  --bg: #F8FAFC; --surface: #FFFFFF; --line: #E2E8F0; --line-2: #CBD5E1;
  --text: #0F172A; --muted: #64748B;
  --blue: #0284C7; --blue-50: #E0F2FE; --blue-700: #0369A1;
  --mint: #10B981; --mint-50: #D1FAE5; --mint-700: #047857;
  --amber: #B45309; --amber-50: #FEF3C7; --red: #DC2626; --red-50: #FEE2E2;
  --radius: 14px; --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 1px 3px rgba(15, 23, 42, .06);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
h1 { font-size: 22px; margin: 4px 0 20px; }
h2 { font-size: 17px; margin: 0 0 6px; }
.muted { color: var(--muted); font-size: 14px; margin: 0 0 12px; }
.error { color: var(--red); font-size: 14px; min-height: 1em; margin: 8px 0 0; }
input, select, textarea { font: inherit; color: inherit; border: 1px solid var(--line-2); border-radius: var(--radius-sm); padding: 10px 12px; background: var(--surface); width: 100%; min-height: 44px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 3px solid var(--blue-50); border-color: var(--blue); }
label { display: block; font-size: 14px; font-weight: 500; color: #334155; }
label > input, label > select, label > textarea { margin-top: 6px; }

/* Botones */
.btn { font: inherit; font-weight: 600; border: 1px solid transparent; border-radius: var(--radius-sm); padding: 10px 16px; min-height: 44px; cursor: pointer; background: var(--surface); color: var(--text); display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; }
.btn.primary { background: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-700); }
.btn.success { background: var(--mint); color: #fff; }
.btn.success:hover { background: var(--mint-700); }
.btn.ghost { border-color: var(--line-2); }
.btn.ghost:hover { background: var(--bg); }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn.icon { min-width: 44px; padding: 0; font-size: 22px; line-height: 1; border-color: var(--line); }
.btn.danger { color: var(--red); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* Acceso */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; display: grid; gap: 14px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.logo { width: 34px; height: 34px; border-radius: 10px; background: var(--blue); color: #fff; display: grid; place-items: center; font-size: 13px; letter-spacing: .5px; }

/* Barra superior */
.topbar { position: sticky; top: 0; z-index: 5; background: var(--surface); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 16px; padding: 10px 24px; }
.tabs { display: flex; gap: 4px; flex: 1; justify-content: center; }
.tabs button { font: inherit; font-weight: 600; border: 0; background: none; color: var(--muted); padding: 10px 14px; border-radius: var(--radius-sm); cursor: pointer; min-height: 44px; display: inline-flex; align-items: center; gap: 6px; }
.tabs button[aria-selected="true"] { background: var(--blue-50); color: var(--blue-700); }
#app > main { max-width: 1080px; margin: 0 auto; padding: 20px 24px 64px; }
section[data-panel] { display: grid; gap: 16px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.toolbar input[type="search"] { max-width: 320px; }
.spacer { flex: 1; }
.datenav { display: flex; gap: 6px; align-items: center; }
.datenav input { width: auto; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.row-end { display: flex; justify-content: flex-end; margin-top: 12px; }
.badge { background: var(--blue); color: #fff; font-size: 12px; border-radius: 99px; padding: 1px 7px; }
.badge.warn { background: var(--amber); }

/* Estadísticas */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; }
.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 13px; color: var(--muted); }

/* Citas */
.list { display: grid; gap: 10px; }
.appt { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--line-2); border-radius: var(--radius); padding: 14px 16px; display: grid; grid-template-columns: 88px 1fr auto; gap: 14px; align-items: center; box-shadow: var(--shadow); }
.appt.pendiente { border-left-color: #F59E0B; }
.appt.confirmada { border-left-color: var(--blue); }
.appt.completada { border-left-color: var(--mint); }
.appt.cancelada { opacity: .6; }
.appt .time { font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; }
.appt .time small { display: block; font-weight: 500; color: var(--muted); font-size: 13px; }
.appt .who { font-weight: 600; }
.appt .meta { color: var(--muted); font-size: 14px; }
.appt .meta a { color: var(--blue-700); text-decoration: none; }
.appt .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.status { display: inline-block; font-size: 12px; font-weight: 600; border-radius: 99px; padding: 2px 9px; margin-left: 6px; vertical-align: 1px; }
.status.pendiente { background: var(--amber-50); color: var(--amber); }
.status.confirmada { background: var(--blue-50); color: var(--blue-700); }
.status.completada { background: var(--mint-50); color: var(--mint-700); }
.status.cancelada { background: #F1F5F9; color: var(--muted); }
.empty.full { grid-column: 1 / -1; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); background: var(--surface); border: 1px dashed var(--line-2); border-radius: var(--radius); }

/* Disponibilidad */
.daypick, .daystrip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.daypick button, .daystrip button { font: inherit; border: 1px solid var(--line-2); background: var(--surface); border-radius: var(--radius-sm); padding: 8px 4px; cursor: pointer; text-align: center; min-height: 52px; line-height: 1.2; }
.daypick button small, .daystrip button small { display: block; font-size: 12px; color: var(--muted); text-transform: capitalize; }
.daypick button[aria-pressed="true"] { background: var(--blue); border-color: var(--blue); color: #fff; }
.daypick button[aria-pressed="true"] small { color: #E0F2FE; }
.daystrip button[aria-current="true"] { border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue-50); }
.daystrip .count { display: block; font-size: 12px; font-weight: 600; color: var(--mint-700); }
.daystrip .dot { display: none; width: 6px; height: 6px; border-radius: 50%; background: var(--mint); margin: 2px auto 0; }
.sm-only { display: none; }
.daystrip .count.zero { color: var(--muted); font-weight: 500; }
.quick { display: flex; gap: 6px; margin: 10px 0 14px; flex-wrap: wrap; }
.grid-form { display: grid; grid-template-columns: repeat(4, 1fr) auto auto; gap: 12px; align-items: end; }
.seg { border: 0; padding: 0; margin: 0; display: flex; gap: 0; }
.seg legend { font-size: 14px; font-weight: 500; color: #334155; margin-bottom: 6px; padding: 0; }
.seg label { margin: 0; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg span { display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px; border: 1px solid var(--line-2); background: var(--surface); cursor: pointer; font-weight: 600; font-size: 14px; }
.seg label:first-of-type span { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.seg label:last-of-type span { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.seg label + label span { border-left: 0; }
.seg input:checked + span { background: var(--blue-50); color: var(--blue-700); border-color: var(--blue); }
.seg input:focus-visible + span { outline: 3px solid var(--blue-50); }
.seg.inline span { min-height: 36px; }
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.chip { font: inherit; font-size: 14px; font-weight: 600; border-radius: var(--radius-sm); padding: 8px 6px; min-height: 44px; border: 1px solid var(--line-2); background: var(--surface); cursor: pointer; text-align: center; font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 6px; }
.legend .chip { min-height: 0; padding: 2px 10px; font-size: 12px; cursor: default; }
.chip.on { background: var(--blue-50); border-color: var(--blue); color: var(--blue-700); }
.chip.off { color: #94A3B8; border-style: dashed; }
.chip.booked { background: var(--mint-50); border-color: var(--mint); color: var(--mint-700); cursor: not-allowed; }
.chip small { display: block; font-size: 11px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.past { opacity: .45; }

/* Inventario */
.switch { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; }
.switch input { width: 20px; height: 20px; min-height: 0; margin: 0; accent-color: var(--blue); }
.alert { border-radius: var(--radius-sm); padding: 12px 14px; font-size: 14px; }
.alert.warn { background: var(--amber-50); color: #78350F; border: 1px solid #FCD34D; }
.inv { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
.item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 8px; box-shadow: var(--shadow); }
.item.low { border-color: #FCD34D; background: #FFFDF5; }
.item .top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.item .name { font-weight: 600; }
.item .qty { font-weight: 700; font-size: 18px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.item .qty small { font-weight: 500; font-size: 13px; color: var(--muted); }
.bar { height: 6px; background: #F1F5F9; border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--mint); border-radius: 99px; }
.item.low .bar i { background: #F59E0B; }
.item .foot { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.item .foot .btns { display: flex; gap: 6px; }
.lowtag { color: var(--amber); font-weight: 600; }

/* Diálogos */
.dlg { border: 0; border-radius: 18px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 24px); box-shadow: 0 20px 50px rgba(15, 23, 42, .25); color: var(--text); }
.dlg::backdrop { background: rgba(15, 23, 42, .45); }
.dlg form { padding: 20px; display: grid; gap: 14px; }
.dlg header, .dlg footer { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.dlg header h2 { margin: 0; font-size: 19px; }
.dlg footer { justify-content: flex-end; position: sticky; bottom: -20px; background: var(--surface); padding: 12px 0 0; margin-bottom: -4px; }
.dlg .muted { margin: 0; }
.field { display: grid; gap: 6px; }
.label { font-size: 14px; font-weight: 500; color: #334155; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pills button { font: inherit; font-size: 14px; font-weight: 600; border: 1px solid var(--line-2); background: var(--surface); border-radius: 99px; padding: 8px 14px; min-height: 40px; cursor: pointer; }
.pills button[aria-pressed="true"] { background: var(--blue); border-color: var(--blue); color: #fff; }
.supplies { display: grid; gap: 6px; }
.supply { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; padding: 6px 6px 6px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.supply .nm { font-size: 14px; font-weight: 500; }
.supply .nm small { display: block; color: var(--muted); font-weight: 400; }
.supply .nm small.short { color: var(--red); font-weight: 600; }
.stepper { display: flex; align-items: center; border: 1px solid var(--line-2); border-radius: var(--radius-sm); overflow: hidden; }
.stepper button { font: inherit; font-size: 18px; border: 0; background: var(--bg); width: 40px; height: 40px; cursor: pointer; }
.stepper input { width: 52px; min-height: 40px; border: 0; border-radius: 0; text-align: center; padding: 0; margin: 0; -moz-appearance: textfield; }
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; }
.rm { border: 0; background: none; color: var(--muted); font-size: 20px; width: 36px; height: 40px; cursor: pointer; }
.history ul { list-style: none; padding: 0; margin: 8px 0 0; font-size: 13px; display: grid; gap: 4px; max-height: 180px; overflow: auto; }
.history li { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); }
.history li b.neg { color: var(--red); }
.history li b.pos { color: var(--mint-700); }
.history summary { cursor: pointer; font-size: 14px; font-weight: 500; color: var(--blue-700); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--text); color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 14px; font-weight: 500; opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100vw - 32px); z-index: 20; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { background: var(--mint-700); }
.toast.warn { background: var(--amber); }

/* Tablet */
@media (max-width: 900px) {
  .grid-form { grid-template-columns: repeat(2, 1fr); }
  .grid-form .btn { grid-column: 1 / -1; }
}
/* Celular */
@media (max-width: 640px) {
  body { font-size: 15px; }
  .topbar { flex-wrap: wrap; padding: 8px 16px; gap: 8px; }
  .topbar .brand { flex: 1; }
  .tabs { order: 3; flex-basis: 100%; justify-content: stretch; }
  .tabs button { flex: 1; justify-content: center; padding: 8px 6px; font-size: 14px; }
  #app > main { padding: 16px 16px 64px; }
  .card { padding: 16px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .appt { grid-template-columns: 64px 1fr; }
  .appt .actions { grid-column: 1 / -1; justify-content: stretch; }
  .appt .actions .btn { flex: 1; }
  .toolbar > .btn.primary { width: 100%; }
  .toolbar input[type="search"] { max-width: none; }
  .daypick, .daystrip { grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
  .daypick button, .daystrip button { font-size: 13px; padding: 6px 2px; }
  .daystrip .lbl { display: none; }
  .daystrip .dot, .sm-only { display: block; }
  .inv { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}

/* Expediente incrustado: el odontograma se desplaza dentro de su tarjeta, no la página */
#expediente { min-width: 0; max-width: 100%; }
section[data-panel] > * { min-width: 0; }
#expediente .dc-record, #expediente .dc-record > *, #expediente .dc-chart-card > * { min-width: 0; }

/* Consultorio */
.settings h3 { margin: 20px 0 8px; font-size: 16px; }
.settings-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.settings-grid .span-2 { grid-column: 1 / -1; }
.hours { display: grid; gap: 6px; margin-bottom: 12px; }
.hour-row { display: grid; grid-template-columns: 120px 1fr 1fr; gap: 10px; align-items: center; padding: 6px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); transition: background .2s, opacity .2s; }
.hour-row.closed { opacity: .6; background: var(--bg, #F8FAFC); }
.hour-row .switch { font-weight: 600; }
.hour-row label:not(.switch) { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.hour-row label > input[type="time"] { margin-top: 0; min-height: 40px; }
.hour-row .closed-label { grid-column: 2 / -1; color: var(--muted); font-size: 14px; }
.settings .preview { margin: 12px 0 0; }
.settings .preview .muted { margin: 0; }
@media (max-width: 640px) {
  .settings-grid { grid-template-columns: 1fr; }
  .hour-row { grid-template-columns: 1fr 1fr; }
  .hour-row .switch { grid-column: 1 / -1; }
}
