/* Marktparse design system — scoped build (canonical source, edit here).
   Shell (.app/.rail/.topbar/.content) is global; rail uses .rail-item (renamed from .nav-item).
   Collision-prone component classes (btn/card/badge/modal/panel/status/chip/toolbar/grid/switch/tab/form-label)
   are scoped under .mp-ui so Bootstrap keeps working on pages not yet migrated.
   Wrap migrated page content in `.content-inner.mp-ui`. */

/* ============================================================
   Marktparse — Rediseño
   Sistema sobrio, denso, power-user. Acento bermellón (朱).
   ============================================================ */

:root {
  /* Type */
  --font-sans: "Hanken Grotesk", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  /* Accent (bermellón / shu-iro) — same across themes, used sparingly */
  --accent: oklch(0.62 0.18 33);
  --accent-strong: oklch(0.56 0.19 33);
  --accent-soft: oklch(0.62 0.18 33 / 0.12);
  --accent-line: oklch(0.62 0.18 33 / 0.30);
  --accent-contrast: #ffffff;

  /* Semantic (sober, tinted) */
  --ok: oklch(0.58 0.11 155);
  --ok-soft: oklch(0.58 0.11 155 / 0.14);
  --warn: oklch(0.68 0.13 70);
  --warn-soft: oklch(0.68 0.13 70 / 0.16);
  --info: oklch(0.60 0.10 245);
  --info-soft: oklch(0.60 0.10 245 / 0.14);

  --radius: 10px;
  --radius-sm: 7px;
  --radius-lg: 16px;
  --rail-w: 246px;
  --rail-w-collapsed: 64px;
  --topbar-h: 56px;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

/* ---- Light theme ---- */
:root, [data-theme="light"] {
  --bg: oklch(0.984 0.003 70);
  --bg-grad: oklch(0.97 0.006 60);
  --surface: oklch(1 0 0);
  --surface-2: oklch(0.975 0.003 70);
  --surface-hover: oklch(0.965 0.004 60);
  --border: oklch(0.915 0.004 70);
  --border-strong: oklch(0.86 0.005 70);
  --text: oklch(0.24 0.012 60);
  --text-muted: oklch(0.52 0.01 60);
  --text-faint: oklch(0.66 0.008 60);
  --rail-bg: oklch(0.995 0.002 70);
  --rail-text: oklch(0.40 0.01 60);
  --shadow-sm: 0 1px 2px oklch(0.2 0.02 60 / 0.05), 0 1px 1px oklch(0.2 0.02 60 / 0.04);
  --shadow-md: 0 4px 16px oklch(0.2 0.02 60 / 0.07), 0 1px 3px oklch(0.2 0.02 60 / 0.05);
  --shadow-lg: 0 16px 40px oklch(0.2 0.02 60 / 0.12);
  --scrim: oklch(0.2 0.012 60 / 0.42);
  --seigaiha: oklch(0.62 0.18 33 / 0.045);
}

/* ---- Dark theme ---- */
[data-theme="dark"] {
  --bg: oklch(0.165 0.006 265);
  --bg-grad: oklch(0.185 0.008 265);
  --surface: oklch(0.205 0.007 265);
  --surface-2: oklch(0.232 0.008 265);
  --surface-hover: oklch(0.255 0.009 265);
  --border: oklch(0.30 0.009 265);
  --border-strong: oklch(0.38 0.01 265);
  --text: oklch(0.95 0.004 265);
  --text-muted: oklch(0.70 0.01 265);
  --text-faint: oklch(0.56 0.01 265);
  --rail-bg: oklch(0.185 0.007 265);
  --rail-text: oklch(0.72 0.01 265);
  --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.4);
  --shadow-md: 0 6px 20px oklch(0 0 0 / 0.45);
  --shadow-lg: 0 20px 50px oklch(0 0 0 / 0.6);
  --scrim: oklch(0 0 0 / 0.55);
  --accent: oklch(0.68 0.17 35);
  --accent-strong: oklch(0.72 0.17 35);
  --accent-soft: oklch(0.68 0.17 35 / 0.16);
  --accent-line: oklch(0.68 0.17 35 / 0.34);
  --seigaiha: oklch(0.68 0.17 35 / 0.07);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-size: 14px;
  letter-spacing: -0.006em;
}
#root { height: 100vh; }
button { font-family: inherit; cursor: pointer; }
::selection { background: var(--accent-soft); }

/* Scrollbars */
*::-webkit-scrollbar { width: 11px; height: 11px; }
*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 99px;
  border: 3px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--text-faint); background-clip: padding-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* ============================================================
   App shell
   ============================================================ */
.app {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: visible;
  transition: grid-template-columns .28s var(--ease);
}
.app.collapsed { grid-template-columns: var(--rail-w-collapsed) 1fr; }

/* ---- Sidebar ---- */
.rail {
  background: var(--rail-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  align-self: start;
  z-index: 20;
}
.rail-head {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.logo {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: var(--accent);
  display: grid; place-items: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px var(--accent-soft);
}
.logo svg { width: 18px; height: 18px; color: #fff; }
.brand {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
}
.brand small { display: block; font-size: 10.5px; font-weight: 500; color: var(--text-faint); letter-spacing: 0.04em; text-transform: uppercase; margin-top: -1px; }

.rail-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 12px 10px 16px; }
.nav-group { margin-bottom: 14px; }
.nav-group-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 6px 10px;
  white-space: nowrap;
  overflow: hidden;
}
.rail-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--rail-text);
  font-size: 13.5px;
  font-weight: 500;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  white-space: nowrap;
  position: relative;
  transition: background .14s, color .14s;
}
.rail-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.rail-item .chev { margin-left: auto; width: 14px; height: 14px; opacity: .5; transition: transform .2s; }
.rail-item.open .chev { transform: rotate(180deg); }
.rail-item:hover { background: var(--surface-hover); color: var(--text); }
.rail-item.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 600;
}
.rail-item.active::before {
  content: "";
  position: absolute;
  left: -10px; top: 8px; bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.nav-label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.nav-badge {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 1px 6px;
  border-radius: 99px;
}
.rail-item.danger:hover { background: oklch(0.62 0.18 33 / 0.08); color: var(--accent-strong); }

.nav-sub { overflow: hidden; }
.nav-sub-item {
  display: block;
  padding: 6px 10px 6px 38px;
  font-size: 12.5px;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  border: none; background: none; width: 100%; text-align: left;
  white-space: nowrap;
}
.nav-sub-item:hover { background: var(--surface-hover); color: var(--text); }
.nav-sub-item.active { color: var(--accent-strong); font-weight: 600; background: var(--accent-soft); }

.rail-fly { position: relative; }

/* Rail plegado (solo escritorio): los submenús se muestran como flyout al
   posar el ratón / foco sobre el icono del grupo. Sin esto, un grupo colapsado
   deja sus subítems inaccesibles. En móvil el rail se expande como drawer, así
   que esta regla se limita a >760px para no descolocar el flyout ahí. */
@media (min-width: 761px) {
  /* Con el rail plegado el contenido es solo iconos (corto), así que se permite
     desbordar para que el flyout no lo recorte overflow-x:hidden de .rail-scroll. */
  .collapsed .rail-scroll { overflow: visible; }
  .collapsed .rail-fly .nav-sub {
    /* !important + mayor especificidad para ganar al [hidden]{display:none!important}
       que inyecta Bootstrap; si no, el flyout nunca se muestra. */
    display: block !important;
    position: absolute;
    left: calc(100% + 8px);
    top: 0;
    min-width: 184px;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    z-index: 40;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .12s var(--ease), visibility .12s var(--ease);
  }
  .collapsed .rail-fly:hover .nav-sub,
  .collapsed .rail-fly:focus-within .nav-sub {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }
  .collapsed .rail-fly .nav-sub-item { padding-left: 12px; padding-right: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .collapsed .rail-fly .nav-sub { transition: none; }
}

/* ============================================================
   Shared page primitives (forms, panels, alerts, .mp-ui charts)
   ============================================================ */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.mp-ui .panel-head {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px; border-bottom: 1px solid var(--border);
}
.mp-ui .panel-head h3 { margin: 0; font-size: 14px; font-weight: 700; letter-spacing: -0.01em; }
.mp-ui .panel-head .panel-ico { width: 28px; height: 28px; border-radius: 7px; background: var(--surface-2); border: 1px solid var(--border); display: grid; place-items: center; color: var(--text-muted); }
.mp-ui .panel-head .panel-ico svg { width: 15px; height: 15px; }
.mp-ui .panel-body { padding: 16px; }
.mp-ui .panel-head .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
/* Evita que canvas/tablas (min-width intrínseco) estiren las columnas */
.grid-2 > *, .grid-3 > * { min-width: 0; }
.mp-ui .chart-box canvas { max-width: 100%; }
.grid-cards { display: grid; gap: 16px; }
@media (max-width: 980px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* Form controls */
.form-row { display: flex; flex-direction: column; gap: 6px; }
.mp-ui .form-label { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.input, .select-input {
  height: 36px; padding: 0 11px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-family: inherit; font-size: 13px; width: 100%; outline: none;
  transition: border-color .14s, background .14s;
}
.input:focus, .select-input:focus { border-color: var(--accent-line); background: var(--surface); }
.input::placeholder { color: var(--text-faint); }
textarea.input { height: auto; padding: 9px 11px; resize: vertical; }

/* Alert / banner */
.banner {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px; border-radius: var(--radius); font-size: 13px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-muted);
}
.banner svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }
.banner.info { background: var(--info-soft); border-color: transparent; color: var(--info); }
.banner.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.banner.accent { background: var(--accent-soft); border-color: transparent; color: var(--accent-strong); }

/* Health badge */
.health { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 99px; }
.health .sd { width: 6px; height: 6px; border-radius: 99px; }
.health.ok { background: var(--ok-soft); color: var(--ok); }
.health.ok .sd { background: var(--ok); }
.health.warn { background: var(--warn-soft); color: var(--warn); }
.health.warn .sd { background: var(--warn); }
.health.error { background: var(--accent-soft); color: var(--accent-strong); }
.health.error .sd { background: var(--accent); }

.chart-box { position: relative; height: 260px; }
.chart-box.sm { height: 200px; }

/* Avatar in tables */
.av-sm { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), var(--accent-strong)); color: #fff; display: grid; place-items: center; font-size: 11px; font-weight: 700; flex-shrink: 0; }

/* Editable cell */
td[contenteditable] { outline: none; border-radius: 5px; transition: box-shadow .12s; }
td[contenteditable]:focus { box-shadow: inset 0 0 0 2px var(--accent-line); background: var(--surface); }

/* Icon-only action buttons in table */
.icon-act { width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text-muted); display: inline-grid; place-items: center; transition: all .12s; }
.icon-act svg { width: 14px; height: 14px; }
.icon-act:hover { background: var(--surface-hover); color: var(--text); }
.icon-act.danger:hover { background: var(--accent-soft); color: var(--accent-strong); border-color: var(--accent-line); }

/* Checkbox */
.cbx { width: 18px; height: 18px; border-radius: 5px; border: 1.5px solid var(--border-strong); background: var(--surface); display: inline-grid; place-items: center; cursor: pointer; transition: all .12s; }
.cbx svg { width: 12px; height: 12px; color: #fff; opacity: 0; }
.cbx.on { background: var(--accent); border-color: var(--accent); }
.cbx.on svg { opacity: 1; }

/* Map placeholder */
.map-ph {
  height: 360px; border-radius: var(--radius); border: 1px solid var(--border);
  background:
    linear-gradient(oklch(0.6 0.05 230 / 0.04), oklch(0.6 0.05 230 / 0.04)),
    repeating-linear-gradient(0deg, transparent, transparent 39px, var(--border) 39px, var(--border) 40px),
    repeating-linear-gradient(90deg, transparent, transparent 39px, var(--border) 39px, var(--border) 40px),
    var(--surface-2);
  position: relative; overflow: hidden;
}
.map-pin { position: absolute; transform: translate(-50%, -100%); color: var(--accent); cursor: pointer; transition: transform .15s; }
.map-pin:hover { transform: translate(-50%, -110%) scale(1.15); }
.map-pin svg { width: 26px; height: 26px; filter: drop-shadow(0 2px 4px oklch(0.2 0.02 60 / 0.3)); }
.map-badge { position: absolute; top: 12px; left: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 99px; padding: 5px 12px; font-size: 12px; font-weight: 600; box-shadow: var(--shadow-sm); display: flex; align-items: center; gap: 7px; }

/* Steps (how it works) */
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 760px) { .steps { grid-template-columns: 1fr; } }
.step {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px 18px; text-align: center; position: relative; transition: border-color .15s, transform .15s;
}
.step:hover { border-color: var(--accent-line); transform: translateY(-2px); }
.step-ico { width: 48px; height: 48px; border-radius: 12px; background: var(--accent-soft); color: var(--accent-strong); display: grid; place-items: center; margin: 0 auto 14px; position: relative; }
.step-ico svg { width: 22px; height: 22px; }
.step-num { position: absolute; top: -7px; right: -7px; width: 22px; height: 22px; border-radius: 99px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; font-family: var(--font-mono); }
.step h4 { margin: 0 0 5px; font-size: 14.5px; font-weight: 700; }
.step p { margin: 0; font-size: 12.5px; color: var(--text-muted); }

/* Cart site card */
.cart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; transition: border-color .15s, box-shadow .15s; }
.cart-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); }
.cart-card-head { display: flex; align-items: center; gap: 9px; padding: 12px 14px; border-bottom: 1px solid var(--border); font-weight: 700; font-size: 13.5px; }
.cart-card-items { padding: 10px 14px; display: flex; flex-direction: column; gap: 8px; }
.cart-line { display: flex; align-items: center; gap: 9px; font-size: 12.5px; color: var(--text-muted); }
.cart-line .ci-thumb { width: 34px; height: 34px; border-radius: 7px; background: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 6px, var(--surface-hover) 6px, var(--surface-hover) 12px); flex-shrink: 0; }
.cart-card-foot { display: flex; gap: 8px; padding: 11px 14px; border-top: 1px solid var(--border); }

/* FAQ */
.faq-item { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin-bottom: 10px; overflow: hidden; }
.faq-q { display: flex; align-items: center; gap: 12px; padding: 14px 16px; font-weight: 600; font-size: 14px; cursor: pointer; width: 100%; background: none; border: none; color: var(--text); text-align: left; }
.faq-q .fq-ico { margin-left: auto; transition: transform .2s; color: var(--text-faint); }
.faq-item.open .fq-ico { transform: rotate(45deg); }
.faq-a { padding: 0 16px; max-height: 0; overflow: hidden; transition: max-height .25s var(--ease), padding .25s var(--ease); color: var(--text-muted); font-size: 13.5px; line-height: 1.6; }
.faq-item.open .faq-a { padding: 0 16px 16px; max-height: 200px; }

/* Settings field rows */
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 13px 0; border-bottom: 1px solid var(--border); }
.setting-row:last-child { border-bottom: none; }
.setting-row .sr-label { font-size: 13.5px; font-weight: 500; }
.setting-row .sr-control { width: 260px; flex-shrink: 0; display: flex; justify-content: flex-end; }
@media (max-width: 600px) { .setting-row { flex-direction: column; align-items: stretch; } .setting-row .sr-control { width: 100%; justify-content: stretch; } }

/* Segmented tab pills (settings nav) */
.vtabs { display: flex; flex-direction: column; gap: 3px; }
.vtab { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius-sm); border: none; background: none; color: var(--text-muted); font-size: 13.5px; font-weight: 500; text-align: left; width: 100%; transition: all .12s; }
.vtab svg { width: 16px; height: 16px; }
.vtab:hover { background: var(--surface-hover); color: var(--text); }
.vtab.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }

.collapsed .nav-group-label, .collapsed .nav-label, .collapsed .nav-badge, .collapsed .chev, .collapsed .brand, .collapsed .nav-sub { display: none; }
.collapsed .rail-item { justify-content: center; padding: 9px; }
.collapsed .rail-head { justify-content: center; padding: 0; }

.rail-foot {
  border-top: 1px solid var(--border);
  padding: 10px;
  flex-shrink: 0;
}

/* ---- Topbar ---- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 100vh; min-height: 100dvh; overflow: visible; background: var(--bg); }
.topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in oklch, var(--surface) 78%, transparent);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 15;
}
.icon-btn {
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: none;
  color: var(--text-muted);
  display: grid; place-items: center;
  transition: background .14s, color .14s, border-color .14s;
}
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn:hover { background: var(--surface-hover); color: var(--text); border-color: var(--border); }

.search {
  flex: 1;
  max-width: 440px;
  display: flex;
  align-items: center;
  gap: 9px;
  height: 36px;
  padding: 0 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-faint);
  transition: border-color .15s, background .15s;
}
.search:focus-within { border-color: var(--accent-line); background: var(--surface); }
.search svg { width: 16px; height: 16px; flex-shrink: 0; }
.search input {
  border: none; background: none; outline: none;
  font-family: inherit; font-size: 13px; color: var(--text);
  width: 100%;
}
.search input::placeholder { color: var(--text-faint); }
.kbd {
  font-family: var(--font-mono); font-size: 10.5px;
  border: 1px solid var(--border); border-radius: 5px;
  padding: 1px 5px; color: var(--text-faint);
  background: var(--surface);
}
.topbar-spacer { flex: 1; }
.tb-tab {
  height: 36px; padding: 0 14px;
  border: none; background: none;
  font-size: 13px; font-weight: 500;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; gap: 7px;
}
.tb-tab:hover { background: var(--surface-hover); color: var(--text); }
.tb-tab.active { color: var(--text); background: var(--surface-2); font-weight: 600; }
.dot { width: 6px; height: 6px; border-radius: 99px; background: var(--accent); }

.avatar {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff; display: grid; place-items: center;
  font-size: 12px; font-weight: 700;
}
.account-menu-trigger { border: 0; padding: 0; cursor: pointer; }
.account-menu-trigger:hover, .account-menu-trigger:focus-visible {
  color: #fff; box-shadow: 0 0 0 3px var(--accent-soft); outline: none;
}
.account-menu .dropdown-menu {
  min-width: 190px; padding: 6px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.account-menu-user {
  padding: 7px 10px 5px; color: var(--text-muted);
  font-size: 12px; font-weight: 700; overflow: hidden; text-overflow: ellipsis;
}
.account-menu .dropdown-divider { border-color: var(--border); margin: 4px 0; }
.account-menu .dropdown-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: 13px;
}
.account-menu .dropdown-item:hover,
.account-menu .dropdown-item:focus { background: var(--surface-hover); color: var(--text); }
.account-menu .account-menu-logout:hover,
.account-menu .account-menu-logout:focus { background: var(--accent-soft); color: var(--accent-strong); }

/* ---- Content scroll ---- */
.content { flex: 1; min-height: 0; overflow-y: visible; position: relative; }
.content-inner { padding: 22px 26px 60px; max-width: 1680px; margin: 0 auto; }

/* Page header */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px 20px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head-text { min-width: 0; }
/* Bloque, NO flex: un título largo debe ajustarse a varias líneas dentro de su
   contenedor. Con display:flex el texto era un ítem con min-width:auto y se
   desbordaba en vez de envolver. El count-pill fluye en línea tras el título. */
.page-title { font-size: 22px; font-weight: 700; letter-spacing: -0.025em; margin: 0; line-height: 1.15; text-wrap: balance; overflow-wrap: break-word; }
.page-title .count-pill { vertical-align: middle; margin-left: 3px; }
.page-sub { color: var(--text-muted); font-size: 13px; margin: 4px 0 0; max-width: 68ch; text-wrap: pretty; }
.page-head-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; flex-shrink: 0; }
@media (max-width: 560px) { .page-head-actions { width: 100%; } }
.count-pill {
  font-family: var(--font-mono); font-size: 11px; font-weight: 500;
  color: var(--accent-strong); background: var(--accent-soft);
  padding: 2px 9px; border-radius: 99px; letter-spacing: 0;
}

.mp-ui /* Buttons */
.btn {
  height: 36px; padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 8px;
  transition: background .14s, border-color .14s, transform .06s;
  white-space: nowrap;
}
.mp-ui .btn svg { width: 15px; height: 15px; }
.mp-ui .btn:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.mp-ui .btn:active { transform: translateY(1px); }
.mp-ui .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.mp-ui .btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.mp-ui .btn.ghost { background: none; border-color: transparent; color: var(--text-muted); }
.mp-ui .btn.ghost:hover { background: var(--surface-hover); color: var(--text); }
.mp-ui .btn.sm { height: 30px; padding: 0 11px; font-size: 12.5px; }

/* Seigaiha — subtle texture, only where intentional */
.seigaiha-bg {
  background-image: radial-gradient(circle at 10px 20px, transparent 8.5px, var(--seigaiha) 9px, var(--seigaiha) 10px, transparent 10.5px),
    radial-gradient(circle at 30px 20px, transparent 8.5px, var(--seigaiha) 9px, var(--seigaiha) 10px, transparent 10.5px);
  background-size: 40px 20px;
  background-position: 0 0, 0 0;
}

.mp-ui /* ============================================================
   Cards / grid (Marktparse)
   ============================================================ */
.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  position: sticky; top: 0; z-index: 8;
  box-shadow: var(--shadow-sm);
}
.tb-label { font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-faint); }
.field {
  height: 34px; min-width: 150px;
  display: flex; align-items: center; gap: 8px;
  padding: 0 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text); font-size: 13px;
}
.field svg { width: 14px; height: 14px; color: var(--text-faint); }
.field select, .field input {
  border: none; background: none; outline: none; color: var(--text);
  font-family: inherit; font-size: 13px; width: 100%;
}
.field select { cursor: pointer; appearance: none; }
.field.focus, .field:focus-within { border-color: var(--accent-line); }
.filter-select { position: relative; padding: 0; gap: 0; }
/* El icono guía de la izquierda: era `.bi-building` porque el primer
   desplegable con tema fue el de tiendas, pero ya hay de revista, era y
   palabra clave. Se selecciona por posición, no por icono concreto. */
.filter-select > .bi:first-child { margin-left: 10px; color: var(--text-faint); pointer-events: none; }
.filter-select-native { position: absolute; width: 1px !important; height: 1px; opacity: 0; pointer-events: none; }
.filter-select-control {
  min-width: 0; flex: 1; height: 32px; border: 0; padding: 0 10px 0 8px;
  background: transparent; color: var(--text); font: inherit; text-align: left;
  display: flex; align-items: center; gap: 8px;
}
.filter-select-control span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.filter-select-control .bi { color: var(--text-faint); font-size: 12px; transition: transform .14s; }
.filter-select.open .filter-select-control .bi { transform: rotate(180deg); }
.filter-select-menu {
  position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; min-width: 100%;
  max-height: 260px; overflow-y: auto; padding: 5px; background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
}
.filter-select-option {
  width: 100%; border: 0; border-radius: 6px; padding: 8px 9px; background: transparent;
  color: var(--text); font: inherit; font-size: 13px; text-align: left;
}
.filter-select-option:hover, .filter-select-option:focus-visible { background: var(--surface-hover); outline: none; }
.filter-select-option[aria-selected="true"] { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.divider-v { width: 1px; height: 22px; background: var(--border); }

.segment {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.segment button {
  border: none; background: none; color: var(--text-muted);
  height: 26px; padding: 0 9px; border-radius: 5px;
  display: grid; place-items: center; transition: background .12s, color .12s;
}
.segment button svg { width: 15px; height: 15px; }
.segment button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

.mp-ui /* Toggle switch */
.switch {
  width: 36px; height: 21px; border-radius: 99px;
  background: var(--border-strong); border: none; position: relative;
  transition: background .18s; flex-shrink: 0;
}
.mp-ui .switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 17px; height: 17px; border-radius: 99px; background: #fff;
  transition: transform .18s var(--ease); box-shadow: var(--shadow-sm);
}
.mp-ui .switch.on { background: var(--accent); }
.mp-ui .switch.on::after { transform: translateX(15px); }

.mp-ui .chip {
  height: 30px; padding: 0 12px;
  display: inline-flex; align-items: center; gap: 7px;
  border-radius: 99px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-muted);
  font-size: 12.5px; font-weight: 500; white-space: nowrap;
  transition: all .14s;
}
.mp-ui .chip:hover { border-color: var(--border-strong); color: var(--text); }
.mp-ui .chip.active { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent-strong); font-weight: 600; }
.mp-ui .chip .num { font-family: var(--font-mono); font-size: 11px; opacity: .8; }

.mp-ui /* Product grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(196px, 1fr));
  gap: 14px;
}
.mp-ui .card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex; flex-direction: column;
  transition: border-color .15s, box-shadow .18s, transform .18s;
  position: relative;
  /* La fila de acciones decide si cabe su etiqueta según el ancho de la card,
     no del viewport: el grid es auto-fill y la columna varía. */
  container: card / inline-size;
}
.mp-ui .card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.mp-ui .card.unseen::after {
  content: ""; position: absolute; top: 10px; left: 10px;
  width: 7px; height: 7px; border-radius: 99px; background: var(--accent);
  box-shadow: 0 0 0 3px var(--surface);
}
.mp-ui .card-img {
  aspect-ratio: 1 / 1; position: relative; overflow: hidden;
  background: var(--surface-2);
}
.mp-ui .card-img .ph {
  width: 100%; height: 100%;
  display: grid; place-items: center;
  background: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 9px, var(--surface-hover) 9px, var(--surface-hover) 18px);
  color: var(--text-faint); font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.05em;
}
.mp-ui .card-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.price-tag {
  position: absolute; left: 8px; bottom: 8px;
  font-family: var(--font-mono); font-weight: 600; font-size: 13px;
  background: oklch(0.18 0.01 60 / 0.82); color: #fff;
  padding: 3px 9px; border-radius: 7px;
  backdrop-filter: blur(4px);
  border: 1px solid oklch(1 0 0 / 0.12);
}
.fav {
  position: absolute; right: 8px; bottom: 8px;
  width: 30px; height: 30px; border-radius: 8px;
  background: oklch(0.18 0.01 60 / 0.55); border: 1px solid oklch(1 0 0 / 0.14);
  color: #fff; display: grid; place-items: center;
  backdrop-filter: blur(4px); transition: all .14s;
}
.fav svg { width: 15px; height: 15px; }
.fav:hover { background: oklch(0.18 0.01 60 / 0.8); }
.fav.on { background: var(--accent); border-color: var(--accent); }
.fav.on svg { fill: #fff; }

.mp-ui .card-body { padding: 10px 11px 11px; display: flex; flex-direction: column; gap: 7px; flex: 1; }
.src {
  align-self: flex-start;
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.02em;
  padding: 2px 8px; border-radius: 5px;
  display: inline-flex; align-items: center; gap: 5px;
}
.src .sdot { width: 6px; height: 6px; border-radius: 99px; }
.src.mercari { background: var(--info-soft); color: var(--info); }
.src.mercari .sdot { background: var(--info); }
.src.yahoo { background: var(--warn-soft); color: var(--warn); }
.src.yahoo .sdot { background: var(--warn); }

.mp-ui /* Real badge row (brand-pill / store-pill / new-pill / meta-pill) */
.badge-row { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.mp-ui .badge {
  font-size: 10px; font-weight: 600; letter-spacing: 0.01em;
  padding: 2px 7px; border-radius: 5px;
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
}
.brand-pill {
  background: color-mix(in oklch, var(--c, var(--text-muted)) 14%, transparent);
  color: var(--c, var(--text-muted));
}
.brand-pill .bdot { width: 5px; height: 5px; border-radius: 99px; background: var(--c, var(--text-muted)); }
.store-pill { background: var(--surface-2); border: 1px solid var(--border); color: var(--text-muted); }
.new-pill { background: var(--accent-soft); color: var(--accent-strong); }
.meta-pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10.5px; color: var(--text-faint); font-weight: 500;
}
.meta-pill svg { width: 11px; height: 11px; }

.mp-ui /* Shipping chip over image */
.chip-img {
  position: absolute; left: 8px; top: 8px;
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10px; font-weight: 600;
  padding: 3px 8px; border-radius: 6px;
  background: oklch(0.18 0.01 60 / 0.6); color: #fff;
  border: 1px solid oklch(1 0 0 / 0.14); backdrop-filter: blur(4px);
}
.mp-ui .chip-img svg { width: 12px; height: 12px; }
.mp-ui .card-title {
  font-size: 12.5px; line-height: 1.35; font-weight: 500;
  color: var(--text); margin: 0;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  min-height: 2.7em;
}
.mp-ui .mp-pub-badge {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mp-ui .card-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; }
.meta-time { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--text-faint); font-family: var(--font-mono); }
.meta-time svg { width: 12px; height: 12px; }
/* Fila única: el botón principal absorbe el ancho libre y los de icono son
   cuadrados. En grid con columnas fijas, el botón de precio objetivo (que solo
   existe en artículos de la wishlist) caía a una segunda fila. */
.mp-ui .card-actions {
  display: flex; align-items: center; flex-wrap: nowrap;
  gap: 6px; padding: 0 11px 11px;
}
.mp-ui .card-actions > * { min-width: 0; }
.mp-ui .card-actions > .btn { flex: 0 0 auto; }
.mp-ui .card-actions > .btn:not(.ghost) { flex: 1 1 0; justify-content: center; }
/* Icono suelto: cuadrado a la altura del botón, sin padding lateral muerto. */
.mp-ui .card-actions .btn.sm.ghost { width: 30px; padding: 0; justify-content: center; }
/* Enlace al artículo: acento sin peso de botón primario. */
.mp-ui .card-actions .btn-open { color: var(--accent-strong); border-color: var(--accent-line); }
/* La etiqueta del botón principal se trunca con elipsis si la card va justa */
.mp-ui .card-actions .btn-lbl {
  min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* Por debajo de ~240px la etiqueta no cabe junto a los tres iconos y se leía
   "Ver artí…". Mejor icono solo: el enlace conserva su nombre accesible. */
@container card (max-width: 239px) {
  .mp-ui .card-actions .btn-lbl { display: none; }
}

/* List/table view (Marktparse) */
.list-row {
  display: grid;
  grid-template-columns: 52px 1fr 110px 92px 88px 64px;
  align-items: center; gap: 14px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  transition: background .12s;
}
.list-row:hover { background: var(--surface-hover); }
.list-thumb { width: 44px; height: 44px; border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.list-thumb img { width: 100%; height: 100%; object-fit: cover; }
.list-title { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============================================================
   Mybuyee — KPIs + tabs + table
   ============================================================ */
.kpi-row { display: grid; grid-template-columns: repeat(7, 1fr); gap: 12px; margin-bottom: 20px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 14px;
  display: flex; flex-direction: column; gap: 6px;
  position: relative; overflow: hidden;
  transition: border-color .15s, transform .15s;
}
.kpi:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.kpi-label { font-size: 11px; font-weight: 600; color: var(--text-muted); letter-spacing: 0.02em; display: flex; align-items: center; gap: 6px; }
.kpi-label svg { width: 13px; height: 13px; color: var(--text-faint); }
.kpi-val { font-family: var(--font-mono); font-size: 20px; font-weight: 600; letter-spacing: -0.02em; }
.kpi-val .unit { font-size: 11px; color: var(--text-faint); font-weight: 500; margin-left: 3px; }
.kpi.accent .kpi-val { color: var(--accent-strong); }
.kpi.money-out .kpi-val { color: var(--text); }
.kpi.money-in .kpi-val { color: var(--ok); }

.mp-ui .tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.mp-ui .tab {
  border: none; background: none; color: var(--text-muted);
  font-size: 13.5px; font-weight: 500; padding: 10px 14px;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  white-space: nowrap; transition: color .14s, border-color .14s;
}
.mp-ui .tab:hover { color: var(--text); }
.mp-ui .tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.mp-ui .tab .tcount { font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); margin-left: 6px; }

.action-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 13px 15px; margin-bottom: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.action-bar .hint { color: var(--text-faint); font-size: 12px; margin-left: auto; }

.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table.data { width: 100%; border-collapse: collapse; }
table.data th {
  text-align: left; font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-faint); padding: 11px 16px; border-bottom: 1px solid var(--border);
  background: var(--surface-2); white-space: nowrap; position: sticky; top: 0;
}
table.data th.num, table.data td.num { text-align: right; font-family: var(--font-mono); }
table.data td { padding: 11px 16px; border-bottom: 1px solid var(--border); font-size: 13px; white-space: nowrap; }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr { transition: background .1s; }
table.data tbody tr:hover { background: var(--surface-hover); }
table.data tbody tr.row-open { background: var(--surface-2); }
table.data tbody tr.row-open:hover { background: var(--surface-2); }

/* Expand button + items sub-panel */
.expand-btn {
  width: 26px; height: 26px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-muted); display: grid; place-items: center;
  transition: transform .18s var(--ease), background .12s, color .12s;
}
.expand-btn:hover { background: var(--surface-hover); color: var(--text); }
.expand-btn.open { transform: rotate(90deg); background: var(--accent-soft); color: var(--accent-strong); border-color: var(--accent-line); }
.items-row td { padding: 0 !important; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.items-panel { padding: 4px 16px 14px 56px; }
.items-head {
  display: flex; align-items: center; gap: 7px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-faint); padding: 12px 0 8px;
}
.items-head svg { width: 13px; height: 13px; }
table.data.sub { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
table.data.sub th { background: var(--surface-hover); padding: 8px 12px; font-size: 9.5px; }
table.data.sub td { padding: 8px 12px; font-size: 12px; }
.mp-ui table.data a { color: var(--accent-strong); text-decoration: none; font-weight: 500; }
.mp-ui table.data a:hover { text-decoration: underline; }
.item-thumb {
  width: 30px; height: 30px; border-radius: 6px;
  background: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 5px, var(--surface-hover) 5px, var(--surface-hover) 10px);
  display: grid; place-items: center; font-size: 7px; color: var(--text-faint); font-family: var(--font-mono);
}
.pkg-cell { display: flex; align-items: center; gap: 11px; }
.pkg-ico { width: 32px; height: 32px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); display: grid; place-items: center; color: var(--text-muted); flex-shrink: 0; }
.pkg-ico svg { width: 16px; height: 16px; }
.pkg-id { font-family: var(--font-mono); font-size: 12.5px; font-weight: 500; }
.mono { font-family: var(--font-mono); }
.muted { color: var(--text-muted); }

.mp-ui .status {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 99px;
}
.mp-ui .status .sd { width: 6px; height: 6px; border-radius: 99px; }
.mp-ui .status.arrived { background: var(--warn-soft); color: var(--warn); }
.mp-ui .status.arrived .sd { background: var(--warn); }
.mp-ui .status.shipped { background: var(--ok-soft); color: var(--ok); }
.mp-ui .status.shipped .sd { background: var(--ok); }
.mp-ui .status.archived { background: var(--surface-2); color: var(--text-faint); border: 1px solid var(--border); }
.mp-ui .status.archived .sd { background: var(--text-faint); }
.mp-ui .status.consolidated { background: var(--info-soft); color: var(--info); }
.mp-ui .status.consolidated .sd { background: var(--info); }
.mp-ui .status.consolidating { background: var(--accent-soft); color: var(--accent-strong); }
.mp-ui .status.consolidating .sd { background: var(--accent); }

/* Empty / fade-in — base state is visible; animation is enhancement only */
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.fade-in { opacity: 1; }
@media (prefers-reduced-motion: no-preference) {
  .fade-in { animation: fadeUp .3s var(--ease); }
}

.mp-ui /* ============================================================
   Modal
   ============================================================ */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: oklch(0.1 0.01 265 / 0.6);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  animation: fadeIn .15s var(--ease);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
/* :not(.fade) deja fuera los modales de Bootstrap que vivan dentro de .mp-ui */
.mp-ui .modal:not(.fade) {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 520px;
  animation: slideUp .18s var(--ease);
  max-height: 92vh; overflow-y: auto;
}
@keyframes slideUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.mp-ui .modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 20px; border-bottom: 1px solid var(--border);
}
.mp-ui .modal-head h3 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -0.02em; flex: 1; }
.mp-ui .modal-head .mh-ico { width: 32px; height: 32px; border-radius: 9px; background: var(--accent-soft); color: var(--accent-strong); display: grid; place-items: center; }
.mp-ui .modal-head .mh-ico svg { width: 17px; height: 17px; }
.mp-ui .modal:not(.fade) .modal-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.mp-ui .modal-foot {
  display: flex; align-items: center; gap: 8px; justify-content: flex-end;
  padding: 14px 20px; border-top: 1px solid var(--border);
}
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid-2 .full { grid-column: 1 / -1; }
.form-inline { display: flex; align-items: center; justify-content: space-between; }
.mp-ui .form-inline .form-label { margin: 0; color: var(--text); font-size: 13.5px; font-weight: 500; }

@media (max-width: 1100px) {
  .kpi-row { grid-template-columns: repeat(4, 1fr); }
}
/* Backdrop del drawer móvil: inerte fuera del media query */
.rail-backdrop { display: none; }

@media (max-width: 760px) {
  /* Drawer: el rail deja de ocupar columna; .main toma todo el ancho */
  .app, .app.collapsed { grid-template-columns: 1fr; }
  .rail {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: var(--rail-w);
    background: var(--rail-bg);
    border-right: 1px solid var(--border);
    transform: translateX(-100%);
    transition: transform .28s var(--ease);
    /* sobre el contenido, por debajo de los modales Bootstrap (z-index 3000+) */
    z-index: 2000;
  }
  .app.rail-open .rail {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  /* En móvil el drawer se muestra siempre expandido: neutraliza .collapsed */
  .app.collapsed .nav-group-label,
  .app.collapsed .nav-label,
  .app.collapsed .nav-badge,
  .app.collapsed .chev,
  .app.collapsed .brand,
  .app.collapsed .nav-sub { display: revert; }
  .app.collapsed .rail-item { justify-content: flex-start; padding: 8px 10px; }
  .app.collapsed .rail-head { justify-content: flex-start; padding: 0 14px; }

  .rail-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: var(--scrim);
    z-index: 1990;
    opacity: 0;
    pointer-events: none;
    transition: opacity .28s var(--ease);
  }
  .app.rail-open .rail-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .search { display: none; }

  /* Ajustes genéricos de página en móvil */
  .content-inner { padding: 16px 14px 48px; }
  .mp-ui .toolbar { position: static; }
  .mp-ui .toolbar .field { flex: 1 1 140px; min-width: 0; }
  .mp-ui .table-wrap { overflow-x: auto; }
  .form-grid-2 { grid-template-columns: 1fr; }
  .mp-ui .page-head > div { flex-wrap: wrap; }
  .mp-ui .panel-head { flex-wrap: wrap; row-gap: 8px; }
  .mp-ui .panel-head .right { flex-wrap: wrap; row-gap: 6px; justify-content: flex-end; }
  .items-panel { padding: 4px 12px 12px; }
  /* El panel NO scrollea en horizontal: cada .table-wrap contiene su propio
     scroll (arriba), así sólo se desplaza la tabla, no el bloque entero. */
  .mp-ui .panel-body { overflow-x: clip; }
}

/* ============================================================
   Compat: controles Bootstrap residuales dentro de .mp-ui
   (formularios/accordions que conservan estructura BS5 pero
   deben verse con los tokens del diseño)
   ============================================================ */
.mp-ui .form-control, .mp-ui .form-select {
  background-color: var(--surface-2);
  border-color: var(--border-strong);
  color: var(--text);
  border-radius: 8px;
  font-size: 13px;
}
.mp-ui .form-control::placeholder { color: var(--text-faint); }
.mp-ui .form-control:focus, .mp-ui .form-select:focus {
  background-color: var(--surface-2);
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-soft);
  color: var(--text);
}
.mp-ui .input-group-text {
  background-color: var(--surface-hover);
  border-color: var(--border-strong);
  color: var(--text-faint);
  border-radius: 8px;
}
.mp-ui .form-check-input { border-color: var(--border-strong); background-color: var(--surface-2); }
.mp-ui .form-check-input:checked { background-color: var(--accent); border-color: var(--accent); }
.mp-ui .form-check-input:focus { border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }
.mp-ui .form-text { color: var(--text-faint); }

.mp-ui .badge.text-bg-success, .mp-ui .badge.bg-success { background: var(--ok-soft) !important; color: var(--ok) !important; }
.mp-ui .badge.text-bg-warning, .mp-ui .badge.bg-warning { background: var(--warn-soft) !important; color: var(--warn) !important; }
.mp-ui .badge.text-bg-danger, .mp-ui .badge.bg-danger { background: var(--accent-soft) !important; color: var(--accent-strong) !important; }
.mp-ui .badge.text-bg-light, .mp-ui .badge.bg-secondary,
.mp-ui .badge.bg-secondary-subtle, .mp-ui .badge.bg-warning-subtle,
.mp-ui .badge.text-bg-primary { background: var(--surface-2) !important; color: var(--text-muted) !important; border: 1px solid var(--border); }

.mp-ui .btn-outline-success, .mp-ui .btn-outline-primary,
.mp-ui .btn-outline-info, .mp-ui .btn-outline-secondary {
  --bs-btn-color: var(--text-muted); --bs-btn-border-color: var(--border-strong);
  --bs-btn-hover-bg: var(--surface-2); --bs-btn-hover-color: var(--text); --bs-btn-hover-border-color: var(--border-strong);
  --bs-btn-active-bg: var(--surface-2); --bs-btn-active-color: var(--text); --bs-btn-active-border-color: var(--border-strong);
  border-radius: 8px; font-size: 12.5px; font-weight: 600;
}
.mp-ui .btn-outline-danger, .mp-ui .btn-danger {
  --bs-btn-color: var(--accent-strong); --bs-btn-bg: transparent; --bs-btn-border-color: var(--accent-line);
  --bs-btn-hover-bg: var(--accent-soft); --bs-btn-hover-color: var(--accent-strong); --bs-btn-hover-border-color: var(--accent-strong);
  --bs-btn-active-bg: var(--accent-soft); --bs-btn-active-color: var(--accent-strong); --bs-btn-active-border-color: var(--accent-strong);
  border-radius: 8px; font-size: 12.5px; font-weight: 600;
}

.mp-ui .accordion {
  --bs-accordion-bg: var(--surface);
  --bs-accordion-border-color: var(--border);
  --bs-accordion-btn-bg: var(--surface);
  --bs-accordion-btn-color: var(--text);
  --bs-accordion-active-bg: var(--surface-2);
  --bs-accordion-active-color: var(--text);
  --bs-accordion-btn-focus-box-shadow: 0 0 0 3px var(--accent-soft);
  --bs-accordion-border-radius: var(--radius);
  --bs-accordion-inner-border-radius: calc(var(--radius) - 1px);
}
.mp-ui .accordion-button { font-size: 13.5px; font-weight: 600; }

.mp-ui .dropdown-menu {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  color: var(--text);
}

.mp-ui .table {
  --bs-table-bg: transparent;
  --bs-table-color: var(--text);
  --bs-table-border-color: var(--border);
  --bs-table-striped-bg: var(--surface-hover);
  --bs-table-hover-bg: var(--surface-hover);
  font-size: 13px;
}
.mp-ui .table > :not(caption) > * > * { border-color: var(--border); }
.mp-ui .table-secondary { --bs-table-bg: var(--surface-2); --bs-table-color: var(--text-muted); }

/* ============================================================
   Keywords panel — dos paneles (empresas ↔ keywords), alta/edición inline
   ============================================================ */
.kw-prices-hint { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; }
.kw-prices-hint svg, .kw-prices-hint i { font-size: 12px; }
.kw-help { margin-bottom: 16px; }

.kw-layout { display: grid; grid-template-columns: 232px minmax(0, 1fr); gap: 18px; align-items: start; }

/* ---- Panel izquierdo: empresas ---- */
.kw-aside { min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.kw-aside-search { width: 100%; }
.kw-co-list { display: flex; flex-direction: column; gap: 2px; }
.kw-co {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  padding: 8px 10px; border: none; background: none;
  border-radius: var(--radius-sm); color: var(--text-muted);
  font-size: 13.5px; font-weight: 500; position: relative;
  transition: background .12s, color .12s;
}
.kw-co:hover { background: var(--surface-hover); color: var(--text); }
.kw-co.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.kw-co.active::before {
  content: ""; position: absolute; left: -10px; top: 7px; bottom: 7px;
  width: 3px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.kw-co-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kw-co-count { flex-shrink: 0; }
.kw-co.active .kw-co-count { color: var(--accent-strong); background: color-mix(in oklch, var(--accent) 18%, transparent); }
.kw-co-empty { font-size: 12.5px; color: var(--text-faint); padding: 6px 10px; margin: 0; }

/* ---- Panel derecho ---- */
.kw-main { min-width: 0; display: flex; flex-direction: column; }
.kw-main-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; margin-bottom: 14px; flex-wrap: wrap;
}
.kw-main-title { display: flex; align-items: center; gap: 9px; min-width: 0; }
.kw-main-title h4 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -0.02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kw-main-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.kw-search { width: 220px; max-width: 100%; }

/* ---- Formulario de alta inline ---- */
.kw-add-form {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 16px;
}
.kw-add-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.kw-field .form-label { margin: 0; }
.kw-field-fast { justify-content: flex-start; }
.kw-switch-label { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; height: 36px; }
.kw-switch-text { font-size: 12.5px; }
.kw-add-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-top: 14px; flex-wrap: wrap;
}
.kw-add-targets { font-size: 12.5px; min-width: 0; }
.kw-add-targets > summary {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  list-style: none; color: var(--text-muted);
  padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); user-select: none;
}
.kw-add-targets > summary::-webkit-details-marker { display: none; }
.kw-add-targets > summary:hover { border-color: var(--border-strong); color: var(--text); }
.kw-add-targets > summary svg, .kw-add-targets > summary i { font-size: 13px; color: var(--text-faint); }
.kw-add-targets[open] > summary { border-color: var(--accent-line); color: var(--text); }
.kw-add-targets #kwTargetSummary { color: var(--text); font-weight: 600; }
.kw-targets-grid {
  display: flex; flex-wrap: wrap; gap: 6px 14px;
  margin-top: 10px; padding: 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface);
}
.kw-target-item { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; cursor: pointer; }
.kw-add-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

/* ---- Tabla de keywords (sobre table.data) ---- */
.kw-table-wrap {
  overflow-x: auto; overflow-y: hidden;
  scrollbar-width: thin; -webkit-overflow-scrolling: touch;
}
.kw-table { width: 100%; }
.kw-table th.kw-th-actions { width: 1%; }
.kw-table td.kw-c-actions { text-align: right; white-space: nowrap; }
.kw-c-actions .icon-act + .icon-act { margin-left: 4px; }
.kw-table td.kw-c-min, .kw-table td.kw-c-max { color: var(--text); }
.kw-row-off td:not(.kw-c-actions):not(.kw-c-enabled) { color: var(--text-faint); }
.kw-row-off .kw-c-keyword { color: var(--text-muted); }
.kw-row.editing { background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--accent-line); }
.kw-row.editing:hover { background: var(--surface-2); }
.kw-edit-input {
  height: 30px; width: 100%; min-width: 80px; padding: 0 8px;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 6px; color: var(--text); font-family: inherit; font-size: 12.5px; outline: none;
}
.kw-edit-input:focus { border-color: var(--accent-line); }
.kw-edit-input[disabled] { opacity: .5; cursor: not-allowed; }
.kw-edit-input.num { font-family: var(--font-mono); text-align: right; }

/* Fast pill (sobre .status) */
.mp-ui .status.fast { background: var(--warn-soft); color: var(--warn); }
.mp-ui .status.fast .sd { background: var(--warn); }

/* Feedback inline y confirmación accesible */
.kw-inline-error, .kw-row-error {
  color: var(--accent-strong); font-size: 12.5px; line-height: 1.4;
}
.kw-inline-error { margin: 10px 0 0; }
.kw-row-error { flex-basis: 100%; text-align: right; }
.kw-target-help { margin: 8px 0 0; font-size: 12px; }
.kw-c-actions.confirming { display: flex; justify-content: flex-end; gap: 6px; }
.kw-toggle[disabled], .kw-fast[disabled], .kw-notify[disabled] {
  opacity: .55; cursor: wait;
}

/* Botón ocupado (pending) */
.btn.is-busy { opacity: .7; pointer-events: none; }
.kw-spinner {
  width: 14px; height: 14px; border-radius: 99px;
  border: 2px solid currentColor; border-right-color: transparent;
  display: inline-block; animation: kwspin .6s linear infinite;
}
@keyframes kwspin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .kw-spinner { animation-duration: 0s; } }

/* ---- Estados vacíos ---- */
.kw-empty { text-align: center; padding: 40px 20px; }
.kw-empty-ico {
  width: 44px; height: 44px; border-radius: 12px; margin: 0 auto 12px;
  display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-faint);
}
.kw-empty-ico svg, .kw-empty-ico i { font-size: 19px; }
.kw-empty-title { margin: 0 0 4px; font-size: 14px; font-weight: 700; color: var(--text); }
.kw-empty-sub { margin: 0 auto; font-size: 13px; color: var(--text-muted); max-width: 42ch; }
.kw-empty-select .kw-empty-ico { background: var(--accent-soft); border-color: transparent; color: var(--accent-strong); }
.kw-no-match { text-align: center; padding: 28px 20px; margin: 0; color: var(--text-muted); font-size: 13px; }

/* ---- Responsive: dos paneles → apilado, empresas en fila ---- */
@media (max-width: 860px) {
  .kw-layout { grid-template-columns: 1fr; gap: 14px; }
  .kw-aside { gap: 8px; }
  .kw-co-list {
    flex-direction: row; gap: 6px;
    overflow-x: auto; padding: 2px 0 6px;
    scrollbar-width: thin; scroll-snap-type: x proximity;
  }
  .kw-co {
    flex: 0 0 auto; width: auto; min-height: 44px;
    border: 1px solid var(--border); border-radius: 99px;
    scroll-snap-align: nearest;
  }
  .kw-co-name { flex: 0 0 auto; overflow: visible; }
  .kw-co.active { border-color: var(--accent-line); }
  .kw-co.active::before { display: none; }
  .kw-search { width: 100%; }
  .kw-main-tools { width: 100%; }
  .kw-main-tools .kw-search { flex: 1 1 auto; }
}

@media (max-width: 640px) {
  .kw-body { overflow-x: visible; }
  .kw-main-head { align-items: flex-start; }
  .kw-main-tools {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px;
  }
  .kw-main-tools .field, .kw-main-tools .btn { min-height: 44px; }
  .kw-add-grid { grid-template-columns: 1fr; }
  .kw-add-foot { align-items: flex-start; }
  .kw-add-targets { width: 100%; }
  .kw-targets-grid { max-height: 220px; overflow-y: auto; }
  /* Tarjeta densa 2D: cabecera (keyword) + atributos en pares + los tres
     switches en filas, en lugar de una fila por atributo (más compacta y
     alineada). */
  .mp-ui .kw-table-wrap { border: 0; overflow: visible; background: transparent; }
  .kw-table, .kw-table tbody, .kw-table tr, .kw-table td { display: block; width: 100%; }
  .kw-table thead {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
  }
  .kw-table tbody { display: grid; gap: 10px; }
  .kw-table .kw-row {
    display: grid; grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "keyword keyword"
      "trans   trans"
      "cat     brand"
      "min     max"
      "fast    notify"
      "active  actions";
    gap: 11px 14px; align-items: start;
    padding: 13px 14px; border: 1px solid var(--border);
    border-radius: var(--radius); background: var(--surface);
  }
  /* Atributo por defecto: etiqueta encima, valor debajo, a la izquierda. */
  .kw-table .kw-row > td {
    display: flex; flex-direction: column; gap: 3px;
    min-width: 0; padding: 0; border: 0;
    text-align: left; white-space: normal; word-break: break-word;
  }
  .kw-table .kw-row > td::before {
    content: attr(data-label); color: var(--text-faint);
    font-size: 10px; font-weight: 700; letter-spacing: .06em;
    text-transform: uppercase; text-align: left;
  }
  .kw-table .kw-c-keyword {
    grid-area: keyword; font-size: 15px; font-weight: 700;
    padding-bottom: 11px; border-bottom: 1px solid var(--border);
  }
  .kw-table .kw-c-keyword::before { display: none; }
  .kw-table .kw-c-translated { grid-area: trans; }
  .kw-table .kw-c-category { grid-area: cat; }
  .kw-table .kw-c-brand { grid-area: brand; }
  .kw-table .kw-c-min { grid-area: min; }
  .kw-table .kw-c-max { grid-area: max; }
  /* Valor de min/max a la izquierda (la clase .num los alinea a la derecha;
     hace falta la especificidad de `.kw-row > td` para ganarle). */
  .kw-table .kw-row > td.kw-c-min,
  .kw-table .kw-row > td.kw-c-max { text-align: left; }
  /* Switches: etiqueta + control en línea, una fila cada uno. La especificidad
     `.kw-row > td.clase` es necesaria para ganar al `.kw-row > td` base. */
  .kw-table .kw-c-fast { grid-area: fast; }
  .kw-table .kw-c-notify { grid-area: notify; }
  .kw-table .kw-c-enabled { grid-area: active; }
  .kw-table .kw-row > td.kw-c-fast,
  .kw-table .kw-row > td.kw-c-notify,
  .kw-table .kw-row > td.kw-c-enabled {
    flex-direction: row; align-items: center; justify-content: space-between;
    gap: 10px; min-height: 40px;
    padding-top: 11px; border-top: 1px solid var(--border);
  }
  .kw-table .kw-c-fast::before,
  .kw-table .kw-c-notify::before,
  .kw-table .kw-c-enabled::before { order: -1; margin: 0; }
  /* Acciones: editar + borrar juntos, a la derecha en su fila. */
  .kw-table .kw-c-actions { grid-area: actions; }
  .kw-table .kw-row > td.kw-c-actions {
    flex-direction: row; align-items: center;
    justify-content: flex-end; gap: 8px; min-height: 40px;
    padding-top: 11px; border-top: 1px solid var(--border);
  }
  .kw-table .kw-c-actions::before { display: none; }
  .kw-table .icon-act { min-width: 44px; min-height: 44px; }
  .kw-edit-input { min-height: 40px; }
  .kw-row-error {
    grid-column: 1 / -1; text-align: left;
    padding-top: 9px; border-top: 1px solid var(--border);
  }
}
