/* ===== Consultorio odontológico — estilos ===== */
:root {
  --primary: #0d9488;
  --bg: #f3f6f9;
  --card: #fff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --red: #dc2626;
  --blue: #2563eb;
  --green: #16a34a;
  --amber: #d97706;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 8px rgba(15, 23, 42, .04);
  --nav-h: 64px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .6em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
code { background: #eef2f6; padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.ic { width: 18px; height: 18px; flex: none; vertical-align: -3px; }
[hidden] { display: none !important; }

/* ----- Estructura ----- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex: none; background: #0f172a; color: #cbd5e1;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; color: #fff; font-weight: 600; line-height: 1.2; }
.brand:hover { text-decoration: none; }
.brand img { max-width: 44px; max-height: 44px; border-radius: 8px; background: #fff; padding: 3px; object-fit: contain; }
.brand-ic { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: var(--primary); color: #fff; flex: none; }
.brand-ic .ic { width: 22px; height: 22px; }
.brand-ic.big { width: 60px; height: 60px; border-radius: 16px; }
.brand-ic.big .ic { width: 34px; height: 34px; }
.nav { display: flex; flex-direction: column; gap: 2px; padding: 8px; flex: 1; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 8px; color: #cbd5e1; font-weight: 500; }
.nav a:hover { background: rgba(255, 255, 255, .06); text-decoration: none; color: #fff; }
.nav a.active { background: var(--primary); color: #fff; }
.sidebar-user { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-top: 1px solid rgba(255, 255, 255, .08); font-size: .9rem; }
.sidebar-user a { color: #94a3b8; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 14px 24px; background: var(--card);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 1.2rem; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-brand { display: none; }
.topbar-brand img { height: 32px; max-width: 60px; object-fit: contain; display: block; }
.topbar-brand .brand-ic { width: 32px; height: 32px; }
.topbar-actions { display: flex; gap: 8px; }
.back { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; color: var(--text); }
.back:hover { background: var(--bg); }
.content { padding: 24px; max-width: 1200px; width: 100%; }

/* ----- Componentes ----- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: 18px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 16px; }
.cols { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
a.stat { color: var(--text); }
a.stat:hover { text-decoration: none; border-color: var(--primary); }
.stat b { display: block; font-size: 1.6rem; line-height: 1.1; }
.stat span { color: var(--muted); font-size: .85rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 14px;
  border-radius: 9px; border: 1px solid transparent; background: var(--primary); color: #fff; font: inherit;
  font-weight: 600; cursor: pointer; white-space: nowrap; line-height: 1.2; min-height: 40px;
}
.btn:hover { text-decoration: none; filter: brightness(.95); }
.btn-light { background: var(--card); color: var(--text); border-color: var(--border); }
.btn-danger { background: #fff; color: var(--red); border-color: #fecaca; }
.btn-wa { background: #16a34a; }
.btn-sm { padding: 5px 10px; min-height: 32px; font-size: .85rem; }
.btn-block { width: 100%; }
.btn-icon { padding: 0; width: 36px; min-height: 36px; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; }

.alert { padding: 11px 14px; border-radius: 10px; margin-bottom: 14px; border: 1px solid; }
.alert-ok { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.alert-error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-warn { background: #fffbeb; border-color: #fde68a; color: #92400e; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .78rem; font-weight: 600; background: #eef2f6; color: var(--muted); white-space: nowrap; }
.b-pendiente { background: #fef3c7; color: #92400e; }
.b-confirmado { background: #dbeafe; color: #1e40af; }
.b-atendido { background: #dcfce7; color: #166534; }
.b-ausente { background: #fee2e2; color: #991b1b; }
.b-cancelado { background: #f1f5f9; color: #64748b; text-decoration: line-through; }

/* ----- Formularios ----- */
.form label, label.field { display: block; margin-bottom: 14px; font-weight: 500; font-size: .9rem; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=time], input[type=number],
input[type=tel], input[type=search], input:not([type]), select, textarea {
  display: block; width: 100%; margin-top: 5px; padding: 10px 12px; font: inherit; font-size: 16px; color: var(--text);
  background: #fff; border: 1px solid #cbd5e1; border-radius: 9px; min-height: 42px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 35%, transparent); border-color: var(--primary); }
input[type=file] { margin-top: 6px; max-width: 100%; }
.radios { margin-bottom: 14px; }
.radio { display: flex !important; gap: 8px; align-items: flex-start; font-weight: 400 !important; }
.radio input { margin-top: 4px; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.hint { font-size: .8rem; color: var(--muted); font-weight: 400; }
fieldset { border: 0; padding: 0; margin: 0 0 8px; }
legend { font-weight: 700; margin-bottom: 10px; padding: 0; }
.search-bar { display: flex; gap: 8px; margin-bottom: 16px; }
.search-bar input { margin: 0; }

/* ----- Tablas (se transforman en tarjetas en el celular) ----- */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border); }
.table td { padding: 11px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .actions { text-align: right; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 26px 10px; }

/* ----- Listas ----- */
.list { list-style: none; margin: 0; padding: 0; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-main { flex: 1; min-width: 0; }
.list-main b, .list-main a { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.time { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 52px; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: color-mix(in srgb, var(--primary) 15%, #fff); color: var(--primary); display: grid; place-items: center; font-weight: 700; flex: none; }
.avatar.big { width: 64px; height: 64px; font-size: 1.4rem; }

/* ----- Paciente ----- */
.patient-head { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.patient-head .info { flex: 1; min-width: 200px; }
.patient-head h2 { margin: 0 0 4px; font-size: 1.3rem; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 16px; color: var(--muted); font-size: .9rem; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: 10px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--primary); border-color: var(--primary); text-decoration: none; }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 12px; }
.kv dt { color: var(--muted); font-size: .88rem; }
.kv dd { margin: 0; white-space: pre-line; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 0 0 18px 22px; border-left: 2px solid var(--border); margin-left: 6px; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: var(--primary); }
.timeline li:last-child { border-color: transparent; }
.timeline .when { font-weight: 700; }
.timeline p { margin: 4px 0; white-space: pre-line; }

/* ----- Agenda ----- */
.date-nav { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.date-nav input { width: auto; margin: 0; }
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; margin-bottom: 16px; }
.day {
  display: flex; flex-direction: column; align-items: center; padding: 8px 2px; border-radius: 10px; background: var(--card);
  border: 1px solid var(--border); color: var(--text); font-size: .8rem; position: relative;
}
.day b { font-size: 1.15rem; }
.day:hover { text-decoration: none; border-color: var(--primary); }
.day.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.day.today:not(.active) { border-color: var(--primary); color: var(--primary); }
.day .count { position: absolute; top: 4px; right: 5px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--amber); color: #fff; font-size: .7rem; display: grid; place-items: center; padding: 0 4px; }
.slot { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--card); margin-bottom: 8px; }
.slot.free { background: transparent; border-style: dashed; color: var(--muted); }
.slot.free:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.slot.st-cancelado { opacity: .55; }
.slot.st-atendido { border-left: 4px solid var(--green); }
.slot.st-confirmado { border-left: 4px solid var(--blue); }
.slot.st-pendiente { border-left: 4px solid var(--amber); }
.slot.st-ausente { border-left: 4px solid var(--red); }
.slot .list-main small { color: var(--muted); }
.slot-actions { display: flex; gap: 6px; align-items: center; }
.slot-actions select { width: auto; margin: 0; min-height: 34px; padding: 4px 8px; font-size: .85rem; }

/* ----- Buscador de pacientes ----- */
.picker { position: relative; }
.picker-list { position: absolute; left: 0; right: 0; top: 100%; z-index: 30; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, .12); max-height: 280px; overflow: auto; }
.picker-list button { display: block; width: 100%; text-align: left; padding: 10px 12px; border: 0; background: none; font: inherit; cursor: pointer; border-bottom: 1px solid var(--border); }
.picker-list button:hover, .picker-list button:focus { background: var(--bg); }
.picker-list small { color: var(--muted); }
.picker-selected { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 5px; padding: 9px 12px; border-radius: 9px; background: color-mix(in srgb, var(--primary) 10%, #fff); border: 1px solid color-mix(in srgb, var(--primary) 35%, #fff); font-weight: 600; }

/* ----- Recetas ----- */
.med-row { display: grid; grid-template-columns: 2fr .7fr 2fr auto; gap: 8px; align-items: end; margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px dashed var(--border); }
.med-row label { margin: 0 !important; }
.paper { background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 26px; max-width: 620px; box-shadow: 0 4px 18px rgba(0, 0, 0, .06); }
.paper-head { display: flex; gap: 16px; align-items: center; border-bottom: 2px solid var(--primary); padding-bottom: 12px; margin-bottom: 14px; }
.paper-head img { max-height: 60px; max-width: 120px; object-fit: contain; }
.paper .rp { font-size: 1.4rem; font-weight: 800; margin: 14px 0 6px; }
.paper ol { padding-left: 20px; }
.paper li { margin-bottom: 8px; }
.paper .firma { margin-top: 40px; text-align: right; }
.paper .firma img { max-height: 70px; display: block; margin-left: auto; }
.paper .firma span { display: inline-block; border-top: 1px solid #333; padding-top: 4px; min-width: 200px; text-align: center; font-size: .85rem; }

/* ----- Odontograma ----- */
.odonto-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 6px; }
.odonto-wrap svg { display: block; min-width: 640px; width: 100%; max-width: 980px; margin: 0 auto; user-select: none; -webkit-user-select: none; }
.odonto-wrap.readonly svg { min-width: 560px; }
.odonto-face { stroke: #64748b; stroke-width: 1; cursor: pointer; transition: opacity .1s; }
.odonto-face:hover { opacity: .75; }
.readonly .odonto-face { cursor: default; }
.readonly .odonto-face:hover { opacity: 1; }
.odonto-num { font: 600 11px system-ui, sans-serif; fill: #334155; cursor: pointer; }
.odonto-num:hover { fill: var(--primary); }
.odonto-num.has-note { fill: var(--primary); text-decoration: underline; }
.tools { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.tool { display: inline-flex; align-items: center; gap: 6px; padding: 7px 10px; border-radius: 99px; border: 1px solid var(--border); background: #fff; cursor: pointer; font-size: .85rem; font-weight: 500; user-select: none; }
.tool input { display: none; }
.tool .sw { width: 14px; height: 14px; border-radius: 3px; border: 2px solid currentColor; flex: none; }
.tool.on { border-color: var(--text); box-shadow: 0 0 0 2px var(--text) inset; }
.tool-group { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; width: 100%; margin-top: 4px; }
.save-state { font-size: .85rem; color: var(--muted); }
.save-state.ok { color: var(--green); }
.save-state.err { color: var(--red); }
.legend-list { columns: 2; column-gap: 24px; font-size: .9rem; padding-left: 18px; margin: 0; }
.legend-list li { break-inside: avoid; margin-bottom: 4px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
dialog { border: 0; border-radius: 16px; padding: 0; width: min(440px, calc(100vw - 24px)); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
dialog::backdrop { background: rgba(15, 23, 42, .5); }
.dlg-body { padding: 18px; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.dlg-head h3 { margin: 0; }
.tooth-big { display: block; width: 190px; height: 190px; margin: 0 auto 6px; }
.tooth-big text { font: 700 14px system-ui, sans-serif; pointer-events: none; }
.sw-sym { display: inline-grid; place-items: center; width: 16px; font-weight: 800; }
.mark-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 12px 0; }
.mark-btns button { padding: 9px 8px; border-radius: 9px; border: 1px solid var(--border); background: #fff; font: inherit; font-size: .85rem; cursor: pointer; text-align: left; display: flex; gap: 6px; align-items: center; }
.mark-btns button.on { border-color: currentColor; box-shadow: 0 0 0 1px currentColor inset; font-weight: 700; }

/* ----- Páginas simples ----- */
body.simple { display: flex; justify-content: center; padding: 30px 16px; }
.simple-box { width: 100%; max-width: 560px; }
.simple-head { text-align: center; margin-bottom: 18px; }
.simple-head h1 { margin: 10px 0 4px; font-size: 1.4rem; }
.login-logo { max-height: 90px; max-width: 220px; object-fit: contain; }
.checklist { list-style: none; padding: 0; margin: 0; columns: 1; }
.checklist li { padding: 3px 0; }
.checklist .ok { color: var(--green); }
.checklist .bad { color: var(--red); font-weight: 600; }
.checklist .warn { color: var(--amber); }
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 14px; }
.logo-preview { max-height: 80px; max-width: 220px; object-fit: contain; border: 1px solid var(--border); border-radius: 8px; padding: 6px; background: #fff; display: block; margin-bottom: 8px; }

/* ===== Tablet ===== */
@media (max-width: 1000px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols { grid-template-columns: 1fr; }
  .sidebar { width: 76px; }
  .brand span:not(.brand-ic), .nav a span, .sidebar-user span { display: none; }
  .brand { justify-content: center; padding: 16px 8px; }
  .nav a { justify-content: center; }
  .sidebar-user { justify-content: center; }
}

/* ===== Celular ===== */
@media (max-width: 720px) {
  body { font-size: 15px; }
  .app { display: block; }
  .sidebar {
    position: fixed; bottom: 0; left: 0; right: 0; top: auto; width: 100%; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
    z-index: 50; padding-bottom: env(safe-area-inset-bottom); background: #fff; border-top: 1px solid var(--border); flex-direction: row;
  }
  .brand, .sidebar-user { display: none; }
  .nav { flex-direction: row; padding: 0; gap: 0; }
  .nav a { flex: 1; flex-direction: column; gap: 2px; padding: 9px 2px; border-radius: 0; color: var(--muted); font-size: .68rem; }
  .nav a span { display: block !important; }
  .nav a .ic { width: 22px; height: 22px; }
  .nav a.active { background: none; color: var(--primary); }
  .nav a:hover { background: none; color: var(--primary); }
  .main { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
  .topbar { padding: 10px 14px; }
  .topbar-brand { display: block; }
  .topbar:has(.back) .topbar-brand { display: none; }
  .topbar h1 { font-size: 1.05rem; }
  .topbar-actions .btn span { display: none; }
  .content { padding: 14px; }
  .card { padding: 14px; border-radius: 12px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .stats { gap: 10px; }
  .stat b { font-size: 1.35rem; }
  .kv { grid-template-columns: 1fr; gap: 0; }
  .kv dd { margin-bottom: 8px; }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: 10px 0; border-bottom: 1px solid var(--border); }
  .table tr:last-child { border-bottom: 0; }
  .table td { border: 0; padding: 2px 0; }
  .table td[data-label]:not([data-label=""])::before { content: attr(data-label) ": "; color: var(--muted); font-size: .85rem; }
  .table .actions { text-align: left; padding-top: 6px; }
  .med-row { grid-template-columns: 1fr 90px; }
  .med-row .med-pos { grid-column: 1 / -1; }
  .med-row .med-del { grid-column: 2; grid-row: 1; align-self: end; }
  .med-row .med-name { grid-column: 1; }
  .med-row .med-cant { grid-column: 1 / -1; }
  .slot { flex-wrap: wrap; }
  .slot-actions { width: 100%; justify-content: flex-end; }
  .legend-list { columns: 1; }
  .tools { gap: 5px; }
  .tool { padding: 5px 9px; font-size: .78rem; }
  .paper { padding: 16px; }
  .week .day { font-size: .7rem; }
  .btns .btn { flex: 1 1 auto; }
}

/* ===== Impresión ===== */
@media print {
  .sidebar, .topbar, .no-print, .btns, .tabs { display: none !important; }
  .main, .content { padding: 0; }
  .card { box-shadow: none; border: 0; }
}
