:root {
  --purple: #4D006E;
  --ink: #1F2937;
  --muted: #6B7280;
  --line: #E5E7EB;
  --bg: #F7F5FA;
  --card: #FFFFFF;
  --shadow: 0 18px 48px rgba(25, 12, 47, .12);
  --radius: 22px;
  --branch: #4D006E;
}
* { box-sizing: border-box; }
html, body { margin:0; padding:0; font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif; color:var(--ink); background:linear-gradient(180deg,#faf9fc 0%, #f2eef7 100%); }
button, input, select, textarea { font: inherit; }
button { cursor:pointer; border:none; border-radius:14px; transition:.2s ease; }
button:hover { transform: translateY(-1px); }
button:disabled { opacity:.45; cursor:not-allowed; transform:none; }
.hidden { display:none !important; }
.app { min-height:100vh; }
.start-screen {
  min-height:100vh; display:grid; place-items:center; padding:32px;
}
.start-card {
  width:min(1180px,100%); background:rgba(255,255,255,.92); backdrop-filter: blur(10px);
  border:1px solid rgba(77,0,110,.08); border-radius:32px; box-shadow:var(--shadow); overflow:hidden;
}
.hero {
  display:grid; grid-template-columns: 1fr; gap:0; min-height:680px;
}
.hero-left {
  padding:42px 42px 34px; background:
    radial-gradient(circle at top left, rgba(77,0,110,.12), transparent 36%),
    linear-gradient(180deg, #fff 0%, #faf7fd 100%);
}
.hero-right {
  padding:34px 38px 42px; background:linear-gradient(180deg, rgba(77,0,110,.045) 0%, rgba(77,0,110,.08) 100%);
  border-top:1px solid rgba(77,0,110,.08);
}
.top-brand { display:flex; align-items:center; gap:16px; margin-bottom:18px; }
.top-brand img { width:72px; height:72px; object-fit:contain; }
.brand-title small { display:block; color:var(--purple); font-weight:700; font-size:12px; letter-spacing:.12em; text-transform:uppercase; }
.brand-title h1 { margin:4px 0 6px; font-size:34px; line-height:1.06; }
.brand-title p { margin:0; color:var(--muted); font-size:15px; }
.branch-grid {
  display:grid; grid-template-columns: repeat(5, minmax(110px,1fr)); gap:16px; margin-top:28px;
}
.branch-tile {
  background:#fff; border:2px solid transparent; padding:16px 12px 14px; display:flex; flex-direction:column; align-items:center; gap:10px; box-shadow:0 8px 20px rgba(35,17,58,.07);
}
.branch-tile img { width:72px; height:72px; object-fit:contain; }
.branch-tile span { font-size:14px; font-weight:700; color:#2f2440; text-align:center; }
.branch-tile.active { border-color:var(--branch); box-shadow:0 12px 30px rgba(77,0,110,.16); }
.info-strip {
  display:grid; grid-template-columns: repeat(3,1fr); gap:14px; margin-top:26px;
}
.mini-card {
  background:#fff; border:1px solid rgba(77,0,110,.08); border-radius:18px; padding:14px 16px;
}
.mini-card strong { display:block; font-size:13px; color:var(--muted); margin-bottom:6px; }
.mini-card span { display:block; font-size:17px; font-weight:700; }
.login-panel h2 { margin:0 0 8px; font-size:28px; }
.login-panel p { margin:0 0 18px; color:var(--muted); line-height:1.45; }
.login-grid { display:grid; grid-template-columns: 1fr 1fr; gap:12px; align-items:end; }
.login-grid .field { margin-bottom:0; }
.login-actions{display:flex;justify-content:flex-end;align-items:end;}
.login-grid button { min-height:46px; align-self:end; }
.field {
  display:flex; flex-direction:column; gap:8px; margin-bottom:14px;
}
label { font-size:13px; font-weight:700; color:#423056; display:flex; align-items:center; gap:8px; }
input, select, textarea {
  border:1px solid #d9d5e2; border-radius:14px; background:#fff; padding:12px 14px; min-height:46px; color:var(--ink);
}
textarea { min-height:110px; resize:vertical; }
.primary {
  background:linear-gradient(135deg, var(--purple), #6a1b8f); color:#fff; padding:12px 18px; font-weight:700;
}
.secondary {
  background:#fff; color:var(--purple); border:1px solid rgba(77,0,110,.14); padding:12px 18px; font-weight:700;
}
.ghost {
  background:rgba(77,0,110,.07); color:var(--purple); padding:10px 14px; font-weight:700;
}
.upload-box {
  margin-top:18px; padding:18px; border:1px dashed rgba(77,0,110,.25); border-radius:20px; background:#fff;
}
.upload-actions { display:flex; flex-direction:column; gap:12px; }
.upload-actions button { width:100%; }
.app-shell {
  min-height:100vh; display:grid; grid-template-columns: 1fr 290px;
}
.main-pane { padding:26px 28px 30px; }
.right-panel {
  background:var(--purple); color:#fff; padding:26px 18px; position:sticky; top:0; height:100vh; overflow:auto; display:flex; flex-direction:column;
}
.right-panel h2 { margin:0; font-size:18px; }
.right-panel small { color:rgba(255,255,255,.74); }
.side-brand { display:flex; flex-direction:column; align-items:center; text-align:center; gap:10px; padding-bottom:10px; border-bottom:1px solid rgba(255,255,255,.14); margin-bottom:16px; }
.side-brand img { width:82px; height:82px; object-fit:contain; filter: drop-shadow(0 8px 24px rgba(0,0,0,.18)); }
.side-meta { display:grid; gap:6px; margin-top:4px; }
.side-meta div { font-size:12px; line-height:1.35; color:rgba(255,255,255,.86); }
.filters-grid { display:grid; grid-template-columns: repeat(3,1fr); gap:12px; margin:12px 0 16px; }
.filters-grid .field { margin-bottom:0; }
.summary-stack { display:grid; gap:14px; }
.phase-reminder{margin-top:18px;padding:18px 20px;border:1px solid rgba(77,0,110,.08);border-radius:22px;background:linear-gradient(180deg,#fff,#faf7fd)}
.phase-reminder h3{margin:0 0 8px;font-size:18px;}
.phase-reminder p{margin:0 0 14px;color:var(--muted);font-size:14px;}
.phase-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:12px;}
.phase-pill{display:grid;grid-template-columns:56px 1fr;gap:10px;align-items:center;padding:10px 12px;border-radius:18px;background:#fff;border:1px solid #eadff5;}
.phase-pill img{width:52px;height:52px;object-fit:contain;}
.phase-pill strong{display:block;font-size:13px;}
.phase-pill small{display:block;color:var(--muted);line-height:1.35;}
.side-top-logo{display:flex;justify-content:center;align-items:center;padding:8px 0 20px;}
.side-top-logo img{width:min(150px, 72%);height:auto;object-fit:contain;filter:drop-shadow(0 8px 18px rgba(0,0,0,.14));}
.path-visual{display:flex;align-items:center;gap:12px;margin-top:10px;}
.path-visual img{width:50px;height:50px;object-fit:contain;background:#fff;border-radius:14px;padding:5px;border:1px solid rgba(77,0,110,.08);}
.path-card{position:relative;}
.progression-award{display:flex;align-items:center;gap:12px;padding:14px 16px;border-radius:18px;background:linear-gradient(180deg,#fff,#faf8fc);border:1px solid rgba(77,0,110,.08);margin:12px 0;}
.progression-award img{width:56px;height:56px;object-fit:contain;}
.summary-mini-table { width:100%; border-collapse:collapse; font-size:13px; }
.summary-mini-table th,.summary-mini-table td { padding:8px 6px; border-bottom:1px solid rgba(77,0,110,.08); text-align:left; vertical-align:top; }
.summary-mini-table th { color:var(--muted); font-size:12px; text-transform:uppercase; letter-spacing:.04em; }
.side-section { flex:1; display:flex; flex-direction:column; justify-content:center; }
.side-footer { margin-top:auto; padding-top:18px; border-top:1px solid rgba(255,255,255,.14); display:flex; flex-direction:column; align-items:center; gap:8px; text-align:center; }
.side-footer img { width:64px; height:64px; object-fit:contain; opacity:.95; }
.side-footer .footer-title { font-size:12px; font-weight:700; line-height:1.35; color:rgba(255,255,255,.92); }
.side-footer .footer-serial { font-size:11px; letter-spacing:.08em; text-transform:uppercase; color:rgba(255,255,255,.72); }
.side-btn {
  width:100%; text-align:left; padding:14px 16px; margin-bottom:10px; background:rgba(255,255,255,.08); color:#fff;
  border:1px solid rgba(255,255,255,.08);
}
.side-btn.active { background:#fff; color:var(--purple); }
.side-btn.subtle { background:transparent; border:1px solid rgba(255,255,255,.18); }
.chip {
  display:inline-flex; align-items:center; gap:8px; padding:8px 12px; border-radius:999px; font-size:12px; font-weight:800;
  background:rgba(0,0,0,.05); color:var(--ink); letter-spacing:.03em; text-transform:uppercase;
}
.topbar {
  background:#fff; border:1px solid rgba(77,0,110,.08); border-radius:24px; box-shadow:0 12px 30px rgba(36, 15, 59, .08); 
  padding:20px 22px; display:flex; justify-content:space-between; align-items:center; gap:16px; margin-bottom:24px;
}
.topbar-left { display:flex; align-items:center; gap:16px; min-width:0; }
.topbar-left img { width:62px; height:62px; object-fit:contain; }
.topbar h1 { margin:0; font-size:26px; line-height:1.1; }
.topbar p { margin:5px 0 0; color:var(--muted); }
.top-actions { display:flex; gap:10px; flex-wrap:wrap; justify-content:flex-end; }
.card {
  background:#fff; border:1px solid rgba(77,0,110,.08); border-radius:24px; box-shadow:0 12px 30px rgba(36,15,59,.06); padding:20px;
}
.grid-2 { display:grid; grid-template-columns: 1.1fr .9fr; gap:18px; }
.grid-3 { display:grid; grid-template-columns: repeat(3,1fr); gap:16px; }
.grid-4 { display:grid; grid-template-columns: repeat(4,1fr); gap:14px; }
.section-title { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:14px; }
.section-title h3 { margin:0; font-size:20px; }
.muted { color:var(--muted); }
.stat {
  padding:18px; border-radius:18px; background:linear-gradient(180deg,#fff,#faf8fc); border:1px solid rgba(77,0,110,.08);
}
.stat strong { display:block; color:var(--muted); font-size:12px; text-transform:uppercase; letter-spacing:.05em; }
.stat span { display:block; margin-top:10px; font-size:28px; font-weight:800; }
.protagonist-list { display:flex; flex-direction:column; gap:12px; }
.protagonist-row {
  display:grid; grid-template-columns: 1.3fr .9fr .8fr .8fr auto; gap:12px; align-items:center;
  border:1px solid rgba(77,0,110,.08); border-radius:18px; padding:14px;
}
.protagonist-row:hover { background:#faf8fc; }
.table-lite { width:100%; border-collapse:collapse; }
.table-lite th, .table-lite td { padding:10px 10px; border-bottom:1px solid #efedf3; text-align:left; vertical-align:top; }
.table-lite th { font-size:12px; text-transform:uppercase; letter-spacing:.05em; color:var(--muted); }
.badge {
  display:inline-flex; align-items:center; padding:6px 10px; border-radius:999px; font-size:12px; font-weight:800;
}
.badge.approved { background:rgba(0,122,61,.12); color:#0a6a38; }
.badge.dev { background:rgba(77,0,110,.08); color:var(--purple); }
.badge.warn { background:rgba(237,96,53,.12); color:#b54820; }
.split {
  display:grid; grid-template-columns: 1.25fr .75fr; gap:18px;
}
.profile-head {
  display:flex; align-items:flex-start; justify-content:space-between; gap:16px; margin-bottom:16px;
}
.profile-meta { display:flex; flex-wrap:wrap; gap:10px; margin-top:10px; }
.kv { background:#faf8fc; border:1px solid rgba(77,0,110,.08); padding:10px 12px; border-radius:14px; font-size:13px; }
.profile-blocks { display:grid; grid-template-columns: 1fr 1fr; gap:16px; }
.radar-wrap { display:grid; place-items:center; min-height:380px; }
.radar-caption { text-align:center; color:var(--muted); font-size:13px; margin-top:6px; }
.path-grid { display:grid; grid-template-columns: repeat(auto-fit,minmax(190px,1fr)); gap:12px; }
.path-card {
  border:1px solid rgba(77,0,110,.08); border-radius:18px; padding:14px; background:linear-gradient(180deg,#fff,#fbfafc);
}
.path-card h4 { margin:0 0 8px; font-size:15px; }
.comp-box {
  border:1px solid rgba(77,0,110,.08); border-radius:18px; padding:14px; background:#fff;
}
.comp-line { display:flex; gap:8px; align-items:flex-start; justify-content:space-between; padding:8px 0; border-bottom:1px dashed #ece6f4; }
.comp-line:last-child { border-bottom:none; }
.comp-line small { color:var(--muted); display:block; line-height:1.35; }
.level-pill {
  display:inline-flex; align-items:center; padding:7px 11px; border-radius:999px; font-size:11px; font-weight:800;
  background:rgba(77,0,110,.08); color:var(--purple); white-space:nowrap; border:1px solid rgba(77,0,110,.12);
}
.level-pill.active{background:var(--purple); color:#fff; border-color:var(--purple); box-shadow:0 8px 18px rgba(77,0,110,.22);}
.level-pill input{display:none;}
.toolbar { display:flex; flex-wrap:wrap; gap:10px; }
.modal {
  position:fixed; inset:0; background:rgba(26,15,38,.46); display:none; align-items:center; justify-content:center; padding:28px; z-index:30;
}
.modal.open { display:flex; }
.modal-card {
  width:min(1080px,100%); max-height:90vh; overflow:auto; background:#fff; border-radius:28px; padding:22px; box-shadow:0 28px 80px rgba(0,0,0,.24);
}
.card,.topbar,.upload-box,.right-panel{overflow:visible;}
.modal-card.large { width:min(1280px,100%); }
.close-btn { width:42px; height:42px; border-radius:50%; background:#f3eef8; color:var(--purple); font-weight:900; }
.form-grid-2 { display:grid; grid-template-columns: 1fr 1fr; gap:14px; }
.form-grid-3 { display:grid; grid-template-columns: repeat(3,1fr); gap:14px; }
.picker-row { display:flex; gap:10px; flex-wrap:wrap; }
.toggle-pill {
  padding:10px 13px; border-radius:999px; background:#f3eef8; color:var(--purple); font-weight:800; border:1px solid transparent;
}
.toggle-pill.active { background:var(--purple); color:#fff; }
.assign-box { border:1px solid rgba(77,0,110,.08); border-radius:20px; padding:14px; max-height:210px; overflow:auto; background:#fff; }
.check-grid { display:grid; gap:8px; }
.check-item {
  display:flex; gap:10px; align-items:flex-start; padding:10px 10px; border-radius:14px;
}
.check-item:hover { background:#faf8fc; }
.tooltip {
  position:relative; display:inline-flex; align-items:center; justify-content:center; width:18px; height:18px;
  border-radius:50%; font-size:11px; font-weight:900; background:rgba(77,0,110,.12); color:var(--purple); cursor:help; user-select:none;
}
.tooltip-pop { position:fixed; z-index:9999; max-width:min(320px, calc(100vw - 24px)); background:#2f2440; color:#fff; padding:10px 12px; border-radius:12px; box-shadow:0 16px 40px rgba(0,0,0,.25); font-size:12px; line-height:1.4; pointer-events:none; opacity:0; transform:translateY(4px); transition:.15s ease; }
.tooltip-pop.visible { opacity:1; transform:translateY(0); }
.notice {
  border-radius:16px; background:#faf8fc; border:1px solid rgba(77,0,110,.09); padding:12px 14px; color:#51376a;
}
.inline-actions { display:flex; gap:8px; flex-wrap:wrap; }
.empty {
  border:1px dashed rgba(77,0,110,.18); border-radius:18px; padding:24px; text-align:center; color:var(--muted); background:#fff;
}
@media (max-width: 1100px) {
  .phase-grid { grid-template-columns:1fr 1fr; }
  .hero { grid-template-columns:1fr; }
  .app-shell { grid-template-columns:1fr; }
  .right-panel { position:static; height:auto; order:-1; }
  .grid-2, .split, .profile-blocks, .form-grid-2, .form-grid-3, .grid-3, .grid-4 { grid-template-columns:1fr; }
  .branch-grid { grid-template-columns: repeat(2,minmax(120px,1fr)); }
  .protagonist-row { grid-template-columns:1fr; }
  .topbar, .profile-head, .section-title { flex-direction:column; align-items:flex-start; }
  .top-actions { justify-content:flex-start; }
}
@media (max-width: 720px) {
  .phase-grid { grid-template-columns:1fr; }
  .start-screen { padding:14px; }
  .hero-left, .hero-right, .main-pane { padding:18px; }
  .branch-grid { grid-template-columns: repeat(2,minmax(120px,1fr)); gap:12px; }
  .login-grid { grid-template-columns:1fr; }
  .topbar-left { flex-direction:column; align-items:flex-start; }
  .toolbar, .inline-actions, .top-actions { width:100%; }
  .toolbar button, .inline-actions button, .top-actions button { width:100%; }
  .right-panel { padding:18px; }
}

/* ===== Fase 2: unidades guardadas + estado de sincronización ===== */
.saved-units { margin-bottom: 20px; }
.saved-units h2 { margin: 0 0 6px; font-size: 22px; }
.saved-units > p { margin: 0 0 14px; }
.saved-units-list { display: grid; gap: 10px; }
.saved-unit {
  display: grid; grid-template-columns: 46px 1fr auto; gap: 12px; align-items: center;
  padding: 12px; border: 1px solid rgba(77,0,110,.1); border-radius: 16px; background: #fff;
}
.saved-unit img { width: 46px; height: 46px; object-fit: contain; }
.saved-unit-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.saved-unit-info strong { font-size: 15px; }
.saved-unit-info small { font-size: 12px; color: var(--muted); }
.saved-unit-actions { display: flex; gap: 6px; align-items: center; }
.saved-unit-actions .primary { padding: 8px 14px; }
.saved-unit-actions .ghost { padding: 8px 10px; }
.saved-units-sep {
  text-align: center; margin: 18px 0 10px; border-top: 1px solid rgba(77,0,110,.1);
  line-height: 0;
}
.saved-units-sep span {
  background: linear-gradient(180deg, rgba(77,0,110,.045) 0%, rgba(77,0,110,.08) 100%);
  padding: 0 12px; color: var(--muted); font-size: 13px; line-height: 1;
}

.sync-status {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 13px;
  border-radius: 999px; font-size: 12px; font-weight: 700; color: var(--ink);
  background: rgba(0,0,0,.04); white-space: nowrap;
}
.sync-dot { width: 9px; height: 9px; border-radius: 50%; background: #9ca3af; transition: background .2s; }
.sync-status[data-state="ok"] .sync-dot { background: #0a6a38; }
.sync-status[data-state="pending"] .sync-dot { background: #d98a00; }
.sync-status[data-state="offline"] .sync-dot { background: #9ca3af; }
.sync-status[data-state="error"] .sync-dot { background: #c40f2f; }

/* ===================================================================== */
/* Responsive fino para móvil (≤720px)                                   */
/* Patrón móvil: navegación en barra INFERIOR + tipografía fluida +      */
/* modales tipo bottom-sheet + cero desborde horizontal.                 */
/* ===================================================================== */
@media (max-width: 720px) {
  html, body { overflow-x: hidden; }
  .start-card, .card, .topbar, .modal-card, .upload-box { max-width: 100%; }

  /* Tipografía fluida: títulos que ya no desbordan ni se cortan */
  .brand-title h1 { font-size: clamp(20px, 6.2vw, 30px); line-height: 1.12; overflow-wrap: anywhere; }
  .topbar h1 { font-size: clamp(18px, 5.4vw, 24px); overflow-wrap: anywhere; }
  .login-panel h2, .saved-units h2 { font-size: 21px; }
  .section-title h3 { font-size: 18px; }
  .stat span { font-size: 24px; }

  /* Botonera superior: apilada y a todo el ancho (refuerzo) */
  .top-actions { width: 100%; gap: 8px; }
  .top-actions > * { width: 100%; justify-content: center; }
  .sync-status { justify-content: center; }

  /* --- Barra de navegación INFERIOR (reemplaza el panel morado de arriba) --- */
  .app-shell { grid-template-columns: 1fr; }
  .right-panel {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    height: auto; width: auto; order: 0; z-index: 20;
    flex-direction: row; align-items: stretch; padding: 0;
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -8px 24px rgba(0, 0, 0, .18);
  }
  .side-top-logo, .side-footer, .side-brand { display: none; }
  .side-section { flex: 1; flex-direction: row; justify-content: space-around; margin: 0; }
  .side-btn {
    flex: 1; margin: 0; border: none; border-radius: 0; text-align: center;
    padding: 14px 4px 12px; font-size: 12.5px; font-weight: 700;
    background: transparent; color: rgba(255, 255, 255, .82);
  }
  .side-btn.active { background: rgba(255, 255, 255, .16); color: #fff; box-shadow: inset 0 3px 0 #fff; }
  .side-btn.subtle { border: none; }
  /* Espacio para que la barra fija no tape el contenido */
  .main-pane { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }

  /* Pantalla de inicio: menos padding, todo respira */
  .hero-left, .hero-right { padding: 18px 16px; }
  .start-card { border-radius: 24px; }
  .branch-grid { gap: 10px; }
  .branch-tile { padding: 12px 8px; }
  .branch-tile img { width: 54px; height: 54px; }

  /* Modales tipo bottom-sheet: cómodos y a pantalla casi completa */
  .modal { padding: 0; align-items: flex-end; }
  .modal-card, .modal-card.large {
    width: 100%; max-width: 100%; max-height: 94vh;
    border-radius: 22px 22px 0 0; padding: 18px 16px;
  }
  /* En el modal, mantener el botón de cerrar arriba a la derecha (no debajo) */
  .modal-card .section-title { flex-direction: row; align-items: center; }

  /* Tablas: que no rompan el layout; scroll horizontal dentro de su tarjeta */
  .card { overflow-x: auto; }
  .table-lite th, .table-lite td { padding: 8px 8px; font-size: 13px; }
}

/* Pantallas muy chicas (≤380px): un punto más de ajuste */
@media (max-width: 380px) {
  .branch-grid { grid-template-columns: 1fr 1fr; }
  .stat { padding: 14px; }
  .topbar, .card { padding: 16px; }
}
