:root {
  --bg: #f3f6f7; --card: #fff; --ink: #14272b; --muted: #5d7276; --line: #dde5e7;
  --brand: #0f766e; --brand-d: #0b5a54; --brand-l: #d9f1ee;
  --warn: #b45309; --warn-l: #fef3c7; --bad: #b91c1c; --bad-l: #fee2e2; --ok: #166534; --ok-l: #dcfce7; --info-l: #e0eefc; --info: #1d4f91;
  --radius: 12px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
h1 { font-size: 1.4rem; margin: 0 0 .25rem; } h2 { font-size: 1.1rem; margin: 0 0 .75rem; } h3 { font-size: 1rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: .5rem .9rem; border-radius: 8px; }
button:hover { background: #f1f6f7; }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; } button.primary:hover { background: var(--brand-d); }
button.danger { color: var(--bad); border-color: #f3c4c4; } button.danger:hover { background: var(--bad-l); }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { width: 100%; padding: .55rem .7rem; border: 1px solid #c8d4d7; border-radius: 8px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
label { display: block; font-size: .85rem; color: var(--muted); margin: .6rem 0 .2rem; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; } .row > * { flex: 0 0 auto; } .row .grow { flex: 1 1 200px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: .75rem; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login .box { width: 100%; max-width: 400px; background: var(--card); padding: 2rem; border-radius: 16px; box-shadow: 0 8px 30px rgba(15,60,60,.12); }
.logo { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.2rem; color: var(--brand-d); }
.logo i { width: 34px; height: 34px; border-radius: 9px; background: var(--brand); display: grid; place-items: center; color: #fff; font-style: normal; }
.demo-box { margin-top: 1rem; background: var(--brand-l); border-radius: 10px; padding: .75rem; font-size: .85rem; }
.demo-box button { padding: .25rem .5rem; font-size: .8rem; margin: .15rem .15rem 0 0; }
.err { color: var(--bad); font-size: .9rem; min-height: 1.2em; margin-top: .5rem; }

/* layout */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { background: #0e2f33; color: #cfe3e5; padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .logo { color: #fff; margin: .2rem .5rem 1rem; }
.side .clinic { font-size: .8rem; opacity: .8; margin: 0 .5rem 1rem; }
.side a { display: flex; gap: .6rem; align-items: center; color: inherit; text-decoration: none; padding: .55rem .7rem; border-radius: 8px; margin-bottom: 2px; }
.side a:hover { background: rgba(255,255,255,.08); } .side a.on { background: var(--brand); color: #fff; }
.side .badge { margin-left: auto; }
.side .user { margin: 1rem .5rem 0; font-size: .85rem; border-top: 1px solid rgba(255,255,255,.15); padding-top: .8rem; }
.side .user button { margin-top: .5rem; background: transparent; color: #cfe3e5; border-color: rgba(255,255,255,.3); width: 100%; }
.main { padding: 1.25rem 1.5rem 3rem; min-width: 0; }
.top { display: none; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.page-head { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }

@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .top { display: flex; align-items: center; justify-content: space-between; background: #0e2f33; color: #fff; padding: .6rem 1rem; position: sticky; top: 0; z-index: 20; }
  .top button { background: transparent; color: #fff; border-color: rgba(255,255,255,.35); }
  .side { position: fixed; z-index: 30; left: 0; top: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
  .main { padding: 1rem 1rem 3rem; }
}

/* piezas */
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 99px; font-size: .75rem; font-weight: 600; background: #e8eef0; color: #334; white-space: nowrap; }
.badge.ok { background: var(--ok-l); color: var(--ok); } .badge.warn { background: var(--warn-l); color: var(--warn); } .badge.bad { background: var(--bad-l); color: var(--bad); } .badge.info { background: var(--info-l); color: var(--info); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; }
.kpi b { display: block; font-size: 1.7rem; line-height: 1.1; } .kpi span { color: var(--muted); font-size: .85rem; }
.tablewrap { overflow-x: auto; } table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .6rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; } th { font-size: .8rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
tr.click { cursor: pointer; } tr.click:hover { background: #f5fafa; }
.bars .bar { display: grid; grid-template-columns: 110px 1fr 36px; gap: .5rem; align-items: center; margin: .3rem 0; font-size: .85rem; }
.bars .track { background: #e8f0f1; border-radius: 6px; height: 14px; overflow: hidden; } .bars .fill { background: var(--brand); height: 100%; }
.alert { padding: .75rem 1rem; border-radius: 10px; margin-bottom: .6rem; background: var(--info-l); color: var(--info); }
.alert.urgent { background: var(--bad-l); color: var(--bad); } .alert.warn { background: var(--warn-l); color: var(--warn); }

/* calendario */
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .5rem; }
.day { background: var(--card); border: 1px solid var(--line); border-radius: 10px; min-height: 120px; padding: .5rem; }
.day.today { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.day h4 { margin: 0 0 .4rem; font-size: .8rem; text-transform: capitalize; color: var(--muted); }
.appt { display: block; width: 100%; text-align: left; padding: .35rem .45rem; margin-bottom: .3rem; border-radius: 7px; font-size: .78rem; border: 1px solid transparent; background: var(--brand-l); }
.appt b { display: block; } .appt.completed { background: var(--ok-l); } .appt.cancelled { background: #eee; color: #777; text-decoration: line-through; } .appt.no_show { background: var(--warn-l); }
@media (max-width: 1000px) { .week { grid-template-columns: 1fr; } .day { min-height: 0; } }

/* modal */
.backdrop { position: fixed; inset: 0; background: rgba(10,30,30,.5); display: grid; place-items: center; padding: 1rem; z-index: 50; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; padding: 1.25rem; }
.modal .actions { display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap; margin-top: 1rem; }

/* conversaciones y chat */
.convs { display: grid; grid-template-columns: 320px 1fr; gap: 1rem; align-items: start; }
.convlist { max-height: 70vh; overflow-y: auto; } .convitem { padding: .65rem .8rem; border-bottom: 1px solid var(--line); cursor: pointer; } .convitem:hover, .convitem.on { background: #f1f8f8; }
.convitem .last { color: var(--muted); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat { display: flex; flex-direction: column; height: 62vh; min-height: 360px; }
.msgs { flex: 1; overflow-y: auto; padding: .75rem; background: #e9f0ec; border-radius: 10px; display: flex; flex-direction: column; gap: .4rem; }
.bubble { max-width: 82%; padding: .5rem .75rem; border-radius: 12px; background: #fff; word-wrap: break-word; box-shadow: 0 1px 1px rgba(0,0,0,.08); font-size: .92rem; }
.bubble.me { align-self: flex-end; background: #d8f7c8; } .bubble.staff { background: #dbeafe; } .bubble small { display: block; color: var(--muted); font-size: .7rem; margin-top: .15rem; }
.chat form { display: flex; gap: .5rem; margin-top: .6rem; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin: .6rem 0 0; } .chips button { padding: .25rem .6rem; font-size: .8rem; border-radius: 99px; }
@media (max-width: 800px) { .convs { grid-template-columns: 1fr; } .convlist { max-height: 30vh; } }
.sched-row { display: grid; grid-template-columns: 1.2fr 1fr 1fr auto; gap: .4rem; margin-bottom: .4rem; align-items: center; }
.hours-row { display: grid; grid-template-columns: 90px 1fr 1fr; gap: .4rem; margin-bottom: .3rem; align-items: center; }

/* ajustes de responsividad */
[hidden] { display: none !important; }
.hours-row { grid-template-columns: 82px minmax(0, 1fr) minmax(0, 1fr); }
.hours-row input, .sched-row input, .sched-row select { min-width: 0; }
.alert { overflow-wrap: anywhere; }
.sched-row { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1fr) auto; }
.alert .row > b { flex: 1 1 60%; min-width: 0; }
.badge { white-space: normal; }
