/* =========================================================
   Vet Americana - Sistema de gestion veterinaria
   ========================================================= */

:root {
  --teal-900: #0b3f3c;
  --teal-800: #115e59;
  --teal-700: #0f766e;
  --teal-600: #0d9488;
  --teal-500: #14b8a6;
  --teal-100: #ccfbf1;
  --teal-50: #f0fdfa;

  --amber-600: #d97706;
  --amber-500: #f59e0b;
  --amber-100: #fef3c7;

  --red-700: #b91c1c;
  --red-600: #dc2626;
  --red-100: #fee2e2;
  --red-50: #fef2f2;

  --blue-600: #2563eb;
  --blue-100: #dbeafe;

  --purple-600: #7c3aed;
  --purple-100: #ede9fe;

  --ink-900: #0f172a;
  --ink-700: #334155;
  --ink-500: #64748b;
  --ink-400: #94a3b8;
  --ink-300: #cbd5e1;
  --ink-200: #e2e8f0;
  --ink-100: #f1f5f9;
  --ink-50: #f8fafc;
  --white: #ffffff;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow: 0 4px 16px rgba(15, 23, 42, .08);
  --shadow-lg: 0 18px 40px rgba(15, 23, 42, .16);
  --sidebar-w: 248px;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  font-size: 15px;
  color: var(--ink-900);
  background: var(--ink-100);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--teal-700); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .4rem; line-height: 1.25; font-weight: 650; }
p { margin: 0 0 .6rem; }
ul { margin: 0; padding-left: 1.1rem; }

/* ---------------- Layout ---------------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: linear-gradient(180deg, var(--teal-900) 0%, #0a3330 100%);
  color: #d8efec;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: 1.1rem 1.15rem;
  border-bottom: 1px solid rgba(255, 255, 255, .1);
}
.brand-mark {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: var(--teal-500);
  color: var(--teal-900);
  flex: 0 0 auto;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { color: #fff; font-size: 1rem; letter-spacing: .2px; }
.brand-text small { color: #8fc9c2; font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; }

.nav { flex: 1; padding: .85rem .7rem 1.4rem; }
.nav-group {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .11em;
  color: #74b3ac;
  margin: 1rem .5rem .35rem;
  font-weight: 700;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .55rem .6rem;
  border-radius: var(--radius-sm);
  color: #cfe7e4;
  font-size: .89rem;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: rgba(255, 255, 255, .08); color: #fff; text-decoration: none; }
.nav-link.active { background: var(--teal-600); color: #fff; box-shadow: inset 3px 0 0 var(--teal-500); }
.nav-ico { width: 1.15rem; text-align: center; opacity: .9; font-size: .95rem; }

.sidebar-foot { padding: .85rem 1rem 1.1rem; border-top: 1px solid rgba(255, 255, 255, .1); }
.clinic-mini { display: flex; flex-direction: column; font-size: .76rem; color: #93c4be; }
.clinic-mini strong { color: #dff2ef; font-size: .8rem; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--ink-200);
  padding: .7rem 1.35rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 30;
}
.page-title { font-size: 1.12rem; margin: 0; font-weight: 650; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .7rem; }
.menu-btn { display: none; }
.icon-btn {
  border: 1px solid var(--ink-200);
  background: var(--white);
  border-radius: var(--radius-sm);
  width: 34px; height: 34px;
  cursor: pointer;
  font-size: 1rem;
  color: var(--ink-700);
}

.user-chip { display: flex; align-items: center; gap: .5rem; }
.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--teal-600);
  color: #fff;
  display: grid; place-items: center;
  font-size: .78rem; font-weight: 700;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-meta strong { font-size: .82rem; }
.user-meta small { font-size: .72rem; color: var(--ink-500); }

.content { padding: 1.35rem; flex: 1; max-width: 1400px; width: 100%; }

.footer {
  padding: .9rem 1.35rem;
  border-top: 1px solid var(--ink-200);
  color: var(--ink-500);
  font-size: .78rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  background: var(--white);
}

.overlay {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .5);
  z-index: 35;
}

/* ---------------- Botones ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .5rem .9rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: .87rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: filter .15s, background .15s, border-color .15s;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; filter: brightness(.96); }
.btn-primary { background: var(--teal-700); color: #fff; }
.btn-primary:hover { background: var(--teal-800); }
.btn-secondary { background: var(--white); color: var(--ink-700); border-color: var(--ink-300); }
.btn-secondary:hover { background: var(--ink-50); }
.btn-danger { background: var(--red-600); color: #fff; }
.btn-danger:hover { background: var(--red-700); }
.btn-ghost { background: transparent; color: var(--ink-700); border-color: var(--ink-200); }
.btn-ghost:hover { background: var(--ink-100); }
.btn-sm { padding: .3rem .65rem; font-size: .8rem; }
.btn-block { width: 100%; }
.inline-form { display: inline; }

.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.btn-row.end { justify-content: flex-end; }

/* ---------------- Tarjetas ---------------- */
.card {
  background: var(--white);
  border: 1px solid var(--ink-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.1rem;
  overflow: hidden;
}
.card-head {
  padding: .85rem 1.05rem;
  border-bottom: 1px solid var(--ink-200);
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
}
.card-head h2, .card-head h3 { margin: 0; font-size: .98rem; }
.card-head .spacer { margin-left: auto; }
.card-body { padding: 1.05rem; }
.card-body.tight { padding: 0; }
.card-foot {
  padding: .8rem 1.05rem;
  border-top: 1px solid var(--ink-200);
  background: var(--ink-50);
  display: flex;
  gap: .5rem;
  align-items: center;
  flex-wrap: wrap;
}

.section-title {
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink-500);
  font-weight: 700;
  margin: 1.2rem 0 .6rem;
}

/* ---------------- KPIs ---------------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: .85rem;
  margin-bottom: 1.1rem;
}
.kpi {
  background: var(--white);
  border: 1px solid var(--ink-200);
  border-radius: var(--radius);
  padding: .95rem 1.05rem;
  display: flex;
  align-items: flex-start;
  gap: .8rem;
  box-shadow: var(--shadow-sm);
}
.kpi-ico {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: grid; place-items: center;
  font-size: 1.1rem;
  flex: 0 0 auto;
}
.kpi-ico.teal { background: var(--teal-100); color: var(--teal-700); }
.kpi-ico.blue { background: var(--blue-100); color: var(--blue-600); }
.kpi-ico.amber { background: var(--amber-100); color: var(--amber-600); }
.kpi-ico.purple { background: var(--purple-100); color: var(--purple-600); }
.kpi-ico.red { background: var(--red-100); color: var(--red-700); }
.kpi-body { min-width: 0; }
.kpi-label { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-500); font-weight: 700; }
.kpi-value { font-size: 1.5rem; font-weight: 700; line-height: 1.15; margin-top: .1rem; }
.kpi-note { font-size: .75rem; color: var(--ink-500); }

/* ---------------- Grids ---------------- */
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1.1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1.1rem; }
.split { display: grid; grid-template-columns: 2fr 1fr; gap: 1.1rem; align-items: start; }
@media (max-width: 1000px) { .split { grid-template-columns: 1fr; } }

/* ---------------- Tablas ---------------- */
.table-wrap { overflow-x: auto; }
table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: .87rem;
}
.table th {
  text-align: left;
  padding: .6rem .8rem;
  background: var(--ink-50);
  color: var(--ink-500);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--ink-200);
  white-space: nowrap;
}
.table td {
  padding: .62rem .8rem;
  border-bottom: 1px solid var(--ink-100);
  vertical-align: middle;
}
.table tbody tr:hover { background: var(--teal-50); }
.table tbody tr:last-child td { border-bottom: none; }
.table .right { text-align: right; }
.table .center { text-align: center; }
.table .nowrap { white-space: nowrap; }
.table-actions { display: flex; gap: .35rem; flex-wrap: wrap; }
.table-empty { padding: 2.2rem 1rem; text-align: center; color: var(--ink-500); }
.table-empty strong { display: block; color: var(--ink-700); margin-bottom: .25rem; font-size: .95rem; }

.muted { color: var(--ink-500); font-size: .86rem; }
.cell-main { font-weight: 600; }
.cell-sub { font-size: .76rem; color: var(--ink-500); }

/* ---------------- Badges ---------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .15rem .55rem;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 650;
  background: var(--ink-100);
  color: var(--ink-700);
  white-space: nowrap;
}
.badge-ok { background: var(--teal-100); color: var(--teal-800); }
.badge-warn { background: var(--amber-100); color: var(--amber-600); }
.badge-danger { background: var(--red-100); color: var(--red-700); }
.badge-info { background: var(--blue-100); color: var(--blue-600); }
.badge-purple { background: var(--purple-100); color: var(--purple-600); }
.badge-muted { background: var(--ink-100); color: var(--ink-500); }

.rol-badge { text-transform: capitalize; }
.rol-admin { background: var(--purple-100); color: var(--purple-600); }
.rol-veterinario { background: var(--teal-100); color: var(--teal-800); }
.rol-recepcionista { background: var(--blue-100); color: var(--blue-600); }

.estado-badge { text-transform: capitalize; }
.estado-programada { background: var(--blue-100); color: var(--blue-600); }
.estado-en_curso { background: var(--amber-100); color: var(--amber-600); }
.estado-atendida { background: var(--teal-100); color: var(--teal-800); }
.estado-cancelada { background: var(--red-100); color: var(--red-700); }
.estado-no_se_presento { background: var(--ink-100); color: var(--ink-500); }
.estado-pendiente { background: var(--amber-100); color: var(--amber-600); }
.estado-pagada { background: var(--teal-100); color: var(--teal-800); }
.estado-anulada { background: var(--red-100); color: var(--red-700); }
.estado-activo { background: var(--teal-100); color: var(--teal-800); }
.estado-inactivo { background: var(--ink-100); color: var(--ink-500); }

/* ---------------- Formularios ---------------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: .9rem 1rem;
}
.field { display: flex; flex-direction: column; gap: .3rem; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: .79rem; font-weight: 650; color: var(--ink-700); }
.field .hint { font-size: .73rem; color: var(--ink-500); }
.field input, .field select, .field textarea {
  font-family: inherit;
  font-size: .88rem;
  padding: .5rem .65rem;
  border: 1px solid var(--ink-300);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--ink-900);
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--teal-500);
  box-shadow: 0 0 0 3px rgba(20, 184, 166, .18);
}
.field textarea { min-height: 92px; resize: vertical; line-height: 1.5; }
.field input[type="file"] { padding: .38rem; }
.field-error input, .field-error select, .field-error textarea { border-color: var(--red-600); }
.field-error label { color: var(--red-700); }

.checkbox { flex-direction: row; align-items: center; gap: .5rem; }
.checkbox input { width: auto; }
.checkbox label { font-weight: 500; }
.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: .35rem .8rem;
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--ink-200);
  border-radius: var(--radius-sm);
  padding: .6rem .75rem;
  background: var(--ink-50);
}
.checkbox-grid .checkbox { font-size: .85rem; }
.checkbox-grid .checkbox input { accent-color: var(--teal-700); }

.filters {
  display: flex;
  gap: .6rem;
  flex-wrap: wrap;
  align-items: flex-end;
}
.filters .field { min-width: 140px; }

.form-actions {
  display: flex;
  gap: .6rem;
  justify-content: flex-end;
  padding-top: 1rem;
  margin-top: 1rem;
  border-top: 1px solid var(--ink-200);
  flex-wrap: wrap;
}

/* ---------------- Alertas ---------------- */
.alert {
  display: flex;
  gap: .65rem;
  align-items: flex-start;
  padding: .75rem .95rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  border: 1px solid transparent;
  font-size: .88rem;
}
.alert p { margin: 0; }
.alert-success { background: var(--teal-50); border-color: var(--teal-100); color: var(--teal-800); }
.alert-error { background: var(--red-50); border-color: var(--red-100); color: var(--red-700); }
.alert-warn { background: #fffbeb; border-color: var(--amber-100); color: var(--amber-600); }
.alert-info { background: #eff6ff; border-color: var(--blue-100); color: var(--blue-600); }
.alert-ico {
  width: 22px; height: 22px;
  flex: 0 0 auto;
  border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 700; font-size: .78rem;
  background: rgba(0, 0, 0, .07);
}
.alert-close {
  margin-left: auto;
  border: none; background: none;
  font-size: 1.15rem; cursor: pointer;
  color: inherit; opacity: .6; line-height: 1;
}
.alert-close:hover { opacity: 1; }
.alert-list { margin: .3rem 0 0; padding-left: 1.1rem; }

/* ---------------- Ficha / detalle ---------------- */
.detail-head {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  flex-wrap: wrap;
}
.pet-avatar {
  width: 66px; height: 66px;
  border-radius: 14px;
  object-fit: cover;
  background: var(--teal-100);
  display: grid; place-items: center;
  font-size: 1.6rem; color: var(--teal-700);
  border: 1px solid var(--ink-200);
  flex: 0 0 auto;
}
.detail-meta { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .35rem; }
.detail-actions { margin-left: auto; display: flex; gap: .5rem; flex-wrap: wrap; }

.data-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .75rem 1rem; }
.data-item { border-left: 2px solid var(--ink-200); padding-left: .65rem; }
.data-item dt { font-size: .71rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-500); font-weight: 700; }
.data-item dd { margin: .1rem 0 0; font-size: .89rem; font-weight: 500; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li {
  position: relative;
  padding: 0 0 1rem 1.4rem;
  border-left: 2px solid var(--ink-200);
}
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before {
  content: "";
  position: absolute;
  left: -6px; top: 4px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--teal-500);
  border: 2px solid var(--white);
}
.timeline-date { font-size: .74rem; color: var(--ink-500); font-weight: 600; }
.timeline-title { font-weight: 650; font-size: .92rem; }
.timeline-body { font-size: .85rem; color: var(--ink-700); }

/* ---------------- Barras simples ---------------- */
.bar-list { display: flex; flex-direction: column; gap: .6rem; }
.bar-item { font-size: .84rem; }
.bar-top { display: flex; justify-content: space-between; gap: .5rem; margin-bottom: .2rem; }
.bar-track { height: 8px; background: var(--ink-100); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--teal-500); border-radius: 999px; }
.bar-fill.alt { background: var(--blue-600); }
.bar-fill.warn { background: var(--amber-500); }

/* ---------------- Graficos ---------------- */
.chart-box { position: relative; height: 250px; }
.chart-box.tall { height: 320px; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 100%; }
.bars .bar-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: .2rem; min-width: 0; }
.bars .bar { width: 100%; background: var(--teal-500); border-radius: 3px 3px 0 0; min-height: 2px; }
.bars .bar.v2 { background: var(--blue-600); }
.bars .bar-label { font-size: .62rem; color: var(--ink-500); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

.legend { display: flex; gap: .9rem; flex-wrap: wrap; font-size: .76rem; color: var(--ink-500); margin-top: .6rem; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: .3rem; }

/* ---------------- Agenda ---------------- */
.agenda-list { display: flex; flex-direction: column; }
.agenda-item {
  display: grid;
  grid-template-columns: 92px 1fr auto;
  gap: .85rem;
  align-items: center;
  padding: .7rem .95rem;
  border-bottom: 1px solid var(--ink-100);
}
.agenda-item:last-child { border-bottom: none; }
.agenda-item:hover { background: var(--teal-50); }
.agenda-time { font-weight: 700; color: var(--teal-700); font-size: .95rem; }
.agenda-time small { display: block; font-weight: 500; color: var(--ink-500); font-size: .72rem; }
.agenda-main { min-width: 0; }
.agenda-title { font-weight: 650; font-size: .93rem; }
.agenda-sub { font-size: .78rem; color: var(--ink-500); }
@media (max-width: 700px) {
  .agenda-item { grid-template-columns: 72px 1fr; }
  .agenda-item > :last-child { grid-column: 1 / -1; }
}

/* ---------------- Impresion ---------------- */
@media print {
  .sidebar, .topbar, .footer, .btn, .table-actions, .card-foot { display: none !important; }
  body { background: #fff; }
  .card { border: none; box-shadow: none; }
  .content { padding: 0; }
  .print-only { display: block !important; }
}
.print-only { display: none; }

/* ---------------- Responsivo ---------------- */
@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: var(--shadow-lg);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .menu-btn { display: grid; place-items: center; }
  .user-meta, .rol-badge { display: none; }
  .content { padding: .9rem; }
  .topbar { padding: .6rem .9rem; }
}

/* ---------------- Login ---------------- */
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(1100px 520px at 12% -10%, rgba(20, 184, 166, .22), transparent 60%),
    radial-gradient(900px 480px at 105% 108%, rgba(124, 58, 237, .18), transparent 60%),
    linear-gradient(160deg, #0b3f3c 0%, #08302e 100%);
}
.login-wrap { width: 100%; max-width: 420px; }
.login-card {
  background: var(--white);
  border-radius: 18px;
  padding: 2rem 1.8rem 1.6rem;
  box-shadow: var(--shadow-lg);
}
.login-brand { text-align: center; margin-bottom: 1.4rem; }
.login-brand .brand-mark {
  width: 54px; height: 54px;
  margin: 0 auto .7rem;
  border-radius: 15px;
  display: grid; place-items: center;
  background: var(--teal-700); color: #fff;
}
.login-brand h1 { font-size: 1.15rem; margin-bottom: .15rem; }
.login-brand p { color: var(--ink-500); font-size: .84rem; margin: 0; }
.login-form { display: flex; flex-direction: column; gap: .85rem; }
.login-demo { margin-top: 1.4rem; border-top: 1px solid var(--ink-200); padding-top: .9rem; }
.login-demo-title { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-500); font-weight: 700; margin-bottom: .45rem; }
.login-demo table { width: 100%; border-collapse: collapse; font-size: .74rem; }
.login-demo td { padding: .22rem .2rem; color: var(--ink-700); }
.login-demo code { background: var(--ink-100); padding: .05rem .3rem; border-radius: 4px; font-size: .72rem; color: var(--teal-800); }
