/* ============================================================
   Variables & Reset
   ============================================================ */
:root {
  --primary:      #1d4ed8;
  --primary-h:    #1e40af;
  --secondary:    #64748b;
  --bg:           #f1f5f9;
  --surface:      #ffffff;
  --border:       #e2e8f0;
  --text:         #1e293b;
  --text-muted:   #64748b;
  --ingresado:    #f59e0b;
  --ingresado-bg: #fffbeb;
  --proceso:      #3b82f6;
  --proceso-bg:   #eff6ff;
  --cerrado:      #10b981;
  --cerrado-bg:   #ecfdf5;
  --danger:       #ef4444;
  --danger-bg:    #fef2f2;
  --shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:    0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg:    0 10px 15px rgba(0,0,0,.07), 0 4px 6px rgba(0,0,0,.05);
  --radius:       10px;
  --radius-sm:    6px;
  --navbar-h:     60px;
  --transition:   .18s ease;
}

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

html { font-size: 15px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ============================================================
   Navbar
   ============================================================ */
.navbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--navbar-h);
  background: var(--primary);
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  gap: 1rem;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: .55rem;
  flex-shrink: 0;
}

.brand-logo { color: #93c5fd; display: flex; align-items: center; }
.brand-name { font-weight: 700; font-size: 1rem; color: #fff; white-space: nowrap; }
.brand-sub  { font-size: .7rem; color: #93c5fd; white-space: nowrap; display: none; }
@media (min-width: 768px) { .brand-sub { display: inline; } }

.navbar-center {
  flex: 1;
  display: flex;
  justify-content: center;
  gap: .25rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .45rem .9rem;
  border-radius: var(--radius-sm);
  color: #bfdbfe;
  text-decoration: none;
  font-size: .875rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
}
.nav-link:hover, .nav-link.active {
  background: rgba(255,255,255,.15);
  color: #fff;
}

.navbar-user {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-shrink: 0;
}

.user-info {
  display: flex;
  align-items: center;
  gap: .5rem;
}

.user-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: rgba(255,255,255,.2);
  color: #fff;
  font-weight: 700;
  font-size: .9rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.user-details {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.user-name { font-size: .8rem; font-weight: 600; color: #fff; }
.user-role { font-size: .65rem; padding: 1px 6px; border-radius: 10px; width: fit-content; }
.user-role.administrador { background: #fef3c7; color: #92400e; }
.user-role.operador       { background: #dbeafe; color: #1e40af; }

.btn-logout {
  display: flex; align-items: center;
  color: #bfdbfe;
  padding: .35rem;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}
.btn-logout:hover { color: #fff; background: rgba(255,255,255,.15); }

.notif-badge {
  background: var(--danger);
  color: #fff;
  font-size: .7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 12px;
  animation: pulse 1.5s infinite;
}

.hamburger {
  display: none;
  background: none; border: none;
  color: #fff; font-size: 1.3rem; cursor: pointer;
}
@media (max-width: 640px) { .hamburger { display: block; } }

/* ============================================================
   Main content
   ============================================================ */
.main-content {
  margin-top: var(--navbar-h);
  padding: 1.5rem;
  max-width: 1600px;
  margin-left: auto;
  margin-right: auto;
}

/* ============================================================
   Page header
   ============================================================ */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.page-title    { font-size: 1.4rem; font-weight: 700; color: var(--text); }
.page-subtitle { font-size: .82rem; color: var(--text-muted); margin-top: .2rem; }

/* ============================================================
   Stats cards
   ============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow);
  border-left: 4px solid transparent;
  transition: transform var(--transition), box-shadow var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.stat-ingresado { border-color: var(--ingresado); }
.stat-proceso   { border-color: var(--proceso); }
.stat-cerrado   { border-color: var(--cerrado); }
.stat-total     { border-color: var(--primary); }

.stat-icon {
  width: 44px; height: 44px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-ingresado .stat-icon { background: var(--ingresado-bg); color: var(--ingresado); }
.stat-proceso   .stat-icon { background: var(--proceso-bg);   color: var(--proceso); }
.stat-cerrado   .stat-icon { background: var(--cerrado-bg);   color: var(--cerrado); }
.stat-total     .stat-icon { background: #eff6ff;             color: var(--primary); }

.stat-value { font-size: 1.8rem; font-weight: 800; display: block; line-height: 1; }
.stat-label { font-size: .75rem; color: var(--text-muted); margin-top: .2rem; display: block; }

/* ============================================================
   Toolbar
   ============================================================ */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1rem;
}
.toolbar-left  { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.toolbar-right { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }

.search-box {
  display: flex;
  align-items: center;
  gap: .5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .45rem .75rem;
  box-shadow: var(--shadow);
}
.search-box svg { color: var(--text-muted); flex-shrink: 0; }
.search-box input {
  border: none; outline: none;
  font-size: .875rem; color: var(--text);
  background: transparent;
  width: 220px;
}

.filter-select {
  padding: .45rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .875rem;
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
}

.total-label { font-size: .8rem; color: var(--text-muted); }

.new-alert {
  display: flex; align-items: center; gap: .35rem;
  background: var(--danger-bg); color: var(--danger);
  font-size: .8rem; font-weight: 600;
  padding: .35rem .75rem;
  border-radius: 20px;
  animation: pulse 1.5s infinite;
  cursor: pointer;
}

/* ============================================================
   Table
   ============================================================ */
.table-wrapper {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
.data-table thead { background: #f8fafc; }
.data-table th {
  padding: .75rem 1rem;
  text-align: left;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  user-select: none;
}
.data-table th[data-sort] { cursor: pointer; }
.data-table th[data-sort]:hover { color: var(--primary); }
.sort-icon { opacity: .4; font-size: .7rem; }

.data-table td {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  white-space: nowrap;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #f8fafc; }
.data-table tbody tr.row-new { background: #fef9c3 !important; animation: fadeIn .4s; }

.table-empty {
  text-align: center;
  padding: 3rem !important;
  color: var(--text-muted);
}

/* Status badges */
.badge {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .25rem .65rem;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; }
.badge-ingresado { background: var(--ingresado-bg); color: #92400e; }
.badge-ingresado::before { background: var(--ingresado); }
.badge-proceso   { background: var(--proceso-bg);   color: #1e40af; }
.badge-proceso::before   { background: var(--proceso); }
.badge-cerrado   { background: var(--cerrado-bg);   color: #065f46; }
.badge-cerrado::before   { background: var(--cerrado); }

/* Action buttons */
.btn-icon {
  display: inline-flex; align-items: center;
  padding: .3rem;
  border: none; background: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
}
.btn-icon:hover { background: var(--bg); color: var(--primary); }

/* ============================================================
   Modal
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  padding: 1rem;
  backdrop-filter: blur(2px);
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  animation: slideUp .2s ease;
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.1rem 1.4rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h3 { font-size: 1.05rem; font-weight: 700; }
.modal-close {
  background: none; border: none;
  font-size: 1.4rem; cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: .25rem;
  border-radius: 4px;
}
.modal-close:hover { background: var(--bg); color: var(--text); }

.modal-body {
  padding: 1.25rem 1.4rem;
  overflow-y: auto;
  flex: 1;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
  margin-bottom: 1.25rem;
}
@media (max-width: 480px) { .detail-grid { grid-template-columns: 1fr; } }

.detail-item {
  display: flex; flex-direction: column; gap: .15rem;
}
.detail-item-full { grid-column: 1 / -1; }
.detail-label { font-size: .7rem; font-weight: 700; text-transform: uppercase; color: var(--text-muted); }
.detail-value { font-size: .9rem; font-weight: 500; color: var(--text); }

.obs-section { margin-top: .75rem; }
.obs-label { font-size: .82rem; font-weight: 600; color: var(--text); margin-bottom: .4rem; display: block; }
.required { color: var(--danger); }
.obs-section textarea {
  width: 100%;
  padding: .65rem .85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .875rem;
  resize: vertical;
  font-family: inherit;
  color: var(--text);
  transition: border var(--transition);
}
.obs-section textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29,78,216,.1);
}
.char-count { font-size: .72rem; color: var(--text-muted); display: block; text-align: right; }

.obs-view { margin-top: .75rem; }
.obs-text {
  font-size: .875rem;
  color: var(--text);
  background: var(--bg);
  padding: .75rem;
  border-radius: var(--radius-sm);
  white-space: pre-wrap;
}

.modal-actions {
  display: flex; gap: .75rem; flex-wrap: wrap;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .5rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: .875rem; font-weight: 600;
  border: none; cursor: pointer;
  text-decoration: none;
  transition: background var(--transition), transform var(--transition);
}
.btn:active { transform: scale(.97); }

.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover  { background: var(--primary-h); }
.btn-secondary{ background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover{ background: var(--border); }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover   { background: #dc2626; }
.btn-full     { width: 100%; justify-content: center; padding: .7rem; }

/* ============================================================
   Connection status
   ============================================================ */
.connection-status {
  display: flex; align-items: center; gap: .4rem;
  font-size: .78rem; color: var(--text-muted);
}
.dot {
  width: 8px; height: 8px; border-radius: 50;
  border-radius: 50%;
}
.dot-connecting { background: var(--ingresado); animation: pulse 1.2s infinite; }
.dot-connected  { background: var(--cerrado); }
.dot-disconnected{ background: var(--danger); }

/* ============================================================
   Toast notifications
   ============================================================ */
.toast-container {
  position: fixed;
  bottom: 1.5rem; right: 1.5rem;
  z-index: 300;
  display: flex; flex-direction: column; gap: .5rem;
}

.toast {
  display: flex; align-items: flex-start; gap: .65rem;
  background: var(--surface);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: .85rem 1rem;
  min-width: 280px; max-width: 380px;
  animation: slideLeft .25s ease;
  font-size: .875rem;
}
.toast-success { border-color: var(--cerrado); }
.toast-danger  { border-color: var(--danger); }
.toast-warning { border-color: var(--ingresado); }
.toast-title   { font-weight: 700; }
.toast-body    { color: var(--text-muted); font-size: .8rem; margin-top: .15rem; }

/* ============================================================
   Charts
   ============================================================ */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}
@media (max-width: 768px) { .charts-row { grid-template-columns: 1fr; } }

.chart-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}
.chart-full { }
.chart-title { font-size: .95rem; font-weight: 700; margin-bottom: 1rem; color: var(--text); }
.chart-container { position: relative; height: 260px; }
.chart-tall { height: 320px; }

/* ============================================================
   Login page
   ============================================================ */
.login-page {
  background: linear-gradient(135deg, #1e3a8a 0%, #1d4ed8 50%, #2563eb 100%);
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}

.login-wrapper {
  width: 100%;
  max-width: 420px;
}

.login-card {
  background: var(--surface);
  border-radius: calc(var(--radius) * 1.5);
  padding: 2.5rem 2rem;
  box-shadow: 0 20px 40px rgba(0,0,0,.25);
}

.login-logo {
  display: flex; justify-content: center;
  margin-bottom: 1rem;
}

.login-title {
  text-align: center;
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: .35rem;
}

.login-subtitle {
  text-align: center;
  font-size: .8rem;
  color: var(--text-muted);
  margin-bottom: 1.75rem;
}

.form-group {
  margin-bottom: 1.1rem;
}
.form-group label {
  display: block;
  font-size: .8rem; font-weight: 600;
  color: var(--text);
  margin-bottom: .4rem;
}

.input-icon {
  display: flex; align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 .75rem;
  gap: .5rem;
  transition: border var(--transition), box-shadow var(--transition);
}
.input-icon:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29,78,216,.12);
}
.input-icon svg { color: var(--text-muted); flex-shrink: 0; }
.input-icon input {
  flex: 1;
  border: none; outline: none;
  padding: .65rem 0;
  font-size: .9rem; color: var(--text);
  background: transparent;
}
.toggle-pw {
  background: none; border: none;
  color: var(--text-muted); cursor: pointer;
  padding: 0; display: flex; align-items: center;
}

.alert {
  display: flex; align-items: center; gap: .5rem;
  padding: .75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  margin-bottom: 1.1rem;
}
.alert-danger { background: var(--danger-bg); color: #991b1b; border: 1px solid #fecaca; }

.login-footer {
  text-align: center;
  font-size: .72rem;
  color: var(--text-muted);
  margin-top: 1.25rem;
}

/* ============================================================
   Licencia médica (modal)
   ============================================================ */
.licencia-section {
  margin: 1rem 0;
  border: 1px solid #c7d2fe;
  border-radius: var(--radius-sm);
  background: #f5f7ff;
  padding: .85rem 1rem;
  animation: fadeIn .2s ease;
}
.licencia-header {
  display: flex; align-items: center; gap: .45rem;
  font-weight: 600; font-size: .88rem; color: #3730a3;
  margin-bottom: .75rem;
}
.licencia-resumen {
  margin-bottom: .8rem;
}
.lic-table {
  width: 100%; border-collapse: collapse; font-size: .8rem;
}
.lic-table th {
  background: #e0e7ff; color: #3730a3;
  padding: .35rem .6rem; text-align: left; font-weight: 600;
  border-bottom: 1px solid #c7d2fe;
}
.lic-table td {
  padding: .35rem .6rem; border-bottom: 1px solid #e0e7ff;
  vertical-align: middle;
}
.lic-table tr.lic-activo td { background: #eef2ff; }
.lic-bar-wrap {
  width: 90px; height: 7px; background: #e0e7ff;
  border-radius: 4px; display: inline-block; vertical-align: middle;
}
.lic-bar { height: 100%; border-radius: 4px; background: #4f46e5; }
.lic-bar.lic-bar-warn { background: #f59e0b; }
.lic-bar.lic-bar-danger { background: #ef4444; }
.licencia-form-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: .6rem .8rem;
}
@media (max-width: 520px) { .licencia-form-grid { grid-template-columns: 1fr; } }
.lic-field { display: flex; flex-direction: column; gap: .25rem; }
.lic-label { font-size: .75rem; font-weight: 600; color: var(--text-muted); }
.lic-input {
  padding: .42rem .6rem; border: 1px solid #c7d2fe;
  border-radius: var(--radius-sm); font-size: .85rem;
  background: #fff; color: var(--text); outline: none;
  transition: border-color var(--transition);
}
.lic-input:focus { border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99,102,241,.12); }
.lic-select { appearance: none; cursor: pointer; }
.lic-disp {
  font-size: .78rem; color: #4f46e5; font-weight: 600;
}
.lic-disp.lic-warn  { color: #d97706; }
.lic-disp.lic-danger{ color: #dc2626; }
.lic-readonly-box {
  background: #eef2ff; border: 1px solid #c7d2fe;
  border-radius: var(--radius-sm); padding: .65rem .85rem;
  font-size: .84rem;
}
.lic-readonly-box strong { color: #3730a3; }

/* ============================================================
   Spinner
   ============================================================ */
.loading-spinner {
  display: inline-block;
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: auto;
}

/* ============================================================
   Animations & utils
   ============================================================ */
.hidden { display: none !important; }

@keyframes spin    { to { transform: rotate(360deg); } }
@keyframes pulse   { 0%,100% { opacity: 1; } 50% { opacity: .5; } }
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes slideLeft { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: none; } }

/* ============================================================
   Responsive tweaks
   ============================================================ */
@media (max-width: 640px) {
  .main-content { padding: .75rem; }
  .navbar-center { display: none; }
  .user-details   { display: none; }
  .search-box input { width: 140px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* ============================================================
   Pagination
   ============================================================ */
.page-size-label {
  display: flex; align-items: center; gap: .4rem;
  font-size: .8rem; color: var(--text-muted);
}
.pagination-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: .65rem 1rem; margin-top: .25rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 0 0 10px 10px; border-top: none;
  flex-wrap: wrap; gap: .5rem;
}
.pagination-info { font-size: .8rem; color: var(--text-muted); }
.pagination-controls { display: flex; gap: .25rem; align-items: center; }
.pg-btn {
  min-width: 30px; height: 30px; padding: 0 .45rem;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text);
  font-size: .8rem; cursor: pointer; transition: all .15s;
}
.pg-btn:hover:not(:disabled) { background: var(--primary); color: #fff; border-color: var(--primary); }
.pg-btn:disabled { opacity: .35; cursor: default; }
.pg-btn.pg-active { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 700; }
.pg-ellipsis { padding: 0 .3rem; color: var(--text-muted); font-size: .85rem; }
