/* =====================================================================
   MEDIVALLE SF S.A.S. — Seguimiento a Pacientes (pacientes.medivalle.co)
   ===================================================================== */
:root {
  --brand-dark: #064e3b;
  --brand-mid: #047857;
  --brand-light: #10b981;
  --brand-soft: #ecfdf5;
  --bg-page: #f1f5f9;
  --bg-card: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --warn: #d97706;
  --warn-bg: #fffbeb;
  --info: #2563eb;
  --info-bg: #eff6ff;
  --purple: #7c3aed;
  --purple-bg: #f5f3ff;
  --teal: #0d9488;
  --teal-bg: #f0fdfa;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-page);
  color: var(--text-main);
  font-size: 13.5px;
  line-height: 1.45;
}

.hidden { display: none !important; }

/* LOGIN */
.login-overlay {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #064e3b 0%, #047857 55%, #0f766e 100%);
  padding: 20px;
}
.login-card {
  background: #fff;
  width: 100%;
  max-width: 410px;
  border-radius: 16px;
  padding: 34px 30px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.login-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}
.login-logo .logo-badge {
  width: 46px; height: 46px; border-radius: 12px;
  background: linear-gradient(135deg, var(--brand-dark), var(--brand-light));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 20px;
}
.login-logo h1 { font-size: 19px; color: var(--brand-dark); }
.login-logo p { font-size: 12px; color: var(--text-muted); }

/* LAYOUT */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px;
  background: linear-gradient(180deg, #053e30 0%, #064e3b 55%, #046c4e 100%);
  color: #e2f5ee;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,.12);
}
.sidebar-brand .brand-title { font-size: 21px; font-weight: 800; letter-spacing: .5px; color: #fff; }
.sidebar-brand .brand-sub { font-size: 11px; color: #a7f3d0; margin-top: 2px; }

.sidebar-nav { padding: 12px 10px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; background: transparent; border: none; color: #d1fae5;
  padding: 10px 12px; border-radius: 9px; cursor: pointer;
  font-size: 13.5px; font-weight: 500; text-align: left;
  transition: background .15s, color .15s; margin-bottom: 4px;
}
.nav-item:hover { background: rgba(255,255,255,.1); color: #fff; }
.nav-item.active { background: var(--brand-light); color: #fff; font-weight: 600; box-shadow: 0 4px 12px rgba(16,185,129,.3); }
.nav-item .nav-icon { width: 20px; text-align: center; font-size: 15px; }

.sidebar-footer {
  padding: 12px 14px; border-top: 1px solid rgba(255,255,255,.12);
  font-size: 11.5px; color: #a7f3d0;
}

/* MAIN CONTENT */
.main-content { flex: 1; padding: 18px 24px 30px; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px; margin-bottom: 16px;
}
.topbar-title h1 { font-size: 22px; font-weight: 800; color: var(--text-main); display: flex; align-items: center; gap: 8px; }
.topbar-title p { color: var(--text-muted); font-size: 12.5px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.date-pill {
  background: #fff; border: 1px solid var(--border); padding: 7px 13px;
  border-radius: 9px; font-weight: 600; font-size: 12.5px; color: var(--brand-dark);
}
.user-pill {
  display: flex; align-items: center; gap: 8px;
  background: #fff; border: 1px solid var(--border); padding: 6px 12px; border-radius: 9px;
}
.user-pill strong { font-size: 12.5px; }

/* KPI GRID */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(145px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
@media (max-width: 1280px) { .kpi-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 720px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }

.kpi-card {
  border-radius: var(--radius); padding: 14px 15px; cursor: pointer;
  border: 1px solid transparent; transition: transform .15s, box-shadow .15s;
  display: flex; align-items: center; gap: 12px; box-shadow: var(--shadow);
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(15,23,42,.1); }
.kpi-card .kpi-ico { font-size: 26px; line-height: 1; }
.kpi-card .kpi-label { font-size: 12px; font-weight: 600; color: #334155; }
.kpi-card .kpi-val { font-size: 26px; font-weight: 800; line-height: 1.1; margin-top: 2px; }

.kpi-green  { background: #e8f8f0; border-color: #bbf7d0; } .kpi-green .kpi-val  { color: #047857; }
.kpi-amber  { background: #fef7e6; border-color: #fde68a; } .kpi-amber .kpi-val  { color: #b45309; }
.kpi-red    { background: #fef0f0; border-color: #fecaca; } .kpi-red .kpi-val    { color: #b91c1c; }
.kpi-blue   { background: #edf4ff; border-color: #bfdbfe; } .kpi-blue .kpi-val   { color: #1d4ed8; }
.kpi-purple { background: #f3efff; border-color: #ddd6fe; } .kpi-purple .kpi-val { color: #6d28d9; }
.kpi-teal   { background: #ebfaf8; border-color: #99f6e4; } .kpi-teal .kpi-val   { color: #0f766e; }

/* CARDS & FILTERS */
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.filters-layout {
  display: grid; grid-template-columns: 220px 1fr 155px; gap: 16px; align-items: start;
}
@media (max-width: 1120px) { .filters-layout { grid-template-columns: 1fr; } }

.filter-section-title {
  font-size: 12.5px; font-weight: 700; color: var(--brand-dark);
  margin-bottom: 10px; display: flex; align-items: center; gap: 6px;
}
.radio-list { display: flex; flex-direction: column; gap: 6px; }
.radio-opt {
  display: flex; align-items: center; gap: 8px; padding: 7px 11px;
  border-radius: 8px; cursor: pointer; font-weight: 500; font-size: 13px;
  border: 1px solid transparent;
}
.radio-opt:hover { background: #f8fafc; }
.radio-opt.active { background: var(--brand-dark); color: #fff; font-weight: 600; }
.radio-opt input { accent-color: var(--brand-light); }

.filter-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); gap: 10px;
}
.field label {
  display: block; font-size: 11.5px; font-weight: 600; color: #475569; margin-bottom: 4px;
}
.field input, .field select, .field textarea {
  width: 100%; padding: 7px 10px; border: 1px solid #cbd5e1; border-radius: 8px;
  font-size: 13px; color: var(--text-main); background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--brand-mid); box-shadow: 0 0 0 3px rgba(4,120,87,.12);
}

.days-pills { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.days-pills span { font-size: 12px; font-weight: 600; color: #475569; margin-right: 4px; }
.day-pill {
  padding: 5px 11px; border-radius: 7px; border: 1px solid #cbd5e1;
  background: #fff; cursor: pointer; font-size: 12px; font-weight: 600; color: #334155;
}
.day-pill.active { background: var(--brand-mid); color: #fff; border-color: var(--brand-mid); }

.filter-actions-col { display: flex; flex-direction: column; gap: 8px; padding-top: 22px; }

/* BUTTONS */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; font-weight: 600; font-size: 13px;
  cursor: pointer; border: 1px solid transparent; transition: all .15s;
}
.btn-primary { background: var(--brand-mid); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-excel { background: #fff; color: var(--brand-dark); border-color: #10b981; }
.btn-excel:hover { background: var(--brand-soft); }
.btn-secondary { background: #f1f5f9; color: #334155; border-color: #cbd5e1; }
.btn-secondary:hover { background: #e2e8f0; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 5px 9px; font-size: 12px; border-radius: 6px; }
.btn-icon {
  padding: 5px 8px; border-radius: 6px; border: 1px solid #cbd5e1;
  background: #fff; cursor: pointer; font-size: 13px;
}
.btn-icon:hover { background: var(--brand-soft); border-color: var(--brand-mid); }

/* TABLE */
.table-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px; flex-wrap: wrap; gap: 8px;
}
.table-header h2 { font-size: 15.5px; font-weight: 700; color: var(--brand-dark); }
.table-wrap { overflow-x: auto; border-radius: 10px; border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 12.8px; }
thead th {
  background: var(--brand-dark); color: #fff; text-align: left;
  padding: 10px 10px; font-weight: 600; white-space: nowrap; font-size: 12px;
}
tbody td {
  padding: 9px 10px; border-bottom: 1px solid #f1f5f9; vertical-align: middle;
}
tbody tr:hover { background: #f8fafc; }

/* BADGES */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.b-green  { background: #dcfce7; color: #166534; }
.b-amber  { background: #fef3c7; color: #92400e; }
.b-red    { background: #fee2e2; color: #991b1b; }
.b-blue   { background: #dbeafe; color: #1e40af; }
.b-purple { background: #ede9fe; color: #5b21b6; }
.b-gray   { background: #f1f5f9; color: #475569; }
.b-teal   { background: #ccfbf1; color: #115e59; }

.pagination {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 12px; flex-wrap: wrap; gap: 10px; font-size: 12.5px; color: var(--text-muted);
}
.page-btns { display: flex; gap: 5px; }

/* FOOTER LEGEND */
.legend-bar {
  display: grid; grid-template-columns: 240px 1fr 200px; gap: 14px;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 16px; font-size: 12px;
}
@media (max-width: 1024px) { .legend-bar { grid-template-columns: 1fr; } }
.legend-title { font-weight: 700; color: var(--brand-dark); margin-bottom: 6px; }
.legend-items { display: flex; flex-wrap: wrap; gap: 10px; }

/* FICHA PACIENTE */
.ficha-grid { display: grid; grid-template-columns: 290px 1fr 220px; gap: 16px; }
@media (max-width: 1150px) { .ficha-grid { grid-template-columns: 1fr; } }

.alert-banner {
  padding: 12px 14px; border-radius: 10px; margin-bottom: 12px;
  border-left: 4px solid; font-size: 12.8px;
}
.banner-warn { background: #fffbeb; border-color: #f59e0b; color: #92400e; }
.banner-info { background: #eff6ff; border-color: #3b82f6; color: #1e40af; }

.timeline {
  display: flex; align-items: center; gap: 0; overflow-x: auto; padding: 18px 8px;
}
.tl-step { flex: 1; min-width: 92px; text-align: center; position: relative; }
.tl-step::before {
  content: ''; position: absolute; top: 15px; left: -50%; width: 100%; height: 3px;
  background: #cbd5e1; z-index: 0;
}
.tl-step:first-child::before { display: none; }
.tl-step.done::before { background: var(--brand-light); }
.tl-dot {
  width: 30px; height: 30px; border-radius: 50%; margin: 0 auto 6px;
  display: flex; align-items: center; justify-content: center; font-weight: 700;
  font-size: 12px; position: relative; z-index: 1; background: #e2e8f0; color: #475569;
}
.tl-step.done .tl-dot { background: var(--brand-light); color: #fff; }
.tl-step.next .tl-dot { background: #fff; border: 3px solid var(--brand-mid); color: var(--brand-dark); box-shadow: 0 0 0 4px rgba(16,185,129,.2); }
.tl-label { font-weight: 700; font-size: 12px; }
.tl-date { font-size: 11px; color: var(--text-muted); }

/* MODALS & TOAST */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,.55);
  display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 16px;
}
.modal {
  background: #fff; border-radius: 14px; width: 100%; max-width: 540px;
  max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 50px rgba(0,0,0,.3);
}
.modal-head {
  padding: 15px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  background: var(--brand-dark); color: #fff; border-radius: 14px 14px 0 0;
}
.modal-body { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.modal-foot {
  padding: 12px 18px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
}
.toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 2000;
  background: #0f172a; color: #fff; padding: 11px 16px; border-radius: 10px;
  box-shadow: 0 10px 25px rgba(0,0,0,.25); font-size: 13px; font-weight: 500;
}
.toast.ok { background: var(--brand-dark); }
.toast.err { background: var(--danger); }
