/*
 * TIC4Grow — hoja de estilos base.
 *
 * Sin build ni framework: CSS plano con variables. Los colores de cada empresa
 * llegan como variables --t4g-* inyectadas por ThemeService en el <body>, así
 * que la temática se aplica sin generar un CSS por cliente.
 */

:root {
  --t4g-primary: #1f6feb;
  --t4g-secondary: #6b7280;
  --t4g-accent: #f59e0b;
  --t4g-background: #f5f7fa;
  --t4g-surface: #ffffff;
  --t4g-text: #1f2937;
  --t4g-muted: #6b7280;

  --t4g-success: #16a34a;
  --t4g-danger: #dc2626;
  --t4g-warning: #d97706;
  --t4g-border: #e5e7eb;

  --t4g-radius: 10px;
  --t4g-gap: 1rem;
  --t4g-shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--t4g-text);
  background: var(--t4g-background);
}

/* El dashboard de madurez digital ignora la temática de la empresa. */
body.neutral-palette {
  --t4g-primary: #1f6feb;
  --t4g-secondary: #6b7280;
  --t4g-accent: #f59e0b;
  --t4g-background: #f5f7fa;
  --t4g-surface: #ffffff;
  --t4g-text: #1f2937;
}

a { color: var(--t4g-primary); }

h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }

/* --- Layout ------------------------------------------------------------- */

.topbar {
  background: var(--t4g-primary);
  color: #fff;
  padding: .6rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.topbar .brand {
  font-weight: 700;
  color: #fff;
  text-decoration: none;
  font-size: 1.05rem;
  white-space: nowrap;
}

.topbar nav {
  display: flex;
  gap: .25rem;
  flex-wrap: wrap;
  flex: 1;
}

.topbar nav a {
  color: #fff;
  text-decoration: none;
  padding: .35rem .6rem;
  border-radius: var(--t4g-radius);
  opacity: .85;
  white-space: nowrap;
}

.topbar nav a:hover { opacity: 1; background: rgba(255, 255, 255, .14); }
.topbar nav a.is-active { opacity: 1; background: rgba(255, 255, 255, .22); }

.topbar .session { display: flex; align-items: center; gap: .5rem; font-size: .85rem; }

.container { max-width: 1180px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.page-head .subtitle { color: var(--t4g-muted); margin: 0; }

/* --- Rejillas y tarjetas ------------------------------------------------ */

.grid { display: grid; gap: var(--t4g-gap); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.card {
  background: var(--t4g-surface);
  border: 1px solid var(--t4g-border);
  border-radius: var(--t4g-radius);
  padding: 1rem;
  box-shadow: var(--t4g-shadow);
}

.card h2, .card h3 { margin-top: 0; }
.card + .card { margin-top: var(--t4g-gap); }

.stat { display: flex; flex-direction: column; gap: .15rem; }
.stat .value { font-size: 1.8rem; font-weight: 700; line-height: 1; }
.stat .label { color: var(--t4g-muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; }
.stat .hint { color: var(--t4g-muted); font-size: .8rem; }

/* --- Tablas ------------------------------------------------------------- */

.table-wrap { overflow-x: auto; }

table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th, table.data td { padding: .55rem .6rem; text-align: left; border-bottom: 1px solid var(--t4g-border); }
table.data th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--t4g-muted); white-space: nowrap; }
table.data tbody tr:hover { background: rgba(0, 0, 0, .02); }
table.data td.numeric, table.data th.numeric { text-align: right; }

/* --- Formularios -------------------------------------------------------- */

.field { margin-bottom: .9rem; }
.field label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: .25rem; }
.field .help { color: var(--t4g-muted); font-size: .82rem; margin-top: .2rem; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="url"], input[type="color"], select, textarea {
  width: 100%;
  padding: .5rem .6rem;
  border: 1px solid var(--t4g-border);
  border-radius: var(--t4g-radius);
  background: var(--t4g-surface);
  color: var(--t4g-text);
  font: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--t4g-primary) 45%, transparent);
  outline-offset: 1px;
  border-color: var(--t4g-primary);
}

textarea { min-height: 90px; resize: vertical; }
select[multiple] { min-height: 130px; }

.checkline { display: flex; align-items: center; gap: .45rem; margin-bottom: .35rem; }
.checkline input { width: auto; }

fieldset { border: 1px solid var(--t4g-border); border-radius: var(--t4g-radius); padding: .8rem; margin: 0 0 1rem; }
legend { font-weight: 600; font-size: .9rem; padding: 0 .35rem; }

/* --- Botones ------------------------------------------------------------ */

.btn {
  display: inline-block;
  padding: .5rem .9rem;
  border: 1px solid transparent;
  border-radius: var(--t4g-radius);
  background: var(--t4g-primary);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}

.btn:hover { filter: brightness(.94); }
.btn.secondary { background: var(--t4g-surface); color: var(--t4g-text); border-color: var(--t4g-border); }
.btn.accent { background: var(--t4g-accent); color: #1f2937; }
.btn.success { background: var(--t4g-success); }
.btn.danger { background: var(--t4g-danger); }
.btn.small { padding: .3rem .55rem; font-size: .82rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* --- Avisos y etiquetas ------------------------------------------------- */

.alert { padding: .7rem .9rem; border-radius: var(--t4g-radius); margin-bottom: 1rem; border: 1px solid; }
.alert.success { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.alert.error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert.info { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.alert ul { margin: .3rem 0 0; padding-left: 1.1rem; }

.badge {
  display: inline-block;
  padding: .12rem .45rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
  background: var(--t4g-border);
  color: var(--t4g-text);
  white-space: nowrap;
}

.badge.success { background: #d1fae5; color: #065f46; }
.badge.danger { background: #fee2e2; color: #991b1b; }
.badge.warning { background: #fef3c7; color: #92400e; }
.badge.info { background: #dbeafe; color: #1e40af; }
.badge.muted { background: #f3f4f6; color: #4b5563; }

.trend-up { color: var(--t4g-success); font-weight: 600; }
.trend-down { color: var(--t4g-danger); font-weight: 600; }
.trend-flat { color: var(--t4g-muted); }

/* --- Barras de progreso ------------------------------------------------- */

.progress { background: var(--t4g-border); border-radius: 999px; height: 8px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--t4g-primary); border-radius: 999px; }
.progress.accent > span { background: var(--t4g-accent); }
.progress.danger > span { background: var(--t4g-danger); }

/* --- Listas de elementos del juego -------------------------------------- */

.item-list { list-style: none; margin: 0; padding: 0; }

.item {
  border: 1px solid var(--t4g-border);
  border-radius: var(--t4g-radius);
  padding: .75rem;
  margin-bottom: .6rem;
  background: var(--t4g-surface);
}

.item .item-head { display: flex; justify-content: space-between; gap: .75rem; align-items: baseline; flex-wrap: wrap; }
.item .item-title { font-weight: 600; }
.item .item-meta { color: var(--t4g-muted); font-size: .84rem; display: flex; gap: .6rem; flex-wrap: wrap; }
.item .points { font-weight: 700; color: var(--t4g-accent); white-space: nowrap; }

.evidence-form { margin-top: .6rem; border-top: 1px dashed var(--t4g-border); padding-top: .6rem; }
.evidence-form[hidden] { display: none; }

/* --- Gráficos ----------------------------------------------------------- */

.chart-box { position: relative; width: 100%; }
.chart-box canvas { width: 100%; height: auto; display: block; }

.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .85rem; margin-top: .5rem; }
.legend span { display: flex; align-items: center; gap: .35rem; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* --- Mensajería --------------------------------------------------------- */

.thread { display: flex; flex-direction: column; gap: .6rem; }
.message { border: 1px solid var(--t4g-border); border-radius: var(--t4g-radius); padding: .7rem; background: var(--t4g-surface); }
.message.own { border-left: 3px solid var(--t4g-primary); }
.message .meta { color: var(--t4g-muted); font-size: .8rem; margin-bottom: .3rem; }
.message .body { white-space: pre-wrap; }

/* --- Utilidades --------------------------------------------------------- */

.muted { color: var(--t4g-muted); }
.small { font-size: .85rem; }
.mt { margin-top: 1rem; }
.mb { margin-bottom: 1rem; }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }
.empty-state { color: var(--t4g-muted); padding: 1.25rem; text-align: center; }

.pagination { display: flex; gap: .3rem; flex-wrap: wrap; margin-top: 1rem; list-style: none; padding: 0; }
.pagination li { border: 1px solid var(--t4g-border); border-radius: var(--t4g-radius); background: var(--t4g-surface); }
.pagination li span, .pagination li a { display: block; padding: .3rem .6rem; text-decoration: none; }
.pagination li.active { background: var(--t4g-primary); border-color: var(--t4g-primary); }
.pagination li.active span { color: #fff; }

/* --- Responsive --------------------------------------------------------- */

@media (max-width: 900px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: stretch; }
  .topbar nav { overflow-x: auto; }
  .container { padding: 1rem .75rem 2.5rem; }
}

/* --- Impresión ---------------------------------------------------------- */

@media print {
  .topbar, .no-print { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
}
