:root {
  --graphite: #1B1C29;
  --graphite-2: #262838;
  --violet: #5B5DE6;
  --violet-dark: #4547C4;
  --bg: #F4F5FA;
  --card: #FFFFFF;
  --border: #E4E6F0;
  --text: #1B1C29;
  --text-muted: #6B6E85;
  --verde: #1FA45C;
  --verde-bg: #E6F7EE;
  --amarillo: #C77E00;
  --amarillo-bg: #FFF4DF;
  --rojo: #D14545;
  --rojo-bg: #FCE8E8;
  --whatsapp: #22B04B;
  --email: #3B6FE6;
  --radius: 10px;
  --sombra: 0 2px 10px rgba(27, 28, 41, 0.06);
  --font-display: 'Segoe UI', ui-sans-serif, -apple-system, BlinkMacSystemFont, sans-serif;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.oculto { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }
a { color: var(--violet); }

/* ============ AUTENTICACION ============ */
.vista-auth {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(circle at 15% 20%, rgba(91,93,230,0.25), transparent 45%),
    radial-gradient(circle at 85% 80%, rgba(34,176,75,0.18), transparent 45%),
    var(--graphite);
  padding: 24px;
}
.auth-panel {
  width: 100%; max-width: 420px;
  background: var(--card);
  border-radius: 16px;
  padding: 36px 32px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}
.auth-marca { text-align: center; margin-bottom: 24px; }
.auth-logo {
  width: 48px; height: 48px; border-radius: 12px;
  background: linear-gradient(135deg, var(--violet), var(--violet-dark));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 18px; margin: 0 auto 12px;
  letter-spacing: 0.02em;
}
.auth-marca h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.01em; }
.auth-marca p { color: var(--text-muted); font-size: 13.5px; margin: 0; }

.auth-tabs { display: flex; gap: 4px; background: var(--bg); border-radius: 10px; padding: 4px; margin-bottom: 20px; }
.auth-tab { flex: 1; border: none; background: transparent; padding: 9px; border-radius: 8px; font-size: 13.5px; font-weight: 600; color: var(--text-muted); }
.auth-tab.activo { background: var(--card); color: var(--violet); box-shadow: var(--sombra); }

.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-muted); }
.auth-form input {
  padding: 10px 12px; border-radius: 8px; border: 1.5px solid var(--border);
  font-size: 14px; color: var(--text); outline: none; transition: border-color .15s;
}
.auth-form input:focus { border-color: var(--violet); }
.auth-error { color: var(--rojo); font-size: 12.5px; min-height: 4px; }

.btn {
  border: none; border-radius: 8px; padding: 10px 16px; font-size: 14px; font-weight: 600;
  transition: transform .06s ease, box-shadow .15s ease, background .15s ease;
}
.btn:active { transform: scale(0.98); }
.btn-block { width: 100%; }
.btn-primario { background: var(--violet); color: #fff; }
.btn-primario:hover { background: var(--violet-dark); }
.btn-secundario { background: var(--bg); color: var(--text); border: 1.5px solid var(--border); }
.btn-secundario:hover { background: #EAEBF5; }
.btn-peligro { background: var(--rojo-bg); color: var(--rojo); }
.btn-peligro:hover { background: #f8d3d3; }
.btn-whatsapp { background: var(--whatsapp); color: #fff; }
.btn-email { background: var(--email); color: #fff; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 6px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ============ APP SHELL ============ */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 250px; flex-shrink: 0; background: var(--graphite); color: #fff;
  display: flex; flex-direction: column; padding: 20px 14px;
  position: sticky; top: 0; height: 100vh;
}
.sidebar-marca { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; border-bottom: 1px solid rgba(255,255,255,0.08); margin-bottom: 14px; }
.sidebar-marca strong { display: block; font-size: 13.5px; }
.sidebar-usuario { display: block; font-size: 11.5px; color: rgba(255,255,255,0.5); }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px; text-align: left;
  background: transparent; border: none; color: rgba(255,255,255,0.7);
  padding: 10px 12px; border-radius: 8px; font-size: 13.5px; font-weight: 500;
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.activo { background: var(--violet); color: #fff; }
.nav-icono { font-size: 15px; width: 18px; text-align: center; }

.btn-logout {
  margin-top: 14px; background: transparent; border: 1px solid rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.75); padding: 10px; border-radius: 8px; font-size: 13px;
}
.btn-logout:hover { background: rgba(255,255,255,0.08); color: #fff; }

.btn-menu-movil {
  display: none; position: fixed; top: 14px; left: 14px; z-index: 40;
  background: var(--graphite); color: #fff; border: none; border-radius: 8px;
  width: 40px; height: 40px; font-size: 18px;
}

.contenido { flex: 1; padding: 28px 32px; max-width: 1280px; }

/* ============ COMPONENTES GENERALES ============ */
.vista-header { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 12px; margin-bottom: 22px; }
.vista-header h2 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.01em; }
.vista-header p { margin: 0; color: var(--text-muted); font-size: 13.5px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--sombra); }
.card + .card { margin-top: 16px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }

.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.stat-card .stat-valor { font-size: 26px; font-weight: 700; font-family: var(--font-mono); }
.stat-card .stat-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 4px; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); padding: 8px 10px; border-bottom: 1.5px solid var(--border); }
tbody td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: #FAFAFD; }
.tabla-wrap { overflow-x: auto; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.badge-verde { background: var(--verde-bg); color: var(--verde); }
.badge-amarillo { background: var(--amarillo-bg); color: var(--amarillo); }
.badge-rojo { background: var(--rojo-bg); color: var(--rojo); }
.badge-gris { background: #EEEFF6; color: var(--text-muted); }
.badge-violeta { background: #EEEEFC; color: var(--violet); }

.punto { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.punto-verde { background: var(--verde); }
.punto-amarillo { background: var(--amarillo); }
.punto-rojo { background: var(--rojo); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid label, .form-full label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.form-full { grid-column: 1 / -1; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=number], input[type=datetime-local], select, textarea {
  padding: 9px 11px; border-radius: 8px; border: 1.5px solid var(--border); outline: none; color: var(--text);
}
input:focus, select:focus, textarea:focus { border-color: var(--violet); }
textarea { resize: vertical; min-height: 70px; }

/* Tabs tipo "carpeta" para giros/proyectos — elemento distintivo */
.carpeta-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.carpeta-tab {
  position: relative; padding: 9px 16px 8px; border-radius: 8px 8px 0 0; border: 1.5px solid var(--border); border-bottom: none;
  background: #ECEDF5; color: var(--text-muted); font-size: 12.5px; font-weight: 700; letter-spacing: .01em;
}
.carpeta-tab.activo { background: var(--card); color: var(--text); border-color: var(--border); box-shadow: 0 -2px 0 var(--tab-color, var(--violet)) inset; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(27,28,41,0.5); display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal {
  background: var(--card); border-radius: 14px; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
  padding: 24px; box-shadow: 0 30px 60px rgba(0,0,0,0.3);
}
.modal.modal-ancho { max-width: 820px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-header h3 { margin: 0; font-size: 17px; }
.modal-cerrar { background: none; border: none; font-size: 20px; color: var(--text-muted); }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.toast-contenedor { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--graphite); color: #fff; padding: 12px 16px; border-radius: 8px; font-size: 13.5px; box-shadow: var(--sombra); animation: entrar .18s ease; max-width: 320px; }
.toast.exito { background: var(--verde); }
.toast.error { background: var(--rojo); }
@keyframes entrar { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: translateY(0);} }

.vacio { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.vacio-icono { font-size: 30px; margin-bottom: 8px; }

.chip-fila { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 20px; padding: 4px 10px 4px 4px; font-size: 12.5px;
}
.chip-avatar { width: 20px; height: 20px; border-radius: 50%; background: var(--violet); color: #fff; display:flex; align-items:center; justify-content:center; font-size: 10px; font-weight: 700;}

.tabs-secundarias { display: flex; gap: 4px; background: var(--bg); border-radius: 10px; padding: 4px; margin-bottom: 18px; width: fit-content; }
.tabs-secundarias button { background: transparent; border: none; padding: 8px 16px; border-radius: 7px; font-size: 13px; font-weight: 600; color: var(--text-muted); }
.tabs-secundarias button.activo { background: var(--card); color: var(--violet); box-shadow: var(--sombra); }

.qr-caja { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 20px; text-align: center; }
.qr-caja img { width: 220px; height: 220px; border-radius: 12px; border: 1.5px solid var(--border); }

.filtro-fila { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; align-items: center; }
.filtro-fila input, .filtro-fila select { min-width: 160px; }

.progreso-barra { width: 100%; height: 7px; background: var(--bg); border-radius: 10px; overflow: hidden; }
.progreso-relleno { height: 100%; background: var(--violet); border-radius: 10px; transition: width .3s ease; }

.designer-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.designer-tabs button { background: var(--bg); border: 1px solid var(--border); padding: 6px 12px; border-radius: 6px; font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.designer-tabs button.activo { background: var(--violet); color: #fff; border-color: var(--violet); }
.designer-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; height: 420px; }
.designer-editor { width: 100%; height: 100%; font-family: var(--font-mono); font-size: 12.5px; border-radius: 8px; border: 1.5px solid var(--border); padding: 10px; resize: none; }
.designer-preview { border: 1.5px solid var(--border); border-radius: 8px; overflow: auto; background: #fff; }
.designer-preview iframe { width: 100%; height: 100%; border: none; }

.media-preview { max-width: 100%; max-height: 160px; border-radius: 8px; border: 1.5px solid var(--border); }

@media (max-width: 900px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .designer-grid { grid-template-columns: 1fr; height: auto; }
  .designer-editor { height: 220px; }
  .designer-preview { height: 220px; }
}

@media (max-width: 780px) {
  .btn-menu-movil { display: block; }
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 50; transform: translateX(-100%);
    transition: transform .2s ease; box-shadow: 0 0 40px rgba(0,0,0,0.3);
  }
  .sidebar.abierto { transform: translateX(0); }
  .contenido { padding: 70px 16px 24px; }
}
