/* ============================================
   FLOSSY — Premium Dark Design System
   Apple-inspired · Glassmorphism · iPad-ready
   ============================================ */

/* ---------- Design Tokens ---------- */
:root {
  --bg-primary: #121110;
  --bg-secondary: #1a1816;
  --bg-card: rgba(30, 28, 25, 0.7);
  --bg-card-hover: rgba(42, 39, 35, 0.85);
  --border-color: rgba(245, 236, 227, 0.08);
  --border-hover: rgba(245, 236, 227, 0.15);
  --text-primary: #f5ece3;
  --text-secondary: rgba(245, 236, 227, 0.65);
  --text-muted: rgba(245, 236, 227, 0.4);

  --blue: #2ECC87; /* Flossy green for links and selection */
  --blue-bg: rgba(46, 204, 135, 0.12);
  --teal: #F07060; /* Coral warm */
  --teal-bg: rgba(240, 112, 96, 0.12);
  --purple: #d946ef;
  --purple-bg: rgba(217, 70, 239, 0.12);
  --green: #10b981;
  --green-bg: rgba(16, 185, 129, 0.12);
  --red: #f43f5e;
  --red-bg: rgba(244, 63, 94, 0.12);
  --amber: #f59e0b;
  --amber-bg: rgba(245, 158, 11, 0.12);

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 20px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.45);
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Day Mode (Light Theme Override) */
[data-theme="light"] {
  --bg-primary: #f5f5f7;
  --bg-secondary: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-card-hover: rgba(240, 240, 245, 0.9);
  --border-color: rgba(0, 0, 0, 0.08);
  --border-hover: rgba(0, 0, 0, 0.15);
  --text-primary: #1d1d1f;
  --text-secondary: rgba(29, 29, 31, 0.65);
  --text-muted: rgba(29, 29, 31, 0.4);

  --blue: #2ECC87; /* Flossy green */
  --blue-bg: rgba(46, 204, 135, 0.1);
  --teal: #F07060;
  --teal-bg: rgba(240, 112, 96, 0.1);
  --purple: #8633a6;
  --purple-bg: rgba(134, 51, 166, 0.1);
  --green: #1e824c;
  --green-bg: rgba(30, 130, 76, 0.1);
  --red: #d9383a;
  --red-bg: rgba(217, 56, 58, 0.1);
  --amber: #d97706;
  --amber-bg: rgba(217, 119, 6, 0.1);

  --shadow: 0 8px 32px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .control-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='rgba(29,29,31,0.5)' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
}

[data-theme="light"] #sidebar {
  background: #ffffff;
  border-right-color: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .nav-item:hover {
  background: rgba(46, 204, 135, 0.06);
}

[data-theme="light"] .sidebar-header {
  border-bottom-color: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .sidebar-footer {
  border-top-color: rgba(0, 0, 0, 0.08);
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  height: 100%;
}

body {
  background: var(--bg-primary);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text-primary);
  line-height: 1.5;
  overflow: hidden;
  height: 100%;
  width: 100%;
}

/* ---------- App Layout ---------- */
#app {
  display: flex;
  height: 100%;
  width: 100%;
}

/* ---------- Sidebar ---------- */
#sidebar {
  width: 260px;
  background: #1B2A4A;
  border-right: 1px solid var(--border-color);
  flex-shrink: 0;
  transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 100;
}

#sidebar.collapsed {
  width: 68px;
}

#sidebar.collapsed .logo-brand,
#sidebar.collapsed .nav-label,
#sidebar.collapsed .sidebar-footer-text {
  opacity: 0;
  width: 0;
  overflow: hidden;
}

.sidebar-header {
  padding: 24px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.logo {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.logo-brand {
  display: flex;
  flex-direction: column;
  min-width: 0;
  transition: var(--transition);
}

.logo-text {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  white-space: nowrap;
  transition: var(--transition);
  color: #ffffff;
}

[data-theme="light"] .logo-text {
  color: #1B2A4A;
}

.logo-subtitle {
  font-size: 0.65rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.45);
  white-space: nowrap;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  margin-top: 1px;
}

[data-theme="light"] .logo-subtitle {
  color: rgba(27, 42, 74, 0.45);
}

#nav-menu {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.nav-item {
  padding: 11px 20px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: var(--transition);
  margin: 2px 12px;
  white-space: nowrap;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  color: rgba(255, 255, 255, 0.6);
  position: relative;
  border-left: 3px solid transparent;
}

[data-theme="light"] .nav-item {
  color: rgba(27, 42, 74, 0.55);
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.85);
}

[data-theme="light"] .nav-item:hover {
  color: #1B2A4A;
}

.nav-item.active {
  background: rgba(46, 204, 135, 0.12);
  color: #2ECC87;
  border-left-color: #2ECC87;
  font-weight: 600;
}

.nav-item.active .nav-icon {
  color: #2ECC87;
}

.nav-icon {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.nav-icon svg {
  width: 20px;
  height: 20px;
}

.nav-label {
  font-size: 0.88rem;
  font-weight: 500;
  transition: var(--transition);
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-details {
  flex: 1;
  min-width: 0;
}

.user-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: capitalize;
}

.logout-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
}

.logout-btn:hover {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}

.sync-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ---------- Main Area ---------- */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ---------- Header ---------- */
#header {
  height: 64px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
  gap: 16px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.header-left h1 {
  font-size: 1.2rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.06);
}

.icon-btn:active {
  transform: scale(0.92);
}

/* ---------- Content ---------- */
#content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* ---------- Select Controls ---------- */
.control-select {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 8px 36px 8px 12px;
  font-size: 0.85rem;
  font-family: 'Inter', sans-serif;
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='rgba(240,240,245,0.5)' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  min-height: 44px;
  transition: var(--transition);
}

.control-select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(46, 204, 135, 0.15);
}

.control-select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* ---------- KPI Grid & Cards ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
}

.kpi-card:hover {
  border-color: var(--border-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.kpi-icon {
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  width: 24px;
  height: 24px;
  color: var(--text-secondary);
}

.kpi-icon svg {
  width: 20px;
  height: 20px;
}

.kpi-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.kpi-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

.kpi-delta {
  font-size: 0.8rem;
  margin-top: 8px;
  font-weight: 500;
}

.kpi-delta.positive {
  color: var(--green);
}

.kpi-delta.negative {
  color: var(--red);
}

.kpi-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ---------- Card ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.06), transparent);
}

.card:hover {
  border-color: var(--border-hover);
}

.section-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 4px;
  margin-bottom: 24px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: var(--transition);
  white-space: nowrap;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  border: none;
  background: none;
}

.tab:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.tab.active {
  background: var(--blue);
  color: white;
  box-shadow: 0 2px 8px rgba(46, 204, 135, 0.3);
}

.tab-content {
  display: none;
  animation: fadeIn 0.3s ease;
}

.tab-content.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Data Table ---------- */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-md);
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.data-table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 1;
}

.data-table th.sortable {
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.data-table th.sortable:hover {
  color: var(--text-secondary);
}

.data-table th.sorted-asc::after {
  content: ' ▲';
  font-size: 0.65rem;
}

.data-table th.sorted-desc::after {
  content: ' ▼';
  font-size: 0.65rem;
}

.data-table td {
  padding: 12px 16px;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.data-table tr {
  transition: background 0.15s ease;
}

.data-table tbody tr:hover td {
  background: rgba(255, 255, 255, 0.03);
}

.data-table tbody tr.clickable {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.data-table tbody tr.clickable:active td {
  background: rgba(46, 204, 135, 0.08);
}

.data-table tfoot td {
  font-weight: 600;
  border-top: 2px solid var(--border-color);
  border-bottom: none;
}

/* ---------- Pills ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 100px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.pill-green { background: var(--green-bg); color: var(--green); }
.pill-red { background: var(--red-bg); color: var(--red); }
.pill-amber { background: var(--amber-bg); color: var(--amber); }
.pill-blue { background: var(--blue-bg); color: var(--blue); }
.pill-purple { background: var(--purple-bg); color: var(--purple); }
.pill-teal { background: var(--teal-bg); color: var(--teal); }

/* ---------- Buttons ---------- */
.btn {
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  font-family: 'Inter', sans-serif;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background: var(--blue);
  color: white;
}

.btn-primary:hover {
  filter: brightness(1.1);
  box-shadow: 0 4px 16px rgba(46, 204, 135, 0.3);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--border-hover);
}

.btn-danger {
  background: var(--red);
  color: white;
}

.btn-success {
  background: var(--green);
  color: white;
}

/* ---------- Chart Container ---------- */
.chart-container {
  position: relative;
  width: 100%;
  min-height: 280px;
  height: 320px;
}
.chart-container canvas {
  width: 100% !important;
  height: 100% !important;
}


/* ---------- Loading Overlay ---------- */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 15, 0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

#loading-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-color);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.page-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- Semáforo ---------- */
.semaforo-green { color: var(--green); }
.semaforo-amber { color: var(--amber); }
.semaforo-red { color: var(--red); }

/* ---------- Grid Layouts ---------- */
.two-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.three-cols {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}

.gap-16 { gap: 16px; }
.gap-24 { gap: 24px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }

/* ---------- Progress Bar ---------- */
.progress-bar {
  height: 6px;
  background: var(--bg-secondary);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
  background: linear-gradient(90deg, var(--blue), var(--teal));
}

/* ---------- Avatar ---------- */
.avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 700;
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  color: white;
}

.avatar-sm {
  width: 36px;
  height: 36px;
  font-size: 0.85rem;
}

/* ---------- Search Input ---------- */
.search-input {
  width: 100%;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: 'Inter', sans-serif;
  outline: none;
  transition: var(--transition);
  min-height: 44px;
}

.search-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(46, 204, 135, 0.15);
}

.search-input::placeholder {
  color: var(--text-muted);
}

/* ---------- Filter Row ---------- */
.filter-row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.filter-row .control-select {
  min-width: 140px;
}

/* ---------- Acceptance by Origin (inline KPI) ---------- */
.kpi-origen-inline {
  grid-column: span 3;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.kpi-origen-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}

/* ---------- Acceptance by Origin (shared) ---------- */
.origen-acep-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 2px 0;
}

.kpi-origen-inline .origen-acep-grid {
  gap: 8px;
}

.origen-acep-row {
  display: grid;
  grid-template-columns: 130px 1fr 90px;
  align-items: center;
  gap: 12px;
}

.origen-acep-label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.origen-acep-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.origen-acep-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
  text-transform: capitalize;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.origen-acep-bar-wrap {
  height: 8px;
  background: var(--border-color);
  border-radius: 4px;
  overflow: hidden;
}

.origen-acep-bar {
  height: 100%;
  border-radius: 4px;
  transition: width 1s cubic-bezier(0.4, 0, 0.2, 1);
  min-width: 4px;
}

.origen-acep-stats {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
}

.origen-acep-pct {
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.origen-acep-detail {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Clickable row */
.origen-acep-clickable {
  cursor: pointer;
  border-radius: 8px;
  padding: 6px 8px;
  margin: -6px -8px;
  transition: background 0.2s ease;
}
.origen-acep-clickable:hover {
  background: var(--bg-card-hover, rgba(0,0,0,0.03));
}
.origen-acep-clickable.active {
  background: var(--bg-card-hover, rgba(0,0,0,0.04));
}

.origen-acep-chevron {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  transition: transform 0.3s ease;
  display: inline-block;
  margin-left: 2px;
}
.origen-acep-clickable.active .origen-acep-chevron {
  transform: rotate(90deg);
}

/* Patient panel (collapsed by default) */
.origen-pacientes-panel {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  padding-left: 18px;
  border-left: 2px solid var(--border-color);
  margin-left: 4px;
}
.origen-pacientes-panel.open {
  margin-top: 4px;
  margin-bottom: 4px;
}

.origen-pac-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  border-bottom: 1px solid var(--border-color);
}
.origen-pac-item:last-child {
  border-bottom: none;
}

.origen-pac-name {
  flex: 1;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.origen-pac-importe {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-secondary);
  white-space: nowrap;
}

.origen-pac-empty {
  font-size: 0.72rem;
  color: var(--text-muted);
  padding: 8px 0;
  font-style: italic;
}

.pill-green {
  background: rgba(46, 204, 135, 0.15);
  color: #2ECC87;
}
.pill-amber {
  background: rgba(240, 112, 96, 0.15);
  color: #F07060;
}

@media (max-width: 600px) {
  .kpi-origen-inline { grid-column: span 5; }
  .origen-acep-row {
    grid-template-columns: 100px 1fr 70px;
    gap: 8px;
  }
  .origen-acep-name { font-size: 0.72rem; }
  .origen-acep-pct { font-size: 0.8rem; }
}

/* ---------- Quick Links ---------- */
.quick-links {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.quick-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: var(--transition);
  -webkit-tap-highlight-color: transparent;
  min-height: 56px;
}

.quick-link:hover {
  border-color: var(--border-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.quick-link .ql-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  color: var(--blue);
}

.quick-link .ql-icon svg {
  width: 20px;
  height: 20px;
}

.quick-link .ql-label {
  font-size: 0.85rem;
  font-weight: 500;
}

/* ---------- Agenda Grid ---------- */
.agenda-grid {
  display: grid;
  gap: 2px;
  border-radius: var(--radius-md);
  overflow: hidden;
}

.agenda-day-header {
  background: var(--bg-secondary);
  padding: 12px;
  text-align: center;
  font-weight: 600;
  font-size: 0.85rem;
  border-bottom: 2px solid var(--border-color);
}

.agenda-slot {
  background: var(--bg-card);
  padding: 8px 10px;
  min-height: 48px;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.8rem;
  transition: var(--transition);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.agenda-slot:hover {
  background: var(--bg-card-hover);
}

.agenda-slot.slot-pv {
  border-left: 3px solid var(--blue);
}

.agenda-slot.slot-urg {
  border-left: 3px solid var(--red);
}

.agenda-slot.slot-ctrl {
  border-left: 3px solid var(--green);
}

.agenda-slot.slot-empty {
  opacity: 0.4;
}

/* ---------- Hero Card ---------- */
.hero-card {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 32px;
  background: linear-gradient(135deg, rgba(46, 204, 135, 0.1), rgba(139, 92, 246, 0.08));
  border: 1px solid rgba(46, 204, 135, 0.2);
  border-radius: var(--radius-lg);
  margin-bottom: 24px;
}

.hero-info {
  flex: 1;
  min-width: 0;
}

.hero-name {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.hero-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

/* ---------- Week Nav ---------- */
.week-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 16px;
}

.week-label {
  font-size: 1rem;
  font-weight: 600;
}

/* ---------- Sync Status ---------- */
.sync-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.sync-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: var(--transition);
}

.sync-module {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-color);
}

.sync-module:last-child {
  border-bottom: none;
}

.sync-card-clickable:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

/* ---------- View Mode Tabs ---------- */
.view-mode-tabs {
  display: flex;
  gap: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 3px;
  overflow: hidden;
}

.view-tab {
  padding: 6px 14px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.2s;
  white-space: nowrap;
}

.view-tab:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.view-tab.active {
  background: var(--accent);
  color: white;
  box-shadow: 0 2px 8px rgba(46, 204, 135, 0.3);
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ---------- Empty State ---------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  color: var(--text-muted);
  text-align: center;
}

.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state .empty-text {
  font-size: 1rem;
  font-weight: 500;
}

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .three-cols {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-lg);
  }

  #sidebar.open {
    transform: translateX(0);
  }

  #sidebar.collapsed {
    width: 260px;
    transform: translateX(-100%);
  }

  .two-cols,
  .three-cols {
    grid-template-columns: 1fr;
  }

  #header {
    padding: 0 16px;
  }

  #content {
    padding: 16px;
  }

  .kpi-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }

  .header-controls {
    flex-wrap: wrap;
  }

  .hero-card {
    flex-direction: column;
    text-align: center;
    padding: 24px;
  }
}


/* ============================================
   SAAS ADDITIONS — Login, Admin, Modals, Toast
   ============================================ */

/* ---------- Login Page ---------- */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background: var(--bg-primary);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}

.login-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--blue), var(--teal), var(--purple));
}

.login-header {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo {
  font-size: 3rem;
  display: block;
  margin-bottom: 12px;
}

.login-title {
  font-size: 1.8rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--blue) 0%, var(--teal) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.login-subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.login-error {
  background: var(--red-bg);
  color: var(--red);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 16px;
  border: 1px solid rgba(244, 63, 94, 0.2);
}

.login-btn {
  width: 100%;
  padding: 14px;
  font-size: 1rem;
  margin-top: 8px;
}

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

/* ---------- Form Inputs ---------- */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.form-input {
  width: 100%;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: 'Inter', sans-serif;
  outline: none;
  transition: var(--transition);
  min-height: 48px;
}

.form-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.form-input::placeholder {
  color: var(--text-muted);
}

select.form-input {
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='rgba(240,240,245,0.5)' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

/* ---------- User Info (Sidebar) ---------- */
.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.user-info:hover {
  background: rgba(255, 255, 255, 0.05);
}

.user-details {
  min-width: 0;
  overflow: hidden;
}

.user-name {
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: capitalize;
}

.user-menu {
  margin-top: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.user-menu-item {
  display: block;
  width: 100%;
  padding: 10px 16px;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 0.85rem;
  font-family: 'Inter', sans-serif;
  text-align: left;
  cursor: pointer;
  transition: var(--transition);
}

.user-menu-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

/* ---------- Admin Toolbar ---------- */
.admin-toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
  animation: fadeIn 0.2s ease;
}

.modal {
  width: 100%;
  max-width: 480px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.3s ease;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.modal-header h2 {
  font-size: 1.2rem;
  font-weight: 600;
}

.modal-close {
  font-size: 1.2rem;
  color: var(--text-muted);
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 24px;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Toast Notifications ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 14px 24px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  font-family: 'Inter', sans-serif;
  z-index: 2000;
  opacity: 0;
  transform: translateY(12px);
  transition: all 0.3s ease;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}

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

.toast-success {
  background: var(--green);
  color: white;
}

.toast-error {
  background: var(--red);
  color: white;
}

.toast-info {
  background: var(--blue);
  color: white;
}

/* ---------- Collapsed sidebar user ---------- */
#sidebar.collapsed .user-details,
#sidebar.collapsed .user-menu {
  display: none !important;
}
