/* ============================================================================
   Gestiona mi Veterinaria — Sistema de diseño
   Capa compartida por las tres apps (panel de clínica, médico y dueño).
   Se carga ANTES del CSS de cada app: aquí viven los tokens y las primitivas.

   WHITE LABEL: toda la identidad se deriva de --brand-*. Para re-marcar una
   clínica basta con sobrescribir esas variables en un <style> por tenant.
   ========================================================================= */

:root {
  /* ---- Marca (único punto de personalización) ---- */
  --brand-50:  #ECFDF9;
  --brand-100: #D2F3EC;
  --brand-200: #A7E5D9;
  --brand-500: #12968A;
  --brand-600: #0F7B6C;   /* color de acción principal */
  --brand-700: #0B5F54;
  --on-brand:  #FFFFFF;

  /* ---- Neutros (sesgo frío, elegidos, no grises puros) ---- */
  --bg:          #F7F8FA;
  --surface:     #FFFFFF;
  --surface-2:   #FBFCFD;
  --border:      #E7E9EE;
  --border-2:    #D6DAE1;
  --ink:         #0F172A;
  --ink-2:       #344054;
  --text-muted:  #667085;
  --text-faint:  #98A2B3;

  /* ---- Semánticos: discretos, nunca neón ---- */
  --ok:    #067647;  --ok-bg:   #ECFDF3;  --ok-br:   #ABEFC6;
  --warn:  #B54708;  --warn-bg: #FFFAEB;  --warn-br: #FEDF89;
  --err:   #B42318;  --err-bg:  #FEF3F2;  --err-br:  #FECDCA;
  --info:  #175CD3;  --info-bg: #EFF8FF;  --info-br: #B2DDFF;

  /* ---- Espaciado: cuadrícula de 8 px ---- */
  --s1:4px; --s2:8px; --s3:12px; --s4:16px; --s5:20px;
  --s6:24px; --s7:32px; --s8:40px; --s9:48px; --s10:64px;

  /* ---- Radios ---- */
  --r-sm:8px; --r:10px; --r-md:12px; --r-lg:16px; --r-full:999px;

  /* ---- Elevación: borde fino + halo mínimo (nunca sombras pesadas) ---- */
  --sh-xs: 0 1px 2px rgba(16,24,40,.05);
  --sh-sm: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.04);
  --sh-md: 0 4px 8px -2px rgba(16,24,40,.08), 0 2px 4px -2px rgba(16,24,40,.04);
  --sh-lg: 0 12px 16px -4px rgba(16,24,40,.08), 0 4px 6px -2px rgba(16,24,40,.03);
  --ring:  0 0 0 4px rgba(15,123,108,.14);

  /* ---- Tipografía ---- */
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text",
          "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;

  /* ---- Movimiento ---- */
  --t: 170ms cubic-bezier(.2,.7,.2,1);
  --t-fast: 120ms cubic-bezier(.2,.7,.2,1);

  /* ---- Alias heredados (los usan estilos inline del JS: no eliminar) ---- */
  --line: var(--border);
  --bg-soft: var(--surface-2);
  --card: var(--surface);
  --blue: var(--brand-600);
  --blue-dark: var(--brand-700);
  --blue-deep: var(--brand-700);
  --muted: var(--text-muted);
  --danger: var(--err);
  --radius: var(--r-md);
  --shadow: var(--sh-sm);

  font-size: 16px;
  color-scheme: light;
}

/* ---------------------------------------------------------------- Base --- */

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv11", "ss01";
}

h1, h2, h3, h4 { font-weight: 600; letter-spacing: -.015em; color: var(--ink); text-wrap: balance; }
h1 { font-size: 24px; line-height: 1.25; }
h2 { font-size: 19px; line-height: 1.3; }
h3 { font-size: 15px; line-height: 1.4; }

a { color: var(--brand-600); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }

:focus-visible { outline: 2px solid var(--brand-600); outline-offset: 2px; border-radius: var(--r-sm); }

::selection { background: var(--brand-100); color: var(--brand-700); }

/* Cifras siempre alineadas en columnas */
.tbl td, .kpi .num, .stat b, [class*="amt"] { font-variant-numeric: tabular-nums; }

/* Iconos de línea (set Lucide vía icon()). Heredan el color del contexto. */
.ico-svg { display: inline-block; vertical-align: -.18em; flex: none; }
.btn .ico-svg { vertical-align: middle; }

/* ------------------------------------------------------------ Tipografía - */

.muted { color: var(--text-muted); }
.mini  { font-size: 12px; line-height: 1.5; }
.sub   { font-size: 13px; color: var(--text-muted); font-weight: 400; }
.right { text-align: right; }

.section-title {
  font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-faint); margin: var(--s6) 0 var(--s3);
}

.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s4); flex-wrap: wrap; margin-bottom: var(--s5);
}
.page-head h1 { font-size: 22px; }

/* --------------------------------------------------------------- Botones - */

.btn {
  --btn-bg: var(--brand-600);
  --btn-fg: var(--on-brand);
  --btn-br: var(--brand-600);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  height: 38px; padding: 0 var(--s4);
  background: var(--btn-bg); color: var(--btn-fg);
  border: 1px solid var(--btn-br); border-radius: var(--r);
  font-size: 13.5px; font-weight: 550; white-space: nowrap;
  box-shadow: var(--sh-xs);
  transition: background var(--t), border-color var(--t), box-shadow var(--t), transform var(--t-fast);
}
.btn:hover { --btn-bg: var(--brand-700); --btn-br: var(--brand-700); }
.btn:active { transform: translateY(.5px); }
.btn:focus-visible { box-shadow: var(--ring); outline: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.btn.ghost {
  --btn-bg: var(--surface); --btn-fg: var(--ink-2); --btn-br: var(--border-2);
}
.btn.ghost:hover { --btn-bg: var(--surface-2); --btn-br: var(--border-2); color: var(--ink); }

.btn.danger { --btn-bg: var(--err); --btn-br: var(--err); }
.btn.danger:hover { --btn-bg: #912018; --btn-br: #912018; }

.btn.sm, .btn.small { height: 32px; padding: 0 var(--s3); font-size: 12.5px; border-radius: var(--r-sm); }
.btn.block { width: 100%; }

/* --------------------------------------------------------------- Tarjetas - */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--sh-xs);
  padding: var(--s5);
  margin-bottom: var(--s4);
}
.card h3 { margin-bottom: var(--s3); }
.card h3 .see {
  float: right; font-size: 12px; font-weight: 500; color: var(--brand-600); cursor: pointer;
}
.card h3 .see:hover { text-decoration: underline; }

/* ------------------------------------------------------------ Formularios - */

.field { margin-bottom: var(--s4); }
.field label {
  display: block; font-size: 13px; font-weight: 550; color: var(--ink-2); margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%; min-height: 40px; padding: 9px var(--s3);
  background: var(--surface);
  border: 1px solid var(--border-2); border-radius: var(--r);
  font-size: 14px; color: var(--ink);
  box-shadow: var(--sh-xs);
  transition: border-color var(--t), box-shadow var(--t);
}
.field textarea { min-height: 84px; resize: vertical; line-height: 1.55; padding-top: var(--s2); }
.field input::placeholder, .field textarea::placeholder { color: var(--text-faint); }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--brand-500); box-shadow: var(--ring);
}
.field input[type="file"] { padding: 7px var(--s3); background: var(--surface-2); cursor: pointer; }
.field input[type="checkbox"] { width: auto; min-height: 0; box-shadow: none; accent-color: var(--brand-600); }

/* Dos campos en fila; se apilan en pantallas pequeñas */
.frow { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4); }

.hint { font-size: 12.5px; color: var(--text-muted); margin-top: var(--s3); text-align: center; }

.actions {
  display: flex; justify-content: flex-end; gap: var(--s2);
  margin-top: var(--s5); padding-top: var(--s4); border-top: 1px solid var(--border);
}

/* Filas de ítems dinámicos (facturas, indicaciones…) */
.item-row { display: grid; gap: var(--s2); align-items: center; margin-bottom: var(--s2); }
.item-row input, .item-row select {
  min-height: 36px; padding: 7px var(--s3);
  border: 1px solid var(--border-2); border-radius: var(--r-sm);
  background: var(--surface); font-size: 13px;
}
.item-row input:focus, .item-row select:focus { outline: none; border-color: var(--brand-500); box-shadow: var(--ring); }
.item-del { color: var(--text-faint); font-size: 15px; transition: color var(--t); }
.item-del:hover { color: var(--err); }

/* ------------------------------------------------------------------ Chips - */

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: var(--r-full);
  font-size: 12px; font-weight: 550; letter-spacing: .01em;
  background: var(--brand-50); color: var(--brand-700);
  border: 1px solid var(--brand-100);
}
.chip.ok   { background: var(--ok-bg);   color: var(--ok);   border-color: var(--ok-br); }
.chip.warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-br); }
.chip.bad  { background: var(--err-bg);  color: var(--err);  border-color: var(--err-br); }
.chip.off  { background: var(--surface-2); color: var(--text-muted); border-color: var(--border); }

/* ------------------------------------------------------------------ KPIs -- */

.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s4); margin-bottom: var(--s4); }
.cards.c4 { grid-template-columns: repeat(4, 1fr); }
.cards.c5 { grid-template-columns: repeat(5, 1fr); }

.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: var(--s4) var(--s5); box-shadow: var(--sh-xs);
  transition: border-color var(--t), box-shadow var(--t), transform var(--t-fast);
}
.kpi .num { font-size: 26px; font-weight: 600; letter-spacing: -.02em; line-height: 1.15; color: var(--ink); }
.kpi .lbl {
  font-size: 11.5px; font-weight: 550; letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-faint); margin-top: 5px;
}
.kpi.warn .num  { color: var(--warn); }
.kpi.alert .num { color: var(--err); }

.kpi.click { cursor: pointer; position: relative; }
.kpi.click:hover { border-color: var(--border-2); box-shadow: var(--sh-md); transform: translateY(-1px); }
.kpi.click::after {
  content: ""; position: absolute; top: 14px; right: 14px;
  width: 6px; height: 6px; border-top: 1.5px solid var(--text-faint); border-right: 1.5px solid var(--text-faint);
  transform: rotate(45deg); opacity: 0; transition: opacity var(--t);
}
.kpi.click:hover::after { opacity: 1; }

/* ----------------------------------------------------------------- Tablas - */

.tbl-wrap {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  box-shadow: var(--sh-xs); overflow: hidden;
}
.tbl-wrap + .tbl-wrap { margin-top: var(--s4); }
.tbl { width: 100%; border-collapse: collapse; overflow-x: auto; }
.tbl th {
  padding: 10px var(--s4); text-align: left;
  font-size: 11.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
  color: var(--text-faint); background: var(--surface-2);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.tbl td {
  padding: 13px var(--s4); font-size: 13.5px; color: var(--ink-2);
  border-bottom: 1px solid var(--border); vertical-align: middle;
}
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr { transition: background var(--t-fast); }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl tr.click { cursor: pointer; }
.tbl .right { text-align: right; }
/* Acciones discretas: se revelan al pasar el cursor por la fila */
.tbl td .btn.sm { opacity: .75; transition: opacity var(--t); }
.tbl tr:hover td .btn.sm { opacity: 1; }
/* Fila de botones de acción: espaciado uniforme, alineados a la derecha,
   envuelven ordenadamente en vez de descuadrarse. */
.acc-btns { display: flex; flex-wrap: wrap; gap: var(--s2); justify-content: flex-end; align-items: center; }
.acc-btns .btn { flex: 0 0 auto; }

.empty-row { text-align: center; color: var(--text-muted); padding: var(--s8) var(--s4) !important; }

/* Barra de filtros / búsqueda sobre una tabla */
.toolbar {
  display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; margin-bottom: var(--s4);
}
.toolbar input[type="text"], .toolbar select, .toolbar input[type="date"] {
  height: 36px; padding: 0 var(--s3);
  background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--r);
  font-size: 13.5px; box-shadow: var(--sh-xs);
  transition: border-color var(--t), box-shadow var(--t);
}
.toolbar input[type="text"] { min-width: 240px; }
.toolbar input:focus, .toolbar select:focus { outline: none; border-color: var(--brand-500); box-shadow: var(--ring); }

/* ----------------------------------------------------------- Estados UI --- */

.skeleton {
  border-radius: var(--r-md); color: transparent; user-select: none;
  background: linear-gradient(90deg, #EEF0F3 25%, #F6F7F9 37%, #EEF0F3 63%);
  background-size: 400% 100%; animation: shimmer 1.4s ease infinite;
  min-height: 88px;
}
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

.empty {
  text-align: center; color: var(--text-muted); padding: var(--s8) var(--s5);
  background: var(--surface); border: 1px dashed var(--border-2); border-radius: var(--r-md);
}
.empty .ico { display: block; font-size: 26px; margin-bottom: var(--s2); opacity: .55; }

.toast {
  position: fixed; left: 50%; bottom: var(--s6); transform: translateX(-50%);
  z-index: 90; max-width: min(420px, calc(100vw - 32px));
  padding: 11px var(--s4);
  background: var(--ink); color: #fff;
  border-radius: var(--r); box-shadow: var(--sh-lg);
  font-size: 13.5px; font-weight: 500;
  animation: toast-in 220ms cubic-bezier(.2,.7,.2,1);
}
.toast.err { background: var(--err); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* -------------------------------------------------------------- Utilidades */

.row { display: flex; align-items: center; gap: var(--s2); }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }

.back-btn {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--text-muted); font-size: 13.5px; font-weight: 500;
  margin-bottom: var(--s4); transition: color var(--t);
}
.back-btn:hover { color: var(--ink); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Móvil: los pares de campos se apilan */
@media (max-width: 640px) {
  .frow { grid-template-columns: 1fr; gap: 0; }
  .cards, .cards.c4, .cards.c5 { grid-template-columns: repeat(2, 1fr); }
}
