:root{
  --bg: #f4f7fb;
  --bg-accent: #eef4ff;
  --card: rgba(255,255,255,.9);
  --card-solid:#ffffff;
  --text:#162033;
  --muted:#64748b;
  --muted-2:#8a97aa;
  --border:rgba(148,163,184,.22);
  --line:rgba(148,163,184,.18);
  --primary:#295dff;
  --primary-2:#4f46e5;
  --primary-soft:#eef2ff;
  --sidebar:#0f172a;
  --sidebar-soft:#1e293b;
  --success:#16a34a;
  --success-soft:#dcfce7;
  --warning:#d97706;
  --warning-soft:#fff3dd;
  --danger:#dc2626;
  --danger-soft:#fee2e2;
  --info:#0ea5e9;
  --info-soft:#e0f2fe;
  --shadow-sm: 0 6px 18px rgba(15,23,42,.06);
  --shadow: 0 22px 54px rgba(15,23,42,.12);
  --shadow-lg: 0 28px 80px rgba(15,23,42,.18);
  --radius-sm: 12px;
  --radius: 18px;
  --radius-lg: 24px;
}

*{ box-sizing:border-box; }
html,body{ min-height:100%; }
body{
  margin:0;
  color:var(--text);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Arial, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(79,70,229,.12), transparent 28%),
    radial-gradient(circle at right 20%, rgba(14,165,233,.10), transparent 22%),
    linear-gradient(180deg, #f9fbff 0%, var(--bg) 38%, #eef3f9 100%);
}
body::before{
  content:"";
  position:fixed;
  inset:0;
  pointer-events:none;
  background-image: linear-gradient(rgba(255,255,255,.04) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.04) 1px, transparent 1px);
  background-size: 32px 32px;
  opacity:.35;
}
a{ color:inherit; text-decoration:none; }

.app-shell{
  display:grid;
  grid-template-columns: 290px minmax(0, 1fr);
  min-height:100vh;
  position:relative;
  z-index:1;
}

.sidebar{
  background: linear-gradient(180deg, rgba(15,23,42,.98) 0%, rgba(15,23,42,.95) 100%);
  color:#e5eefc;
  padding:24px 18px;
  border-right:1px solid rgba(255,255,255,.06);
  display:flex;
  flex-direction:column;
  gap:20px;
  position:sticky;
  top:0;
  height:100vh;
}
.sidebar-brand,
.sidebar-user-card{
  display:flex;
  align-items:center;
  gap:14px;
}
.brand-mark{
  width:52px;
  height:52px;
  border-radius:16px;
  display:grid;
  place-items:center;
  font-weight:900;
  letter-spacing:.08em;
  color:#fff;
  background: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
  box-shadow: 0 18px 38px rgba(37,99,235,.26);
}
.brand-title{
  font-size:1.15rem;
  font-weight:800;
}
.brand-subtitle{
  color:#93a5c3;
  font-size:.88rem;
  margin-top:2px;
}
.user-avatar{
  width:44px;
  height:44px;
  border-radius:14px;
  display:grid;
  place-items:center;
  font-weight:800;
  color:#fff;
  background: linear-gradient(135deg, #334155, #1d4ed8);
}
.sidebar-user-card{
  background: rgba(255,255,255,.05);
  border:1px solid rgba(255,255,255,.06);
  border-radius:18px;
  padding:14px;
}
.user-name{ font-weight:700; }
.user-role{ color:#93a5c3; font-size:.9rem; text-transform:capitalize; }

.sidebar-nav{
  display:grid;
  gap:8px;
}
.navlink{
  display:flex;
  align-items:center;
  gap:12px;
  padding:12px 14px;
  border-radius:14px;
  color:#dbe7fb;
  transition: transform .18s ease, background .18s ease, border-color .18s ease;
  border:1px solid transparent;
}
.navlink:hover{
  background: rgba(255,255,255,.08);
  border-color: rgba(255,255,255,.08);
  transform: translateX(3px);
}
.nav-icon{
  width:28px;
  height:28px;
  border-radius:10px;
  display:grid;
  place-items:center;
  background: rgba(255,255,255,.08);
  color:#c7d2fe;
  font-size:.95rem;
}
.sidebar-cta{
  display:grid;
  gap:10px;
  margin-top:auto;
}
.sidebar-note{
  display:grid;
  gap:6px;
  background: linear-gradient(180deg, rgba(255,255,255,.07), rgba(255,255,255,.03));
  border:1px solid rgba(255,255,255,.08);
  color:#c9d6ec;
  padding:14px;
  border-radius:18px;
  font-size:.9rem;
}

.workspace{
  min-width:0;
  padding:18px 22px 28px;
}
.workspace-topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  padding:18px 24px;
  border:1px solid rgba(255,255,255,.6);
  background: rgba(255,255,255,.66);
  backdrop-filter: blur(16px);
  border-radius:22px;
  box-shadow: var(--shadow-sm);
  margin-bottom:18px;
}
.eyebrow{
  font-size:.78rem;
  text-transform:uppercase;
  letter-spacing:.18em;
  color:var(--muted);
  font-weight:800;
}
.workspace-title{
  font-size:1.1rem;
  font-weight:800;
  margin-top:4px;
}
.workspace-badge{
  border-radius:999px;
  padding:10px 14px;
  color:#1d4ed8;
  background:var(--primary-soft);
  border:1px solid rgba(79,70,229,.12);
  font-weight:800;
  white-space:nowrap;
}

.container{
  max-width: 1380px;
  margin:0 auto;
}
.narrow{ max-width:560px; }

.pagehead{
  display:flex;
  justify-content:space-between;
  align-items:flex-end;
  gap:16px;
  margin: 6px 0 18px;
  padding: 8px 2px;
  flex-wrap:wrap;
}
.pagehead > div:first-child{
  max-width:820px;
}
.actions{
  display:flex;
  gap:10px;
  align-items:center;
  flex-wrap:wrap;
}
h1{
  margin:0 0 8px;
  font-size: clamp(2rem, 2.9vw, 2.9rem);
  letter-spacing:-.04em;
  line-height:1.02;
}
h2{ margin:0 0 10px; font-size:1.55rem; letter-spacing:-.03em; }
h3{ margin:0 0 10px; font-size:1.08rem; }
h4{ margin:0; }

.muted{ color:var(--muted); }
.desc{ color:#334155; line-height:1.68; }

.sp-card{
  position:relative;
  background: linear-gradient(180deg, rgba(255,255,255,.95), rgba(255,255,255,.88));
  border:1px solid rgba(255,255,255,.78);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding:20px 22px;
  margin:16px 0;
  overflow:hidden;
}
.sp-card::after{
  content:"";
  position:absolute;
  inset:0;
  border-radius:inherit;
  pointer-events:none;
  background: linear-gradient(180deg, rgba(255,255,255,.24), transparent 28%);
}
.sp-card > *{ position:relative; z-index:1; }
.ai-card,
.formula-card{
  background: linear-gradient(180deg, rgba(239,244,255,.92), rgba(255,255,255,.88));
}
.objective-hero{
  background: linear-gradient(135deg, rgba(37,99,235,.96) 0%, rgba(79,70,229,.94) 46%, rgba(14,165,233,.92) 100%);
  color:#ffffff;
  border:0;
  box-shadow: var(--shadow-lg);
}
.objective-hero .desc,
.objective-hero .muted,
.objective-hero .k,
.objective-hero .v{ color:#fff; }
.objective-hero .stat{
  background: rgba(255,255,255,.14);
  border:1px solid rgba(255,255,255,.18);
}
.objective-hero .tag-alert{
  background: rgba(255,255,255,.18);
  color:#fff;
  border-color:rgba(255,255,255,.2);
}

.stats{
  display:grid;
  grid-template-columns: repeat(4, minmax(0,1fr));
  gap:14px;
  margin:18px 0 0;
}
.stat{
  background: rgba(255,255,255,.7);
  border:1px solid rgba(148,163,184,.18);
  border-radius:16px;
  padding:16px;
  min-height:104px;
}
.k{
  color:var(--muted);
  font-size:.77rem;
  font-weight:800;
  text-transform:uppercase;
  letter-spacing:.11em;
}
.v{
  font-size:1.85rem;
  font-weight:900;
  margin-top:8px;
  letter-spacing:-.04em;
}

.kpi-grid{
  display:grid;
  grid-template-columns: repeat(6, minmax(0,1fr));
  gap:14px;
  margin-bottom:14px;
}
.kpi{
  position:relative;
  overflow:hidden;
  padding:18px;
  border-radius:18px;
  border:1px solid rgba(255,255,255,.76);
  background: linear-gradient(180deg, rgba(255,255,255,.94), rgba(255,255,255,.84));
  box-shadow: var(--shadow-sm);
}
.kpi::before{
  content:"";
  position:absolute;
  inset:0 auto auto 0;
  width:100%;
  height:5px;
  background: linear-gradient(90deg, #2563eb, #7c3aed);
}
.kpi:nth-child(2)::before{ background: linear-gradient(90deg, #16a34a, #22c55e); }
.kpi:nth-child(3)::before{ background: linear-gradient(90deg, #d97706, #f59e0b); }
.kpi:nth-child(4)::before{ background: linear-gradient(90deg, #dc2626, #fb7185); }
.kpi:nth-child(5)::before{ background: linear-gradient(90deg, #475569, #64748b); }
.kpi:nth-child(6)::before{ background: linear-gradient(90deg, #0ea5e9, #2563eb); }
.kpi .v{ font-size:2rem; }

.grid2,.grid3,.grid4{
  display:grid;
  gap:14px;
}
.grid2{ grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid3{ grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid4{ grid-template-columns: minmax(0,2fr) repeat(3, minmax(0,1fr)); }
.full{ grid-column:1 / -1; }
.end{ display:flex; align-items:flex-end; justify-content:flex-end; }
.inline{ display:flex; gap:10px; align-items:center; flex-wrap:wrap; }
.inline input{ width:220px; }
.stack{ display:grid; gap:10px; }

label{
  display:block;
  margin:12px 0 7px;
  font-size:.78rem;
  font-weight:800;
  letter-spacing:.08em;
  text-transform:uppercase;
  color:#334155;
}
input,textarea,select{
  width:100%;
  border:1px solid rgba(148,163,184,.3);
  background:#ffffff;
  color:var(--text);
  border-radius:14px;
  padding:12px 14px;
  font:inherit;
  box-shadow: inset 0 1px 1px rgba(255,255,255,.45);
  transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}
textarea{ min-height:120px; resize:vertical; }
input:focus,textarea:focus,select:focus{
  outline:none;
  border-color: rgba(37,99,235,.55);
  box-shadow: 0 0 0 4px rgba(37,99,235,.12);
  transform: translateY(-1px);
}

.btn{
  appearance:none;
  border:1px solid rgba(148,163,184,.26);
  background:rgba(255,255,255,.82);
  color:var(--text);
  border-radius:14px;
  padding:11px 15px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:8px;
  cursor:pointer;
  font-weight:700;
  line-height:1;
  box-shadow: 0 8px 20px rgba(15,23,42,.05);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease, background .18s ease;
}
.btn:hover{
  transform: translateY(-1px);
  box-shadow: 0 14px 24px rgba(15,23,42,.08);
  border-color: rgba(100,116,139,.35);
}
.btn.primary{
  color:#fff;
  border-color: transparent;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-2) 100%);
}
.btn.primary:hover{ filter:brightness(1.04); }
.btn.danger{
  color:#fff;
  border-color:transparent;
  background: linear-gradient(135deg, #dc2626 0%, #ef4444 100%);
}
.btn.ghost{
  background: rgba(255,255,255,.02);
  color:#d7e4f8;
  border-color: rgba(255,255,255,.08);
  box-shadow:none;
}
.btn.ghost:hover{
  background: rgba(255,255,255,.08);
  border-color: rgba(255,255,255,.14);
}
.wide{ width:100%; }

.alert{
  border-radius:16px;
  padding:12px 14px;
  border:1px solid rgba(220,38,38,.18);
  background: var(--danger-soft);
  color:#991b1b;
  font-weight:600;
  margin: 10px 0;
}
.footer{
  text-align:center;
  color:var(--muted);
  font-size:.92rem;
  padding:18px 8px 6px;
}

.sp-table{
  width:100%;
  border-collapse:separate;
  border-spacing:0 10px;
}
.sp-table th{
  text-align:left;
  padding:0 14px 10px;
  font-size:.74rem;
  color:var(--muted);
  font-weight:800;
  letter-spacing:.08em;
  text-transform:uppercase;
}
.sp-table td{
  padding:14px;
  background: rgba(248,250,252,.82);
  border-top:1px solid rgba(255,255,255,.9);
  border-bottom:1px solid var(--line);
  vertical-align:top;
}
.sp-table tbody tr td:first-child{
  border-left:1px solid var(--line);
  border-top-left-radius:14px;
  border-bottom-left-radius:14px;
}
.sp-table tbody tr td:last-child{
  border-right:1px solid var(--line);
  border-top-right-radius:14px;
  border-bottom-right-radius:14px;
}
.sp-table tbody tr:hover td{
  background:#ffffff;
}
.sep{ border:0; border-top:1px solid var(--line); margin: 18px 0; }

.pill{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  padding:7px 11px;
  border-radius:999px;
  font-size:.77rem;
  font-weight:800;
  border:1px solid rgba(148,163,184,.24);
  background:#f8fafc;
  color:#334155;
}
.pill.verde{ background:var(--success-soft); color:#166534; border-color:rgba(22,163,74,.16); }
.pill.amarillo{ background:var(--warning-soft); color:#9a3412; border-color:rgba(217,119,6,.18); }
.pill.rojo{ background:var(--danger-soft); color:#991b1b; border-color:rgba(220,38,38,.16); }
.pill.status{ background:var(--info-soft); color:#075985; border-color:rgba(14,165,233,.16); }

.notes{
  margin:0;
  white-space:pre-wrap;
  border-radius:16px;
  padding:16px;
  background:#f8fafc;
  border:1px dashed rgba(100,116,139,.26);
  line-height:1.65;
}
.progressbar{
  height:10px;
  width:100%;
  background:#e5edf7;
  border-radius:999px;
  overflow:hidden;
  margin-top:10px;
}
.progressbar span{
  display:block;
  height:100%;
  background: linear-gradient(90deg, #2563eb, #38bdf8);
  border-radius:inherit;
}

.donut{
  width:190px;
  height:190px;
  margin:16px auto;
  border-radius:50%;
  background: conic-gradient(#16a34a 0 calc(var(--verde) * 1%), #f59e0b calc(var(--verde) * 1%) calc((var(--verde) + var(--amarillo)) * 1%), #dc2626 calc((var(--verde) + var(--amarillo)) * 1%) 100%);
  position:relative;
  box-shadow: inset 0 0 0 10px rgba(255,255,255,.6), 0 20px 40px rgba(15,23,42,.1);
}
.donut::after{
  content:"";
  position:absolute;
  inset:48px;
  background:#fff;
  border-radius:50%;
  border:1px solid rgba(148,163,184,.2);
}
.legend{
  display:flex;
  justify-content:center;
  gap:16px;
  flex-wrap:wrap;
  color:var(--muted);
  font-size:.92rem;
}
.dot{
  width:10px;
  height:10px;
  display:inline-block;
  border-radius:999px;
  margin-right:6px;
}
.verde-dot{ background:#16a34a; }
.amarillo-dot{ background:#f59e0b; }
.rojo-dot{ background:#dc2626; }

.tag-alert{
  display:inline-flex;
  align-items:center;
  gap:6px;
  margin:4px 6px 0 0;
  padding:6px 10px;
  border-radius:999px;
  background:var(--danger-soft);
  color:#991b1b;
  border:1px solid rgba(220,38,38,.14);
  font-size:.78rem;
  font-weight:800;
}
.alert-list{ margin-top:14px; }

.ai-chip{
  display:inline-flex;
  align-items:center;
  gap:8px;
  width:max-content;
  padding:7px 12px;
  border-radius:999px;
  background: rgba(37,99,235,.1);
  color:#1d4ed8;
  border:1px solid rgba(37,99,235,.12);
  font-size:.74rem;
  font-weight:900;
  text-transform:uppercase;
  letter-spacing:.08em;
  margin-bottom:12px;
}
.ai-grid{ display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:14px; margin-top:14px; }
.ai-text{
  margin:6px 0 0;
  padding:14px;
  border-radius:16px;
  border:1px solid rgba(255,255,255,.9);
  background:#fff;
  line-height:1.65;
}
.ai-actions{ display:flex; justify-content:flex-end; gap:10px; flex-wrap:wrap; margin-top:14px; }
.assist-box{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:16px;
  background: linear-gradient(135deg, #eff6ff, #eef2ff);
  border:1px solid rgba(37,99,235,.12);
  border-radius:20px;
  padding:18px;
  margin-bottom:16px;
}
.ai-result,
.formula-box,
.formula-substitution,
.formula-result,
.metric-form,
.evidence-box,
.history-list,
.indicator-card,
.kv,
.access-box{
  box-shadow: inset 0 1px 0 rgba(255,255,255,.6);
}
.ai-result{
  background: linear-gradient(180deg, #ffffff, #f8fbff);
  border:1px solid rgba(37,99,235,.12);
  border-radius:20px;
  padding:16px;
  margin-bottom:16px;
}
.hidden{ display:none; }

.formula-head{
  display:flex;
  justify-content:space-between;
  gap:16px;
  align-items:flex-start;
}
.formula-result{
  min-width:140px;
  text-align:center;
  border-radius:18px;
  padding:16px 18px;
  background: linear-gradient(135deg, rgba(37,99,235,.14), rgba(79,70,229,.16));
  border:1px solid rgba(37,99,235,.12);
  color:#1d4ed8;
  font-size:2.35rem;
  font-weight:900;
}
.formula-box{
  font-size:1.15rem;
  font-weight:800;
  letter-spacing:-.02em;
  background:#fff;
  border:1px solid rgba(148,163,184,.18);
  border-radius:18px;
  padding:18px;
  margin:12px 0 10px;
  overflow:auto;
}
.formula-substitution,
.mini-substitution{
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.formula-substitution{
  background:#f8fafc;
  border:1px dashed rgba(100,116,139,.28);
  border-radius:16px;
  padding:14px 16px;
  overflow:auto;
}
.mini-formula{
  font-weight:900;
  line-height:1.55;
  margin-bottom:8px;
}
.mini-substitution{
  font-size:.8rem;
  background:#f8fafc;
  border:1px solid rgba(148,163,184,.18);
  border-radius:14px;
  padding:10px 12px;
  margin-bottom:8px;
}
.indicator-card{
  border-radius:20px;
  padding:18px;
  margin:16px 0;
  background: linear-gradient(180deg, rgba(255,255,255,.94), rgba(247,250,252,.9));
  border:1px solid rgba(255,255,255,.88);
}
.indicator-head,
.section-head{
  display:flex;
  justify-content:space-between;
  align-items:flex-start;
  gap:16px;
  margin-bottom:14px;
}
.sparkline{
  width:100%;
  height:94px;
  color:#2563eb;
  background: linear-gradient(180deg, #eff6ff, #ffffff);
  border:1px solid rgba(37,99,235,.12);
  border-radius:16px;
  padding:10px;
}
.metric-form{
  display:grid;
  gap:8px;
  background:#f8fafc;
  border:1px solid rgba(148,163,184,.18);
  border-radius:18px;
  padding:16px;
}
.history-list{
  max-height:240px;
  overflow:auto;
  border:1px solid rgba(148,163,184,.18);
  border-radius:16px;
  background:#fff;
}
.history-item{
  padding:11px 12px;
  border-bottom:1px solid rgba(148,163,184,.14);
}
.history-item:last-child{ border-bottom:0; }
.evidence-box{
  margin-top:14px;
  padding:14px;
  border:1px dashed rgba(100,116,139,.28);
  border-radius:18px;
  background:#fbfcfe;
}
.evidence-list{ display:grid; gap:7px; margin-top:10px; }
.evidence-link{ font-weight:800; color:#1d4ed8; }

.kv{
  display:flex;
  justify-content:space-between;
  gap:14px;
  padding:10px 0;
  border-bottom:1px dashed rgba(148,163,184,.2);
}
.kv:last-child{ border-bottom:0; }
.kv .v{ font-size:1rem; margin-top:0; font-weight:700; text-align:right; }
code{
  display:inline-block;
  padding:4px 8px;
  border-radius:10px;
  background:#f8fafc;
  border:1px solid rgba(148,163,184,.18);
  color:#334155;
}
.indent{ padding-left: calc(18px + (var(--d) * 22px)); position: relative; }
.indent::before{
  content:"";
  width:16px;
  height:16px;
  border-left:1px solid rgba(100,116,139,.34);
  border-bottom:1px solid rgba(100,116,139,.34);
  position:absolute;
  left: calc(10px + (var(--d) * 22px));
  top: 16px;
}

.form{ display:grid; gap:8px; }

/* Login */
.auth-body{
  min-height:100vh;
  display:grid;
  place-items:center;
  padding:32px;
}
.login-shell{
  width:min(1180px, 100%);
  display:grid;
  grid-template-columns: 1.15fr .85fr;
  background: rgba(255,255,255,.76);
  backdrop-filter: blur(16px);
  border:1px solid rgba(255,255,255,.84);
  border-radius:32px;
  overflow:hidden;
  box-shadow: var(--shadow-lg);
  position:relative;
  z-index:1;
}
.login-hero{
  padding:48px;
  background: linear-gradient(135deg, rgba(15,23,42,.98) 0%, rgba(30,41,59,.95) 46%, rgba(37,99,235,.92) 100%);
  color:#fff;
  display:flex;
  flex-direction:column;
  justify-content:center;
}
.login-hero h1{
  font-size: clamp(2.2rem, 4vw, 3.8rem);
  line-height:1;
  margin:0 0 18px;
}
.login-hero p{
  margin:0;
  color:#d7e4f8;
  max-width:620px;
  line-height:1.75;
  font-size:1.03rem;
}
.login-chip{
  width:max-content;
  border-radius:999px;
  padding:8px 14px;
  margin-bottom:16px;
  background: rgba(255,255,255,.1);
  border:1px solid rgba(255,255,255,.12);
  font-size:.78rem;
  font-weight:900;
  letter-spacing:.1em;
  text-transform:uppercase;
}
.login-highlights{
  display:grid;
  gap:12px;
  margin-top:28px;
}
.login-highlight{
  display:flex;
  justify-content:space-between;
  gap:12px;
  padding:14px 16px;
  border-radius:18px;
  background: rgba(255,255,255,.08);
  border:1px solid rgba(255,255,255,.1);
}
.login-highlight strong{ display:block; }
.login-highlight span{ color:#d7e4f8; }
.login-panel{
  padding:42px 34px;
  background: linear-gradient(180deg, rgba(255,255,255,.96), rgba(248,250,252,.92));
}
.login-panel-head{
  display:flex;
  align-items:center;
  gap:14px;
  margin-bottom:18px;
}
.login-panel-head h2{ margin:0; }
.login-form{ margin-top:8px; }
.access-box{
  border-radius:20px;
  background:#f8fafc;
  border:1px solid rgba(148,163,184,.18);
  padding:16px;
  margin-bottom:12px;
}
.access-grid{
  display:grid;
  gap:8px;
  margin-top:10px;
  color:#475569;
  font-size:.95rem;
}

@media (max-width: 1180px){
  .kpi-grid{ grid-template-columns: repeat(3, minmax(0,1fr)); }
}
@media (max-width: 1040px){
  .app-shell{ grid-template-columns: 1fr; }
  .sidebar{
    position:relative;
    height:auto;
    border-right:0;
    border-bottom:1px solid rgba(255,255,255,.06);
  }
  .workspace{ padding-top:14px; }
  .grid2,.grid3,.grid4,.stats,.ai-grid{ grid-template-columns:1fr; }
  .inline input{ width:100%; }
  .formula-head,
  .indicator-head,
  .section-head,
  .pagehead,
  .workspace-topbar{ flex-direction:column; align-items:flex-start; }
  .login-shell{ grid-template-columns:1fr; }
}
@media (max-width: 760px){
  body{ font-size:15px; }
  .auth-body{ padding:16px; }
  .workspace{ padding:14px; }
  .sidebar{ padding:18px 14px; }
  .sp-card{ padding:18px; }
  .kpi-grid{ grid-template-columns:1fr; }
  .donut{ width:160px; height:160px; }
  .donut::after{ inset:42px; }
  .login-hero,
  .login-panel{ padding:26px 22px; }
}

/* Periodicidad de mediciones */
.schedule-line{
  display:flex;
  align-items:center;
  gap:10px;
  flex-wrap:wrap;
  margin-top:10px;
}
.schedule-detail-grid{
  grid-column:1 / -1;
  margin-top:14px;
}
.schedule-card{
  background:linear-gradient(180deg, #ffffff, #f8fbff);
  border:1px solid rgba(37,99,235,.12);
  border-radius:18px;
  padding:16px;
}
@media (min-width:1181px){
  .kpi-grid{ grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); }
}

/* configuración institucional + análisis de desviaciones */
.sidebar-logo{
  width:54px;
  height:54px;
  border-radius:16px;
  object-fit:contain;
  background:#fff;
  padding:6px;
  box-shadow:0 18px 38px rgba(15,23,42,.24);
}
.large-mark{ width:74px; height:74px; margin:0 auto 14px; }
.success-alert{
  background:var(--success-soft);
  color:#166534;
  border-color:rgba(22,163,74,.22);
}
.preview-card{ align-self:start; }
.institution-preview{
  text-align:center;
  padding:18px;
  border-radius:22px;
  background:linear-gradient(180deg,#ffffff,#f8fafc);
  border:1px solid rgba(148,163,184,.18);
}
.institution-logo-preview{
  max-width:180px;
  max-height:92px;
  object-fit:contain;
  display:block;
  margin:0 auto 14px;
}
.report-preview{
  margin-top:18px;
  border-radius:18px;
  padding:16px;
  background:#f8fafc;
  border:1px dashed rgba(100,116,139,.28);
}
.deviation-card{
  background:linear-gradient(135deg, rgba(255,255,255,.96), rgba(239,246,255,.9));
  border-color:rgba(37,99,235,.14);
}
.deviation-stats .stat{
  background:rgba(255,255,255,.78);
}
.smart-list{
  margin:10px 0 0;
  padding-left:20px;
  line-height:1.7;
  color:#334155;
}
.smart-list li{ margin:6px 0; }
.suggested-action-box{
  margin-top:16px;
  padding:16px;
  border-radius:18px;
  background:#fff;
  border:1px solid rgba(37,99,235,.12);
}
.schedule-line{
  display:flex;
  gap:8px;
  align-items:center;
  flex-wrap:wrap;
  margin-top:8px;
}
.schedule-detail-grid{ margin-top:14px; }
.schedule-card{
  border-radius:18px;
  padding:16px;
  background:#ffffff;
  border:1px solid rgba(148,163,184,.18);
}

/* NEXO SG */
.ai-engine-meta{
  display:flex;
  gap:8px;
  align-items:center;
  flex-wrap:wrap;
  margin:12px 0 14px;
}
.persisted-ai-box{
  margin-top:16px;
  padding:16px;
  border-radius:18px;
  background:linear-gradient(180deg,#ffffff,#f8fbff);
  border:1px solid rgba(37,99,235,.12);
}

/* NEXIA SG - sugerencias múltiples de redacción */
.assist-controls{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  justify-content:flex-end;
}
.ghost-soft{
  background: rgba(255,255,255,.72);
  color:#1d4ed8;
  border-color: rgba(37,99,235,.18);
}
.assist-summary{
  background: rgba(255,255,255,.72);
  border:1px solid rgba(37,99,235,.12);
  border-radius:16px;
  padding:12px 14px;
  color:#334155;
  line-height:1.6;
  margin-bottom:14px;
}
.suggestions-grid{
  display:grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap:14px;
}
.suggestion-card{
  display:flex;
  flex-direction:column;
  gap:10px;
  background: linear-gradient(180deg, rgba(255,255,255,.96), rgba(248,250,252,.92));
  border:1px solid rgba(148,163,184,.20);
  border-radius:18px;
  padding:16px;
  box-shadow: 0 12px 28px rgba(15,23,42,.06);
}
.suggestion-head{
  display:flex;
  justify-content:space-between;
  gap:10px;
  align-items:center;
}
.suggestion-style{
  display:inline-flex;
  width:max-content;
  padding:7px 11px;
  border-radius:999px;
  background: rgba(37,99,235,.10);
  color:#1d4ed8;
  border:1px solid rgba(37,99,235,.12);
  font-size:.76rem;
  font-weight:900;
  text-transform:uppercase;
  letter-spacing:.08em;
}
.suggestion-counter{
  color:var(--muted);
  font-size:.82rem;
  font-weight:800;
}
.suggestion-text{
  margin:0;
  padding:12px;
  background:#fff;
  border:1px solid rgba(148,163,184,.18);
  border-radius:14px;
  color:#334155;
  line-height:1.6;
}
.title-option{
  font-weight:800;
  color:#172554;
}
.suggestion-reading{
  margin:0;
  color:var(--muted);
  line-height:1.55;
  font-size:.92rem;
}
.suggestion-actions{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  margin-top:auto;
  padding-top:4px;
}
@media (max-width: 1040px){
  .suggestions-grid{ grid-template-columns:1fr; }
  .assist-controls{ justify-content:flex-start; }
}

/* NEXIA SG - evaluación de calidad del objetivo */
.quality-result{
  background: linear-gradient(180deg, rgba(255,255,255,.96), rgba(239,246,255,.86));
  border:1px solid rgba(37,99,235,.12);
}
.quality-headline{
  display:flex;
  justify-content:space-between;
  gap:18px;
  align-items:flex-start;
  margin-bottom:16px;
}
.quality-score-ring{
  min-width:118px;
  height:118px;
  border-radius:999px;
  display:grid;
  place-items:center;
  text-align:center;
  background:
    radial-gradient(circle at center, #ffffff 0 54%, transparent 56%),
    conic-gradient(#2563eb 0 calc(var(--score, 72) * 1%), rgba(148,163,184,.18) calc(var(--score, 72) * 1%) 100%);
  border:1px solid rgba(37,99,235,.12);
  box-shadow:0 16px 34px rgba(37,99,235,.12);
  color:#1d4ed8;
  font-weight:900;
}
.quality-score-ring span{
  display:block;
  font-size:2.15rem;
  letter-spacing:-.06em;
  line-height:1;
}
.quality-score-ring small{
  display:block;
  margin-top:-28px;
  color:var(--muted);
  font-size:.8rem;
}
.quality-criteria-grid{
  display:grid;
  grid-template-columns: repeat(5, minmax(0,1fr));
  gap:12px;
  margin:14px 0 16px;
}
.quality-criterion-card{
  padding:14px;
  border-radius:18px;
  background:#ffffff;
  border:1px solid rgba(148,163,184,.18);
  box-shadow:0 10px 24px rgba(15,23,42,.05);
}
.quality-criterion-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  margin-bottom:10px;
}
.quality-bar{
  height:9px;
  width:100%;
  overflow:hidden;
  border-radius:999px;
  background:#e5edf7;
  margin-bottom:10px;
}
.quality-bar span{
  display:block;
  height:100%;
  border-radius:inherit;
  background: linear-gradient(90deg, #2563eb, #38bdf8);
}
.quality-rec{
  margin:.45rem 0 0;
  color:#1d4ed8;
  font-weight:700;
  line-height:1.45;
}
.quality-notes-grid{
  margin-top:10px;
}
@media (max-width: 1180px){
  .quality-criteria-grid{ grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 760px){
  .quality-headline{ flex-direction:column; }
  .quality-criteria-grid{ grid-template-columns:1fr; }
}

/* NEXIA SG - evaluación integrada a los campos del objetivo */
.objective-input-grid{
  display:grid;
  grid-template-columns:minmax(0, 1.05fr) minmax(360px, .95fr);
  gap:18px;
  align-items:start;
  margin-bottom:18px;
}
.objective-input-card,
.inline-quality-panel{
  border:1px solid rgba(148,163,184,.20);
  border-radius:20px;
  background:linear-gradient(180deg, rgba(255,255,255,.96), rgba(248,250,252,.88));
  padding:18px;
  box-shadow:0 12px 28px rgba(15,23,42,.05);
}
.inline-quality-panel{
  position:sticky;
  top:18px;
}
.section-minihead{
  display:flex;
  justify-content:space-between;
  align-items:flex-start;
  gap:14px;
  margin-bottom:4px;
}
.compact-assist{
  margin-top:4px;
}
.inline-quality-panel .quality-result{
  margin-top:14px;
  padding:14px;
  border-radius:18px;
}
.inline-quality-panel .quality-headline{
  align-items:center;
  margin-bottom:12px;
}
.inline-quality-panel .quality-score-ring{
  min-width:88px;
  width:88px;
  height:88px;
}
.inline-quality-panel .quality-score-ring span{
  font-size:1.65rem;
}
.inline-quality-panel .quality-score-ring small{
  margin-top:-22px;
}
.quality-score-ring.inactive-score{
  color:#64748b;
  background:
    radial-gradient(circle at center, #ffffff 0 54%, transparent 56%),
    conic-gradient(rgba(148,163,184,.45) 0 0%, rgba(148,163,184,.18) 0% 100%);
  box-shadow:none;
}
.quality-source-card{
  background:#fff;
  border:1px solid rgba(148,163,184,.18);
  border-radius:16px;
  padding:13px;
  margin:12px 0 14px;
}
.source-review{
  display:grid;
  gap:6px;
  margin-top:8px;
}
.source-review strong{
  color:#172554;
  font-size:.82rem;
}
.source-review p{
  margin:0;
  padding:10px 12px;
  border-radius:12px;
  background:#f8fafc;
  border:1px solid rgba(148,163,184,.16);
  color:#334155;
  line-height:1.55;
}
.persisted-source{
  margin-top:0;
}
.inline-quality-panel .quality-criteria-grid{
  grid-template-columns:1fr;
}
@media (max-width: 1180px){
  .objective-input-grid{ grid-template-columns:1fr; }
  .inline-quality-panel{ position:relative; top:auto; }
}
.quality-stale{
  margin:10px 0 12px;
  padding:10px 12px;
  border-radius:14px;
  background:#fff7ed;
  border:1px solid rgba(217,119,6,.18);
  color:#9a3412;
  font-weight:700;
  line-height:1.45;
}

/* NEXIA SG - memoria documental */
.knowledge-results,
.knowledge-chunks{
  display:grid;
  gap:14px;
}
.knowledge-result,
.knowledge-chunk{
  border:1px solid rgba(148,163,184,.18);
  background: linear-gradient(180deg, rgba(255,255,255,.94), rgba(248,250,252,.92));
  border-radius:18px;
  padding:16px;
  box-shadow: var(--shadow-sm);
}
.result-head{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:12px;
  margin-bottom:8px;
}
.knowledge-chunk:target{
  outline:3px solid rgba(37,99,235,.18);
  border-color:rgba(37,99,235,.35);
}
@media (max-width: 760px){
  .result-head{ flex-direction:column; align-items:flex-start; }
}

/* Chat NEXIA */
.chat-layout{
  display:grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap:16px;
  align-items:start;
}
.chat-sidebar{ position:sticky; top:18px; }
.chat-thread-list,
.quick-prompts{
  display:grid;
  gap:10px;
}
.chat-thread{
  display:grid;
  gap:4px;
  padding:12px 13px;
  border-radius:16px;
  background:#f8fafc;
  border:1px solid rgba(148,163,184,.18);
}
.chat-thread:hover,
.chat-thread.active{
  background:linear-gradient(135deg, rgba(37,99,235,.12), rgba(79,70,229,.08));
  border-color:rgba(37,99,235,.18);
}
.chat-thread span{ color:var(--muted); font-size:.84rem; }
.chat-panel{
  min-height:680px;
  display:flex;
  flex-direction:column;
}
.chat-panel-head{
  display:flex;
  justify-content:space-between;
  gap:16px;
  align-items:flex-start;
}
.chat-rename{
  display:flex;
  gap:10px;
  margin:10px 0 14px;
}
.chat-messages{
  display:grid;
  gap:16px;
  padding:12px 0;
  flex:1;
}
.chat-message{
  display:flex;
  gap:12px;
  align-items:flex-start;
}
.chat-message.user{ flex-direction:row-reverse; }
.chat-avatar{
  width:44px;
  height:44px;
  flex:0 0 44px;
  border-radius:14px;
  display:grid;
  place-items:center;
  font-weight:900;
  color:#fff;
  background:linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow:0 14px 26px rgba(37,99,235,.18);
}
.chat-message.user .chat-avatar{
  background:linear-gradient(135deg, #334155, #64748b);
}
.chat-bubble{
  max-width:min(860px, 84%);
  padding:14px 16px;
  border-radius:20px;
  background:#ffffff;
  border:1px solid rgba(148,163,184,.18);
  box-shadow:var(--shadow-sm);
}
.chat-message.user .chat-bubble{
  background:linear-gradient(135deg, rgba(37,99,235,.12), rgba(14,165,233,.08));
}
.chat-meta{
  display:flex;
  gap:10px;
  align-items:center;
  flex-wrap:wrap;
  margin-bottom:8px;
  color:var(--muted);
  font-size:.88rem;
}
.chat-meta strong{ color:var(--text); }
.chat-text{
  white-space:pre-wrap;
  line-height:1.65;
  color:#243044;
}
.chat-refs{
  margin-top:12px;
  display:grid;
  gap:8px;
  padding-top:12px;
  border-top:1px dashed rgba(148,163,184,.3);
}
.chat-ref{
  display:grid;
  gap:4px;
  padding:10px 12px;
  border-radius:14px;
  background:#f8fafc;
  border:1px solid rgba(148,163,184,.16);
}
.chat-ref:hover{ background:#fff; }
.chat-ref span{ color:var(--muted); font-size:.88rem; }
.chat-ref em{ color:#475569; font-style:normal; line-height:1.45; }
.chat-form{
  display:grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap:12px;
  align-items:end;
  padding-top:14px;
  border-top:1px solid rgba(148,163,184,.18);
}
.chat-form textarea{ min-height:86px; }
.empty-chat{
  min-height:360px;
  display:grid;
  place-items:center;
  align-content:center;
  text-align:center;
  gap:12px;
  padding:24px;
  border-radius:22px;
  background:linear-gradient(180deg, rgba(239,246,255,.9), rgba(255,255,255,.86));
  border:1px dashed rgba(37,99,235,.18);
}
@media (max-width: 1040px){
  .chat-layout{ grid-template-columns:1fr; }
  .chat-sidebar{ position:relative; top:auto; }
  .chat-form{ grid-template-columns:1fr; }
  .chat-bubble{ max-width:100%; }
}
