/* Backoffice · Encuesta de satisfacción Orientak
   Identidad de orientak.com: verde #30bb9f, verde profundo #114138, Inter. */

:root {
  color-scheme: light;
  --teal: #30bb9f;
  --teal-hover: #29a88e;
  --teal-strong: #1d7a67;
  --teal-deep: #114138;
  --teal-deeper: #0c302a;
  --teal-tint: #e8f6f2;
  --teal-tint-2: #d3efe8;
  --bg: #f4f8f7;
  --surface: #ffffff;
  --ink: #0f2620;
  --text: #36444b;
  --muted: #66737b;
  --line: #e1ebe8;
  --line-strong: #c4d6d0;
  --rose: #c42f55;
  --rose-tint: #fdeef2;
  --amber: #a86400;
  --amber-tint: #fff4dc;
  --ok: #157a3a;
  --ok-tint: #e5f6ea;
  /* Gráficos (validados con el validador de paleta: CVD y contraste) */
  --s1: #1d8f78;
  --s2: #2a78d6;
  --s3: #c42f55;
  --lk1: #b8324f;
  --lk2: #e98a9f;
  --lk3: #b9c0bd;
  --lk4: #5fbda7;
  --lk5: #1a7f6b;
  --grid: #e6ece9;
  --axis: #c4ccc9;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(17, 65, 56, .05), 0 4px 16px rgba(17, 65, 56, .05);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --side: 248px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4 { color: var(--ink); line-height: 1.25; margin: 0; }
h1 { font-size: 1.6rem; letter-spacing: -.01em; }
h2 { font-size: 1.12rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }
a { color: var(--teal-strong); }
small, .muted { color: var(--muted); }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- Estructura ---------- */
.shell { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: linear-gradient(180deg, var(--teal-deep) 0%, var(--teal-deeper) 100%);
  color: #cfe7e0; padding: 20px 14px; display: flex; flex-direction: column; gap: 18px;
}
.sidebar .brand { display: flex; flex-direction: column; gap: 6px; padding: 4px 8px 12px; border-bottom: 1px solid rgba(255,255,255,.1); }
.sidebar .brand img { width: 150px; height: auto; }
.sidebar .brand span { font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; color: #9fd9c8; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-group { font-size: .72rem; text-transform: uppercase; letter-spacing: .1em; color: #8fbcae; margin: 12px 10px 4px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: #dcefe9; text-decoration: none; font-weight: 500; font-size: .93rem;
}
.nav a svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav a.active { background: rgba(48,187,159,.22); color: #fff; box-shadow: inset 3px 0 0 var(--teal); }
.nav .badge { margin-left: auto; }
.sidebar .user { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid rgba(255,255,255,.1); font-size: .85rem; }
.sidebar .user strong { color: #fff; display: block; }
.sidebar .user a, .sidebar .user .link-salir { color: #9fd9c8; }
.sidebar .user .link-salir { font-size: inherit; }

.main { min-width: 0; padding: 26px 32px 48px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 20px; margin-bottom: 18px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.mobile-bar { display: none; }

/* ---------- Tarjetas y rejillas ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); min-width: 0; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 6px 14px; margin-bottom: 14px; }
.card-head p { margin: 2px 0 0; color: var(--muted); font-size: .88rem; }
.grid { display: grid; gap: 16px; }
.grid + .grid, .grid + .card, .card + .grid { margin-top: 16px; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.g-1-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }

/* ---------- Indicadores ---------- */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.kpi-label { font-size: .8rem; color: var(--muted); font-weight: 500; display: flex; gap: 6px; align-items: center; }
.kpi-value { font-size: 1.85rem; font-weight: 700; color: var(--ink); line-height: 1.15; margin-top: 4px; letter-spacing: -.01em; }
.kpi-value small { font-size: .9rem; font-weight: 600; color: var(--muted); }
.kpi-foot { font-size: .8rem; color: var(--muted); margin-top: 4px; }
.kpi.is-hero { background: linear-gradient(140deg, #1b7d69 0%, #114138 100%); border-color: transparent; color: #e3f5f0; }
.kpi.is-hero .kpi-label, .kpi.is-hero .kpi-foot { color: #bfe7dc; }
.kpi.is-hero .kpi-value { color: #fff; }
.delta { font-weight: 600; font-size: .8rem; white-space: nowrap; }
.delta.mejor { color: var(--ok); }
.delta.peor { color: var(--rose); }
.delta.neutro { color: var(--muted); }
.kpi.is-hero .delta.mejor { color: #b6f0cf; }
.kpi.is-hero .delta.peor { color: #ffc9d6; }
.kpi.is-hero .delta.neutro { color: #cfe7e0; }

/* Semáforo (estado): siempre icono + texto */
.estado { display: inline-flex; align-items: center; gap: 5px; font-size: .78rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.estado::before { font-size: .8rem; }
.estado-ok { background: var(--ok-tint); color: var(--ok); }
.estado-ok::before { content: "✓"; }
.estado-aviso { background: var(--amber-tint); color: var(--amber); }
.estado-aviso::before { content: "!"; font-weight: 800; }
.estado-alerta { background: var(--rose-tint); color: var(--rose); }
.estado-alerta::before { content: "▲"; font-size: .62rem; }
.estado-sin { background: #eef1f0; color: var(--muted); }
.estado-sin::before { content: "–"; }

.badge { display: inline-block; min-width: 20px; padding: 1px 7px; border-radius: 99px; font-size: .74rem; font-weight: 700; text-align: center; background: var(--rose); color: #fff; }
.badge-soft { background: var(--teal-tint); color: var(--teal-strong); }
.badge-gray { background: #eef1f0; color: var(--muted); }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px; font-size: .78rem; font-weight: 500; background: #eef3f1; color: var(--text); border: 1px solid var(--line); }
.tag-positiva { background: #e6f5f0; border-color: #c4e7dc; color: #145f50; }
.tag-negativa { background: var(--rose-tint); border-color: #f4cbd6; color: #8f1f3d; }
.tag-neutra { background: #eef1f6; border-color: #d9e0ea; color: #3a4a63; }

/* ---------- Filtros ---------- */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 18px; box-shadow: var(--shadow); }
.filters label { display: flex; flex-direction: column; gap: 3px; font-size: .75rem; font-weight: 600; color: var(--muted); }
.filters select, .filters input { min-width: 0; }
.filters .grow { flex: 1; }
.filter-summary { font-size: .85rem; color: var(--muted); margin: -8px 0 16px; }

/* ---------- Formularios ---------- */
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 8px; padding: 8px 11px; min-height: 38px;
}
textarea { width: 100%; min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(48,187,159,.3); border-color: var(--teal-strong); }
input[type=checkbox], input[type=radio] { min-height: 0; accent-color: var(--teal-strong); width: 16px; height: 16px; }
.form-stack { display: flex; flex-direction: column; gap: 14px; }
.form-stack label, .form-grid label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: .88rem; color: var(--ink); }
.form-stack label.check, .form-grid label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.form-grid .full { grid-column: 1 / -1; }
.hint { font-size: .83rem; color: var(--muted); font-weight: 400; margin: 0; }
.inline-form { display: inline; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 38px; padding: 8px 16px; border-radius: 9px; border: 1px solid transparent;
  font: 600 .9rem/1.2 var(--font); text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn svg { width: 16px; height: 16px; }
.btn:focus-visible { outline: 3px solid #0e5f50; outline-offset: 2px; }
.btn-primary { background: var(--teal); color: #06231d; }
.btn-primary:hover { background: var(--teal-hover); }
.btn-dark { background: var(--teal-deep); color: #fff; }
.btn-dark:hover { background: #0c332c; }
.btn-ghost { background: var(--surface); color: var(--teal-strong); border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--teal-tint); }
.btn-danger { background: var(--surface); color: var(--rose); border-color: #efc2cf; }
.btn-danger:hover { background: var(--rose-tint); }
.btn-sm { min-height: 30px; padding: 5px 11px; font-size: .82rem; border-radius: 7px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.link-btn { background: none; border: 0; padding: 0; color: var(--teal-strong); font: inherit; text-decoration: underline; cursor: pointer; }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 9px 10px; border-bottom: 1px solid var(--line-strong); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.c, th.c { text-align: center; }
tbody tr:hover td { background: #f8fbfa; }
.table-sum td { font-weight: 700; background: #f6faf9; }
.row-muted td { color: var(--muted); }
.quarter-table th.n { min-width: 74px; }
.quarter-table .sec td { background: #f4f8f7; font-weight: 700; color: var(--ink); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.quarter-table td.cur, .quarter-table th.cur { background: #eef8f5; }

/* ---------- Mensajes ---------- */
.flash { padding: 11px 14px; border-radius: 10px; margin-bottom: 14px; font-weight: 500; border: 1px solid; }
.flash-ok { background: var(--ok-tint); border-color: #bfe5cb; color: #0f5a2a; }
.flash-error { background: var(--rose-tint); border-color: #f2c4d0; color: #8f1f3d; }
.flash-info { background: #eef4fb; border-color: #cfe0f3; color: #1e4a7a; }
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-size: 1.02rem; margin-bottom: 4px; }
.note { font-size: .83rem; color: var(--muted); border-left: 3px solid var(--teal-tint-2); padding: 2px 0 2px 10px; margin: 12px 0 0; }

/* ---------- Gráficos ---------- */
.viz { position: relative; }
.viz svg { display: block; width: 100%; height: auto; overflow: visible; }
.viz text { font-family: var(--font); }
.viz .grid-line { stroke: var(--grid); stroke-width: 1; }
.viz .axis-line { stroke: var(--axis); stroke-width: 1; }
.viz .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.viz .lbl { fill: var(--text); font-size: 12px; }
.viz .val { fill: var(--ink); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.viz .meta-line { stroke: var(--teal-deep); stroke-width: 1.5; }
.viz .meta-txt { fill: var(--teal-deep); font-size: 11px; font-weight: 600; }
.viz .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.viz .area { stroke: none; opacity: .1; }
.viz .dot { stroke: var(--surface); stroke-width: 2; }
.viz .hit { fill: transparent; cursor: default; }
.viz .hit:focus { outline: none; }
.viz .hit:focus + .focus-ring, .viz .hit:hover + .focus-ring { opacity: 1; }
.viz .focus-ring { fill: none; stroke: var(--ink); stroke-width: 1; opacity: 0; pointer-events: none; }
.viz .crosshair { stroke: var(--axis); stroke-width: 1; opacity: 0; pointer-events: none; }
.viz-tip {
  position: fixed; z-index: 100; top: 0; left: 0; pointer-events: none; opacity: 0; transition: opacity .12s;
  background: var(--ink); color: #fff; font-size: .8rem; line-height: 1.4; padding: 7px 10px; border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0,0,0,.18); white-space: nowrap; transform: translate(-50%, calc(-100% - 10px));
}
.viz-tip b { font-weight: 700; }
.viz-tip .sw { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .82rem; color: var(--text); margin: 0 0 10px; padding: 0; list-style: none; }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend .sw-line { width: 14px; height: 2px; border-radius: 2px; }

/* Barras horizontales (HTML) */
.hbars { display: flex; flex-direction: column; gap: 10px; }
.hbar { display: grid; grid-template-columns: minmax(120px, 190px) minmax(0, 1fr) 56px; align-items: center; gap: 10px; }
.hbar .name { font-size: .88rem; color: var(--ink); line-height: 1.25; }
.hbar .name small { display: block; font-size: .75rem; }
.hbar .track { position: relative; height: 22px; background: linear-gradient(90deg, var(--grid) 1px, transparent 1px) 0 0 / 25% 100%; border-left: 1px solid var(--axis); }
.hbar .fill { position: absolute; left: 0; top: 3px; height: 16px; background: var(--s1); border-radius: 0 4px 4px 0; }
.hbar .goal { position: absolute; top: -3px; bottom: -3px; width: 0; border-left: 2px solid var(--teal-deep); }
.hbar .v { font-weight: 700; color: var(--ink); text-align: right; font-variant-numeric: tabular-nums; }
.hbars-compact .hbar { grid-template-columns: 56px minmax(0, 1fr) 44px; }
.hbar-axis { display: grid; grid-template-columns: minmax(120px, 190px) minmax(0, 1fr) 56px; gap: 10px; font-size: .72rem; color: var(--muted); }
.hbar-axis .ticks { display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; }

/* Barras segmentadas (Likert y NPS) */
.seg { display: flex; gap: 2px; height: 28px; border-radius: 0; }
.seg > span { position: relative; display: flex; align-items: center; padding: 0 6px; font-size: .74rem; font-weight: 700; color: #fff; border-radius: 4px; min-width: 0; overflow: visible; white-space: nowrap; }
.seg > span.dark-txt { color: #0b0b0b; }
.seg > span[data-w="0"] { display: none; }
.seg-thin { height: 10px; }
.seg-thin > span { padding: 0; }
.likert { display: flex; flex-direction: column; gap: 9px; }
.likert-row { display: grid; grid-template-columns: minmax(120px, 190px) minmax(0, 1fr) 44px; align-items: center; gap: 10px; }
.likert-row .name { font-size: .86rem; color: var(--ink); line-height: 1.25; }
.likert-row .n { font-size: .78rem; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.lk1 { background: var(--lk1); } .lk2 { background: var(--lk2); } .lk3 { background: var(--lk3); }
.lk4 { background: var(--lk4); } .lk5 { background: var(--lk5); }
.nps-det { background: var(--lk1); } .nps-pas { background: var(--lk3); } .nps-pro { background: var(--lk5); }

details.table-view { margin-top: 12px; font-size: .85rem; }
details.table-view summary { cursor: pointer; color: var(--teal-strong); font-weight: 600; }
details.table-view table { margin-top: 8px; }

/* ---------- Comentarios ---------- */
.comment { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; background: var(--surface); }
.comment + .comment { margin-top: 12px; }
.comment.is-reviewed { background: #fbfdfc; }
.comment-meta { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; font-size: .8rem; color: var(--muted); margin-bottom: 10px; }
.comment-meta .scores { display: inline-flex; gap: 6px; }
.comment-q { font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; margin: 10px 0 3px; }
.comment-text { color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.comment-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.tag-form { display: inline-flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tag-form select { min-height: 30px; padding: 3px 8px; font-size: .82rem; }
.sugerida { border-style: dashed; cursor: pointer; background: #fff; }
.sugerida:hover { background: var(--teal-tint); }
.tag button { background: none; border: 0; padding: 0 0 0 2px; color: inherit; cursor: pointer; font-size: .95rem; line-height: 1; opacity: .6; }
.tag button:hover { opacity: 1; }

/* ---------- Recogida ---------- */
.link-box { display: flex; gap: 8px; align-items: center; }
.link-box input { flex: 1; font-family: ui-monospace, Consolas, monospace; font-size: .84rem; background: #f8fbfa; }
.qr { width: 180px; height: 180px; background: #fff; padding: 8px; border: 1px solid var(--line); border-radius: 10px; }
.qr svg { width: 100%; height: 100%; display: block; }

/* ---------- Acceso ---------- */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(80% 60% at 100% 0%, rgba(48,187,159,.18), transparent 60%), var(--bg); }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 30px 28px; box-shadow: 0 10px 40px rgba(17,65,56,.10); }
.auth-card h1 { font-size: 1.35rem; margin: 6px 0 14px; }
.auth-logo { display: block; width: 170px; height: auto; margin: 0 auto 10px; }
.auth-card .muted { font-size: .85rem; margin-top: 14px; }

/* ---------- Responsive ---------- */
@media (max-width: 1280px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1200px) {
  .g-2-1, .g-1-2, .g-2 { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 270px; z-index: 50; transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .mobile-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 16px; background: var(--teal-deep); position: sticky; top: 0; z-index: 40; }
  .mobile-bar img { height: 34px; width: auto; }
  .mobile-bar button { background: rgba(255,255,255,.12); color: #fff; border: 0; border-radius: 8px; padding: 8px 12px; font: 600 .9rem var(--font); }
  .main { padding: 18px 16px 40px; }
  .g-2, .g-3 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-value { font-size: 1.5rem; }
  .hbar, .hbar-axis, .likert-row { grid-template-columns: minmax(0, 1fr) 44px; }
  .hbar .name, .likert-row .name { grid-column: 1 / -1; }
  .hbar-axis > span:first-child { display: none; }
  .card { padding: 16px; }
}

/* ---------- Impresión ---------- */
@media print {
  .sidebar, .mobile-bar, .filters, .actions, .no-print { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; }
  .card, .kpi { box-shadow: none; break-inside: avoid; }
  body { background: #fff; }
}
