/* CRM Dra. Julia Ardaya — colores del logo: dorado y gris cálido.
   Tres tamaños: computadora (menú lateral completo), tablet (menú de íconos) y celular (barra inferior). */

:root {
  --bg: #faf8f3;
  --surface: #ffffff;
  --surface-2: #f6f2e7;
  --surface-3: #efe9d9;
  --border: #ebe5d5;
  --text: #36322e;
  --muted: #857e76;
  --gold: #c9a61f;
  --gold-dark: #8a7012;
  --gold-soft: #f8f1d6;
  --gray: #5f5a54;
  --ok: #3f7d5c;
  --ok-soft: #e3f1e8;
  --warn: #a4741a;
  --warn-soft: #faefd9;
  --danger: #b14a43;
  --danger-soft: #f8e2df;
  --info: #4d6f9e;
  --info-soft: #e4ebf6;
  --wa: #1fae55;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(60, 45, 20, .04), 0 4px 16px rgba(60, 45, 20, .05);
  --shadow-lg: 0 20px 60px rgba(40, 30, 10, .18);
  --sidebar: 252px;
  --tabbar: 64px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: "Cormorant Garamond", Georgia, serif; font-weight: 600; margin: 0; letter-spacing: .01em; }
h1 { font-size: 34px; line-height: 1.1; }
h2 { font-size: 27px; line-height: 1.15; }
h3 { font-size: 21px; }
h4 { font-size: 17px; }
a { color: var(--gold-dark); }
p { margin: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); font-size: 14px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
svg.i { width: 20px; height: 20px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
svg.i.sm { width: 16px; height: 16px; }
svg.i.lg { width: 26px; height: 26px; }

/* ---------- Formularios ---------- */
input, select, textarea {
  font: inherit; width: 100%; padding: 11px 13px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23857e76' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px; }
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--gold); }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; cursor: pointer; }

/* ---------- Botones ---------- */
.btn {
  font: inherit; font-weight: 500; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 16px; min-height: 42px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--gray); border-color: var(--gray); color: #fff; }
.btn.primary:hover { background: var(--text); }
.btn.gold { background: var(--gold); border-color: var(--gold); color: #fff; }
.btn.gold:hover { background: var(--gold-dark); }
.btn.wa { background: var(--wa); border-color: var(--wa); color: #fff; }
.btn.wa:hover { filter: brightness(.94); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger-soft); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 6px 11px; min-height: 34px; font-size: 13px; }
.btn.block { width: 100%; }
.btn.icon { padding: 0; width: 42px; }
.btn.icon.sm { width: 34px; }
.icon-btn { border: 0; background: transparent; cursor: pointer; color: var(--muted); padding: 8px; border-radius: 8px; display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------- Login ---------- */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(circle at 15% 15%, #f6ecc6 0, transparent 45%), radial-gradient(circle at 85% 85%, #ece6d8 0, transparent 45%), var(--bg); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); padding: 30px 28px; border-radius: 22px;
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column; gap: 14px; }
.login-card .muted { text-align: center; margin-top: -4px; }
.logo { display: block; width: 100%; aspect-ratio: 750 / 490; object-fit: cover; object-position: center 55%; }
.login-logo { max-width: 290px; margin: 0 auto; }

/* ---------- Estructura ---------- */
.app { min-height: 100vh; min-height: 100dvh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar); z-index: 30;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 14px; gap: 12px; overflow-y: auto;
}
.sidebar-logo { max-width: 190px; margin: 0 auto; }
.brand-mark { width: 40px; height: 40px; border-radius: 50%; display: none; place-items: center; flex-shrink: 0;
  background: linear-gradient(135deg, var(--gold), #e3c95f); color: #fff; font-family: "Cormorant Garamond", serif; font-size: 18px; font-weight: 600; }
.search-btn { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg); color: var(--muted); font: inherit; font-size: 14px; cursor: pointer; }
.search-btn:hover { border-color: var(--gold); }
.search-btn kbd { margin-left: auto; font-family: inherit; font-size: 11px; background: var(--surface); border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--radius-sm); color: var(--text); text-decoration: none; font-weight: 500; font-size: 14.5px; position: relative; }
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--gold-soft); color: var(--gold-dark); }
.nav a.active::before { content: ""; position: absolute; left: -14px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--gold); }
.nav .dot { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 600; display: grid; place-items: center; }
.sidebar-foot { display: flex; flex-direction: column; gap: 6px; border-top: 1px solid var(--border); padding-top: 10px; }
.sync-state { font-size: 12px; color: var(--ok); display: flex; align-items: center; gap: 6px; justify-content: center; }
.sync-state.busy { color: var(--muted); }
.sync-state.offline { color: var(--danger); font-weight: 600; }

.mobile-top { display: none; }
.tabbar { display: none; }

.main { margin-left: var(--sidebar); padding: 30px 36px 70px; max-width: calc(1240px + var(--sidebar)); }

/* ---------- Encabezados de página ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head .sub { color: var(--muted); margin-top: 6px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; font-size: 14px; margin-bottom: 10px; }
.back:hover { color: var(--text); }

/* ---------- Tarjetas ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush .card-head { padding: 18px 20px 0; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h3 { display: flex; align-items: center; gap: 8px; }
.card-head h3 svg { color: var(--gold); }
.grid { display: grid; gap: 16px; }
.grid > *, .stack > * { min-width: 0; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.dash { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); align-items: start; }

.hero { background: linear-gradient(120deg, #fffdf6 0%, #f8efcf 100%); border: 1px solid #efe2b4; border-radius: 20px; padding: 24px 26px; margin-bottom: 18px;
  display: flex; justify-content: space-between; align-items: center; gap: 18px; flex-wrap: wrap; }
.hero h1 { font-size: 36px; }
.hero .date { color: var(--gold-dark); text-transform: capitalize; margin-top: 4px; font-weight: 500; }
.quick { display: flex; gap: 8px; flex-wrap: wrap; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); display: flex; gap: 14px; align-items: center; text-decoration: none; color: inherit; min-width: 0; }
a.stat:hover { border-color: var(--gold); }
.stat .ico { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--gold-soft); color: var(--gold-dark); flex-shrink: 0; }
.stat .ico.ok { background: var(--ok-soft); color: var(--ok); }
.stat .ico.info { background: var(--info-soft); color: var(--info); }
.stat .ico.warn { background: var(--warn-soft); color: var(--warn); }
.stat .val { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .lbl { font-size: 13px; color: var(--muted); }

.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; font-size: 14px; }
.alert svg { margin-top: 1px; }
.alert.danger { background: var(--danger-soft); color: var(--danger); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.info { background: var(--info-soft); color: var(--info); }

/* ---------- Listas ---------- */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 2px; border-bottom: 1px solid var(--border); min-width: 0; }
.list-item:last-child { border-bottom: 0; }
.list-item.link { cursor: pointer; border-radius: 10px; }
.list-item.link:hover { background: var(--surface-2); }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .end { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.time-pill { font-weight: 600; font-size: 13px; background: var(--surface-2); padding: 6px 8px; border-radius: 10px; min-width: 60px; text-align: center; line-height: 1.25; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.time-pill small { display: block; font-weight: 500; color: var(--muted); font-size: 11px; }
.empty { color: var(--muted); padding: 26px 8px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; font-size: 14px; }
.empty svg { width: 34px; height: 34px; color: var(--border); stroke-width: 1.5; }

.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--gold-soft); color: var(--gold-dark);
  display: grid; place-items: center; font-weight: 600; flex-shrink: 0; font-size: 14px; }
.avatar.lg { width: 68px; height: 68px; font-size: 24px; font-family: "Cormorant Garamond", serif; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.gold { background: var(--gold-soft); color: var(--gold-dark); }

/* ---------- Tablas (se vuelven tarjetas en celular) ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--bg); }
tbody tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #fdfbf5; }
.right { text-align: right !important; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.cell-user { display: flex; align-items: center; gap: 10px; min-width: 0; }
.cell-user .name { font-weight: 500; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; align-items: center; }
.toolbar .search { position: relative; flex: 1; min-width: 200px; max-width: 380px; }
.toolbar .search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.toolbar .search input { padding-left: 38px; }
.toolbar select, .toolbar input[type="month"] { width: auto; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { font: inherit; font-size: 13.5px; font-weight: 500; border: 0; background: transparent; padding: 7px 14px; border-radius: 9px; cursor: pointer; color: var(--muted); white-space: nowrap; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }

/* ---------- Pestañas ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: 20px 0 18px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { font: inherit; font-size: 14px; border: 0; background: transparent; padding: 11px 14px; cursor: pointer; color: var(--muted); font-weight: 500;
  border-bottom: 2px solid transparent; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.tabs button.active { color: var(--gold-dark); border-bottom-color: var(--gold); }
.tabs .count { font-size: 11px; background: var(--surface-2); border-radius: 8px; padding: 1px 7px; }

/* ---------- Ficha del cliente ---------- */
.client-head { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.client-head .grow { flex: 1; min-width: 220px; }
.client-head .meta { display: flex; gap: 6px 16px; flex-wrap: wrap; color: var(--muted); font-size: 14px; margin-top: 6px; }
.client-head .meta span { display: inline-flex; align-items: center; gap: 5px; }
.client-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.mini-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
.mini-stats div { background: var(--bg); border-radius: 12px; padding: 10px 14px; }
.mini-stats b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.mini-stats span { font-size: 12px; color: var(--muted); }

.dl { display: grid; grid-template-columns: 170px 1fr; gap: 10px 16px; margin: 0; }
.dl dt { color: var(--muted); font-size: 13px; }
.dl dd { margin: 0; white-space: pre-wrap; word-break: break-word; }

.timeline { display: flex; flex-direction: column; gap: 4px; }
.tl-item { position: relative; padding: 4px 0 18px 26px; }
.tl-item::before { content: ""; position: absolute; left: 6px; top: 10px; bottom: -4px; width: 2px; background: var(--border); }
.tl-item:last-child::before { display: none; }
.tl-item::after { content: ""; position: absolute; left: 1px; top: 6px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 3px solid var(--gold); }
.tl-item .tl-date { font-size: 13px; color: var(--muted); }
.tl-item .tl-title { font-weight: 600; margin-top: 2px; }
.tl-item p { margin-top: 4px; white-space: pre-wrap; font-size: 14px; }
.tl-item .tl-actions { margin-top: 8px; display: flex; gap: 6px; }

/* Fotos */
.photo-cols { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.photo { position: relative; border-radius: 12px; overflow: hidden; aspect-ratio: 1; background: var(--surface-2); cursor: zoom-in; border: 0; padding: 0; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo .cap { position: absolute; inset: auto 0 0; padding: 18px 8px 6px; font-size: 11px; color: #fff; background: linear-gradient(transparent, rgba(0, 0, 0, .55)); text-align: left; }
.photo-view img { width: 100%; max-height: 70vh; object-fit: contain; border-radius: 12px; background: #111; }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.compare img { width: 100%; aspect-ratio: 3/4; object-fit: cover; border-radius: 12px; }
.compare .lbl { text-align: center; font-weight: 600; margin-top: 6px; font-size: 13px; }

/* ---------- Formularios ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-section { font-family: "Cormorant Garamond", serif; font-size: 19px; font-weight: 600; color: var(--gold-dark); margin-top: 8px; grid-column: 1 / -1; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 6px; }
.form-actions .spacer { flex: 1; }
.with-btn { display: flex; gap: 6px; }
.with-btn select, .with-btn input { flex: 1; min-width: 0; }

/* Editor de cotización */
.items { display: flex; flex-direction: column; gap: 8px; }
.item-row { display: grid; grid-template-columns: minmax(0, 1fr) 76px 120px 120px 36px; gap: 8px; align-items: center; }
.item-row .sub { text-align: right; font-weight: 500; font-variant-numeric: tabular-nums; }
.items-head { font-size: 11.5px; text-transform: uppercase; color: var(--muted); font-weight: 600; letter-spacing: .05em; }
.totals { margin-left: auto; width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 6px; margin-top: 12px; font-variant-numeric: tabular-nums; }
.totals div { display: flex; justify-content: space-between; gap: 10px; }
.totals .grand { font-size: 21px; font-weight: 600; border-top: 1px solid var(--border); padding-top: 8px; color: var(--gold-dark); }
.sticky-actions { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 18px 0 4px; z-index: 5; }

/* Documento (cotización / recibo) */
.doc { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 40px; max-width: 820px; box-shadow: var(--shadow); }
.doc-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 2px solid var(--gold-soft); padding-bottom: 18px; margin-bottom: 20px; flex-wrap: wrap; align-items: flex-start; }
.doc-logo { width: 220px; margin-left: -10px; }
.doc .doc-meta { text-align: right; font-size: 14px; }
.doc .doc-meta h3 { color: var(--gold-dark); }
.doc table { margin: 16px 0; }
.doc th { background: var(--surface-2); }
.doc-foot { margin-top: 26px; font-size: 13px; color: var(--muted); white-space: pre-wrap; border-top: 1px solid var(--border); padding-top: 14px; }

/* ---------- Calendario ---------- */
.cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.cal-head h3 { margin: 0 6px; min-width: 170px; text-transform: capitalize; }
.cal-head .seg { margin-left: auto; }
.cal-layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 16px; align-items: start; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); box-shadow: var(--shadow); }
.cal .dow { padding: 9px 4px; font-size: 11.5px; font-weight: 600; text-transform: uppercase; color: var(--muted); text-align: center; background: var(--bg); letter-spacing: .04em; }
.cal .day { min-height: 108px; border-top: 1px solid var(--border); border-left: 1px solid var(--border); padding: 6px; cursor: pointer; display: flex; flex-direction: column; gap: 3px; min-width: 0; background: var(--surface); }
.cal .day:nth-child(7n+1) { border-left: 0; }
.cal .day:hover { background: #fdfbf5; }
.cal .day.other { background: #fbfaf6; }
.cal .day.other .dnum { color: #c9c1b6; }
.cal .day.today .dnum { background: var(--gold); color: #fff; }
.cal .day.selected { box-shadow: inset 0 0 0 2px var(--gold); }
.cal .dnum { font-size: 13px; font-weight: 600; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-variant-numeric: tabular-nums; }
.chip { font-size: 11px; padding: 2px 6px; border-radius: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.t-cita { background: var(--gold-soft); color: var(--gold-dark); }
.t-control { background: var(--info-soft); color: var(--info); }
.t-procedimiento { background: var(--ok-soft); color: var(--ok); }
.t-otro { background: var(--warn-soft); color: var(--warn); }
.chip.cancelada { text-decoration: line-through; opacity: .55; }
.dots { display: none; gap: 3px; flex-wrap: wrap; justify-content: center; }
.dots i { width: 6px; height: 6px; border-radius: 50%; }
.dots i.t-cita { background: var(--gold); }
.dots i.t-control { background: var(--info); }
.dots i.t-procedimiento { background: var(--ok); }
.dots i.t-otro { background: var(--warn); }
.more { font-size: 11px; color: var(--muted); padding-left: 4px; }
.legend { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.legend .chip { font-size: 12px; padding: 4px 10px; }
.agenda-day { margin-bottom: 18px; }
.agenda-day h4 { text-transform: capitalize; margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.agenda-day.is-today h4 { color: var(--gold-dark); }
.ev-bar { width: 4px; align-self: stretch; border-radius: 4px; flex-shrink: 0; }
.ev-bar.t-cita { background: var(--gold); }
.ev-bar.t-control { background: var(--info); }
.ev-bar.t-procedimiento { background: var(--ok); }
.ev-bar.t-otro { background: var(--warn); }

/* ---------- Gráficos ---------- */
.bars { display: flex; align-items: flex-end; gap: 12px; height: 200px; padding-top: 24px; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; min-width: 0; }
.bar .fill { width: 100%; max-width: 54px; background: var(--gold); border-radius: 6px 6px 0 0; min-height: 2px; position: relative; }
.bar.current .fill { background: var(--gold-dark); }
.bar .v { font-size: 11px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.bar .l { font-size: 12px; color: var(--muted); text-transform: capitalize; }
.hbars { display: flex; flex-direction: column; gap: 12px; }
.hbar .top { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; margin-bottom: 5px; }
.hbar .top span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.hbar .track { height: 8px; background: var(--surface-2); border-radius: 8px; overflow: hidden; }
.hbar .track div { height: 100%; background: var(--gold); border-radius: 8px; }

/* Inventario */
.stock { font-weight: 600; font-variant-numeric: tabular-nums; }
.stock.low { color: var(--danger); }

/* ---------- Modal y hoja inferior ---------- */
.modal { position: fixed; inset: 0; background: rgba(40, 32, 20, .45); display: flex; align-items: flex-start; justify-content: center; padding: 48px 16px; z-index: 60; overflow-y: auto; animation: fade .15s; }
.modal-card { background: var(--surface); border-radius: 20px; width: 100%; max-width: 700px; box-shadow: var(--shadow-lg); animation: rise .18s ease-out; }
.modal-card.wide { max-width: 900px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); border-radius: 20px 20px 0 0; z-index: 2; }
.modal-body { padding: 20px 22px 24px; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(12px); opacity: 0; } }

.search-results { margin-top: 12px; max-height: 60vh; overflow-y: auto; }
.more-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.more-grid a, .more-grid button { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 16px 8px; border-radius: 14px; background: var(--bg); border: 1px solid var(--border);
  text-decoration: none; color: var(--text); font: inherit; font-size: 13px; font-weight: 500; cursor: pointer; }
.more-grid svg { color: var(--gold-dark); }

.toast { position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%); background: var(--text); color: #fff; padding: 12px 20px; border-radius: 14px; z-index: 80; box-shadow: var(--shadow-lg); font-size: 14px; display: flex; align-items: center; gap: 8px; max-width: calc(100vw - 32px); }

/* ============ Computadora mediana ============ */
@media (max-width: 1280px) {
  .main { padding: 26px 26px 60px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cal-layout { grid-template-columns: minmax(0, 1fr) 290px; }
}

/* ============ Tablet: menú de íconos ============ */
@media (max-width: 1100px) {
  :root { --sidebar: 84px; }
  .sidebar { padding: 14px 8px; align-items: center; }
  .sidebar-logo { display: none; }
  .brand-mark { display: grid; }
  .search-btn { width: 52px; height: 44px; justify-content: center; padding: 0; }
  .search-btn span, .search-btn kbd { display: none; }
  .nav a { flex-direction: column; gap: 4px; font-size: 10.5px; padding: 9px 4px; width: 68px; text-align: center; }
  .nav a.active::before { left: -8px; }
  .nav .dot { position: absolute; top: 4px; right: 8px; min-width: 16px; height: 16px; font-size: 10px; padding: 0 4px; }
  .sidebar-foot { width: 100%; align-items: center; }
  .sidebar-foot .btn span { display: none; }
  .sync-state span { display: none; }
  .grid.dash { grid-template-columns: minmax(0, 1fr); }
  .cal-layout { grid-template-columns: minmax(0, 1fr); }
  .photo-cols { grid-template-columns: 1fr; }
}

/* ============ Celular: barra inferior ============ */
@media (max-width: 700px) {
  body { font-size: 15px; }
  input, select, textarea { font-size: 16px; } /* evita el zoom automático en iPhone */
  h1 { font-size: 28px; }
  h2 { font-size: 24px; }
  .sidebar { display: none; }
  .mobile-top { display: flex; position: sticky; top: 0; z-index: 30; align-items: center; gap: 10px; padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top));
    background: rgba(255, 255, 255, .92); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--border); }
  .mobile-top .brand-mark { display: grid; width: 36px; height: 36px; font-size: 16px; }
  .mobile-top .title { flex: 1; font-family: "Cormorant Garamond", serif; font-size: 21px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .mobile-top .sync-state { font-size: 11px; }
  .mobile-top .sync-state:not(.offline):not(.busy) { display: none; }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: rgba(255, 255, 255, .96); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom); }
  .tabbar a, .tabbar button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; height: var(--tabbar);
    font: inherit; font-size: 10.5px; font-weight: 500; color: var(--muted); text-decoration: none; border: 0; background: transparent; cursor: pointer; position: relative; }
  .tabbar .active { color: var(--gold-dark); }
  .tabbar .active svg { stroke-width: 2.2; }
  .tabbar .dot { position: absolute; top: 8px; left: calc(50% + 6px); width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
  .main { margin-left: 0; padding: 16px 14px calc(var(--tabbar) + 30px + env(safe-area-inset-bottom)); }
  .toast { bottom: calc(var(--tabbar) + 16px + env(safe-area-inset-bottom)); }

  .page-head { margin-bottom: 16px; align-items: stretch; }
  .page-head .actions { width: 100%; }
  .page-head .actions > * { flex: 1; }
  .page-head h1.nav-title { display: none; } /* el título ya está en la barra superior */
  .hide-phone { display: none !important; }
  .page-head .sub { margin-top: 0; }
  .hero { padding: 18px; border-radius: 18px; }
  .hero h1 { font-size: 28px; }
  .quick { width: 100%; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .quick .btn { flex-direction: column; gap: 4px; padding: 10px 4px; font-size: 12px; white-space: normal; text-align: center; min-height: 64px; }
  .stats { gap: 10px; }
  .stat { padding: 12px; gap: 10px; flex-direction: column; align-items: flex-start; }
  .stat .ico { width: 36px; height: 36px; border-radius: 10px; }
  .stat .val { font-size: 19px; }
  .card { padding: 16px; border-radius: 14px; }
  .grid.cols-2, .grid.cols-3, .form-grid { grid-template-columns: 1fr; }
  .dl { grid-template-columns: 1fr; gap: 2px; }
  .dl dd { margin-bottom: 10px; }
  .mini-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .client-head .actions { width: 100%; display: grid; grid-template-columns: repeat(4, 1fr); }
  .client-head .actions .btn { flex-direction: column; gap: 3px; font-size: 11.5px; padding: 8px 2px; min-height: 56px; }

  /* Tablas como tarjetas */
  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr { border-bottom: 1px solid var(--border); padding: 12px 2px; display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; }
  table.responsive tbody tr:last-child { border-bottom: 0; }
  table.responsive td { border: 0; padding: 0; }
  table.responsive td.main-cell { grid-column: 1; }
  table.responsive td.end-cell { grid-column: 2; grid-row: 1; text-align: right; }
  table.responsive td.sub-cell { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
  table.responsive td.sub-cell:empty, table.responsive td.hide-m { display: none; }
  table.responsive td[data-label].sub-cell::before { content: attr(data-label) ": "; }
  table.responsive .row-actions { justify-content: flex-start; grid-column: 1 / -1; }
  table.responsive td.actions-cell { grid-column: 1 / -1; }
  .card.flush .table-wrap { padding: 0 14px; }

  .item-row { grid-template-columns: minmax(0, 1fr) 58px 92px 30px; gap: 6px; }
  .item-row .sub, .items-head .sub { display: none; }
  .totals { max-width: none; }
  .sticky-actions { bottom: calc(var(--tabbar) + env(safe-area-inset-bottom)); }
  .sticky-actions .form-actions .btn { flex: 1; }
  .sticky-actions .spacer { display: none; }

  .cal .day { min-height: 54px; padding: 4px 2px; align-items: center; }
  .cal .chip, .cal .more { display: none; }
  .cal .dots { display: flex; }
  .cal-head h3 { min-width: 0; flex: 1; font-size: 19px; }
  .cal-head .seg { margin-left: 0; width: 100%; }
  .cal-head .seg button { flex: 1; }

  .doc { padding: 20px; }
  .doc-logo { width: 170px; }
  .doc .doc-meta { text-align: left; }

  .modal { padding: 0; align-items: flex-end; }
  .modal-card, .modal-card.wide { border-radius: 20px 20px 0 0; max-height: 94vh; max-height: 94dvh; overflow-y: auto; animation: sheet .22s ease-out; }
  .modal-body { padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); }
  .modal-head { padding: 14px 16px; }
  .modal .form-actions .btn { flex: 1; }
  .modal .form-actions .spacer { display: none; }
  .bars { gap: 6px; }
  .bar .v { display: none; }
  .photo-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  @keyframes sheet { from { transform: translateY(40px); opacity: .4; } }
}

/* ---------- Impresión: solo el documento o la ficha ---------- */
@media print {
  body { background: #fff; }
  .no-print, .sidebar, .mobile-top, .tabbar, .page-head, .toast, .modal, .tabs { display: none !important; }
  .main { margin: 0; padding: 0; max-width: none; }
  .doc, .card { border: 0; box-shadow: none; padding: 0; max-width: none; }
  .card + .card, .stack > .card { margin-top: 18px; }
}
