*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --blue: #1A6BFF; --blue-dark: #1259E0; --blue-light: #EEF4FF;
  --orange: #FFAA00; --orange-light: #FFF8EC;
  --green: #10B981; --green-light: #ECFDF5;
  --red: #EF4444; --red-light: #FEF2F2;
  --bg: #F4F6FB; --surface: #FFFFFF;
  --sidebar-bg: #0F1629; --sidebar-text: rgba(255,255,255,0.6); --sidebar-active: #FFFFFF;
  --border: #E8ECF4; --text: #111827; --text-2: #6B7280; --text-3: #9CA3AF;
  --radius: 14px; --shadow: 0 2px 12px rgba(0,0,0,0.06); --shadow-lg: 0 8px 32px rgba(0,0,0,0.10);
}
body { font-family: 'DM Sans', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; display: flex; overflow: hidden; }

/* LOGIN */
#login-screen { position: fixed; inset: 0; background: var(--sidebar-bg); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.login-card { background: var(--surface); border-radius: 24px; padding: 48px 40px; width: 100%; max-width: 400px; box-shadow: var(--shadow-lg); }
.login-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 32px; }
.login-logo-icon { width: 48px; height: 48px; background: var(--blue); border-radius: 12px; overflow: hidden; }
.login-logo-text { font-size: 1.4rem; font-weight: 700; }
.login-logo-sub { font-size: 0.75rem; color: var(--text-2); margin-top: 1px; }
.login-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 6px; }
.login-sub { font-size: 0.9rem; color: var(--text-2); margin-bottom: 32px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.83rem; font-weight: 500; color: var(--text-2); margin-bottom: 6px; }
.form-group input { width: 100%; padding: 12px 14px; border: 1.5px solid var(--border); border-radius: 10px; font-family: 'DM Sans', sans-serif; font-size: 0.95rem; outline: none; transition: border-color 0.2s; }
.form-group input:focus { border-color: var(--blue); }
.btn-login { width: 100%; padding: 13px; background: var(--blue); color: white; border: none; border-radius: 10px; font-family: 'DM Sans', sans-serif; font-size: 0.95rem; font-weight: 600; cursor: pointer; margin-top: 8px; transition: background 0.2s; }
.btn-login:hover { background: var(--blue-dark); }
.login-error { background: var(--red-light); color: var(--red); border-radius: 8px; padding: 10px 14px; font-size: 0.85rem; margin-top: 14px; display: none; }

/* SIDEBAR */
#sidebar { width: 240px; min-width: 240px; background: var(--sidebar-bg); height: 100vh; display: flex; flex-direction: column; position: fixed; left: 0; top: 0; bottom: 0; z-index: 100; }
.sidebar-header { padding: 24px 20px 20px; border-bottom: 1px solid rgba(255,255,255,0.06); }
.sidebar-logo { display: flex; align-items: center; gap: 10px; }
.sidebar-logo-icon { width: 36px; height: 36px; background: var(--blue); border-radius: 9px; overflow: hidden; }
.sidebar-logo-text { color: white; font-weight: 700; font-size: 1.05rem; }
.sidebar-logo-badge { font-size: 0.6rem; font-weight: 600; background: var(--orange); color: white; padding: 2px 6px; border-radius: 4px; margin-left: auto; }
.sidebar-nav { flex: 1; padding: 16px 12px; overflow-y: auto; }
.nav-section-title { font-size: 0.65rem; font-weight: 600; color: rgba(255,255,255,0.25); letter-spacing: 0.08em; text-transform: uppercase; padding: 0 8px; margin: 16px 0 6px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; cursor: pointer; color: var(--sidebar-text); font-size: 0.88rem; font-weight: 400; transition: all 0.15s; text-decoration: none; position: relative; }
.nav-item:hover { background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.85); }
.nav-item.active { background: rgba(26,107,255,0.2); color: var(--sidebar-active); font-weight: 500; }
.nav-item.active::before { content: ''; position: absolute; left: 0; top: 6px; bottom: 6px; width: 3px; background: var(--blue); border-radius: 0 3px 3px 0; }
.nav-icon { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.8; }
.sidebar-footer { padding: 14px 12px; border-top: 1px solid rgba(255,255,255,0.06); }
.admin-info { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; }
.admin-avatar { width: 30px; height: 30px; background: var(--blue); border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 0.75rem; font-weight: 700; color: white; }
.admin-email { font-size: 0.75rem; color: var(--sidebar-text); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-logout { background: none; border: none; color: rgba(255,255,255,0.3); cursor: pointer; padding: 4px; border-radius: 6px; transition: color 0.2s; }
.btn-logout:hover { color: var(--red); }

/* MAIN */
#main { margin-left: 240px; flex: 1; height: 100vh; overflow-y: auto; display: none; }
.topbar { position: sticky; top: 0; background: rgba(244,246,251,0.9); backdrop-filter: blur(12px); padding: 16px 28px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); z-index: 50; }
.topbar-title { font-size: 1.1rem; font-weight: 600; }
.topbar-sub { font-size: 0.8rem; color: var(--text-2); margin-top: 1px; }
.tag-live { display: flex; align-items: center; gap: 5px; font-size: 0.72rem; font-weight: 500; color: var(--green); background: var(--green-light); padding: 4px 10px; border-radius: 20px; }
.tag-live::before { content: ''; width: 6px; height: 6px; background: var(--green); border-radius: 50%; animation: pulse-live 2s infinite; }
@keyframes pulse-live { 0%,100%{opacity:1} 50%{opacity:0.3} }
.content { padding: 24px 28px; }
.section { display: none; }
.section.active { display: block; }

/* KPI */
.kpi-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 16px; margin-bottom: 24px; }
.kpi-card { background: var(--surface); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); border: 1px solid var(--border); position: relative; overflow: hidden; }
.kpi-card::after { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; }
.kpi-card.blue::after { background: var(--blue); } .kpi-card.orange::after { background: var(--orange); } .kpi-card.green::after { background: var(--green); } .kpi-card.red::after { background: var(--red); }
.kpi-label { font-size: 0.78rem; font-weight: 500; color: var(--text-2); margin-bottom: 8px; }
.kpi-value { font-size: 2rem; font-weight: 700; line-height: 1; margin-bottom: 6px; }
.kpi-card.blue .kpi-value { color: var(--blue); } .kpi-card.orange .kpi-value { color: var(--orange); } .kpi-card.green .kpi-value { color: var(--green); } .kpi-card.red .kpi-value { color: var(--red); }
.kpi-sub { font-size: 0.75rem; color: var(--text-3); }
.kpi-icon { position: absolute; right: 16px; top: 16px; width: 36px; height: 36px; border-radius: 9px; display: flex; align-items: center; justify-content: center; }
.kpi-card.blue .kpi-icon { background: var(--blue-light); } .kpi-card.orange .kpi-icon { background: var(--orange-light); } .kpi-card.green .kpi-icon { background: var(--green-light); } .kpi-card.red .kpi-icon { background: var(--red-light); }

/* CHARTS */
.charts-row { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; margin-bottom: 24px; }
.card { background: var(--surface); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-title { font-size: 0.9rem; font-weight: 600; }
.card-sub { font-size: 0.75rem; color: var(--text-2); }
.chart-container { position: relative; height: 200px; }

/* TABLA */
.table-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); overflow: hidden; }
.table-header { padding: 16px 20px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); flex-wrap: wrap; gap: 10px; }
.search-box { display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 7px 12px; }
.search-box input { border: none; background: none; outline: none; font-family: 'DM Sans', sans-serif; font-size: 0.85rem; color: var(--text); width: 200px; }
.filter-bar { display: flex; gap: 6px; padding: 12px 20px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.filter-chip { padding: 5px 12px; border-radius: 20px; font-size: 0.78rem; font-weight: 500; cursor: pointer; white-space: nowrap; border: 1.5px solid var(--border); background: var(--surface); color: var(--text-2); transition: all 0.15s; }
.filter-chip.active { background: var(--blue); color: white; border-color: var(--blue); }
table { width: 100%; border-collapse: collapse; }
thead tr { background: var(--bg); }
th { padding: 10px 20px; text-align: left; font-size: 0.75rem; font-weight: 600; color: var(--text-2); letter-spacing: 0.03em; text-transform: uppercase; }
td { padding: 12px 20px; font-size: 0.85rem; border-top: 1px solid var(--border); vertical-align: middle; }
tr:hover td { background: var(--bg); }
.badge { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 20px; font-size: 0.72rem; font-weight: 600; }
.badge.free { background: var(--bg); color: var(--text-2); }
.badge.pro { background: var(--blue-light); color: var(--blue); }
.badge.multi { background: var(--orange-light); color: var(--orange); }
.badge.activo { background: var(--green-light); color: var(--green); }
.badge.inactivo { background: var(--red-light); color: var(--red); }
.badge.nivel-1 { background: var(--blue-light); color: var(--blue); }
.badge.nivel-2 { background: var(--green-light); color: var(--green); }
.badge.nivel-3 { background: var(--orange-light); color: var(--orange); }
.badge.nivel-4 { background: var(--bg); color: var(--text-2); }
.btn-sm { padding: 5px 12px; border-radius: 7px; font-size: 0.78rem; font-weight: 500; cursor: pointer; border: 1.5px solid var(--border); background: var(--surface); color: var(--text); font-family: 'DM Sans', sans-serif; transition: all 0.15s; }
.btn-sm:hover { border-color: var(--blue); color: var(--blue); }
.btn-sm.danger:hover { border-color: var(--red); color: var(--red); }
.btn-primary { padding: 9px 18px; border-radius: 9px; background: var(--blue); color: white; border: none; font-family: 'DM Sans', sans-serif; font-size: 0.85rem; font-weight: 600; cursor: pointer; transition: background 0.2s; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-secondary { padding: 9px 18px; border-radius: 9px; background: var(--surface); color: var(--text); border: 1.5px solid var(--border); font-family: 'DM Sans', sans-serif; font-size: 0.85rem; font-weight: 500; cursor: pointer; transition: all 0.2s; }
.btn-secondary:hover { border-color: var(--blue); color: var(--blue); }

/* RECENT */
.recent-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.recent-item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.recent-item:last-child { border-bottom: none; }
.recent-avatar { width: 36px; height: 36px; border-radius: 9px; background: var(--blue-light); display: flex; align-items: center; justify-content: center; font-size: 0.8rem; font-weight: 700; color: var(--blue); flex-shrink: 0; }
.recent-name { font-size: 0.85rem; font-weight: 500; }
.recent-meta { font-size: 0.75rem; color: var(--text-2); }
.recent-time { font-size: 0.72rem; color: var(--text-3); margin-left: auto; white-space: nowrap; }

/* MODAL */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 500; display: none; align-items: center; justify-content: center; padding: 20px; }
.modal-overlay.open { display: flex; }
.modal { background: var(--surface); border-radius: 20px; width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg); }
.modal-header { padding: 24px 24px 0; display: flex; align-items: flex-start; justify-content: space-between; }
.modal-title { font-size: 1.1rem; font-weight: 700; }
.modal-sub { font-size: 0.8rem; color: var(--text-2); margin-top: 3px; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--text-2); padding: 4px; border-radius: 6px; font-size: 1.2rem; line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px 24px; }
.modal-footer { padding: 0 24px 24px; display: flex; gap: 10px; justify-content: flex-end; }
.field-group { margin-bottom: 16px; }
.field-group label { display: block; font-size: 0.82rem; font-weight: 500; color: var(--text-2); margin-bottom: 6px; }
.field-group input, .field-group select, .field-group textarea { width: 100%; padding: 10px 12px; border: 1.5px solid var(--border); border-radius: 9px; font-family: 'DM Sans', sans-serif; font-size: 0.9rem; outline: none; transition: border-color 0.2s; background: var(--surface); color: var(--text); }
.field-group input:focus, .field-group select:focus, .field-group textarea:focus { border-color: var(--blue); }
.field-group textarea { resize: vertical; min-height: 80px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* TOGGLE */
.toggle { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; cursor: pointer; inset: 0; background: var(--border); border-radius: 24px; transition: 0.2s; }
.toggle-slider::before { content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: white; border-radius: 50%; transition: 0.2s; }
.toggle input:checked + .toggle-slider { background: var(--blue); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* CONFIG */
.config-section { margin-bottom: 28px; }
.config-section-title { font-size: 0.95rem; font-weight: 700; margin-bottom: 4px; }
.config-section-desc { font-size: 0.8rem; color: var(--text-2); margin-bottom: 12px; }
.config-block { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); padding: 4px 20px; box-shadow: var(--shadow); }
.config-field { display: flex; align-items: center; justify-content: space-between; padding: 14px 0; border-bottom: 1px solid var(--border); gap: 16px; }
.config-field:last-child { border-bottom: none; }
.config-field-info { flex: 1; }
.config-field-label { font-size: 0.88rem; font-weight: 500; }
.config-field-desc { font-size: 0.75rem; color: var(--text-2); margin-top: 2px; }
.config-input { width: 130px; padding: 8px 10px; border: 1.5px solid var(--border); border-radius: 8px; font-family: 'DM Sans', sans-serif; font-size: 0.9rem; text-align: right; outline: none; transition: border-color 0.2s; background: var(--surface); color: var(--text); }
.config-input:focus { border-color: var(--blue); }
.config-input.wide { width: 260px; text-align: left; }
.config-input.full { width: 100%; text-align: left; }

/* COLABORADORES */
.colab-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(280px,1fr)); gap: 16px; padding: 20px; }
.colab-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px; }
.colab-header { display: flex; align-items: center; gap: 12px; }
.colab-logo-box { width: 48px; height: 48px; border-radius: 10px; background: var(--bg); border: 1px solid var(--border); flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 1.4rem; overflow: hidden; }
.colab-logo-box img { width: 100%; height: 100%; object-fit: cover; }
.colab-name { font-size: 0.92rem; font-weight: 600; }
.colab-desc { font-size: 0.78rem; color: var(--text-2); line-height: 1.5; }
.colab-actions { display: flex; gap: 8px; margin-top: 4px; }

/* VENCIMIENTO */
.vence-ok { font-size: 0.75rem; color: var(--green); font-family: 'DM Mono', monospace; }
.vence-pronto { font-size: 0.75rem; color: var(--orange); font-family: 'DM Mono', monospace; }
.vence-caducado { font-size: 0.75rem; color: var(--red); font-family: 'DM Mono', monospace; }

/* SPINNER / EMPTY */
.spinner { width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--blue); border-radius: 50%; animation: spin 0.7s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; padding: 48px; color: var(--text-2); font-size: 0.9rem; }

/* TOAST */
#toast { position: fixed; bottom: 24px; right: 24px; background: var(--text); color: white; padding: 12px 20px; border-radius: 10px; font-size: 0.85rem; font-weight: 500; box-shadow: var(--shadow-lg); transform: translateY(80px); opacity: 0; transition: all 0.3s; z-index: 9999; }
#toast.show { transform: translateY(0); opacity: 1; }
#toast.success { background: var(--green); }
#toast.error { background: var(--red); }
#toast.warning { background: var(--orange); }

/* HAMBURGER */
.hamburger { display: none; background: none; border: none; cursor: pointer; color: var(--text); padding: 4px; border-radius: 6px; align-items: center; justify-content: center; flex-shrink: 0; }
.hamburger:hover { background: var(--border); }

/* SIDEBAR OVERLAY */
#sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 99; }
#sidebar-overlay.visible { display: block; }

@media (max-width: 1100px) { .kpi-grid { grid-template-columns: repeat(2,1fr); } }

@media (max-width: 768px) {
  #sidebar { transform: translateX(-100%); transition: transform 0.25s ease; }
  #sidebar.open { transform: translateX(0); }
  #main { margin-left: 0; }
  .hamburger { display: flex; }
  .content { padding: 14px; }
  .topbar { padding: 12px 16px; gap: 10px; }
  .charts-row { grid-template-columns: 1fr; }
  .recent-grid { grid-template-columns: 1fr; }
  .table-card { overflow-x: auto; }
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal { border-radius: 20px 20px 0 0; max-height: 92vh; max-width: 100%; }
  .field-row { grid-template-columns: 1fr; }
  .config-input.wide { width: 100%; }
  .table-header { flex-direction: column; align-items: stretch; }
  .search-box { width: 100%; }
  .search-box input { width: 100%; flex: 1; }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
}
