@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;600&display=swap');

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

:root {
  --bg:           #0d0f14;
  --surface:      #161a24;
  --surface-2:    #1e2433;
  --surface-3:    #252d3d;
  --border:       #2a3044;
  --accent:       #5b6ff0;
  --accent-h:     #7283f5;
  --accent-glow:  rgba(91,111,240,.25);
  --success:      #3ecf8e;
  --success-bg:   rgba(62,207,142,.12);
  --warning:      #f5a623;
  --warning-bg:   rgba(245,166,35,.12);
  --danger:       #e55353;
  --danger-bg:    rgba(229,83,83,.12);
  --text:         #e8ecf4;
  --text-muted:   #7a8296;
  --text-subtle:  #4a5168;
  --radius:       12px;
  --radius-sm:    8px;
  --radius-xs:    6px;
  --shadow:       0 4px 24px rgba(0,0,0,.45);
  --shadow-sm:    0 2px 8px rgba(0,0,0,.3);
  --font:         'Inter', sans-serif;
  --mono:         'JetBrains Mono', monospace;
  --sidebar-w:    240px;
  --topbar-h:     64px;
  --t:            0.2s ease;
}

:root[data-theme="light"] {
  --bg:           #f3f6fb;
  --surface:      #ffffff;
  --surface-2:    #f8fafc;
  --surface-3:    #eef2f7;
  --border:       #dbe4ef;
  --accent:       #4f46e5;
  --accent-h:     #4338ca;
  --accent-glow:  rgba(79,70,229,.16);
  --success:      #059669;
  --success-bg:   rgba(5,150,105,.12);
  --warning:      #d97706;
  --warning-bg:   rgba(217,119,6,.12);
  --danger:       #dc2626;
  --danger-bg:    rgba(220,38,38,.1);
  --text:         #0f172a;
  --text-muted:   #475569;
  --text-subtle:  #64748b;
  --shadow:       0 8px 24px rgba(15,23,42,.08);
  --shadow-sm:    0 2px 8px rgba(15,23,42,.06);
}

html, body { height: 100%; font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.6; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; transition: color var(--t); }
a:hover { color: var(--accent-h); }
img { max-width: 100%; display: block; }
button { cursor: pointer; font-family: var(--font); }
input, select, textarea { font-family: var(--font); }

/* Scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-subtle); }

/* Typography */
h1 { font-size: 2rem;   font-weight: 700; line-height: 1.2; }
h2 { font-size: 1.5rem; font-weight: 700; line-height: 1.3; }
h3 { font-size: 1.15rem; font-weight: 600; }
h4 { font-size: 1rem;   font-weight: 600; }

/* Utilities */
.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: .5rem; }
.gap-2 { gap: 1rem; }
.gap-3 { gap: 1.5rem; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-2 { margin-bottom: 1rem; }
.w-full { width: 100%; }
.text-muted  { color: var(--text-muted); }
.text-accent { color: var(--accent); }
.text-success{ color: var(--success); }
.text-warning{ color: var(--warning); }
.text-danger { color: var(--danger); }
.text-sm { font-size: .8125rem; }
.text-xs { font-size: .75rem; }
.font-semibold { font-weight: 600; }
.font-bold     { font-weight: 700; }
.mono { font-family: var(--mono); }

/* Animations */
@keyframes fadeInUp  { from { opacity:0; transform:translateY(16px); } to { opacity:1; transform:translateY(0); } }
@keyframes fadeIn    { from { opacity:0; } to { opacity:1; } }
@keyframes scaleIn   { from { opacity:0; transform:scale(.95); } to { opacity:1; transform:scale(1); } }
@keyframes shimmer   { 0% { background-position:-200% 0; } 100% { background-position:200% 0; } }
@keyframes pulse     { 0%,100% { opacity:1; } 50% { opacity:.5; } }

.anim-up    { animation: fadeInUp .4s ease both; }
.anim-fade  { animation: fadeIn   .3s ease both; }
.anim-scale { animation: scaleIn  .25s ease both; }

.divider { height:1px; background:var(--border); margin:1.5rem 0; }


/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .55rem 1.1rem; border-radius: var(--radius-sm); font-size: .875rem;
  font-weight: 500; border: none; transition: all var(--t); white-space: nowrap;
}
.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover  { background: var(--accent-h); box-shadow: 0 0 16px var(--accent-glow); transform: translateY(-1px); }
.btn-success  { background: var(--success); color: #0d0f14; }
.btn-success:hover  { opacity: .88; transform: translateY(-1px); }
.btn-danger   { background: var(--danger-bg); color: var(--danger); border: 1px solid rgba(229,83,83,.3); }
.btn-danger:hover   { background: var(--danger); color: #fff; }
.btn-ghost    { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover    { background: var(--surface-3); border-color: var(--accent); color: var(--accent); }
.btn-icon     { padding: .5rem; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); color: var(--text-muted); }
.btn-icon:hover     { color: var(--accent); border-color: var(--accent); background: var(--accent-glow); }
.btn-sm { padding: .35rem .75rem; font-size: .8125rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none !important; }

/* ===== CARDS ===== */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}
.card-hover { transition: border-color var(--t), transform var(--t), box-shadow var(--t); }
.card-hover:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 8px 32px rgba(91,111,240,.15); }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.card-title  { font-size: 1rem; font-weight: 600; }

/* ===== BADGES ===== */
.badge {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .2rem .65rem; border-radius: 100px; font-size: .75rem; font-weight: 500;
}
.badge::before { content:''; width:6px; height:6px; border-radius:50%; background:currentColor; }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger); }
.badge-accent  { background: var(--accent-glow); color: var(--accent); }
.badge-neutral { background: var(--surface-2);   color: var(--text-muted); }

/* ===== FORM ELEMENTS ===== */
.form-group { display: flex; flex-direction: column; gap: .4rem; }
.form-label { font-size: .8125rem; font-weight: 500; color: var(--text-muted); }
.input, .select, .textarea {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-sm); padding: .6rem .9rem; font-size: .875rem;
  transition: border-color var(--t), box-shadow var(--t); width: 100%;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow);
}
.input::placeholder { color: var(--text-subtle); }
.select { 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 fill='%237a8296' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .75rem center; padding-right: 2.5rem; }
.textarea { resize: vertical; min-height: 90px; }
.input-time-24 {
  font-variant-numeric: tabular-nums;
  font-family: inherit;
  max-width: 5.5rem;
  text-align: center;
  letter-spacing: 0;
}
.input.input-sm.input-time-24 { max-width: 100%; }
.space-franjas-head { display:flex; align-items:center; justify-content:space-between; margin-bottom:6px; }
.space-franjas-head .form-label { margin:0; font-size:.8125rem; }
.space-franjas-grid { display:grid; grid-template-columns:repeat(2, minmax(0,1fr)); gap:6px; }
.franja-block { display:grid; grid-template-columns:22px 1fr auto 1fr auto; align-items:center; gap:4px; padding:4px 6px; background:var(--surface-2); border:1px solid var(--border); border-radius:6px; }
.franja-block-label { font-size:.75rem; font-weight:700; color:var(--text-muted); text-align:center; }
.franja-block .input-time-24 { width:100%; min-width:0; padding:4px 6px; font-size:.8125rem; height:32px; }
@media (max-width:700px){ .space-franjas-grid { grid-template-columns:1fr; } }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.65); backdrop-filter: blur(4px);
  z-index: 1000; display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.modal-overlay.active { opacity: 1; pointer-events: all; }
.modal-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  width: min(520px, 92vw); max-height: 90vh; overflow-y: auto;
  transform: scale(.95); transition: transform .2s ease; box-shadow: 0 16px 64px rgba(0,0,0,.6);
}
.modal-overlay.active .modal-box { transform: scale(1); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 1.25rem; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 1rem; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 1.25rem; line-height: 1; cursor: pointer; padding: .25rem; border-radius: var(--radius-xs); transition: color var(--t); }
.modal-close:hover { color: var(--text); }
.modal-body   { padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem; }
.modal-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: .75rem; }
/* Teclado y clic fuera: portal-modal.js (Enter = confirmar, Esc = cancelar, sin cierre al clic en fondo) */

/* ===== TOAST ===== */
#toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 2000; display: flex; flex-direction: column; gap: .5rem; }
.toast {
  display: flex; align-items: center; gap: .75rem;
  padding: .75rem 1.1rem; border-radius: var(--radius-sm); font-size: .875rem; font-weight: 500;
  box-shadow: var(--shadow); animation: fadeInUp .3s ease both;
  border-left: 3px solid;
}
.toast-success { background: var(--surface); color: var(--success); border-color: var(--success); }
.toast-error   { background: var(--surface); color: var(--danger);  border-color: var(--danger); }
.toast-info    { background: var(--surface); color: var(--accent);  border-color: var(--accent); }

.portal-notifications { position: relative; }
.portal-notifications-btn {
  position: relative; width: 36px; height: 36px; border: 1px solid var(--border);
  border-radius: 999px; background: var(--surface-2); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.portal-notifications-btn:hover { border-color: var(--accent); background: var(--surface-3); }
.portal-notifications-badge {
  position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; background: var(--danger); color: #fff; font-size: .68rem;
  align-items: center; justify-content: center; font-weight: 700;
}
.portal-notifications-panel {
  display: none; position: absolute; top: 44px; right: 0; width: min(340px, 86vw);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); z-index: 1200; overflow: hidden;
}
.portal-notifications-panel.is-open { display: block; }
.portal-notifications-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 12px; border-bottom: 1px solid var(--border);
}
.portal-notifications-list { max-height: 320px; overflow: auto; }
.portal-view-as {
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .2rem .55rem; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface-2);
}
.portal-view-as-label {
  font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); white-space: nowrap;
}
.portal-view-as-select {
  min-width: 128px; height: 30px; padding: 0 .55rem; font-size: .75rem; border: none;
  background: transparent; box-shadow: none;
}
@media (max-width: 720px) {
  .portal-view-as-label { display: none; }
  .portal-view-as-select { min-width: 108px; }
}
.portal-notification-row {
  display: block;
  text-decoration: none;
  color: inherit;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  transition: background var(--t);
}
.portal-notification-row:last-child { border-bottom: 0; }
.portal-notification-row:hover { background: var(--surface-2); }
.portal-notification-row.is-unread { background: rgba(91,111,240,.1); }
.portal-notification-row.is-unread:hover { background: rgba(91,111,240,.15); }
.portal-notification-title { font-weight: 700; font-size: .86rem; }
.portal-notification-body { color: var(--text-muted); font-size: .78rem; margin-top: 2px; }
.portal-notification-empty { color: var(--text-muted); font-size: .82rem; padding: 14px 12px; }


/* ===== BANNER MÓDULO (portal-module-hero.js) ===== */
.portal-module-hero {
  height: 240px;
  border-radius: var(--radius);
  margin-bottom: 2rem;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: flex-end;
  padding: 2rem;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
}
.portal-module-hero-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.82), transparent 55%);
  pointer-events: none;
}
.portal-module-hero-body {
  position: relative;
  z-index: 1;
  max-width: 560px;
}
.portal-module-hero-title {
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
  line-height: 1.15;
}
.portal-module-hero-subtitle {
  opacity: 0.85;
  margin: 0 0 0.75rem;
  line-height: 1.45;
}
.portal-module-hero-badge {
  background: var(--accent);
  color: #fff;
}

/* ===== AVATAR ===== */
.avatar {
  width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), #a78bfa);
  display: flex; align-items: center; justify-content: center;
  font-size: .8125rem; font-weight: 600; color: #fff; flex-shrink: 0;
}
.avatar-lg { width: 48px; height: 48px; font-size: 1rem; }

/* ===== TABLE ===== */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; }
thead th { background: var(--surface-2); padding: .75rem 1rem; text-align: left; font-size: .8125rem; font-weight: 600; color: var(--text-muted); white-space: nowrap; }
tbody td { padding: .75rem 1rem; border-top: 1px solid var(--border); font-size: .875rem; vertical-align: middle; }
tbody tr { transition: background var(--t); }
tbody tr:hover { background: var(--surface-2); }

/* ===== METRIC CARD ===== */
.metric { display: flex; flex-direction: column; gap: .25rem; }
.metric-value { font-size: 2rem; font-weight: 700; font-family: var(--mono); line-height: 1; }
.metric-label { font-size: .8125rem; color: var(--text-muted); }
.metric-delta { font-size: .75rem; display: flex; align-items: center; gap: .25rem; margin-top: .25rem; }
.metric-delta.up   { color: var(--success); }
.metric-delta.down { color: var(--danger); }

/* ===== SKELETON ===== */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: var(--radius-xs);
}

/* ===== QUINCHO CARD ===== */
.quincho-card { overflow: hidden; }
.quincho-img { width:100%; height:180px; object-fit:cover; transition: transform .4s ease; }
.quincho-card:hover .quincho-img { transform: scale(1.04); }
.quincho-img-wrap { overflow: hidden; border-radius: var(--radius) var(--radius) 0 0; }
.quincho-body { padding: 1rem; }
.quincho-meta { display: flex; align-items: center; gap: .75rem; margin-top: .5rem; flex-wrap: wrap; }
.quincho-meta-item { display: flex; align-items: center; gap: .3rem; color: var(--text-muted); font-size: .8125rem; }

/* ===== CALENDAR ===== */
.cal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: .25rem; }
.cal-dow { text-align: center; font-size: .75rem; font-weight: 600; color: var(--text-muted); padding: .35rem 0; }
.cal-day {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-xs); font-size: .8125rem; cursor: pointer;
  transition: all var(--t); border: 1px solid transparent;
}
.cal-day:hover:not(.cal-disabled):not(.cal-past) { border-color: var(--accent); color: var(--accent); background: var(--accent-glow); }
.cal-day.cal-past     { color: var(--text-subtle); cursor: default; }
.cal-day.cal-disabled { color: var(--text-subtle); cursor: not-allowed; opacity: .5; }
.cal-day.cal-partial  { background: var(--warning-bg); color: var(--warning); }
.cal-day.cal-full     { background: var(--danger-bg);  color: var(--danger);  cursor: not-allowed; }
.cal-day.cal-selected { background: var(--accent); color: #fff; border-color: var(--accent); }
.cal-day.cal-today    { border-color: var(--accent); font-weight: 700; }
.cal-day.cal-empty    { cursor: default; }

/* ===== STEP INDICATOR ===== */
.steps { display: flex; align-items: center; gap: 0; margin-bottom: 2rem; }
.step { display: flex; align-items: center; gap: .5rem; }
.step-num { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: .75rem; font-weight: 700; border: 2px solid var(--border); color: var(--text-muted); transition: all var(--t); }
.step.active .step-num   { border-color: var(--accent); background: var(--accent); color: #fff; }
.step.done .step-num     { border-color: var(--success); background: var(--success); color: #0d0f14; }
.step-label { font-size: .8125rem; font-weight: 500; color: var(--text-muted); }
.step.active .step-label { color: var(--text); }
.step-line { flex: 1; height: 1px; background: var(--border); margin: 0 .75rem; }

/* ===== TABS ===== */
.tabs { display: flex; gap: .5rem; margin-bottom: 1.5rem; overflow-x: auto; padding-bottom: .25rem; }
.tabs::-webkit-scrollbar { height: 4px; }
.tabs::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.tab {
  padding: .5rem 1.25rem; border-radius: 100px; background: var(--surface-2);
  color: var(--text-muted); font-size: .875rem; font-weight: 500; cursor: pointer;
  border: 1px solid var(--border); transition: all var(--t); white-space: nowrap;
}
.tab:hover { background: var(--surface-3); color: var(--text); border-color: var(--text-subtle); }
.tab.active { background: var(--accent-glow); color: var(--accent); border-color: var(--accent); }


/* ===== APP SHELL ===== */
.app { display: flex; height: 100vh; overflow: hidden; }

/* Área principal junto al sidebar (.app es flex row). */
#appRoot {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  transition: margin-left .22s ease, width .22s ease;
}
/* Sin Turbo: #appRoot contiene .app completo */
#appRoot > .app {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--surface);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  height: 100vh; overflow: hidden; transition: transform .22s ease;
}
.sidebar-logo {
  display: flex; flex-direction: column; align-items: stretch; gap: .45rem;
  padding: .95rem 1rem .85rem; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-logo-brand {
  display: block; width: 100%;
  background: transparent; border-radius: var(--radius-sm);
  padding: 6px 4px; line-height: 0;
}
.sidebar-logo-brand img {
  width: 100%; height: auto; max-height: 44px;
  object-fit: contain; object-position: left center;
  display: block;
}
.sidebar-logo-sub-row {
  display: flex; align-items: center; gap: .35rem; flex-wrap: wrap;
  min-width: 0;
}
.sidebar-logo-sub {
  font-size: .7rem; font-weight: 400; color: var(--text-muted);
  display: inline; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 100%;
}
.sidebar-tenant-switcher { position: relative; display: inline-flex; align-items: center; }
.sidebar-tenant-switcher-btn {
  border: none; background: transparent; color: var(--accent); cursor: pointer;
  font-size: .7rem; line-height: 1; padding: 2px 4px; border-radius: 4px;
  display: inline-flex; align-items: center; justify-content: center;
}
.sidebar-tenant-switcher-btn:hover { background: var(--accent-glow); }
.sidebar-tenant-switcher-icon {
  display: inline-block;
  transform: rotate(0deg);
  transition: transform .22s ease;
  font-size: .62rem;
}
.sidebar-tenant-switcher-btn.is-open .sidebar-tenant-switcher-icon {
  transform: rotate(90deg);
}
.sidebar-tenant-dropdown-portal {
  position: fixed;
  z-index: 2500;
  min-width: 200px;
  max-width: 280px;
  max-height: 240px;
  overflow: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 16px 40px rgba(0,0,0,.32);
  padding: 4px;
  opacity: 0;
  transform: translateY(-8px) scale(0.97);
  transform-origin: top left;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.sidebar-tenant-dropdown-portal.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.sidebar-tenant-option {
  display: block; width: 100%; text-align: left; border: none; background: transparent;
  color: var(--text); font-size: .78rem; padding: .5rem .65rem; border-radius: 6px; cursor: pointer;
}
.sidebar-tenant-option:hover { background: var(--accent-glow); }
.sidebar-tenant-option.is-active { color: var(--accent); font-weight: 600; background: rgba(91,111,240,.08); }

.sidebar-global-search {
  padding: .75rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: .35rem;
  flex-shrink: 0;
}
.sidebar-global-search .input {
  padding: .5rem .7rem;
  font-size: .8125rem;
}
.sidebar-global-search-hint {
  color: var(--text-subtle);
  font-size: .68rem;
  line-height: 1.25;
}

.sidebar-nav {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: .75rem; display: flex; flex-direction: column; gap: .15rem;
}
.sidebar-sections {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  margin-top: .35rem;
}
.sidebar-section-label {
  font-size: .6875rem; font-weight: 600; color: var(--text-subtle);
  text-transform: uppercase; letter-spacing: .08em;
  padding: .75rem .5rem .35rem;
  font-synthesis: none;
  font-family: var(--font), system-ui, -apple-system, "Segoe UI", sans-serif;
}
.sidebar-group {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
}
.sidebar-group-toggle {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .55rem .75rem;
  border-radius: var(--radius-sm);
  text-align: left;
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
}
.sidebar-group-icon {
  width: 18px;
  margin-right: .45rem;
  text-align: center;
  font-size: .85rem;
  opacity: .85;
}
.sidebar-group-toggle:hover {
  background: var(--surface-2);
  color: var(--text);
}
.sidebar-group-caret {
  font-size: 1rem;
  transform: rotate(-90deg);
  transition: transform .18s ease;
}
.sidebar-group-menu {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  padding: 0;
  transition: max-height .18s ease, opacity .18s ease, padding .18s ease;
}
.sidebar-group.is-open .sidebar-group-menu {
  display: flex;
  flex-direction: column;
  gap: .15rem;
  max-height: 520px;
  opacity: 1;
  padding: .2rem 0 .3rem;
}
.sidebar-group.is-open .sidebar-group-toggle {
  color: var(--text-muted);
}
.sidebar-group.is-open .sidebar-group-caret { transform: rotate(0deg); }
.nav-item {
  display: flex; align-items: center; gap: .75rem;
  padding: .55rem .75rem; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: .875rem; font-weight: 500;
  cursor: pointer; text-decoration: none;
  border: 1px solid transparent;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active {
  background: var(--accent-glow); color: var(--accent);
  border-color: rgba(91,111,240,.25);
}
.nav-item .nav-icon { font-size: 1rem; width: 18px; text-align: center; flex-shrink: 0; }

.sidebar-footer {
  padding: .75rem; border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-user {
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem .75rem; border-radius: var(--radius-sm);
  cursor: pointer;
}
.sidebar-user:hover { background: var(--surface-2); }
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { font-size: .875rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: .75rem; color: var(--text-muted); }

/* ===== MAIN WRAPPER ===== */
.main-wrapper { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* ===== TOPBAR ===== */
.topbar {
  height: var(--topbar-h); flex-shrink: 0;
  background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 1.5rem; gap: 1rem;
}
.sidebar-toggle-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sidebar-toggle-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}
.topbar-title { font-size: 1.0625rem; font-weight: 600; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: .5rem; }

body.sidebar-collapsed .sidebar {
  transform: translateX(calc(-1 * var(--sidebar-w)));
}
body.sidebar-collapsed #appRoot {
  margin-left: calc(-1 * var(--sidebar-w));
  width: calc(100% + var(--sidebar-w));
}

/* ===== CONTENT AREA ===== */
.content {
  flex: 1; overflow-y: auto; padding: 1.75rem;
  display: flex; flex-direction: column; gap: 1.5rem;
}
.content-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.content-title { font-size: 1.375rem; font-weight: 700; }
.content-subtitle { font-size: .875rem; color: var(--text-muted); margin-top: .25rem; }
.portal-global-search-panel {
  border-color: rgba(91,111,240,.35);
  box-shadow: 0 8px 32px rgba(91,111,240,.12);
}
.portal-global-search-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}
.portal-global-search-result {
  display: flex;
  align-items: center;
  gap: .85rem;
  padding: .75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  margin-bottom: .5rem;
}
.portal-global-search-result:hover {
  border-color: var(--accent);
  background: var(--surface-3);
  color: var(--text);
}
.portal-global-search-group {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  margin-bottom: .85rem;
}
.portal-global-search-group:last-child {
  margin-bottom: 0;
}
.portal-global-search-group-title {
  color: var(--text-muted);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.portal-global-search-result-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.portal-global-search-result-body strong,
.portal-global-search-result-body small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.portal-global-search-result-body small {
  color: var(--text-muted);
  font-size: .75rem;
}

/* ===== GRID LAYOUTS ===== */
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.25rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.25rem; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1.25rem; }

/* ===== FILTERS BAR ===== */
.filters { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.filters .input, .filters .select { width: auto; }

/* ===== EMPTY STATE ===== */
.empty-state { display: flex; flex-direction: column; align-items: center; gap: 1rem; padding: 4rem 2rem; text-align: center; }
.empty-icon  { font-size: 3rem; opacity: .4; }
.empty-title { font-size: 1.125rem; font-weight: 600; }
.empty-desc  { color: var(--text-muted); max-width: 320px; }

/* ===== TURNO PICKER ===== */
.turno-list { display: flex; flex-direction: column; gap: .5rem; }
.turno-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: .85rem 1rem; border-radius: var(--radius-sm); border: 1px solid var(--border);
  cursor: pointer; transition: all var(--t); background: var(--surface-2);
}
.turno-item:hover:not(.turno-full) { border-color: var(--accent); background: var(--accent-glow); }
.turno-item.selected { border-color: var(--accent); background: var(--accent-glow); }
.turno-item.turno-full { opacity: .5; cursor: not-allowed; }

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  :root { --sidebar-w: 214px; }
  .sidebar-logo { padding: .85rem .85rem; }
  .sidebar-logo-brand { padding: 8px 10px; }
  .sidebar-logo-brand img { max-height: 38px; }
  .sidebar-group-toggle { padding: .5rem .6rem; font-size: .7rem; }
  .nav-item { padding: .5rem .6rem; font-size: .82rem; }
  .sidebar-footer { padding: .6rem; }
}
@media (max-width: 768px) {
  :root { --sidebar-w: 196px; --topbar-h: 56px; }
  .app { height: 100dvh; }
  .sidebar {
    position: relative;
    left: 0;
    z-index: 10;
    box-shadow: 2px 0 10px rgba(0,0,0,.08);
  }
  .sidebar-nav { padding: .6rem .5rem; }
  .sidebar-group-toggle { letter-spacing: .04em; }
  .sidebar-group-icon { margin-right: .35rem; }
  .sidebar-group.is-open .sidebar-group-menu { max-height: 62dvh; overflow-y: auto; }
  body.sidebar-collapsed .sidebar {
    transform: translateX(calc(-1 * var(--sidebar-w)));
  }
  body.sidebar-collapsed #appRoot {
    margin-left: calc(-1 * var(--sidebar-w));
    width: calc(100% + var(--sidebar-w));
  }
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .content { padding: .9rem; }
  .topbar { padding: 0 1rem; }
  .topbar-title { font-size: .96rem; }
  .sidebar-toggle-btn { width: 32px; height: 32px; }
}

@media (max-height: 760px) {
  .sidebar-logo { padding: .7rem .8rem; }
  .sidebar-nav { padding: .55rem .5rem; }
  .sidebar-group-toggle { padding: .42rem .55rem; }
  .nav-item { padding: .42rem .55rem; font-size: .8rem; }
  .sidebar-footer .btn { padding: .3rem .55rem; }
}




/* ===== QUINCHO/SPACE CARDS ===== */
.quincho-card { overflow: hidden; padding: 0 !important; }
.quincho-img-wrap { position: relative; overflow: hidden; border-radius: var(--radius) var(--radius) 0 0; }
.quincho-img { width: 100%; height: 180px; object-fit: cover; display: block; transition: transform .4s ease; }
.quincho-card:hover .quincho-img { transform: scale(1.04); }
.quincho-body { padding: 1rem; }
.quincho-meta { display: flex; align-items: center; gap: .75rem; margin-top: .5rem; flex-wrap: wrap; }
.quincho-meta-item { display: flex; align-items: center; gap: .3rem; color: var(--text-muted); font-size: .8125rem; }

/* ===== BAR CHART ===== */
.bar-chart-wrap { padding-top: 1.5rem; }
.bar-chart { display: flex; align-items: flex-end; gap: .35rem; height: 80px; }
.bar { flex: 1; background: var(--accent); border-radius: 4px 4px 0 0; opacity: .8; transition: opacity var(--t); position: relative; }
.bar:hover { opacity: 1; }
.bar::after { content: attr(data-val); position: absolute; top: -1.25rem; left: 50%; transform: translateX(-50%); font-size: .7rem; color: var(--text-muted); white-space: nowrap; }
.bar-labels { display: flex; gap: .35rem; margin-top: .35rem; }
.bar-label { flex: 1; text-align: center; font-size: .65rem; color: var(--text-subtle); }

/* ===== ACTIVITY LIST ===== */
.activity-item { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .65rem; background: var(--surface-2); border-radius: var(--radius-sm); margin-bottom: .5rem; }
.activity-main { font-size: .875rem; font-weight: 500; }
.activity-sub  { font-size: .75rem; color: var(--text-muted); margin-top: .1rem; }

/* ===== STATUS PILLS ===== */
.status-pill { display: inline-flex; align-items: center; gap: .35rem; padding: .2rem .65rem; border-radius: 100px; font-size: .75rem; font-weight: 500; }
.status-pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.is-ok      { background: var(--success-bg); color: var(--success); }
.is-warn    { background: var(--warning-bg); color: var(--warning); }
.is-danger  { background: var(--danger-bg);  color: var(--danger); }
.is-neutral { background: var(--surface-2);  color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-accent  { color: var(--accent); }
.text-muted   { color: var(--text-muted); }
.text-sm { font-size: .875rem; }
.text-xs { font-size: .75rem; }
.font-semibold { font-weight: 600; }
.mt-1 { margin-top: .35rem; }
.mt-2 { margin-top: .75rem; }

/* ===== MODALS ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.65); backdrop-filter: blur(4px);
  z-index: 1000; display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.modal-overlay.active { opacity: 1; pointer-events: all; }
.modal-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  width: min(520px, 92vw); max-height: 90vh; overflow-y: auto;
  transform: scale(.95); transition: transform .2s ease; box-shadow: 0 16px 64px rgba(0,0,0,.6);
}
.modal-overlay.active .modal-box { transform: scale(1); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 1.25rem; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 1rem; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 1.25rem; line-height: 1; cursor: pointer; padding: .25rem; border-radius: var(--radius-xs); transition: color var(--t); }
.modal-close:hover { color: var(--text); }
.modal-body   { padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem; }
.modal-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: .75rem; }
/* Teclado y clic fuera: portal-modal.js (Enter = confirmar, Esc = cancelar, sin cierre al clic en fondo) */

/* ===== TOAST ===== */
#toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 2000; display: flex; flex-direction: column; gap: .5rem; }
.toast {
  display: flex; align-items: center; gap: .75rem;
  padding: .75rem 1.1rem; border-radius: var(--radius-sm); font-size: .875rem; font-weight: 500;
  box-shadow: var(--shadow); animation: fadeInUp .3s ease both;
  border-left: 3px solid;
}
.toast-success { background: var(--surface); color: var(--success); border-color: var(--success); }
.toast-error   { background: var(--surface); color: var(--danger);  border-color: var(--danger); }
.toast-info    { background: var(--surface); color: var(--accent);  border-color: var(--accent); }
