/* ==========================================================================
   Activos Pergamino - estilos
   ========================================================================== */
:root {
  --primary: #3B2A20;
  --primary-2: #5C4033;
  --accent: #C8743B;
  --accent-soft: #F6E7DA;
  --bg: #F5F1EB;
  --surface: #FFFFFF;
  --surface-2: #FBF8F4;
  --line: #E7DED3;
  --text: #2A211C;
  --muted: #7B6F66;
  --ok: #2E7D4F;   --ok-soft: #E3F2E8;
  --warn: #A86A12; --warn-soft: #FBF0DC;
  --bad: #B83A2E;  --bad-soft: #FBE5E2;
  --info: #2F6690; --info-soft: #E3EEF7;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(59,42,32,.06), 0 4px 16px rgba(59,42,32,.06);
  --sidebar: 232px;
  --topbar: 58px;
  --bottombar: 64px;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
body .dx-widget { font-family: inherit; }
a { color: var(--primary-2); }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }

.boot { height: 100vh; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--muted); }
.boot-logo, .brand-logo {
  width: 44px; height: 44px; border-radius: 12px; background: var(--primary); color: #E9C9A6;
  display: grid; place-items: center; font-weight: 800; font-size: 20px;
}

/* ---------- Shell ---------- */
.shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar) 1fr; grid-template-rows: var(--topbar) 1fr; }
.topbar {
  grid-column: 1 / -1; position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px; padding: 0 18px;
  background: var(--primary); color: #F5EBDD;
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 16px; white-space: nowrap; }
.topbar .brand-logo { width: 34px; height: 34px; font-size: 15px; background: #2A1D16; }
.topbar .brand small { display: block; font-weight: 400; font-size: 11px; opacity: .7; }
.topbar .spacer { flex: 1; }
.topbar .view-title { font-size: 15px; opacity: .9; display: none; }
.pill-offline { background: var(--warn); color: #fff; border-radius: 99px; padding: 3px 10px; font-size: 12px; cursor: pointer; }
.user-chip { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 5px 8px; border-radius: 10px; }
.user-chip:hover { background: rgba(255,255,255,.08); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.user-chip .u-name { font-size: 13px; line-height: 1.1; }
.user-chip .u-role { font-size: 11px; opacity: .7; }

.sidebar { background: var(--surface); border-right: 1px solid var(--line); padding: 14px 10px; position: sticky; top: var(--topbar); height: calc(100vh - var(--topbar)); overflow-y: auto; }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 10px 6px; }
.nav-item { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 10px; color: var(--text); text-decoration: none; font-weight: 500; }
.nav-item svg { width: 20px; height: 20px; flex: none; stroke: currentColor; }
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--accent-soft); color: var(--primary); }
.nav-item .count { margin-left: auto; background: var(--accent); color: #fff; border-radius: 99px; font-size: 11px; padding: 1px 7px; }

.main { padding: 22px 26px 40px; min-width: 0; }
.bottombar { display: none; }

/* ---------- Page ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { font-size: 22px; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px 18px; }
.card h3 { font-size: 15px; margin-bottom: 12px; }
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.grid-2 > * { min-width: 0; }
.stack { display: grid; gap: 16px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hide { display: none !important; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .k-label { color: var(--muted); font-size: 12px; font-weight: 500; }
.kpi .k-value { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .k-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.ok .k-value { color: var(--ok); } .kpi.bad .k-value { color: var(--bad); }
.kpi.warn .k-value { color: var(--warn); } .kpi.accent .k-value { color: var(--accent); }
.kpi.clickable { cursor: pointer; } .kpi.clickable:hover { border-color: var(--accent); }

/* ---------- Progreso ---------- */
.progress { height: 8px; background: #EFE7DD; border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--ok); border-radius: 99px; transition: width .3s; }
.progress.dual { display: flex; }
.progress.dual > span { border-radius: 0; }
.progress.dual > .p-bad { background: var(--bad); }
.progress-cell { display: flex; align-items: center; gap: 8px; }
.progress-cell .progress { flex: 1; min-width: 60px; }
.progress-cell b { font-variant-numeric: tabular-nums; min-width: 42px; text-align: right; font-weight: 600; }

.my-progress { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; align-items: center; }
.my-progress .big { font-size: 28px; font-weight: 700; }
.my-progress .legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; line-height: 18px; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.muted { background: #EFE9E2; color: var(--muted); }
.badge.accent { background: var(--accent-soft); color: var(--primary-2); }
.tag { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-weight: 700; background: var(--primary); color: #F5EBDD; padding: 3px 9px; border-radius: 8px; font-size: 13px; }

/* ---------- Toolbar filtros ---------- */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters .f-search { flex: 1 1 240px; max-width: 360px; }
.filters .f-select { width: 220px; }
.chips { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
.chips::-webkit-scrollbar { display: none; }
.chips .dx-buttongroup { width: max-content !important; }
.chips .dx-buttongroup-wrapper { flex-wrap: nowrap; }
.chips .dx-buttongroup-item { flex: none; }

/* ---------- Tarjetas de activo ---------- */
.asset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px; }
.asset { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; }
.asset.st-ok { border-left: 4px solid var(--ok); }
.asset.st-bad { border-left: 4px solid var(--bad); }
.asset.st-pend { border-left: 4px solid #D9CFC3; }
.asset-head { padding: 14px 16px 10px; display: grid; gap: 6px; }
.asset-head .top { display: flex; align-items: center; gap: 8px; }
.asset-head .top .cat { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.asset-head .top .badge { margin-left: auto; }
.asset-head .desc { font-weight: 650; font-size: 15px; line-height: 1.3; }
.asset-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: 12px; }
.asset-meta b { color: var(--text); font-weight: 600; }
.asset-body { padding: 10px 16px 14px; border-top: 1px dashed var(--line); display: grid; gap: 10px; background: var(--surface-2); flex: 1; }
.field-label { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.asset-checks { display: flex; gap: 18px; flex-wrap: wrap; }
.asset-foot { display: flex; align-items: center; gap: 8px; }
.asset-foot .spacer { flex: 1; }
.thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; border: 1px solid var(--line); cursor: pointer; background: #eee; }
.saving { font-size: 11px; color: var(--muted); }
.more-wrap { display: flex; justify-content: center; padding: 18px; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty .e-icon { font-size: 36px; margin-bottom: 6px; }

/* ButtonGroup segmentado a todo el ancho en tarjetas */
.seg .dx-buttongroup-wrapper { width: 100%; }
.seg .dx-buttongroup-item { flex: 1; }
.seg .dx-button.dx-item-selected { color: #fff !important; }
.seg .dx-button.dx-item-selected .dx-icon { color: #fff !important; }
.seg-ten .dx-buttongroup-item:nth-child(1).dx-item-selected,
.seg-est .dx-buttongroup-item:nth-child(1).dx-item-selected { background: var(--ok) !important; border-color: var(--ok) !important; }
.seg-ten .dx-buttongroup-item:nth-child(2).dx-item-selected,
.seg-est .dx-buttongroup-item:nth-child(3).dx-item-selected { background: var(--bad) !important; border-color: var(--bad) !important; }
.seg-est .dx-buttongroup-item:nth-child(2).dx-item-selected { background: var(--warn) !important; border-color: var(--warn) !important; }

/* ---------- Escáner ---------- */
.scan-hero { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: end; }
.scan-input { display: flex; gap: 8px; }
.scan-input > :first-child { flex: 1; }
.scan-result { margin-top: 14px; }
.scan-result .alert { padding: 10px 14px; border-radius: 10px; font-weight: 600; margin-bottom: 10px; }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.bad { background: var(--bad-soft); color: var(--bad); }
.alert.info { background: var(--info-soft); color: var(--info); }
.video-wrap { position: relative; background: #000; border-radius: 12px; overflow: hidden; aspect-ratio: 3/4; max-height: 70vh; }
.video-wrap video { width: 100%; height: 100%; object-fit: cover; }
.video-wrap .frame { position: absolute; inset: 22% 10%; border: 3px solid rgba(255,255,255,.85); border-radius: 14px; box-shadow: 0 0 0 999px rgba(0,0,0,.35); }
.chip-stats { display: flex; gap: 8px; flex-wrap: wrap; }
.chip-stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; min-width: 96px; }
.chip-stat b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.chip-stat span { font-size: 12px; color: var(--muted); }

/* ---------- Detalle ---------- */
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; word-break: break-word; }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.timeline li { display: grid; grid-template-columns: 10px 1fr; gap: 10px; font-size: 13px; }
.timeline li::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-top: 5px; }
.timeline .when { color: var(--muted); font-size: 12px; }
.foto-full { max-width: 100%; max-height: 70vh; display: block; margin: 0 auto; border-radius: 10px; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-art { background: var(--primary); color: #F5EBDD; padding: 48px; display: flex; flex-direction: column; justify-content: space-between;
  background-image: radial-gradient(circle at 20% 110%, rgba(200,116,59,.45), transparent 55%), radial-gradient(circle at 110% -10%, rgba(233,201,166,.18), transparent 50%); }
.login-art h1 { font-size: 38px; line-height: 1.1; max-width: 460px; }
.login-art p { opacity: .8; max-width: 420px; font-size: 15px; line-height: 1.5; }
.login-art ul { padding-left: 18px; opacity: .85; line-height: 1.9; }
.login-form { display: grid; place-items: center; padding: 32px 20px; }
.login-box { width: 100%; max-width: 360px; display: grid; gap: 14px; }
.login-box h2 { font-size: 24px; }
.login-err { color: var(--bad); min-height: 18px; font-size: 13px; }

/* ---------- DevExtreme ajustes de marca ---------- */
.dx-button-mode-contained.dx-button-default { background-color: var(--primary); }
.dx-button-mode-contained.dx-button-default.dx-state-hover { background-color: var(--primary-2); }
.dx-button-mode-contained.dx-button-success { background-color: var(--ok); }
.dx-button-mode-contained.dx-button-danger { background-color: var(--bad); }
.dx-checkbox-checked .dx-checkbox-icon { background-color: var(--primary); border-color: var(--primary); }
.dx-texteditor.dx-editor-outlined.dx-state-focused, .dx-texteditor.dx-editor-outlined.dx-state-active { border-color: var(--accent); }
.dx-tabs .dx-tab.dx-tab-selected::after { border-color: var(--accent); }
.dx-datagrid-headers { font-weight: 600; color: var(--muted); }
.dx-datagrid .dx-row > td { vertical-align: middle; }
.dx-datagrid-rowsview .dx-row-focused.dx-data-row > td { background: var(--accent-soft); color: var(--text); }
.dx-popup-title.dx-toolbar { border-bottom-color: var(--line); }
.grid-card { padding: 6px 10px 10px; }
.cell-desc { font-weight: 500; }
.cell-sub { color: var(--muted); font-size: 12px; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1100px) {
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: var(--topbar) 1fr; }
  .sidebar { display: none; }
  .topbar { padding: 0 12px; }
  .topbar .brand small, .user-chip .u-text { display: none; }
  .main { padding: 14px 12px calc(var(--bottombar) + 24px + env(safe-area-inset-bottom)); }
  .bottombar {
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    height: calc(var(--bottombar) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(59,42,32,.06);
  }
  .bottombar a { display: grid; justify-items: center; align-content: center; gap: 3px; font-size: 11px; color: var(--muted); text-decoration: none; font-weight: 600; }
  .bottombar a svg { width: 22px; height: 22px; stroke: currentColor; }
  .bottombar a.active { color: var(--primary); }
  .bottombar a.active svg { stroke: var(--accent); }
  .page-head h1 { font-size: 19px; }
  .asset-grid { grid-template-columns: 1fr; }
  .filters .f-search, .filters .f-select, .filters .chips { flex: 1 1 100%; max-width: none; width: 100%; }
  .my-progress { grid-template-columns: 1fr; }
  .my-progress .big { font-size: 24px; }
  .page-actions { width: 100%; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpi .k-value { font-size: 22px; }
  .kv { grid-template-columns: 110px 1fr; }
  .login { grid-template-columns: 1fr; }
  .login-art { padding: 28px 22px; min-height: auto; }
  .login-art h1 { font-size: 26px; }
  .login-art ul, .login-art .foot { display: none; }
  .scan-hero { grid-template-columns: 1fr; }
}
