body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  margin: 0;
  padding: 24px;
  background:
    radial-gradient(circle at 14% 8%, rgba(59, 130, 246, 0.16) 0, rgba(59, 130, 246, 0) 38%),
    radial-gradient(circle at 86% 14%, rgba(99, 102, 241, 0.15) 0, rgba(99, 102, 241, 0) 36%),
    linear-gradient(180deg, #f8fbff, #eef4ff 46%, #f8fafc 100%);
  color: #0f172a;
  min-height: 100vh;
}

body.auth-pending main {
  visibility: hidden;
}

:root {
  color-scheme: light;
}

main {
  max-width: 1260px;
  margin: 0 auto;
  display: grid;
  gap: 16px;
}

.app-header {
  background: linear-gradient(145deg, #ffffff, #eef6ff);
  border: 1px solid #dbeafe;
  border-radius: 18px;
  padding: 20px 22px;
  box-shadow: 0 16px 36px rgba(15, 23, 42, 0.12);
  display: grid;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-logo {
  width: 210px;
  max-width: 32vw;
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 10px 18px rgba(30, 64, 175, 0.18));
}

h1 {
  margin: 0;
  font-size: clamp(1.28rem, 1.5vw, 1.9rem);
}

.subtitle {
  margin: 4px 0 0;
  color: #475569;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(140px, 1fr));
  gap: 10px;
}

.stat-card {
  background: linear-gradient(180deg, #ffffff, #f8fbff);
  border: 1px solid #dbeafe;
  border-radius: 12px;
  padding: 12px 13px;
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.04);
}

.stat-card strong {
  display: block;
  font-size: 1.35rem;
  color: #1e3a8a;
}

.stat-label {
  font-size: 0.8rem;
  color: #64748b;
}

.card {
  background: #fff;
  border: 1px solid #dbeafe;
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.08);
}

.card > h2 {
  padding-bottom: 10px;
  border-bottom: 1px solid #dbeafe;
}

.auth-card {
  border: 1px solid #c7dcff;
  background:
    linear-gradient(165deg, rgba(255, 255, 255, 0.96), rgba(248, 252, 255, 0.93)),
    radial-gradient(circle at 20% -10%, rgba(37, 99, 235, 0.12), rgba(37, 99, 235, 0));
  box-shadow: 0 22px 42px rgba(37, 99, 235, 0.14);
}

.auth-hero {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: linear-gradient(120deg, #eff6ff, #f8fbff);
  border: 1px solid #dbeafe;
}

.auth-logo {
  width: 88px;
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 8px 16px rgba(29, 78, 216, 0.2));
}

.auth-subtitle {
  margin: 4px 0 0;
  color: #475569;
  font-size: 0.9rem;
}

.hidden {
  display: none !important;
}

.auth-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 10px;
}

.auth-grid label {
  background: #fbfdff;
  border: 1px solid #dbeafe;
  border-radius: 10px;
  padding: 10px;
}

.password-field {
  position: relative;
}

.password-field input {
  padding-right: 44px;
}

.password-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: #1e3a8a;
  border-radius: 6px;
  width: 30px;
  height: 30px;
  cursor: pointer;
  line-height: 1;
}

.password-toggle:hover {
  background: #dbeafe;
}

.session-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.module-nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.module-nav .btn {
  border: 1px solid #bfdbfe;
  background: #f8fbff;
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease;
}

.module-nav .btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 15px rgba(37, 99, 235, 0.16);
}

.module-nav .btn.active {
  background: linear-gradient(160deg, #1d4ed8, #2563eb);
  color: #fff;
  border-color: #1d4ed8;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.33);
}

.role-badge {
  display: inline-block;
  margin-left: 8px;
  background: #dbeafe;
  color: #1e40af;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 0.8rem;
  font-weight: 700;
}

h2 {
  margin: 0 0 10px;
  font-size: 1.12rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 10px;
}

.patient-grid {
  grid-template-columns: repeat(3, minmax(180px, 1fr));
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.88rem;
  color: #334155;
}

.birthdate-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.btn-calendar {
  padding: 8px 10px;
  min-width: 42px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

input,
select {
  width: 100%;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 10px;
  box-sizing: border-box;
  font-size: 0.94rem;
  background: #fdfefe;
  color: #0f172a;
  color-scheme: light;
}

textarea {
  color: #0f172a;
  background: #fdfefe;
  color-scheme: light;
}

input:focus,
select:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.search-input-wrapper {
  position: relative;
}

#searchResults {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 12;
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 300px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #dbeafe;
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.14);
  display: none;
}

#searchResults li {
  padding: 9px 10px;
  display: block;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  background: #ffffff;
  color: #0f172a;
}

#searchResults li:hover {
  background: #2563eb;
  color: #ffffff;
}

#searchResults li.active {
  background: #2563eb;
  color: #ffffff;
}

.result-name {
  font-weight: 600;
}

select option {
  background: #ffffff;
  color: #0f172a;
}

.invoice-dialog table tbody tr:hover {
  background: #eff6ff;
}

.result-cups {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.8rem;
  color: #64748b;
}

.result-tag {
  margin-left: 8px;
  border-radius: 999px;
  padding: 2px 7px;
  background: #dbeafe;
  color: #1d4ed8;
  font-size: 0.72rem;
  font-weight: 700;
}

.feedback {
  margin: 8px 0 0;
  min-height: 18px;
  color: #0f766e;
  font-size: 0.86rem;
}

#departmentCustom {
  display: none;
}

#departmentCustom.visible {
  display: block;
}

.table-section {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  border-radius: 12px;
  overflow: hidden;
}

#topExamsTable {
  table-layout: fixed;
}

#topExamsTable th,
#topExamsTable td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#topExamsTable th:nth-child(1),
#topExamsTable td:nth-child(1) {
  width: 78px;
}

#topExamsTable th:nth-child(2),
#topExamsTable td:nth-child(2) {
  width: 86px;
}

#topExamsTable th:nth-child(3),
#topExamsTable td:nth-child(3) {
  width: 280px;
}

#topExamsTable .portfolio-input-code,
#topExamsTable .portfolio-input-price {
  width: 100%;
  max-width: 100%;
}

#topExamsTable .portfolio-input-code {
  padding-left: 8px;
  padding-right: 8px;
}

#topExamsTable .portfolio-input-cups {
  width: 100%;
  max-width: 100%;
  padding-left: 8px;
  padding-right: 8px;
}

#topExamsTable .portfolio-input-name {
  width: 100%;
  max-width: 100%;
}

#topExamsTable td .price-input,
#topExamsTable td select.price-input {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

thead {
  background: linear-gradient(180deg, #eff6ff, #e2ecff);
}

th,
td {
  padding: 10px 8px;
  border-bottom: 1px solid #e2e8f0;
  text-align: left;
  vertical-align: middle;
}

tbody tr:nth-child(odd) {
  background: #fcfdff;
}

tbody tr:hover {
  background: #eef6ff;
}

.empty-row {
  color: #94a3b8;
  text-align: center;
  font-style: italic;
}

.price-input {
  width: 120px;
  text-align: right;
}

.btn {
  border: none;
  border-radius: 9px;
  padding: 9px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform .14s ease, box-shadow .14s ease, background .14s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-primary {
  background: linear-gradient(150deg, #2563eb, #1d4ed8);
  color: #fff;
  box-shadow: 0 7px 16px rgba(37, 99, 235, 0.28);
}

.btn-primary:hover {
  background: #1d4ed8;
}

.btn-secondary {
  background: #e8eff9;
  color: #0f172a;
}

.btn-secondary:hover {
  background: #cbd5e1;
}

.btn-danger {
  background: #fee2e2;
  color: #b91c1c;
}

.btn-danger:hover {
  background: #fecaca;
}

.btn-retirar {
  border: 1px solid #fecdd3;
  background: linear-gradient(180deg, #fff1f2, #ffe4e6);
  color: #be123c;
  border-radius: 999px;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 800;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(190, 18, 60, 0.15);
}

.btn-retirar:hover {
  background: linear-gradient(180deg, #ffe4e6, #fecdd3);
}

.btn-retirar:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(190, 18, 60, 0.2);
}

.totals-row {
  margin-top: 12px;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  align-items: center;
  font-size: 0.92rem;
}

.totals-row > div {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 8px 11px;
}

.total-box {
  background: #e0ecff !important;
  border-color: #bfdbfe !important;
}

.discount-applied-box {
  background: #fff1f2 !important;
  border-color: #fecaca !important;
  color: #b91c1c;
}

.discount-applied-box strong {
  color: #dc2626;
}

.discount-inline-box {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 6px 10px;
}

.discount-input {
  width: 64px;
  padding: 3px 6px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 0.9rem;
  background: #fff;
  color: #1e293b;
  text-align: right;
  -moz-appearance: textfield;
}

.discount-input::-webkit-outer-spin-button,
.discount-input::-webkit-inner-spin-button {
  opacity: 1;
}

.discount-pct {
  width: 56px;
}

.discount-input:focus {
  outline: none;
  border-color: #94a3b8;
  box-shadow: 0 0 0 2px rgba(148,163,184,0.2);
}

.payment-method-row {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.payment-method-label {
  font-size: 0.88rem;
  color: #475569;
  font-weight: 600;
}

.payment-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 18px;
  background: #f8fafc;
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  color: #475569;
  transition: all 0.15s;
  min-width: 80px;
}

.payment-btn svg {
  width: 22px;
  height: 22px;
  color: #64748b;
  transition: color 0.15s;
}

.payment-btn:hover {
  border-color: #93c5fd;
  background: #eff6ff;
  color: #1d4ed8;
}

.payment-btn:hover svg {
  color: #2563eb;
}

.payment-btn.active {
  background: #dbeafe;
  border-color: #3b82f6;
  color: #1d4ed8;
}

.payment-btn.active svg {
  color: #1d4ed8;
}

.actions-row {
  margin-top: 14px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.history-search {
  margin-bottom: 10px;
}

.history-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.history-head h2 {
  margin: 0;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid #dbeafe;
  background: linear-gradient(180deg, #fbfdff, #f3f8ff);
}

.add-exam-section {
  margin-top: 14px;
  border: 1px solid #dbeafe;
  border-radius: 12px;
  padding: 12px;
  background: linear-gradient(180deg, #ffffff, #f8fbff);
}

.add-exam-section h3 {
  margin-top: 0;
}

.add-exam-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 10px;
}

.lab-routing-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  padding: 10px 12px;
  background: #f0f7ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
}

.lab-routing-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #1e40af;
  margin-right: 4px;
}

.lab-routing-hint {
  font-size: 0.78rem;
  color: #64748b;
}

.lab-btn {
  padding: 5px 14px;
  font-size: 0.82rem;
  border: 1.5px solid #93c5fd;
  background: #fff;
  color: #1e40af;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.lab-btn.active {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
}

.lab-btn-sm {
  padding: 3px 9px;
  font-size: 0.78rem;
  border: 1.5px solid #93c5fd;
  background: #f8fafc;
  color: #1e40af;
  border-radius: 5px;
  cursor: pointer;
  margin-right: 3px;
  transition: background 0.15s, color 0.15s;
}

.lab-btn-sm.active {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
}

.lab-routing-cell {
  white-space: nowrap;
}

.row-actions-cell {
  white-space: nowrap;
  display: flex;
  gap: 6px;
  align-items: center;
}

.sort-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.sort-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #475569;
}

.sort-btn {
  font-size: 0.82rem;
  padding: 4px 12px;
}

.sort-btn.active {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
}

.permissions-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 8px 12px;
  padding: 10px;
  border: 1px solid #dbeafe;
  border-radius: 10px;
  background: #f8fbff;
}

.permissions-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  color: #1e293b;
}

.permissions-grid input[type="checkbox"] {
  width: 16px;
  height: 16px;
}

.delete-confirm {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid #fecaca;
  border-radius: 10px;
  background: #fff5f5;
}

.delete-confirm p {
  margin: 0;
  color: #7f1d1d;
  font-weight: 600;
}

.stats-list {
  margin: 8px 0 16px;
  padding-left: 0;
  list-style: none;
  color: #1f2937;
  display: grid;
  gap: 10px;
}

.stats-shell {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 4px;
}

.stats-block {
  border: 1px solid #dbeafe;
  border-radius: 16px;
  padding: 16px 14px 10px;
  background: linear-gradient(160deg, #ffffff 60%, #f0f7ff);
  box-shadow: 0 4px 16px rgba(30,64,175,0.07), inset 0 0 0 1px rgba(147,197,253,0.14);
}

.stats-block h3 {
  margin: 0 0 12px;
  font-size: 0.96rem;
  color: #1e3a8a;
  letter-spacing: .3px;
  padding-bottom: 8px;
  border-bottom: 2px solid #dbeafe;
}

.stat-detail-item details {
  border: 1px solid #dbeafe;
  border-radius: 12px;
  background: linear-gradient(180deg, #fff, #f8fbff);
  box-shadow: 0 8px 18px rgba(30, 64, 175, 0.08);
}

.stat-detail-item details[open] {
  border-color: #93c5fd;
  box-shadow: 0 12px 24px rgba(37, 99, 235, 0.14);
}

.stat-detail-item summary {
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
  color: #0f172a;
  font-weight: 700;
}

.stat-detail-item summary::-webkit-details-marker {
  display: none;
}

.stat-detail-item summary strong {
  color: #1d4ed8;
  font-size: .93rem;
  text-align: right;
}

.stat-detail-item summary span {
  position: relative;
  padding-left: 16px;
}

.stat-detail-item summary span::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(180deg, #3b82f6, #1d4ed8);
}

.stat-detail-content {
  border-top: 1px dashed #bfdbfe;
  padding: 10px 14px 13px;
  color: #475569;
  font-size: .88rem;
  line-height: 1.42;
}

.mini-actions {
  display: flex;
  gap: 6px;
}

.btn-emoji {
  min-width: 40px;
  padding: 6px 10px;
  font-size: 1.02rem;
  line-height: 1;
}

.package-suggestions {
  margin-top: 8px;
  border: 1px solid #dbeafe;
  border-radius: 10px;
  background: #ffffff;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  max-height: 260px;
  overflow-y: auto;
}

.package-suggestion-item {
  width: 100%;
  border: none;
  border-bottom: 1px solid #e2e8f0;
  background: #ffffff;
  color: #0f172a;
  text-align: left;
  padding: 10px 12px;
  cursor: pointer;
  font-size: 0.87rem;
}

.package-suggestion-item:last-child {
  border-bottom: none;
}

.package-suggestion-item:hover,
.package-suggestion-item:focus-visible {
  background: #eff6ff;
  outline: none;
}

#patientModule .search-section,
#patientModule .table-section,
#patientModule .form-card {
  border: 1px solid #e6effe;
  border-radius: 12px;
  padding: 14px;
  background: linear-gradient(180deg, #fff, #fbfdff);
  box-shadow: inset 0 0 0 1px rgba(147, 197, 253, 0.16);
}

#patientModule {
  display: grid;
  gap: 12px;
}

.mini-actions .btn {
  padding: 6px 10px;
  font-size: 0.78rem;
}

.invoice-dialog {
  width: min(980px, 92vw);
  border: 1px solid #dbeafe;
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 18px 45px rgba(15, 23, 42, 0.25);
}

.invoice-dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.dialog-head h2 {
  margin: 0;
}

.dialog-meta {
  margin-bottom: 10px;
  color: #475569;
  font-size: 0.88rem;
}

@media (max-width: 900px) {
  .stats-grid,
  .form-grid,
  .patient-grid,
  .auth-grid {
    grid-template-columns: 1fr;
  }

  .stats-shell {
    grid-template-columns: 1fr;
  }

  .filter-grid {
    grid-template-columns: 1fr;
  }

  .add-exam-grid {
    grid-template-columns: 1fr;
  }

  body {
    padding: 12px;
  }

  .brand {
    flex-direction: column;
    align-items: flex-start;
  }

  .brand-logo {
    width: 152px;
  }

  .auth-hero {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media print {
  body {
    background: #fff;
    padding: 0;
  }

  .search-section,
  .history-section,
  .form-card,
  .stats-grid,
  .actions-row,
  .btn-retirar,
  .invoice-dialog,
  .feedback {
    display: none !important;
  }

  .card,
  .app-header {
    box-shadow: none;
    border: none;
  }
}
 