/* =======================================================
   FRL PREDIALES — base.css
   Solo estructura: reset, variables, layout sidebar/campo
   NO incluye componentes UI (botones, cards, tablas, etc.)
   ======================================================= */

/* ── RESET ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }

/* ── CSS VARIABLES ──────────────────────────────────── */
:root {
  /* Brand */
  --primary:        #4F46E5;
  --primary-dark:   #3730A3;
  --primary-light:  #EEF2FF;
  --primary-muted:  #6366F1;

  /* Status */
  --success:       #059669;
  --success-light: #D1FAE5;
  --warning:       #D97706;
  --warning-light: #FEF3C7;
  --danger:        #DC2626;
  --danger-light:  #FEE2E2;
  --info:          #0284C7;
  --info-light:    #E0F2FE;

  /* Neutrals */
  --bg:        #F1F5F9;
  --surface:   #FFFFFF;
  --border:    #E2E8F0;
  --text:      #0F172A;
  --text-muted:#64748B;
  --text-light:#94A3B8;

  /* Sidebar */
  --sidebar-bg:          #FFFFFF;
  --sidebar-text:        #6B7280;
  --sidebar-text-active: #111827;
  --sidebar-active-bg:   #EEF2FF;
  --sidebar-hover-bg:    #F9FAFB;
  --sidebar-width:       240px;
  --sidebar-border:      #E5E7EB;

  /* Typography */
  --font: 'Inter', system-ui, -apple-system, sans-serif;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow:    0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);

  /* Spacing */
  --sp-1:.25rem; --sp-2:.5rem;  --sp-3:.75rem; --sp-4:1rem;
  --sp-5:1.25rem; --sp-6:1.5rem; --sp-8:2rem; --sp-10:2.5rem;

  /* Radius */
  --r-sm:.375rem; --r:.5rem; --r-md:.75rem; --r-lg:1rem; --r-full:9999px;

  /* Transition */
  --t: 150ms ease;
}

/* ── BASE TYPOGRAPHY ────────────────────────────────── */
body {
  font-family: var(--font);
  font-size: .9375rem;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: var(--font); }
img { max-width: 100%; }

/* ── SIDEBAR LAYOUT ─────────────────────────────────── */
.app-container { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 200;
  transition: transform var(--t);
  overflow: hidden;
  border-right: 1px solid var(--sidebar-border);
}

.sidebar-brand {
  padding: var(--sp-6) var(--sp-5);
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}
.sidebar-brand-name {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.02em;
}
.sidebar-brand-sub {
  font-size: .75rem;
  color: var(--sidebar-text);
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  padding: var(--sp-3) 0;
  overflow-y: auto;
  overflow-x: hidden;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(0,0,0,.08); border-radius: 2px; }

.sidebar-section {
  padding: var(--sp-4) var(--sp-5) var(--sp-2);
}
.sidebar-section-label {
  font-size: .6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-light);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  margin: 1px var(--sp-2);
  border-radius: var(--r);
  color: var(--sidebar-text);
  font-size: .875rem;
  font-weight: 500;
  transition: all var(--t);
  white-space: nowrap;
}
.sidebar-link:hover { background: var(--sidebar-hover-bg); color: var(--text); }
.sidebar-link.active { background: var(--sidebar-active-bg); color: var(--primary); font-weight: 600; }
.sidebar-link svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .6; transition: opacity var(--t), color var(--t); }
.sidebar-link:hover svg { opacity: .8; }
.sidebar-link.active svg { opacity: 1; color: var(--primary); }

.sidebar-footer {
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-3);
}
.sidebar-user-avatar {
  width: 36px; height: 36px;
  border-radius: var(--r-full);
  background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: .8125rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.sidebar-user-name {
  font-size: .875rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-role { font-size: .6875rem; color: var(--sidebar-text); text-transform: capitalize; }

.sidebar-logout {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r);
  background: #FEF2F2;
  color: #EF4444;
  font-size: .8125rem;
  font-weight: 500;
  transition: all var(--t);
  width: 100%;
  cursor: pointer;
  border: 1px solid #FECACA;
}
.sidebar-logout:hover { background: #FEE2E2; color: #DC2626; }

/* ── MAIN WRAPPER ───────────────────────────────────── */
.main-wrapper {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
}

.main-topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 var(--sp-8);
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}
.topbar-title { font-size: 1rem; font-weight: 600; color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: var(--sp-3); }

.main-content { flex: 1; padding: var(--sp-8); }

/* ── SIDEBAR TOGGLE (mobile) ────────────────────────── */
.sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--sp-2);
  color: var(--text-muted);
  border-radius: var(--r);
  margin-right: var(--sp-2);
}
.sidebar-toggle:hover { background: var(--bg); color: var(--text); }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 199;
}

/* ── CAMPO LAYOUT ───────────────────────────────────── */
.campo-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg);
  max-width: 520px;
  margin: 0 auto;
}

.campo-topbar {
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--sidebar-border);
  padding: .875rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}
.campo-topbar-left { display: flex; align-items: center; gap: .625rem; }
.campo-topbar-brand {
  font-size: 1rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -.02em;
}
.campo-topbar-divider {
  width: 1px; height: 16px;
  background: var(--border);
}
.campo-topbar-page {
  font-size: .875rem;
  font-weight: 500;
  color: var(--text-muted);
}
.campo-topbar-right { display: flex; align-items: center; gap: .625rem; }
.campo-conn-pill {
  display: flex;
  align-items: center;
  gap: .375rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  padding: .25rem .625rem;
  font-size: .75rem;
  font-weight: 500;
  color: var(--text-muted);
}
.campo-topbar-avatar {
  width: 32px; height: 32px;
  border-radius: var(--r-full);
  background: var(--primary);
  color: #fff;
  font-size: .75rem;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-light);
  flex-shrink: 0;
}
.status-dot.online  { background: var(--success); }
.status-dot.offline { background: var(--danger); }
.status-dot.waiting { background: var(--warning); }

.campo-content {
  flex: 1;
  padding: 1rem;
  padding-bottom: 6rem;
  overflow-y: auto;
}

.campo-bottom-nav {
  position: fixed;
  bottom: 0; left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: .5rem 1rem;
  padding-bottom: calc(.5rem + env(safe-area-inset-bottom));
  z-index: 100;
}
.campo-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .2rem;
  padding: .35rem .75rem;
  font-size: .6875rem;
  font-weight: 500;
  color: var(--text-muted);
  border-radius: var(--r);
  transition: color var(--t);
  position: relative;
  text-decoration: none;
}
.campo-nav-item svg { width: 22px; height: 22px; }
.campo-nav-item.active { color: var(--primary); }
.campo-nav-item.active::before {
  content: '';
  position: absolute;
  top: -8px;
  left: 50%; transform: translateX(-50%);
  width: 28px; height: 3px;
  background: var(--primary);
  border-radius: 0 0 var(--r-full) var(--r-full);
}

/* FAB register button */
.campo-nav-item.register-action { color: var(--surface); }
.campo-nav-icon-wrap {
  width: 44px; height: 44px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-radius: var(--r-full);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(79,70,229,.35);
}
.campo-nav-item.register-action svg { width: 20px; height: 20px; }

/* ── FLASH ALERT (usado en header) ─────────────────── */
.alert {
  padding: .875rem 1.125rem;
  border-radius: var(--r);
  font-size: .9rem;
  border: 1px solid transparent;
  margin-bottom: var(--sp-4);
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
}
.alert-success { background: var(--success-light); color: #065F46; border-color: #A7F3D0; }
.alert-error,
.alert-danger  { background: var(--danger-light);  color: #991B1B; border-color: #FECACA; }
.alert-warning { background: var(--warning-light); color: #92400E; border-color: #FDE68A; }
.alert-info    { background: var(--info-light);    color: #075985; border-color: #BAE6FD; }

/* ── UTILIDADES MÍNIMAS (usadas en header inline) ───── */
.flex         { display: flex; }
.items-center { align-items: center; }
.gap-3        { gap: .75rem; }

/* ── ANIMACIONES ────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.animate-fadeIn { animation: fadeIn .25s ease-out both; }

@keyframes frlSlideIn  { from{transform:translateX(120%);opacity:0} to{transform:translateX(0);opacity:1} }
@keyframes frlSlideOut { from{transform:translateX(0);opacity:1} to{transform:translateX(120%);opacity:0} }

/* PWA install button (topbar) */
.btn-sm {
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  padding: .3rem .75rem;
  border-radius: var(--r);
  font-size: .8125rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--t);
  white-space: nowrap;
  font-family: var(--font);
}
.btn-outline {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-outline:hover { background: var(--bg); border-color: var(--text-muted); }

/* ── RESPONSIVE SIDEBAR ─────────────────────────────── */
@media (max-width: 768px) {
  .main-topbar { padding: 0 var(--sp-4); }
  .main-content { padding: var(--sp-4); }
  .sidebar-toggle { display: flex; }
  .sidebar {
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.active { display: block; }
  .main-wrapper { margin-left: 0; }
}

@media (max-width: 480px) {
  #global-toast-container { top: 10px; right: 10px; left: 10px; max-width: 100%; }
}
