/* ============================================================
   ClinOft — Sistema de Gestión Oftalmológica
   Diseño: Navy + Teal + White — Premium Clínico
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700&family=DM+Serif+Display:ital@0;1&display=swap');

/* Variables */
:root {
  --navy:        #0B1E3E;
  --navy-light:  #152B52;
  --navy-muted:  #1E3A6E;
  --teal:        #0D9488;
  --teal-light:  #14B8A6;
  --teal-pale:   #CCFBF1;
  --cyan:        #06B6D4;
  --gold:        #F59E0B;
  --rose:        #F43F5E;
  --orange:      #F97316;
  --slate:       #64748B;
  --slate-light: #94A3B8;
  --ice:         #F0F9FF;
  --white:       #FFFFFF;
  --surface:     #F8FAFC;
  --border:      #E2E8F0;
  --text:        #1E293B;
  --text-muted:  #64748B;
  --sidebar-w:   260px;
  --header-h:    64px;
  --radius:      12px;
  --radius-sm:   8px;
  --shadow-sm:   0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow:      0 4px 16px rgba(11,30,62,.10);
  --shadow-lg:   0 10px 40px rgba(11,30,62,.15);
  --transition:  all .2s ease;
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; scroll-behavior: smooth; }
body {
  font-family: 'Plus Jakarta Sans', sans-serif;
  background: var(--surface);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-wrap {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.login-brand {
  background: linear-gradient(145deg, var(--navy) 0%, var(--navy-muted) 60%, var(--teal) 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  position: relative;
  overflow: hidden;
}
.login-brand::before {
  content: '';
  position: absolute;
  width: 500px; height: 500px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(13,148,136,.3) 0%, transparent 70%);
  top: -100px; right: -100px;
}
.login-brand::after {
  content: '';
  position: absolute;
  width: 300px; height: 300px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(6,182,212,.2) 0%, transparent 70%);
  bottom: -50px; left: -50px;
}
.login-brand-logo {
  font-family: 'DM Serif Display', serif;
  font-size: 2.8rem;
  color: white;
  text-align: center;
  line-height: 1.1;
  position: relative; z-index: 1;
}
.login-brand-logo span { color: var(--teal-light); }
.login-brand-sub {
  color: rgba(255,255,255,.7);
  margin-top: .75rem;
  font-size: .95rem;
  letter-spacing: .05em;
  text-transform: uppercase;
  position: relative; z-index: 1;
}
.login-brand-img {
  margin-top: 2rem;
  position: relative; z-index: 1;
  opacity: .15;
  font-size: 8rem;
  filter: blur(0px);
}
.login-form-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  background: white;
}
.login-form-inner { width: 100%; max-width: 400px; }
.login-title { font-size: 1.8rem; font-weight: 700; color: var(--navy); margin-bottom: .5rem; }
.login-subtitle { color: var(--text-muted); margin-bottom: 2rem; }
.form-label { font-weight: 600; font-size: .85rem; color: var(--navy); margin-bottom: .4rem; }
.form-control {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .65rem 1rem;
  font-family: inherit;
  font-size: .9rem;
  transition: var(--transition);
  width: 100%;
}
.form-control:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(13,148,136,.12);
}
.btn-primary-custom {
  background: linear-gradient(135deg, var(--teal) 0%, var(--navy-muted) 100%);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: .75rem 1.5rem;
  font-family: inherit;
  font-weight: 600;
  font-size: .95rem;
  cursor: pointer;
  width: 100%;
  transition: var(--transition);
  letter-spacing: .02em;
}
.btn-primary-custom:hover { transform: translateY(-1px); box-shadow: var(--shadow); }

/* ============================================================
   LAYOUT PRINCIPAL
   ============================================================ */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--header-h) 1fr;
  min-height: 100vh;
}

/* SIDEBAR */
.sidebar {
  grid-row: 1 / -1;
  background: var(--navy);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
  transition: transform .3s ease;
}
.sidebar-logo {
  padding: 1.5rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center; gap: .75rem;
}
.sidebar-logo-icon {
  width: 38px; height: 38px;
  background: var(--teal);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; color: white;
}
.sidebar-logo-text {
  font-family: 'DM Serif Display', serif;
  font-size: 1.2rem;
  color: white;
  line-height: 1.2;
}
.sidebar-logo-text small { display: block; font-family: 'Plus Jakarta Sans', sans-serif; font-size: .65rem; color: rgba(255,255,255,.5); font-weight: 400; letter-spacing: .05em; text-transform: uppercase; }

.sidebar-user {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,.06);
  display: flex; align-items: center; gap: .75rem;
}
.sidebar-avatar {
  width: 36px; height: 36px;
  background: var(--teal);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: white; font-size: .85rem;
}
.sidebar-user-name { font-size: .85rem; font-weight: 600; color: white; }
.sidebar-user-role { font-size: .72rem; color: rgba(255,255,255,.5); }

.sidebar-nav { padding: 1rem 0; flex: 1; }
.nav-section-label {
  padding: .5rem 1.25rem;
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: rgba(255,255,255,.3);
  margin-top: .5rem;
}
.nav-item {
  display: flex; align-items: center; gap: .75rem;
  padding: .65rem 1.25rem;
  color: rgba(255,255,255,.65);
  text-decoration: none;
  font-size: .875rem;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: var(--transition);
  cursor: pointer;
  user-select: none;
}
.nav-item:hover { color: white; background: rgba(255,255,255,.06); }
.nav-item.active {
  color: white;
  background: rgba(13,148,136,.2);
  border-left-color: var(--teal-light);
}
.nav-item i { font-size: 1rem; width: 20px; text-align: center; }
.nav-item .badge-nav {
  margin-left: auto;
  background: var(--rose);
  color: white;
  border-radius: 999px;
  padding: .1rem .5rem;
  font-size: .7rem;
  font-weight: 700;
}

/* HEADER */
.app-header {
  position: fixed;
  top: 0; left: var(--sidebar-w); right: 0;
  height: var(--header-h);
  background: white;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 1.5rem;
  z-index: 90;
  gap: 1rem;
}
.header-title { font-size: 1.1rem; font-weight: 700; color: var(--navy); flex: 1; }
.header-actions { display: flex; align-items: center; gap: .75rem; }
.notif-btn {
  position: relative;
  width: 38px; height: 38px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: var(--transition);
  color: var(--text-muted);
  font-size: 1.1rem;
}
.notif-btn:hover { background: var(--teal-pale); color: var(--teal); }
.notif-badge {
  position: absolute; top: -4px; right: -4px;
  width: 18px; height: 18px;
  background: var(--rose);
  color: white;
  border-radius: 50%;
  font-size: .65rem;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}

/* MAIN CONTENT */
.app-main {
  margin-left: var(--sidebar-w);
  margin-top: var(--header-h);
  padding: 1.5rem;
  min-height: calc(100vh - var(--header-h));
}

/* ============================================================
   CARDS & STATS
   ============================================================ */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: white;
  border-radius: var(--radius);
  padding: 1.25rem;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex; gap: 1rem; align-items: center;
  transition: var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.stat-icon {
  width: 48px; height: 48px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; flex-shrink: 0;
}
.stat-icon.teal { background: var(--teal-pale); color: var(--teal); }
.stat-icon.navy { background: rgba(11,30,62,.08); color: var(--navy); }
.stat-icon.gold  { background: rgba(245,158,11,.1); color: var(--gold); }
.stat-icon.rose  { background: rgba(244,63,94,.1); color: var(--rose); }
.stat-icon.cyan  { background: rgba(6,182,212,.1); color: var(--cyan); }
.stat-icon.orange{ background: rgba(249,115,22,.1); color: var(--orange); }
.stat-num { font-size: 1.9rem; font-weight: 700; color: var(--navy); line-height: 1; }
.stat-label { font-size: .78rem; color: var(--text-muted); font-weight: 500; margin-top: .2rem; }
.stat-delta { font-size: .75rem; margin-top: .3rem; }
.stat-delta.up   { color: var(--teal); }
.stat-delta.down { color: var(--rose); }

/* TABLE CARD */
.card {
  background: white;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: 1.25rem;
}
.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: .75rem;
  background: white;
}
.card-title {
  font-size: .95rem;
  font-weight: 700;
  color: var(--navy);
  flex: 1;
}
.card-body { padding: 1.25rem; }
.card-body-flush { padding: 0; }

/* TABLA */
.table-custom { width: 100%; border-collapse: collapse; font-size: .85rem; }
.table-custom thead th {
  background: var(--surface);
  color: var(--text-muted);
  font-weight: 600;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}
.table-custom tbody tr { transition: background .15s; }
.table-custom tbody tr:hover { background: var(--ice); }
.table-custom tbody td {
  padding: .8rem 1rem;
  border-bottom: 1px solid rgba(226,232,240,.6);
  vertical-align: middle;
}
.table-custom tbody tr:last-child td { border-bottom: none; }

/* BADGES */
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .25rem .65rem; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.bg-primary-subtle  { background: rgba(11,30,62,.08); }
.text-primary       { color: var(--navy); }
.bg-success-subtle  { background: rgba(13,148,136,.1); }
.text-success       { color: var(--teal); }
.bg-danger-subtle   { background: rgba(244,63,94,.1); }
.text-danger        { color: var(--rose); }
.bg-warning-subtle  { background: rgba(245,158,11,.1); }
.text-warning       { color: var(--gold); }
.bg-orange-subtle   { background: rgba(249,115,22,.1); }
.text-orange        { color: var(--orange); }
.bg-info-subtle     { background: rgba(6,182,212,.1); }
.text-info          { color: var(--cyan); }
.bg-secondary       { background: var(--slate); color: white; }
.bg-light           { background: var(--surface); }
.bg-success         { background: var(--teal); color: white; }

/* BADGE MEDIOS */
.badge-medio {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .25rem .6rem; border-radius: 999px;
  font-size: .75rem; font-weight: 600;
}
.badge-medio.llamada   { background: rgba(11,30,62,.08); color: var(--navy); }
.badge-medio.whatsapp  { background: rgba(37,211,102,.12); color: #128C7E; }
.badge-medio.facebook  { background: rgba(24,119,242,.1); color: #1877F2; }
.badge-medio.instagram { background: rgba(195,42,163,.1); color: #C32AA3; }
.badge-medio.web       { background: rgba(6,182,212,.1); color: var(--cyan); }
.badge-medio.referido  { background: rgba(13,148,136,.1); color: var(--teal); }
.badge-medio.otro      { background: var(--surface); color: var(--slate); }

/* BOTONES */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .5rem 1rem; border-radius: var(--radius-sm);
  font-family: inherit; font-size: .85rem; font-weight: 600;
  cursor: pointer; border: 1.5px solid transparent;
  transition: var(--transition); text-decoration: none;
  white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn-primary  { background: var(--navy); color: white; }
.btn-primary:hover { background: var(--navy-muted); }
.btn-teal     { background: var(--teal); color: white; }
.btn-teal:hover { background: var(--teal-light); }
.btn-outline  { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--surface); }
.btn-danger   { background: var(--rose); color: white; }
.btn-success  { background: var(--teal); color: white; }
.btn-warning  { background: var(--gold); color: white; }
.btn-orange   { background: var(--orange); color: white; }
.btn-sm       { padding: .3rem .75rem; font-size: .78rem; }
.btn-icon     { padding: .4rem .5rem; }

/* FORMS */
.form-group { margin-bottom: 1rem; }
.form-row { display: grid; gap: 1rem; }
.form-row-2 { grid-template-columns: 1fr 1fr; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }
select.form-control { 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'%3E%3Cpath d='M7 10l5 5 5-5z' fill='%2364748b'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .75rem center; padding-right: 2.5rem; }
textarea.form-control { resize: vertical; min-height: 80px; }

/* MODAL */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(11,30,62,.5);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal-box {
  background: white; border-radius: var(--radius);
  padding: 1.75rem; max-width: 560px; width: 90%;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px) scale(.97);
  transition: transform .25s ease;
}
.modal-overlay.open .modal-box { transform: translateY(0) scale(1); }
.modal-title { font-size: 1.1rem; font-weight: 700; color: var(--navy); margin-bottom: 1rem; display: flex; align-items: center; gap: .5rem; }
.modal-actions { margin-top: 1.25rem; display: flex; gap: .75rem; justify-content: flex-end; }

/* TABS */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 1.25rem; }
.tab-item {
  padding: .65rem 1.25rem; font-size: .85rem; font-weight: 600;
  color: var(--text-muted); cursor: pointer; border-bottom: 3px solid transparent;
  margin-bottom: -2px; transition: var(--transition);
}
.tab-item:hover { color: var(--teal); }
.tab-item.active { color: var(--teal); border-bottom-color: var(--teal); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* FILTROS */
.filter-bar {
  display: flex; gap: .75rem; align-items: center;
  flex-wrap: wrap; margin-bottom: 1rem;
}
.filter-bar .form-control { min-width: 160px; width: auto; }
.filter-bar .search-input { min-width: 240px; }

/* PACIENTE INFO */
.patient-pill {
  display: inline-flex; align-items: center; gap: .5rem;
}
.patient-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--teal-pale);
  color: var(--teal);
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 700; flex-shrink: 0;
}
.patient-name { font-weight: 600; color: var(--navy); font-size: .875rem; }
.patient-phone { font-size: .78rem; color: var(--text-muted); }

/* EMPTY STATE */
.empty-state {
  text-align: center; padding: 3rem 1rem;
}
.empty-state i { font-size: 3rem; color: var(--slate-light); margin-bottom: 1rem; display: block; }
.empty-state h4 { color: var(--navy); margin-bottom: .5rem; font-size: 1rem; }
.empty-state p { color: var(--text-muted); font-size: .875rem; }

/* CALENDARIO QUIRÚRGICO */
.cal-header { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-day-header { text-align: center; font-size: .7rem; font-weight: 700; color: var(--text-muted); padding: .4rem; text-transform: uppercase; }
.cal-day {
  min-height: 90px; background: white; border: 1px solid var(--border);
  border-radius: 6px; padding: .4rem;
  font-size: .8rem; transition: var(--transition);
}
.cal-day:hover { border-color: var(--teal); }
.cal-day.today { border-color: var(--teal); background: var(--teal-pale); }
.cal-day.other-month { background: var(--surface); opacity: .5; }
.cal-day-num { font-weight: 700; color: var(--navy); font-size: .8rem; }
.cal-event {
  background: var(--navy); color: white;
  border-radius: 4px; padding: .15rem .4rem;
  font-size: .68rem; margin-top: .2rem; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cal-event:hover { background: var(--teal); }

/* NOTIF DROPDOWN */
.notif-panel {
  position: fixed; top: calc(var(--header-h) + .5rem); right: 1rem;
  width: 360px; background: white;
  border-radius: var(--radius); border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  opacity: 0; transform: translateY(-10px);
  pointer-events: none; transition: all .2s;
}
.notif-panel.open { opacity: 1; transform: translateY(0); pointer-events: all; }
.notif-panel-header { padding: .75rem 1rem; border-bottom: 1px solid var(--border); font-weight: 700; color: var(--navy); font-size: .875rem; }
.notif-item {
  padding: .75rem 1rem; border-bottom: 1px solid rgba(226,232,240,.5);
  display: flex; gap: .75rem; cursor: pointer;
  transition: background .15s;
}
.notif-item:hover { background: var(--surface); }
.notif-item.unread { background: var(--ice); }
.notif-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--rose); margin-top: .35rem; flex-shrink: 0; }
.notif-dot.read { background: var(--border); }
.notif-msg { font-size: .82rem; color: var(--text); line-height: 1.4; }
.notif-time { font-size: .72rem; color: var(--text-muted); margin-top: .2rem; }

/* TIMELINE */
.timeline { position: relative; padding-left: 1.5rem; }
.timeline::before { content:''; position:absolute; left:.35rem; top:0; bottom:0; width:2px; background: var(--border); }
.timeline-item { position: relative; margin-bottom: 1rem; }
.timeline-dot {
  position: absolute; left: -1.5rem; top: .35rem;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--teal); border: 2px solid white; box-shadow: 0 0 0 2px var(--teal);
}
.timeline-content { background: var(--surface); border-radius: var(--radius-sm); padding: .65rem .875rem; }
.timeline-label { font-size: .78rem; font-weight: 600; color: var(--navy); }
.timeline-meta { font-size: .72rem; color: var(--text-muted); margin-top: .2rem; }

/* REPORTES */
.report-metric {
  text-align: center; padding: 1.25rem;
}
.report-metric .num { font-size: 2.5rem; font-weight: 700; color: var(--navy); }
.report-metric .label { font-size: .8rem; color: var(--text-muted); margin-top: .3rem; }
.report-metric .pct { font-size: .85rem; font-weight: 600; color: var(--teal); }

/* RESPONSIVE */
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .app-main, .app-header { margin-left: 0; left: 0; }
  .form-row-3 { grid-template-columns: 1fr 1fr; }
  .login-wrap { grid-template-columns: 1fr; }
  .login-brand { display: none; }
}
@media (max-width: 640px) {
  .form-row-2, .form-row-3 { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .app-main { padding: 1rem; }
}

/* ALERTAS */
.alert { border-radius: var(--radius-sm); padding: .75rem 1rem; font-size: .875rem; margin-bottom: 1rem; display: flex; align-items: center; gap: .5rem; }
.alert-success { background: rgba(13,148,136,.1); color: var(--teal); border: 1px solid rgba(13,148,136,.2); }
.alert-danger  { background: rgba(244,63,94,.1); color: var(--rose); border: 1px solid rgba(244,63,94,.2); }
.alert-warning { background: rgba(245,158,11,.1); color: var(--gold); border: 1px solid rgba(245,158,11,.2); }
.alert-info    { background: rgba(6,182,212,.1); color: var(--cyan); border: 1px solid rgba(6,182,212,.2); }

/* LOADER */
.spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.3); border-top-color: white; border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* PRINT */
@media print {
  .sidebar, .app-header, .btn, .filter-bar { display: none !important; }
  .app-main { margin: 0; padding: 0; }
}
