:root {
  --color-primary-teal: #84C5C8;
  --color-primary-teal-dark: #519095;
  --color-secondary-pink: #EC8CA4;
  --color-secondary-pink-dark: #cc748b;
  --color-text-dark: #4F4F4F;
  --color-text-light: #7A7A7A;
  --color-bg-body: #f4f9f9;
  --color-bg-card: rgba(255, 255, 255, 0.85);
  --color-border: rgba(255, 255, 255, 0.4);

  /* Medical Palette */
  --color-med-blue: #0d6efd;
  --color-med-grey: #6c757d;
  --color-med-red: #dc3545;
  --color-med-green: #198754;
}

body, html {
  overflow-x: hidden;
  width: 100%;
  position: relative;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
  background-color: var(--color-bg-body);
  color: var(--color-text-dark);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Header & Glassmorphism Navigation */
.navbar {
  display: grid;
  grid-template-columns: 80px 1fr 80px; /* Soporte para logo centrado */
  align-items: center;
  padding: 0.5rem 1.5rem;
  background: #ffffff;
  border-bottom: 2px solid #f1f5f9;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2000;
  height: 70px;
}

.navbar-left { justify-self: start; }
.navbar-center { justify-self: center; }
.navbar-right { justify-self: end; display: flex; align-items: center; gap: 1rem; }

/* Ajuste de contenedor para compensar el header fijo */
body {
  padding-top: 70px; /* Altura del navbar */
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.brand-text {
  font-size: 1.5rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  background: linear-gradient(90deg, var(--color-primary-teal-dark), var(--color-secondary-pink));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.nav-links {
  display: flex;
  gap: 1.5rem;
  align-items: center;
}

.nav-links a {
  text-decoration: none;
  color: var(--color-text-light);
  font-weight: 600;
  font-size: 0.95rem;
  transition: color 0.3s ease;
}

.nav-links a:hover, .nav-links a.active {
  color: var(--color-primary-teal-dark);
}

/* Botones Base */
.btn-primary, .btn-secondary, .btn-blue, .btn-grey, .btn-orange, .btn-med-blue, .btn-med-grey, .btn-med-red, .btn-med-green {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.7rem 1.4rem;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.95rem;
  font-family: inherit;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.btn-primary:hover, .btn-secondary:hover, .btn-blue:hover, .btn-grey:hover, .btn-orange:hover, .btn-med-blue:hover, .btn-med-grey:hover, .btn-med-red:hover, .btn-med-green:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

.btn-primary:active, .btn-secondary:active, .btn-blue:active, .btn-grey:active, .btn-orange:active, .btn-med-blue:active, .btn-med-grey:active, .btn-med-red:active, .btn-med-green:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px -1px rgba(0, 0, 0, 0.1);
}

/* Colores de Botones Modernos */
.btn-primary {
  background-color: var(--color-primary-teal);
  color: #fff !important;
}
.btn-primary:hover { background-color: var(--color-primary-teal-dark); color: #fff !important; }

.btn-secondary {
  background-color: var(--color-secondary-pink);
  color: #fff !important;
}
.btn-secondary:hover { background-color: var(--color-secondary-pink-dark); color: #fff !important; }

.btn-blue {
  background-color: #3b82f6; /* Azul moderno */
  color: white !important;
}
.btn-blue:hover { background-color: #2563eb; color: white !important; }

.btn-grey {
  background-color: #64748b; /* Gris neutro */
  color: white !important;
}
.btn-grey:hover { background-color: #475569; color: white !important; }

.btn-orange {
  background-color: #f97316; /* Naranja médico */
  color: white !important;
}
.btn-orange:hover { background-color: #ea580c; color: white !important; }

/* Nuevos Botones Médicos Profesionales */
.btn-med-blue { background-color: var(--color-med-blue); color: white !important; }
.btn-med-blue:hover { background-color: #0b5ed7; color: white !important; }

.btn-med-grey { background-color: var(--color-med-grey); color: white !important; }
.btn-med-grey:hover { background-color: #5c636a; color: white !important; }

.btn-med-red { background-color: var(--color-med-red); color: white !important; }
.btn-med-red:hover { background-color: #bb2d3b; color: white !important; }

.btn-med-green { background-color: var(--color-med-green); color: white !important; }
.btn-med-green:hover { background-color: #157347; color: white !important; }

/* Base Container responsive fluid width */
.container {
  flex: 1;
  padding: 1rem;
  margin: 0 auto;
  width: 100%;
  max-width: 1200px; /* Elite Desktop Cap */
}

@media (min-width: 1024px) {
  .container {
    padding: 2rem 1.5rem;
  }
}

.dash-container {
    max-width: 1200px;
    margin: 0 auto;
}

.consult-container {
    max-width: 1100px;
    margin: 0 auto;
}

.header-action-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

.header-action-row h1 {
  font-size: 2.2rem;
  color: var(--color-primary-teal-dark);
}

/* Cards & Forms */
.card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: 20px;
  padding: 2rem;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.03);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  animation: fadeInUp 0.8s ease backwards;
}

/* Tables */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 1rem;
  border-radius: 8px;
}

.modern-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  text-align: left;
  min-width: 800px; /* Forces scroll on small screens ONLY if not in card mode */
}

.modern-table th {
  padding: 1rem;
  font-weight: 700;
  color: var(--color-primary-teal-dark);
  border-bottom: 2px solid rgba(132, 197, 200, 0.3);
  text-transform: uppercase;
  font-size: 0.85rem;
  letter-spacing: 0.5px;
}

.modern-table td {
  padding: 1.2rem 1rem;
  color: var(--color-text-dark);
  border-bottom: 1px solid rgba(0,0,0,0.04);
  font-weight: 500;
}

.modern-table tr:last-child td {
  border-bottom: none;
}

.modern-table tr:hover td {
  background-color: rgba(132, 197, 200, 0.05);
}

.folio-badge {
  background-color: var(--color-primary-teal);
  color: white;
  padding: 4px 10px;
  border-radius: 6px;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.85rem;
  display: inline-block;
  letter-spacing: 1px;
}

.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--color-text-light);
  font-style: italic;
}

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

.form-group {
  display: flex;
  flex-direction: column;
}

.form-group.full-width {
  grid-column: 1 / -1;
}

.form-group label {
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--color-primary-teal-dark);
  font-size: 0.95rem;
}

.form-control {
  padding: 1rem;
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: 12px;
  font-family: inherit;
  font-size: 1rem;
  color: var(--color-text-dark);
  background-color: rgba(255,255,255,0.7);
  transition: all 0.3s ease;
}

.form-control:focus {
  outline: none;
  border-color: var(--color-primary-teal);
  box-shadow: 0 0 0 4px rgba(132, 197, 200, 0.2);
  background-color: white;
}

textarea.form-control {
  resize: vertical;
  min-height: 150px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
  margin-top: 2rem;
  padding-top: 2rem;
  border-top: 1px solid rgba(0,0,0,0.05);
}

/* Auto-save toast indicator */
.autosave-toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background-color: var(--color-primary-teal-dark);
  color: white;
  padding: 10px 20px;
  border-radius: 30px;
  font-size: 0.85rem;
  font-weight: bold;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(0,0,0,0.1);
  pointer-events: none;
  z-index: 1000;
}

.autosave-toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* Animations */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Responsive Layouts (Mobile-First) */
@media (max-width: 900px) {
  .container {
    padding: 1rem;
  }
  .header-action-row {
    flex-direction: column;
    gap: 1rem;
    align-items: stretch;
  }
  .header-action-row a, .header-action-row button {
    width: 100%;
    justify-content: center;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
  .navbar {
    flex-direction: row;
    padding: 1rem;
    gap: 0.5rem;
  }
  .nav-links {
    width: auto;
    justify-content: flex-end;
    flex-wrap: nowrap;
    gap: 0.5rem;
  }
  
  /* Table scaling for mobile - CONVERT TO CARDS */
  .modern-table, .modern-table thead, .modern-table tbody, .modern-table th, .modern-table td, .modern-table tr {
    display: block;
    min-width: auto !important;
    width: 100% !important;
  }
  
  .modern-table thead tr {
    position: absolute;
    top: -9999px;
    left: -9999px;
  }
  
  .modern-table tr {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    margin-bottom: 1.5rem;
    padding: 1rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
  }
  
  .modern-table td {
    border: none;
    border-bottom: 1px solid #f1f5f9;
    position: relative;
    padding: 0.8rem 1rem !important;
    text-align: left !important;
    min-height: auto;
    display: block; /*Stacked layout */
  }
  
  .modern-table td:last-child {
    border-bottom: none;
    margin-top: 1rem;
    padding-top: 1rem !important;
    border-top: 1px dashed #cbd5e1;
    text-align: center !important;
  }

  .modern-table td:before {
    content: attr(data-label);
    display: block;
    margin-bottom: 4px;
    font-weight: 800;
    color: var(--color-primary-teal-dark);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }
  
  /* Reset relative positioning from previous version */
  .modern-table td:before {
    position: static;
    width: auto;
    padding-right: 0;
  }

  .modern-table td {
    padding-left: 1rem !important;
  }

  /* Sticky Header Compact for Mobile - Elite */
  .navbar {
    padding: 0.5rem 1rem !important;
    height: 65px;
  }
  .navbar-center img {
    height: 45px !important;
    max-height: 50px !important;
  }
  
  /* Mobile Menu Toggle (Hamburger) */
  .nav-toggle {
    display: block !important;
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--color-primary-teal-dark);
    cursor: pointer;
  }

  .nav-links {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    background: white;
    flex-direction: column;
    padding: 1.5rem;
    box-shadow: 0 10px 15px rgba(0,0,0,0.1);
    gap: 1.2rem;
    z-index: 999;
  }

  .nav-links.active {
    display: flex;
  }

  .nav-links a {
    font-size: 1.1rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid #f1f5f9;
  }
}

/* Medical Clean Modal */
.medical-modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}
.medical-modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}
.medical-modal-content {
    background: #ffffff;
    border: 1px solid var(--color-border);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    color: var(--color-text-dark);
    width: 95%;
    max-width: 800px;
    margin: 20px auto;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    border-radius: 12px;
    padding: 2.5rem;
    position: relative;
    transform: translateY(-20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-sizing: border-box;
}
.medical-modal-overlay.active .medical-modal-content {
    transform: translateY(0) scale(1);
}
#modal-data {
    overflow-y: auto;
    flex-grow: 1;
    padding-right: 0.5rem; /* For scrollbar breathing room */
}
.medical-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid rgba(132, 197, 200, 0.2);
    padding-bottom: 1rem;
    margin-bottom: 1rem;
}
.medical-modal-title {
    color: var(--color-primary-teal-dark);
    font-size: 1.5rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin: 0;
}
.medical-modal-close {
    font-size: 2.8rem;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s, transform 0.2s;
    color: #94a3b8;
    margin-left: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
}
.medical-modal-close:hover {
    color: var(--color-secondary-pink);
    transform: scale(1.1);
}
.medical-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}
.medical-label {
    font-size: 0.8rem;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--color-text-light);
    letter-spacing: 0.5px;
    margin-bottom: 0.3rem;
}
.medical-value {
    font-weight: 600;
    font-size: 1.05rem;
    color: var(--color-text-dark);
}
.medical-full {
    grid-column: 1 / -1;
}
.medical-textarea {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    padding: 1rem 1.2rem;
    border-radius: 8px;
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--color-text-dark);
    white-space: pre-wrap;
}

/* Attachment filename - No wrap, just ellipsis */
.attachment-filename {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    color: #334155;
    font-weight: 600;
    display: block;
}

/* File Action Area - Elite Spacing */
.file-action-group {
    display: flex;
    gap: 12px;
    align-items: center;
}
.btn-file-icon {
    width: 45px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-size: 1.4rem;
    transition: all 0.2s;
    cursor: pointer;
}

/* Modal mobile fixes */
@media (max-width: 768px) {
    .medical-modal-content {
        width: 95% !important;
        max-width: 95% !important;
        max-height: 90vh;
        overflow-y: auto;
        padding: 2.5rem 1.5rem 1.5rem !important; /* Más espacio arriba para la X */
        margin: auto;
    }
    .medical-modal-header {
        position: sticky;
        top: -1.5rem;
        background: white;
        z-index: 100;
        padding-top: 1.5rem;
        margin-top: -1.5rem;
        padding-bottom: 1rem;
        /* prevent header buttons from overlapping close button */
        padding-right: 3rem;
    }
    .medical-modal-close {
        position: absolute;
        top: 1rem;
        right: 0.5rem;
        font-size: 3rem !important;
        padding: 0.5rem;
        background: white;
        border-radius: 50%;
        line-height: 0.8;
    }
}

/* Orientation Fixes */
@media screen and (orientation: landscape) and (max-width: 950px) {
    .container {
        padding: 1rem !important;
        margin: 0 auto !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    .header-action-row {
        flex-direction: row !important;
        align-items: center !important;
    }
    .navbar-center img {
        height: 40px !important;
        max-height: 50px !important;
    }
}

/* Elite Split Layout for Consultations */
.elite-split-layout {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

@media (min-width: 1200px) {
    .elite-split-layout {
        display: grid;
        grid-template-columns: 380px 1fr;
        align-items: start;
    }
    .elite-side-panel {
        position: sticky;
        top: 90px;
        max-height: calc(100vh - 120px);
        overflow-y: auto;
        padding-right: 10px;
    }
}

/* Global focus and overflow preventer */
*, *:before, *:after {
    box-sizing: border-box;
}
