:root {
  --ground: #F5F3F0;
  --surface: #FFFFFF;
  --ink: #1A1A1A;
  --neutral: #E8E4DF;
  --accent: #C1440E;
  --text-secondary: rgba(26, 26, 26, .6);
  --text-muted: rgba(26, 26, 26, .4);
  --ok-fg: #2E7D46;
  --ok-bg: #E7F2EA;
  --danger-fg: #B3261E;
  --danger-bg: #F9E7E5;
  --off-fg: #6B6862;
  --off-bg: #EFEDE9;
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --font-display: "Playfair Display", Georgia, serif;
  --shadow-card: 0 1px 3px rgba(26, 26, 26, .06);
  --radius-card: 20px;
  --radius-btn: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.5 var(--font-ui);
  background: var(--ground);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.content a:not(.btn):not(.chip):not(.nav-item):not(.breadcrumb) { color: var(--accent); text-decoration: none; }
.content a:not(.btn):not(.chip):not(.nav-item):not(.breadcrumb):hover { text-decoration: underline; }
.muted { color: var(--text-secondary); }
.mm { color: var(--text-muted); }
.error { color: var(--danger-fg); font-size: 13px; margin: 8px 0; }
code, .mono { font-family: var(--font-mono); font-size: 13px; }

/* ---------- login ---------- */

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--ground); }
.login-card {
  width: 340px; display: flex; flex-direction: column; gap: 10px;
  background: var(--surface); border-radius: var(--radius-card); box-shadow: var(--shadow-card);
  padding: 28px 26px; border: none;
}
.login-card h1 { margin: 0; font-size: 26px; font-family: var(--font-display); font-weight: 400; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-secondary); }

/* ---------- forms ---------- */

input, select, textarea {
  padding: 9px 12px;
  border: 1px solid var(--neutral);
  border-radius: 10px;
  background: var(--neutral);
  color: var(--ink);
  font: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(193, 68, 14, .15);
  background: var(--surface);
}
textarea { font-family: var(--font-mono); font-size: 13px; width: 100%; }

/* ---------- buttons ---------- */

.btn {
  padding: 9px 16px;
  border: 1px solid var(--neutral);
  border-radius: var(--radius-btn);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-weight: 500;
  transition: filter .12s ease, border-color .12s ease;
}
.btn:hover { filter: brightness(0.97); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.secondary { background: var(--surface); border-color: var(--neutral); color: var(--ink); }
.btn.danger { color: var(--danger-fg); background: var(--danger-bg); border-color: transparent; }
.btn.link { background: none; border: none; color: var(--accent); font-size: 13px; padding: 4px 0; text-decoration: underline; }
.btn.small { padding: 4px 11px; font-size: 13px; border-radius: 9px; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- app shell ---------- */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px; flex: none;
  background: var(--ground);
  border-right: 1px solid var(--neutral);
  display: flex; flex-direction: column;
  padding: 18px 12px;
  position: sticky; top: 0; height: 100vh;
}
.sidebar-logo {
  font-weight: 600; font-size: 18px; padding: 6px 10px 18px;
  display: flex; align-items: center; gap: 8px; color: var(--ink);
}
.sidebar-logo span { color: var(--ink); }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar-bottom { display: flex; flex-direction: column; gap: 10px; margin-top: auto; padding-top: 10px; border-top: 1px solid var(--neutral); }

.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: 12px;
  color: var(--text-secondary); text-decoration: none;
  font-size: 14px; font-weight: 500;
  border-left: 3px solid transparent;
}
.nav-item svg { width: 18px; height: 18px; flex: none; }
.nav-item:hover { background: rgba(26, 26, 26, .04); color: var(--ink); }
.nav-item.active {
  background: var(--surface); color: var(--accent);
  box-shadow: var(--shadow-card);
  border-left-color: var(--accent);
}

.sidebar-user { display: flex; flex-direction: column; gap: 8px; padding: 4px 10px 0; }
.sidebar-user .muted { font-size: 12.5px; word-break: break-all; }

.content { flex: 1; min-width: 0; padding: 28px 34px 60px; max-width: 1180px; }

/* ---------- cards ---------- */

.card {
  background: var(--surface);
  border: none;
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 22px 24px;
  margin: 0 0 18px;
}
.card h2 { margin: 0 0 14px; font-size: 15px; font-weight: 600; }
.card h3 { margin: 18px 0 10px; font-size: 13.5px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .03em; }

.card-dark {
  background: var(--ink); color: #F5F3F0;
  border-radius: var(--radius-card); box-shadow: var(--shadow-card);
  padding: 24px 26px; margin: 0 0 18px;
}
.card-dark .muted { color: rgba(245, 243, 240, .6); }
.card-dark .stat-big { font-size: 34px; font-weight: 600; line-height: 1.1; }
.card-dark .stat-label { font-size: 12.5px; color: rgba(245, 243, 240, .55); margin-top: 4px; }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.g-8-4 { grid-template-columns: 2fr 1fr; }
@media (max-width: 900px) { .grid-2, .grid-3, .grid-4, .g-8-4 { grid-template-columns: 1fr; } }

/* ---------- page header / breadcrumb ---------- */

.page-header { margin-bottom: 20px; }
.breadcrumb {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--text-secondary); font-size: 13.5px; text-decoration: none;
  margin-bottom: 10px;
}
.breadcrumb:hover { color: var(--accent); }
.page-title { font-size: 22px; font-weight: 600; margin: 0; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-title .mono { font-size: 15px; font-weight: 400; color: var(--text-secondary); }
.page-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

.greeting { font-family: var(--font-display); font-size: 30px; font-weight: 400; margin: 0 0 2px; }

/* ---------- pills / sub-tabs ---------- */

.pills { display: flex; gap: 6px; margin-bottom: 18px; flex-wrap: wrap; }
.pill {
  padding: 7px 15px; border-radius: 999px; border: 1px solid var(--neutral);
  background: var(--surface); color: var(--text-secondary); cursor: pointer;
  font: inherit; font-size: 13.5px; font-weight: 500;
}
.pill.active { background: var(--ink); color: #fff; border-color: var(--ink); }

/* ---------- badges ---------- */

.badge {
  font-size: 12px; padding: 3px 10px; border-radius: 999px;
  border: none; font-weight: 500; display: inline-block;
}
.badge.ok { color: var(--ok-fg); background: var(--ok-bg); }
.badge.off { color: var(--danger-fg); background: var(--danger-bg); }
.badge.neutral { color: var(--off-fg); background: var(--off-bg); }
.chip {
  font-size: 12.5px; padding: 3px 10px; border-radius: 999px;
  background: var(--neutral); color: var(--ink); display: inline-block;
  text-decoration: none; font-family: var(--font-mono);
}
.chip:hover { background: var(--accent); color: #fff; }

/* ---------- avatar ---------- */

.avatar {
  border-radius: 50%; object-fit: cover; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--neutral); color: var(--text-secondary);
  font-weight: 600; vertical-align: middle;
}
.avatar-xs { width: 22px; height: 22px; font-size: 10px; }
.avatar-sm { width: 28px; height: 28px; font-size: 12px; }
.avatar-lg { width: 56px; height: 56px; font-size: 20px; }

/* ---------- table ---------- */

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--neutral); vertical-align: middle; }
th { color: var(--text-secondary); font-weight: 500; font-size: 12.5px; text-transform: uppercase; letter-spacing: .02em; }
tr:last-child td { border-bottom: none; }
td .sub { font-size: 12px; color: var(--text-muted); }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.mny { color: var(--accent); font-weight: 600; }
.arw { color: var(--accent); font-weight: 700; }
tr.clik { cursor: pointer; }
tr.clik:hover td { background: var(--ground); }
.tnum { font-variant-numeric: tabular-nums; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-secondary); }

body.readonly-admin .superadmin-only { display: none; }

.notice {
  margin-top: 12px; padding: 12px 16px; border-radius: 12px;
  background: var(--ok-bg); color: var(--ok-fg); font-size: 14px; word-break: break-all;
}
.hint { font-size: 12.5px; color: var(--text-muted); margin-top: 6px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #F5F3F0;
  padding: 11px 20px; border-radius: 12px; font-size: 14px; z-index: 20;
  box-shadow: 0 4px 16px rgba(0,0,0,.18);
}

.grant { border-top: 1px solid var(--neutral); padding: 14px 0; }
.grant:first-of-type { border-top: none; padding-top: 0; }
.grant .row { margin-top: 8px; }

.integration { border-top: 1px solid var(--neutral); padding: 14px 0; }
.integration:first-of-type { border-top: none; padding-top: 0; }
.integration .row { margin-top: 8px; }

.color-swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: middle; margin-left: 4px; border: 1px solid var(--neutral); }

.empty-state { color: var(--text-muted); padding: 6px 0; }

/* Texto editable in-situ (p. ej. el nombre en la tabla de usuarios): se ve
   como texto plano hasta que se pasa el mouse. */
.btn-inline {
  background: none; border: 1px dashed transparent; border-radius: 8px;
  padding: 2px 6px; margin: -2px -6px; font: inherit; color: inherit;
  cursor: pointer; text-align: left;
}
.btn-inline:hover { border-color: var(--neutral); background: var(--ground); }

/* Zona de drag & drop para subir archivos a Storage. */
.dropzone {
  margin-top: 14px; padding: 28px 16px; text-align: center;
  border: 2px dashed var(--neutral); border-radius: var(--radius-card);
  background: var(--ground); cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone:hover { border-color: var(--accent); }
.dropzone-over { border-color: var(--accent); background: rgba(193, 68, 14, .08); }
.dropzone p { margin: 0; }

.thumb { width: 42px; height: 42px; border-radius: 8px; object-fit: cover; vertical-align: middle; background: var(--neutral); }

/* Miniaturas de la tabla de archivos de Storage (40x40, ver fileThumb en app.js). */
.thumb-file {
  width: 40px; height: 40px; border-radius: 8px; object-fit: cover;
  vertical-align: middle; background: var(--neutral); display: block;
}
.thumb-ext {
  width: 40px; height: 40px; border-radius: 8px; background: var(--neutral);
  color: var(--text-secondary); display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase;
}

/* ---------- catálogo ---------- */

.catalog-syncing { animation: catalog-pulse 1.3s ease-in-out infinite; }
@keyframes catalog-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }

/* ---------- Métricas ---------- */

.card.metric { padding: 18px 20px; position: relative; overflow: hidden; }
.metric .l { font-size: 12px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .03em; font-weight: 600; }
.metric .n { font-size: 28px; font-weight: 600; letter-spacing: -.01em; line-height: 1.05; margin-top: 8px; }
.metric .n small { font-size: 13px; font-weight: 500; color: var(--text-secondary); }
.metric .f { margin-top: 8px; font-size: 12.5px; color: var(--text-secondary); display: flex; align-items: center; gap: 6px; }
.card-dark .spark { position: absolute; right: 16px; bottom: 14px; width: 110px; height: 32px; opacity: .9; }

.card .ch { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.card .ch h2 { margin: 0; }
.card .meta { font-size: 12.5px; color: var(--text-muted); font-weight: 500; }

svg.chart { display: block; width: 100%; height: auto; }
.area { stroke: none; }
.gridline { stroke: rgba(26, 26, 26, .06); stroke-width: 1; }
.lineser { fill: none; stroke-width: 2; }

.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; vertical-align: middle; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px; font-size: 12.5px; color: var(--text-secondary); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

.donut-wrap { display: flex; align-items: center; gap: 18px; }
.donut { flex: 0 0 120px; }
.donlist { display: flex; flex-direction: column; gap: 9px; font-size: 13px; flex: 1; }
.donlist .r { display: flex; align-items: center; gap: 8px; }
.donlist .r b { margin-left: auto; font-variant-numeric: tabular-nums; }

.gauge { height: 12px; border-radius: 8px; background: var(--neutral); overflow: hidden; display: flex; margin: 10px 0; }
.gauge i { height: 100%; display: block; }

.oprow { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--neutral); }
.oprow:last-child { border-bottom: 0; }
.oprow .on { display: flex; align-items: center; gap: 9px; font-size: 13.5px; }
.oprow .cr { text-align: right; }
.oprow .cr b { font-variant-numeric: tabular-nums; }
.oprow .cr .d { font-size: 11.5px; color: var(--accent); font-weight: 600; }

/* Tab "Preguntar" (agente NL→SQL, hoy un stub honesto) */
.ask-hero { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 6px; }
.ask-badge { width: 42px; height: 42px; border-radius: 12px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 20px; flex: none; }
.sugs { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 6px; }
.sug {
  padding: 8px 13px; border-radius: 999px; border: 1px solid var(--neutral); background: var(--surface);
  cursor: pointer; font: inherit; font-size: 13px; color: var(--ink); transition: border-color .12s, background .12s;
}
.sug:hover { border-color: var(--accent); background: var(--ground); }
.thread { display: flex; flex-direction: column; gap: 14px; margin: 6px 0 16px; min-height: 20px; }
.msg { max-width: 88%; }
.msg.u { align-self: flex-end; background: var(--neutral); border-radius: 16px 16px 4px 16px; padding: 10px 14px; font-size: 14px; }
.msg.a {
  align-self: flex-start; background: var(--surface); border: 1px solid var(--neutral); border-left: 3px solid var(--accent);
  border-radius: 4px 16px 16px 16px; padding: 14px 16px; box-shadow: var(--shadow-card); width: 100%; font-size: 14px;
}
.ask-input { display: flex; gap: 9px; align-items: center; }
.ask-input input { flex: 1; }
