/* ==========================================================================
   AgroMarket Manager — sistema de diseño
   Mobile-first · neutros cálidos · un color principal (verde campo)
   ========================================================================== */

@font-face { font-family: "Inter"; font-style: normal; font-weight: 400; font-display: swap; src: url("../fonts/inter-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 500; font-display: swap; src: url("../fonts/inter-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 600; font-display: swap; src: url("../fonts/inter-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 700; font-display: swap; src: url("../fonts/inter-latin-700-normal.woff2") format("woff2"); }

:root {
  --bg: #f6f6f3;
  --surface: #ffffff;
  --surface-2: #f1f1ed;
  --surface-hover: #f4f4f0;
  --border: #e3e3dc;
  --border-strong: #cfcfc6;
  --text: #191d1a;
  --text-2: #565d58;
  --text-3: #858b86;
  --primary: #2f7d4f;
  --primary-hover: #276a42;
  --primary-soft: #e7f2ea;
  --primary-text: #1f5c38;
  --on-primary: #ffffff;
  --danger: #b4432d;
  --danger-soft: #fbebe7;
  --warning: #9a6311;
  --warning-soft: #fcf2df;
  --info: #2c6390;
  --info-soft: #e8f0f7;
  --focus: rgba(47, 125, 79, .35);
  --shadow-pop: 0 1px 2px rgba(20, 24, 21, .06), 0 8px 24px rgba(20, 24, 21, .10);
  --shadow-sheet: 0 -8px 32px rgba(20, 24, 21, .16);
  --overlay: rgba(18, 22, 19, .42);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --sidebar-w: 264px;
  --topbar-h: 60px;
  --bottombar-h: 64px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

/* Tema oscuro: forzado con data-theme="dark" o automático según el sistema si no se eligió "light". */
:root[data-theme="dark"] {
  --bg: #101311;
  --surface: #171b18;
  --surface-2: #1e231f;
  --surface-hover: #1c211d;
  --border: #2a302b;
  --border-strong: #3a413b;
  --text: #e8ebe8;
  --text-2: #a7aea9;
  --text-3: #7d847f;
  --primary: #4caa72;
  --primary-hover: #5bb980;
  --primary-soft: #1c2d22;
  --primary-text: #8fd3a9;
  --on-primary: #0d1a12;
  --danger: #e0735d;
  --danger-soft: #34201b;
  --warning: #e0a649;
  --warning-soft: #33281a;
  --info: #7fb2dc;
  --info-soft: #1b2733;
  --focus: rgba(76, 170, 114, .45);
  --shadow-pop: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px rgba(0, 0, 0, .45);
  --shadow-sheet: 0 -8px 32px rgba(0, 0, 0, .5);
  --overlay: rgba(0, 0, 0, .6);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101311;
    --surface: #171b18;
    --surface-2: #1e231f;
    --surface-hover: #1c211d;
    --border: #2a302b;
    --border-strong: #3a413b;
    --text: #e8ebe8;
    --text-2: #a7aea9;
    --text-3: #7d847f;
    --primary: #4caa72;
    --primary-hover: #5bb980;
    --primary-soft: #1c2d22;
    --primary-text: #8fd3a9;
    --on-primary: #0d1a12;
    --danger: #e0735d;
    --danger-soft: #34201b;
    --warning: #e0a649;
    --warning-soft: #33281a;
    --info: #7fb2dc;
    --info-soft: #1b2733;
    --focus: rgba(76, 170, 114, .45);
    --shadow-pop: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px rgba(0, 0, 0, .45);
    --shadow-sheet: 0 -8px 32px rgba(0, 0, 0, .5);
    --overlay: rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.5 var(--font);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -.011em; font-weight: 600; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0; }
a { color: var(--primary-text); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.icon { width: 18px; height: 18px; flex: none; }
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 22px; height: 22px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.muted { color: var(--text-2); }
.subtle { color: var(--text-3); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.hidden, [hidden] { display: none !important; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; gap: 12px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px;
  border: 1px solid transparent; border-radius: var(--radius);
  font-weight: 500; font-size: 15px; line-height: 1; white-space: nowrap;
  cursor: pointer; text-decoration: none !important;
  transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus); }
.btn:disabled, .btn.is-loading { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-hover); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--surface); border-color: var(--border-strong); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: var(--radius-sm); }
.btn-icon { width: 44px; padding: 0; }
.btn-icon.btn-sm { width: 36px; }
.btn .spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.link-btn { display: inline-flex; align-items: center; gap: 6px; align-self: flex-start; background: none; border: 0; padding: 0; color: var(--primary-text); font-weight: 500; cursor: pointer; }
.link-btn:hover { text-decoration: underline; text-underline-offset: 2px; }

/* ---------- forms ---------- */
.form { display: flex; flex-direction: column; gap: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.label { font-size: 14px; font-weight: 500; color: var(--text); display: flex; justify-content: space-between; gap: 8px; }
.label .optional { font-weight: 400; color: var(--text-3); font-size: 13px; }
.input, .select, .textarea {
  width: 100%; min-height: 46px; padding: 10px 12px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  font-size: 16px; /* 16px evita el zoom automático en iOS */
  transition: border-color .15s, box-shadow .15s;
  appearance: none; -webkit-appearance: none;
}
.input::placeholder { color: var(--text-3); }
.input:hover, .select:hover { border-color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus); }
.input:disabled, .input[readonly] { background: var(--surface-2); color: var(--text-2); }
.select {
  padding-right: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23858b86' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
.select:disabled { background-color: var(--surface-2); color: var(--text-2); }
.hint { font-size: 13px; color: var(--text-3); }
.textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.field-error { font-size: 13px; color: var(--danger); display: none; }
.field.has-error .input, .field.has-error .select { border-color: var(--danger); }
.field.has-error .field-error { display: block; }
.input-group { position: relative; }
.input-group .input { padding-right: 48px; }
.input-group .input-action {
  position: absolute; right: 2px; top: 50%; transform: translateY(-50%);
  width: 44px; height: 42px; display: grid; place-items: center;
  background: none; border: 0; color: var(--text-3); cursor: pointer; border-radius: var(--radius-sm);
}
.input-group .input-action:hover { color: var(--text); }
.code-input { font-family: var(--mono); font-size: 24px; letter-spacing: .4em; text-align: center; padding-left: calc(12px + .4em); }
.form-section { display: grid; grid-template-columns: 1fr; gap: 16px; padding: 20px 0; border-top: 1px solid var(--border); }
.form-section:first-child { border-top: 0; padding-top: 0; }
.form-section > * { min-width: 0; }
.form-section-head h2 { font-size: 15px; }
.form-section-head p { font-size: 14px; color: var(--text-2); margin-top: 4px; }
.form-actions { display: flex; flex-direction: column-reverse; gap: 10px; padding-top: 4px; }

/* ---------- alerts, badges ---------- */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius); font-size: 14px; border: 1px solid transparent; }
.alert .icon { margin-top: 1px; }
.alert-info { background: var(--info-soft); color: var(--info); }
.alert-success { background: var(--primary-soft); color: var(--primary-text); }
.alert-warning { background: var(--warning-soft); color: var(--warning); }
.alert-danger { background: var(--danger-soft); color: var(--danger); }
.alert + .panel, .alert + section, .stack + .panel, .panel + .panel { margin-top: 16px; }
.stack > .panel + .panel, .stack > .alert + .panel, .stack > .alert + section { margin-top: 0; }
.badge { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px; border-radius: 999px; font-size: 12.5px; font-weight: 500; white-space: nowrap; background: var(--surface-2); color: var(--text-2); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .9; }
.badge-plain::before { display: none; }
.badge-success { background: var(--primary-soft); color: var(--primary-text); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }

/* ---------- surfaces ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.panel-body { padding: 20px 16px; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 16px 0; }
.panel-head p { color: var(--text-2); font-size: 14px; margin-top: 4px; }
.divider { height: 1px; background: var(--border); border: 0; margin: 0; }

/* ---------- auth layout ---------- */
.auth-body { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.auth-main { flex: 1; display: flex; align-items: flex-start; justify-content: center; padding: 32px 16px 24px; }
.auth-card { width: 100%; max-width: 420px; }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; font-weight: 600; font-size: 16px; color: var(--text); }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 9px; background: var(--primary); color: var(--on-primary); flex: none; }
.brand-mark .icon { width: 20px; height: 20px; }
.auth-title { font-size: 24px; letter-spacing: -.02em; }
.auth-subtitle { color: var(--text-2); margin-top: 6px; }
.auth-head { margin-bottom: 24px; }
.auth-foot { margin-top: 22px; font-size: 14px; color: var(--text-2); text-align: center; }
.auth-footer { display: flex; justify-content: center; gap: 16px; padding: 16px; font-size: 13px; color: var(--text-3); flex-wrap: wrap; }
.auth-footer a { color: var(--text-2); }
.auth-footer a.is-active { color: var(--text); font-weight: 600; }
.auth-status { text-align: center; }
.auth-status .status-icon { margin: 0 auto 16px; }
.status-icon { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary-text); }
.status-icon.is-danger { background: var(--danger-soft); color: var(--danger); }
.status-icon.is-neutral { background: var(--surface-2); color: var(--text-2); }
.status-icon .icon { width: 24px; height: 24px; }

/* ---------- app shell ---------- */
.app-body { min-height: 100vh; min-height: 100dvh; }
.sidebar { display: none; }
.app-main { min-width: 0; padding-bottom: calc(var(--bottombar-h) + env(safe-area-inset-bottom) + 24px); }
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h); padding: 0 12px 0 16px;
  display: flex; align-items: center; gap: 8px;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar .brand-mark { width: 30px; height: 30px; border-radius: 8px; }
.topbar .brand-mark .icon { width: 18px; height: 18px; }
.topbar-title { display: none; font-weight: 600; font-size: 15px; }
.topbar-spacer { flex: 1; }
.topbar > .dropdown { flex: none; }
.content { padding: 20px 16px 32px; max-width: 1180px; margin: 0 auto; }
.content-narrow { max-width: 900px; }

.page-header { display: flex; flex-direction: column; gap: 14px; margin-bottom: 22px; }
.page-header h1 { font-size: 22px; letter-spacing: -.02em; }
.page-header p { color: var(--text-2); margin-top: 4px; font-size: 14.5px; }
.page-header .page-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.page-header .page-actions .btn { flex: 1 1 auto; }
.back-link { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; color: var(--text-2); margin-bottom: 10px; }
.back-link:hover { color: var(--text); text-decoration: none; }

/* company switcher */
.switcher {
  display: flex; align-items: center; gap: 10px; min-width: 0; max-width: 100%;
  padding: 6px 10px 6px 6px; min-height: 44px;
  background: transparent; border: 1px solid transparent; border-radius: var(--radius);
  cursor: pointer; text-align: left;
}
.switcher:hover { background: var(--surface-2); }
.switcher[aria-expanded="true"] { background: var(--surface-2); border-color: var(--border); }
.switcher-avatar { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary-text); font-weight: 600; font-size: 13px; flex: none; }
.switcher-text { min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.switcher-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.switcher-meta { font-size: 12px; color: var(--text-3); white-space: nowrap; }
.switcher .chev { color: var(--text-3); width: 16px; height: 16px; margin-left: auto; }
.store-pill { display: none; }

/* dropdown */
.dropdown { position: relative; min-width: 0; }
.menu {
  position: absolute; z-index: 60; top: calc(100% + 6px); left: 0;
  min-width: 260px; max-width: calc(100vw - 24px); padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
}
.menu-right { left: auto; right: 0; }
.menu-label { padding: 8px 10px 4px; font-size: 12px; font-weight: 500; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }
.menu-item {
  width: 100%; display: flex; align-items: center; gap: 10px;
  min-height: 42px; padding: 8px 10px; border-radius: var(--radius-sm);
  background: none; border: 0; color: var(--text); font-size: 14px; text-align: left; cursor: pointer;
  text-decoration: none !important;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); outline: none; }
.menu-item .icon { color: var(--text-3); }
.menu-item .check { margin-left: auto; color: var(--primary); }
.menu-item .grow { display: flex; flex-direction: column; min-width: 0; }
.menu-item-meta { margin-left: auto; font-size: 12px; color: var(--text-3); }
.menu-sep { height: 1px; background: var(--border); margin: 6px 0; }
.menu-item.is-danger { color: var(--danger); }
.menu-item.is-danger .icon { color: var(--danger); }

.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--text-2); font-size: 13px; font-weight: 600; border: 1px solid var(--border); flex: none; }
.avatar-btn { background: none; border: 0; padding: 5px; border-radius: 50%; cursor: pointer; }
.avatar-btn:hover .avatar { border-color: var(--border-strong); }

/* bottom navigation (móvil y tablet) */
.bottombar {
  position: fixed; z-index: 40; left: 0; right: 0; bottom: 0;
  height: calc(var(--bottombar-h) + env(safe-area-inset-bottom));
  padding: 0 4px env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
  background: var(--surface); border-top: 1px solid var(--border);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  height: 100%; min-width: 0; padding: 6px 2px;
  background: none; border: 0; color: var(--text-3); font-size: 11px; font-weight: 500;
  cursor: pointer; text-decoration: none !important; -webkit-tap-highlight-color: transparent;
}
.tab .icon { width: 22px; height: 22px; }
.tab span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab.is-active { color: var(--primary-text); }
.tab-primary .tab-fab { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; background: var(--primary); color: var(--on-primary); margin-top: -18px; box-shadow: 0 4px 12px rgba(47, 125, 79, .35); }
.tab-primary .tab-fab .icon { width: 24px; height: 24px; }
.tab-primary { color: var(--text-2); }

/* sheet (hoja inferior en móvil / diálogo en escritorio) */
.sheet-backdrop { position: fixed; inset: 0; z-index: 80; background: var(--overlay); opacity: 0; transition: opacity .2s; }
.sheet-backdrop.is-open { opacity: 1; }
.sheet {
  position: fixed; z-index: 90; left: 0; right: 0; bottom: 0;
  max-height: 88vh; max-height: 88dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border-radius: 18px 18px 0 0; box-shadow: var(--shadow-sheet);
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .25s cubic-bezier(.2, .8, .2, 1);
}
.sheet.is-open { transform: translateY(0); }
.sheet-handle { width: 40px; height: 4px; border-radius: 4px; background: var(--border-strong); margin: 4px auto 12px; }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.sheet-head h2 { font-size: 18px; }
.sheet-head p { color: var(--text-2); font-size: 14px; margin-top: 4px; }
.sheet-actions { display: flex; flex-direction: column-reverse; gap: 10px; margin-top: 20px; }
body.has-sheet { overflow: hidden; }

/* navegación (sidebar y hoja "Más") */
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group + .nav-group { margin-top: 18px; }
.nav-title { padding: 0 10px 6px; font-size: 11.5px; font-weight: 500; color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  min-height: 44px; padding: 0 10px; border-radius: var(--radius-sm);
  color: var(--text-2); font-size: 14.5px; font-weight: 500; text-decoration: none !important;
}
.nav-link .icon { color: var(--text-3); }
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.is-active { background: var(--primary-soft); color: var(--primary-text); }
.nav-link.is-active .icon { color: var(--primary-text); }
.nav-link > span:not(.nav-tag) { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-link .nav-tag { flex: none; white-space: nowrap; margin-left: auto; font-size: 11px; font-weight: 500; color: var(--text-3); border: 1px solid var(--border); border-radius: 999px; padding: 1px 7px; }

/* ---------- lists & tables ---------- */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-top: 1px solid var(--border); min-width: 0; }
.list-item:first-child { border-top: 0; }
.list-item-main { flex: 1; min-width: 0; }
.list-item-title { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.list-item-meta { font-size: 13.5px; color: var(--text-2); margin-top: 3px; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.list-item-actions { display: flex; align-items: center; gap: 4px; flex: none; }

.table-wrap { width: 100%; overflow-x: auto; }
@media (min-width: 768px) and (max-width: 1199.98px) { .table .col-optional { display: none; } }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-weight: 500; font-size: 12.5px; color: var(--text-3); padding: 10px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; }
/* En móvil las filas se apilan: cada celda muestra su etiqueta (data-label). */
@media (max-width: 767.98px) {
  .table thead { display: none; }
  .table, .table tbody { display: block; width: 100%; }
  .table tr { display: block; }
  .table tr { padding: 12px 16px; border-bottom: 1px solid var(--border); }
  .table tr:last-child { border-bottom: 0; }
  .table td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; align-items: center; gap: 16px; text-align: right; min-width: 0; flex-wrap: wrap; }
  .table td::before { content: attr(data-label); color: var(--text-3); font-size: 13px; text-align: left; }
  .table td.cell-primary { font-weight: 600; font-size: 15px; text-align: left; padding-bottom: 6px; }
  .table td.cell-primary::before { display: none; }
}

/* ---------- empty state ---------- */
.empty { text-align: center; padding: 48px 20px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.empty-icon { width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-2); color: var(--text-2); margin-bottom: 10px; }
.empty-icon .icon { width: 24px; height: 24px; }
.empty h2 { font-size: 16px; }
.empty p { color: var(--text-2); max-width: 380px; font-size: 14.5px; }
.empty .btn { margin-top: 14px; }

/* ---------- checklist (dashboard) ---------- */
.steps { list-style: none; margin: 0; padding: 0; }
.step { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-top: 1px solid var(--border); }
.step:first-child { border-top: 0; }
.step-dot { width: 26px; height: 26px; border-radius: 50%; border: 1.5px dashed var(--border-strong); display: grid; place-items: center; flex: none; color: var(--text-3); }
.step.is-done .step-dot { border: 0; background: var(--primary); color: var(--on-primary); }
.step.is-done .step-dot .icon { width: 15px; height: 15px; }
.step-body { flex: 1; min-width: 0; }
.step-title { font-weight: 500; font-size: 14.5px; }
.step.is-done .step-title { color: var(--text-2); }
.step-hint { font-size: 13px; color: var(--text-3); margin-top: 2px; }

.kv { display: grid; grid-template-columns: 1fr; gap: 14px; }
.kv-item dt { font-size: 12.5px; color: var(--text-3); }
.kv-item dd { margin: 2px 0 0; font-weight: 500; font-size: 14.5px; overflow-wrap: anywhere; }

.dash-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }

/* ---------- settings tabs ---------- */
.subnav { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.subnav::-webkit-scrollbar { display: none; }
.subnav a { padding: 10px 12px; font-size: 14.5px; font-weight: 500; color: var(--text-2); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; text-decoration: none; }
.subnav a:hover { color: var(--text); }
.subnav a.is-active { color: var(--text); border-bottom-color: var(--primary); }

/* ---------- 2FA ---------- */
.qr-box { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 20px; background: var(--surface-2); border-radius: var(--radius); }
.qr-box .qr { background: #fff; padding: 10px; border-radius: 8px; width: 196px; height: 196px; }
.qr-box .qr svg, .qr-box .qr img { width: 100%; height: 100%; }
.secret { font-family: var(--mono); font-size: 14px; letter-spacing: .06em; word-break: break-all; text-align: center; color: var(--text); background: var(--surface); padding: 8px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.codes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 16px; background: var(--surface-2); border-radius: var(--radius); font-family: var(--mono); font-size: 14.5px; text-align: center; }
.status-line { display: flex; align-items: center; gap: 10px; }

/* ---------- toasts ---------- */
.toasts { position: fixed; z-index: 100; left: 12px; right: 12px; bottom: calc(var(--bottombar-h) + env(safe-area-inset-bottom) + 12px); display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.auth-body .toasts { bottom: 16px; }
.toast {
  pointer-events: auto; display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px; border-radius: var(--radius); font-size: 14px;
  background: var(--text); color: var(--bg); box-shadow: var(--shadow-pop);
  animation: toast-in .2s ease-out;
}
.toast .icon { margin-top: 1px; }
.toast.is-error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- error page ---------- */
.error-page { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; text-align: center; }
.error-code { font-size: 13px; font-weight: 600; color: var(--primary-text); letter-spacing: .08em; }
.error-page h1 { margin: 8px 0; font-size: 24px; }
.error-page p { color: var(--text-2); max-width: 420px; margin: 0 auto 20px; }

/* ---------- control segmentado (tema, tipo de movimiento) ---------- */
.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); max-width: 100%; }
.segmented button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex: 1 1 0; min-width: 0;
  min-height: 38px; padding: 0 12px; border: 0; border-radius: 7px; background: transparent;
  color: var(--text-2); font-size: 14px; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); border: 1px solid var(--border); }
.segmented-block { display: flex; width: 100%; }
.segmented-icons button { padding: 0 10px; min-height: 32px; }
.menu .segmented { width: 100%; }
.menu-pad { padding: 2px 4px 6px; }
.auth-footer { align-items: center; }
.menu .segmented button { min-height: 34px; font-size: 13px; }
.auth-footer .segmented button { min-height: 30px; padding: 0 8px; }

/* ---------- barra de filtros ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.toolbar .search { position: relative; flex: 1 1 100%; min-width: 0; }
.toolbar .search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.toolbar .search .input { padding-left: 38px; }
.toolbar .select { flex: 1 1 140px; width: auto; min-width: 0; }
.toolbar .check-chip { flex: 0 0 auto; }
.toolbar .select-like { flex: 1 1 140px; min-width: 0; }
.toolbar .select-like { display: block; }
.toolbar input[type="date"] { display: block; width: 100%; min-width: 0; max-width: 100%; }

.check-chip { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); font-size: 14px; cursor: pointer; user-select: none; }
.check-chip input { width: 16px; height: 16px; accent-color: var(--primary); margin: 0; }
.check-chip:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-text); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { min-height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); font-size: 13px; cursor: pointer; }
.chip:hover { color: var(--text); border-color: var(--text-3); }
.chip.is-active { border-color: var(--primary); color: var(--primary-text); background: var(--primary-soft); }

/* ---------- estadísticas compactas ---------- */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat { padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); min-width: 0; }
.stat-label { font-size: 12.5px; line-height: 1.3; color: var(--text-3); overflow-wrap: anywhere; }
.stat-value { font-size: 22px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat.is-warning .stat-value { color: var(--warning); }
.stat.is-danger .stat-value { color: var(--danger); }
a.stat { color: inherit; text-decoration: none; }
a.stat:hover { border-color: var(--border-strong); }

/* ---------- productos ---------- */
.thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--surface-2); border: 1px solid var(--border); flex: none; display: grid; place-items: center; color: var(--text-3); font-weight: 600; font-size: 14px; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.cell-product { display: flex; align-items: center; gap: 12px; min-width: 0; }
.cell-product .name { font-weight: 600; overflow-wrap: anywhere; }
.cell-product .name, .cell-product .sku { display: block; }
.cell-product .sku { font-size: 12.5px; color: var(--text-3); font-family: var(--mono); }
.qty { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.qty-unit { font-weight: 400; color: var(--text-3); font-size: 12.5px; margin-left: 3px; }
.qty-in { color: var(--primary-text); }
.qty-out { color: var(--danger); }
.row-muted { opacity: .62; }
.row-actions { display: inline-flex; gap: 6px; justify-content: flex-end; }
#movement-form .search { position: relative; display: block; }
#movement-form .search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
#movement-form .search .input { padding-left: 38px; }
.result-btn { width: 100%; background: none; border: 0; text-align: left; cursor: pointer; color: inherit; font: inherit; }
.result-btn:hover, .result-btn:focus-visible { background: var(--surface-hover); outline: none; }

.image-field { display: flex; align-items: center; gap: 16px; }
.image-preview { width: 96px; height: 96px; border-radius: var(--radius); border: 1px dashed var(--border-strong); background: var(--surface-2); display: grid; place-items: center; color: var(--text-3); overflow: hidden; flex: none; }
.image-preview img { width: 100%; height: 100%; object-fit: cover; }
.image-preview.has-image { border-style: solid; }
.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.store-checks { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.store-check { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--border); min-height: 56px; }
.store-check:first-child { border-top: 0; }
.store-check input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); flex: none; margin: 0; }
.store-check label { flex: 1; min-width: 0; font-weight: 500; cursor: pointer; overflow-wrap: anywhere; }
.store-check .input { width: 96px; min-height: 40px; flex: none; text-align: right; }
.store-check .stock-readonly { font-size: 14px; color: var(--text-2); }

/* ---------- paginación ---------- */
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); font-size: 13.5px; color: var(--text-2); }
.pagination .row { gap: 6px; }

/* ---------- navegación: contador ---------- */
.nav-count { margin-left: auto; min-width: 22px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--warning-soft); color: var(--warning); font-size: 11.5px; font-weight: 600; display: inline-grid; place-items: center; font-variant-numeric: tabular-nums; }
.tab { position: relative; }
.tab .tab-dot { position: absolute; top: 8px; left: calc(50% + 6px); width: 8px; height: 8px; border-radius: 50%; background: var(--warning); border: 2px solid var(--surface); }
.switcher-store { color: var(--text-2); }

.list-item-link { color: inherit; text-decoration: none !important; }
.list-item-link:hover { background: var(--surface-hover); }

/* ---------- Fase 3: utilidades ---------- */
.btn-lg { min-height: 52px; font-size: 16px; font-weight: 600; }
.page-note { margin-top: 12px; }
.hint.block { display: block; font-weight: 400; }
.pay-error:not(:empty) { display: block; }
.mono-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-family: var(--mono); letter-spacing: 0; }
.mono-title .badge { font-family: var(--font); }
.check-row { display: flex; align-items: flex-start; gap: 10px; font-size: 14.5px; cursor: pointer; }
.check-row input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--primary); flex: none; }
.check-row .hint { display: block; margin-top: 2px; }
.seg-link { display: inline-flex; align-items: center; justify-content: center; min-height: 38px; padding: 0 12px; border-radius: 7px; color: var(--text-2); font-size: 14px; font-weight: 500; text-decoration: none !important; white-space: nowrap; border: 1px solid transparent; }
.seg-link[aria-checked="true"] { background: var(--surface); color: var(--text); border-color: var(--border); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.toolbar .segmented { flex: 0 1 auto; overflow-x: auto; }
.date-chip { width: 48px; flex: none; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); text-align: center; padding: 5px 0; line-height: 1.1; }
.date-chip-day { display: block; font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.date-chip-month { display: block; font-size: 11px; font-weight: 600; color: var(--primary-text); letter-spacing: .04em; }
.stats-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stats-flush { margin-bottom: 0; }
.stats .stat-value { overflow-wrap: anywhere; }
.method-strip { display: flex; flex-wrap: wrap; gap: 6px; margin: -6px 0 16px; }
.day-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; flex: 1 1 100%; min-width: 0; }
.day-nav .select-like { flex: 1 1 140px; min-width: 0; }
.totals { margin: 0; display: flex; flex-direction: column; gap: 6px; }
.totals div { display: flex; justify-content: space-between; gap: 12px; font-size: 14.5px; }
.totals dt { color: var(--text-2); }
.totals dd { margin: 0; font-variant-numeric: tabular-nums; }
.totals .totals-main { font-size: 17px; font-weight: 700; padding-top: 8px; border-top: 1px solid var(--border); }
.totals .totals-main dt { color: var(--text); }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper .input { text-align: center; font-size: 20px; font-weight: 600; }
.stepper-sm { gap: 6px; flex: none; }
.stepper-sm .num { min-width: 22px; text-align: center; font-weight: 600; }

/* ---------- POS ---------- */
.content.content-pos { max-width: none; padding: 0; }
.pos { display: block; min-height: calc(100dvh - var(--topbar-h)); }
.pos-main { padding: 0 12px 120px; min-width: 0; }
.pos-bar { position: sticky; top: var(--topbar-h); z-index: 20; background: var(--bg); padding: 10px 0 8px; display: flex; flex-direction: column; gap: 8px; }
.pos-bar .row { gap: 10px; min-width: 0; }
.pos-bar .row > .subtle { display: inline-flex; align-items: center; gap: 4px; min-width: 0; }
.pos-market { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; max-width: 70%; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: 999px; background: var(--surface); color: var(--text); font-size: 13.5px; font-weight: 500; cursor: pointer; }
.pos-bar .search { position: relative; display: block; }
.pos-bar .search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.pos-bar .search .input { padding-left: 38px; min-height: 48px; font-size: 16px; }
.pos-cats { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.pos-cats::-webkit-scrollbar { display: none; }
.pos-cats .chip { flex: none; min-height: 36px; }
.pos-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.pos-tile {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; min-width: 0;
  padding: 10px; min-height: 148px; border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface); color: var(--text); text-align: left; cursor: pointer; font: inherit;
  transition: border-color .15s, transform .08s; -webkit-tap-highlight-color: transparent;
}
.pos-tile:hover { border-color: var(--border-strong); }
.pos-tile:active { transform: scale(.98); }
.pos-tile:disabled { opacity: .5; cursor: not-allowed; }
.pos-tile .thumb { width: 100%; height: 72px; border-radius: 8px; font-size: 22px; }
.pos-tile-name { font-weight: 600; font-size: 14px; line-height: 1.25; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pos-tile-price { font-size: 14px; font-weight: 600; color: var(--primary-text); }
.pos-tile-stock { font-size: 12px; color: var(--text-3); margin-top: auto; }
.pos-tile-qty { position: absolute; top: 6px; right: 6px; min-width: 26px; height: 26px; padding: 0 7px; border-radius: 999px; background: var(--primary); color: var(--on-primary); font-size: 13px; font-weight: 700; display: grid; place-items: center; z-index: 1; }
.pos-tile.is-bump { animation: bump .25s ease-out; }
@keyframes bump { 50% { transform: scale(.96); border-color: var(--primary); } }

.pos-cartbar {
  position: fixed; z-index: 35; left: 12px; right: 12px; bottom: calc(var(--bottombar-h) + env(safe-area-inset-bottom) + 10px);
  display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 0 16px;
  border: 0; border-radius: 14px; background: var(--primary); color: var(--on-primary); font: 600 15px var(--font);
  box-shadow: 0 6px 20px rgba(47, 125, 79, .35); cursor: pointer;
}
.pos-cartbar-count { min-width: 28px; height: 28px; padding: 0 8px; border-radius: 999px; background: rgba(255, 255, 255, .22); display: grid; place-items: center; }
.pos-cart {
  position: fixed; z-index: 70; inset: 0; display: flex; flex-direction: column;
  background: var(--surface); transform: translateY(100%); transition: transform .25s cubic-bezier(.2, .8, .2, 1);
  padding-bottom: env(safe-area-inset-bottom);
}
.pos-cart.is-open { transform: none; }
.pos-cart-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.pos-cart-head h2 { flex: 1; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.pos-lines { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.pos-cart-empty { padding: 32px 16px; text-align: center; }
.pos-line { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.pos-line-info { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 0; color: inherit; font: inherit; cursor: pointer; }
.pos-line-name { display: block; font-weight: 600; font-size: 14.5px; overflow-wrap: anywhere; }
.pos-line-meta { display: block; font-size: 12.5px; color: var(--text-3); }
.pos-line-total { font-weight: 600; white-space: nowrap; }
.pos-totals { padding: 12px 14px 14px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; background: var(--surface); }
.pos-totals dl { margin: 0; display: flex; flex-direction: column; gap: 4px; }
.pos-totals dl div { display: flex; justify-content: space-between; font-size: 14px; color: var(--text-2); }
.pos-totals dd { margin: 0; font-variant-numeric: tabular-nums; }
.pos-totals .pos-total { font-size: 19px; font-weight: 700; color: var(--text); padding-top: 4px; }
.pay-total { font-size: 26px; font-weight: 700; color: var(--text) !important; letter-spacing: -.02em; }
.pay-rows { display: flex; flex-direction: column; gap: 12px; }
.pay-row { display: flex; flex-direction: column; gap: 8px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); }
.pay-row-top { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.pay-row > .btn-ghost { align-self: flex-start; }
.pay-summary { margin: 0; display: flex; flex-direction: column; gap: 4px; }
.pay-summary div { display: flex; justify-content: space-between; font-size: 15px; }
.pay-summary dd { margin: 0; font-weight: 700; }
.done-total { font-size: 30px; font-weight: 700; margin-top: 6px; }
.done-change { font-size: 17px; margin-top: 4px; }

@media (min-width: 480px) {
  .pos-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stats-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (min-width: 768px) {
  .pos-main { padding: 0 24px 120px; }
  .pos-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .day-nav { flex: 1 1 auto; }
  .pos-cart { left: auto; width: 420px; border-left: 1px solid var(--border); box-shadow: var(--shadow-sheet); }
  .pos-cartbar { left: auto; width: 380px; }
}
@media (min-width: 1024px) {
  .pos { display: grid; grid-template-columns: minmax(0, 1fr) 380px; }
  .pos-main { padding: 0 24px 32px; }
  .pos-bar { top: var(--topbar-h); }
  .pos-cart { position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h)); transform: none; inset: auto; width: auto; box-shadow: none; z-index: 1; }
  .pos-cart-close, .pos-cartbar { display: none !important; }
}
@media (min-width: 1366px) {
  .pos { grid-template-columns: minmax(0, 1fr) 420px; }
  .pos-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}

/* ==========================================================================
   ≥ 480px: teléfonos grandes
   ========================================================================== */
@media (min-width: 480px) {
  .form-actions { flex-direction: row; justify-content: flex-end; }
  .form-actions .btn { min-width: 140px; }
  .sheet-actions { flex-direction: row; justify-content: flex-end; }
  .codes { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page-header .page-actions .btn { flex: 0 0 auto; }
  .toolbar .search { flex: 1 1 240px; }
}

/* ==========================================================================
   ≥ 768px: tablets
   ========================================================================== */
@media (min-width: 768px) {
  h1, .page-header h1 { font-size: 26px; }
  .auth-main { align-items: center; padding: 48px 24px; }
  .auth-card.is-boxed { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 36px 36px 32px; }
  .content { padding: 28px 28px 40px; }
  .page-header { flex-direction: row; align-items: flex-end; justify-content: space-between; }
  .form-grid.cols-2 { grid-template-columns: 1fr 1fr; }
  .form-grid .span-2 { grid-column: span 2; }
  .form-section { grid-template-columns: 1fr; gap: 16px; padding: 28px 0; }
  .panel-body { padding: 24px; }
  .panel-head { padding: 22px 24px 0; }
  .list-item { padding: 16px 24px; }
  .step { padding: 14px 24px; }
  .kv { grid-template-columns: 1fr 1fr; }
  .codes { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .btn { min-height: 40px; font-size: 14.5px; }
  .btn-icon { width: 40px; }
  .input, .select { min-height: 42px; font-size: 15px; }
  .toasts { left: auto; right: 20px; width: 380px; }
  .switcher-meta { display: block; }
  .store-pill { display: inline-flex; }

  /* La hoja pasa a ser un diálogo centrado */
  .sheet {
    left: 50%; right: auto; bottom: auto; top: 50%; width: min(520px, calc(100vw - 48px));
    border-radius: var(--radius-lg); padding: 24px;
    transform: translate(-50%, -46%); opacity: 0; transition: transform .2s, opacity .2s;
  }
  .sheet.is-open { transform: translate(-50%, -50%); opacity: 1; }
  .sheet-handle { display: none; }
}

/* ==========================================================================
   ≥ 1024px: escritorio con navegación lateral
   ========================================================================== */
@media (min-width: 1024px) {
  .app-body { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .sidebar {
    display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh;
    background: var(--surface); border-right: 1px solid var(--border);
  }
  .sidebar-head { padding: 12px 12px 10px; border-bottom: 1px solid var(--border); }
  .sidebar-head .switcher { width: 100%; }
  .sidebar-nav { flex: 1; overflow-y: auto; padding: 16px 12px; }
  .sidebar-foot { padding: 12px; border-top: 1px solid var(--border); }
  .sidebar .nav-link { min-height: 38px; font-size: 14px; }
  .sidebar .menu { left: 0; right: 0; min-width: 0; }
  .app-main { padding-bottom: 0; }
  .bottombar, .topbar .mobile-only { display: none; }
  .topbar { padding: 0 24px; }
  .topbar-title { display: block; }
  .content { padding: 32px 40px 48px; }
  .toasts { bottom: 20px; }
  .dash-grid { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); align-items: start; }
}

@media (min-width: 1200px) {
  .form-section { grid-template-columns: 200px 1fr; gap: 32px; }
  .dash-grid .form-section { grid-template-columns: 1fr; gap: 16px; }
}

@media (min-width: 1366px) {
  .content { padding: 36px 48px 56px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media print {
  .sidebar, .topbar, .bottombar, .toasts { display: none !important; }
  body { background: #fff; }
}

/* ==========================================================================
   Fase 4: ingresos, gastos, pagos y contabilidad
   ========================================================================== */
.period { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; flex: 1 1 100%; min-width: 0; }
.period .segmented { flex: 0 1 auto; overflow-x: auto; scrollbar-width: none; }
.period .segmented::-webkit-scrollbar { display: none; }
.period-range { display: flex; align-items: center; gap: 6px; flex: 1 1 260px; min-width: 0; }
.period-range .select-like { flex: 1 1 0; min-width: 0; display: block; }
.period-range input[type="date"] { display: block; width: 100%; min-width: 0; max-width: 100%; }
.stat-value-sm { font-size: 17px; line-height: 1.3; }
.stat-meta { font-size: 13px; color: var(--text-2); margin-top: 2px; font-variant-numeric: tabular-nums; }
.link-row { appearance: none; background: none; border: 0; padding: 0; margin: 0; font: inherit; color: var(--text); text-align: left; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; max-width: 100%; }
.link-row:hover .link-row-title, .link-row:focus-visible .link-row-title { text-decoration: underline; }
.link-row-title { font-weight: 600; overflow-wrap: anywhere; color: inherit; }
a.link-row-title { color: var(--text); }
.cell-sub { display: block; font-size: 13px; color: var(--text-2); font-weight: 400; margin-top: 2px; overflow-wrap: anywhere; }
.cell-stack .badge { vertical-align: middle; }
.nowrap { white-space: nowrap; }
.strike { text-decoration: line-through; }
.fieldset-plain { border: 0; padding: 0; margin: 0; min-width: 0; display: flex; flex-direction: column; gap: 18px; }
.fieldset-plain > legend { padding: 0; margin-bottom: 8px; }
fieldset.field.fieldset-plain { gap: 10px; }
.input-lg { font-size: 20px; font-weight: 600; min-height: 52px; }
.receipt-box { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); min-width: 0; }
.receipt-box a { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-pick { position: relative; display: flex; align-items: center; gap: 8px; min-height: 46px; padding: 0 12px; border: 1px dashed var(--border-strong); border-radius: var(--radius); color: var(--text-2); cursor: pointer; min-width: 0; font-size: 14.5px; }
.file-pick span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.file-pick input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.file-pick:focus-within { outline: 2px solid var(--primary); outline-offset: 2px; }
.file-pick[hidden], .receipt-box[hidden] { display: none; }
.btn-danger-text { color: var(--danger); }
.statement .is-sub dt { padding-left: 12px; }
.statement .is-subtotal { font-weight: 600; padding-top: 6px; border-top: 1px dashed var(--border); }
.statement dd { text-align: right; }
.converted { display: block; font-size: 12.5px; color: var(--text-3); font-weight: 400; }
.consolidated-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.panel-gap { margin-top: 16px; }
.page-note-top { margin: -6px 0 14px; }
.alert.page-note { margin-top: 16px; }
.table-compact td { padding-top: 9px; padding-bottom: 9px; }
.input-affix { display: flex; align-items: stretch; min-width: 0; }
.input-affix .input { flex: 1 1 auto; min-width: 0; border-radius: 0; }
.input-affix .affix { display: flex; align-items: center; padding: 0 10px; background: var(--surface-2); border: 1px solid var(--border-strong); color: var(--text-2); font-size: 14px; white-space: nowrap; }
.input-affix .affix:first-child { border-right: 0; border-radius: var(--radius) 0 0 var(--radius); }
.input-affix .affix:last-child { border-left: 0; border-radius: 0 var(--radius) var(--radius) 0; }
@media (max-width: 767.98px) {
  .table td.cell-stack { display: block; text-align: left; }
}
@media (min-width: 480px) {
  .sheet-actions .btn-danger-text { margin-right: auto; }
}
@media (min-width: 1024px) {
  .consolidated-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dash-grid.dash-grid-even { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.statement div > dt { min-width: 0; }
.statement dd { white-space: nowrap; }
.stats-fin { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stats-fin .stat:first-child { grid-column: span 2; }
@media (max-width: 767.98px) {
  .table-lead tr { display: flex; flex-direction: column; }
  .table-lead td.cell-primary { order: -1; }
  .table .col-desktop { display: none; }
}
@media (min-width: 480px) {
  .stats-fin { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stats-fin .stat:first-child { grid-column: auto; }
}
@media (min-width: 1024px) {
  .period { flex: 0 1 auto; }
  .period-range { flex: 0 1 340px; }
  .toolbar .period ~ .select { flex: 1 1 160px; }
}

/* ==========================================================================
   Fase 5: dashboard, reportes y exportaciones
   ========================================================================== */
.page-section { margin-bottom: 16px; }
.stat-sub { font-size: 12.5px; line-height: 1.35; color: var(--text-3); margin-top: 4px; overflow-wrap: anywhere; }
.stat-value.subtle { color: var(--text-3); }
.stat.is-danger .stat-sub { color: var(--text-3); }
.strong { font-weight: 600; }

.dash-panels { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
.chart-box { position: relative; width: 100%; height: 220px; }
.chart-box canvas { display: block; }
.chart-box-h { height: auto; min-height: 96px; }
.chart-table { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 10px; }
.chart-table summary { cursor: pointer; font-size: 13.5px; font-weight: 500; color: var(--text-2); padding: 4px 0; width: fit-content; }
.chart-table summary:hover { color: var(--text); }
.chart-table .table-wrap { margin-top: 6px; }
.chart-table .table td, .chart-table .table th { padding-left: 0; }

.rank-list { list-style: none; margin: 0; padding: 0; }
.rank-list .list-item { gap: 12px; }
.rank-list .num.strong { white-space: nowrap; flex: none; }
.rank-num { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--surface-2); color: var(--text-2); font-size: 12px; font-weight: 600; }
.empty-inline { color: var(--text-3); font-size: 14px; margin: 0; }
.panel-foot { padding: 8px 10px 10px; border-top: 1px solid var(--border); }

.report-groups { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
.list-link { color: inherit; }
.list-link:hover { background: var(--surface-hover); text-decoration: none; }
.list-link:last-child { border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.list-icon { width: 36px; height: 36px; flex: none; display: grid; place-items: center; border-radius: var(--radius); background: var(--primary-soft); color: var(--primary-text); }
.list-icon .icon { width: 18px; height: 18px; }

.table-report th, .table-report td { white-space: nowrap; }
.table-report td.cell-wrap { white-space: normal; min-width: 200px; max-width: 340px; overflow-wrap: break-word; }
@media (min-width: 768px) { .table-report { width: max-content; min-width: 100%; } }
.table-report tr.is-voided td { color: var(--text-3); }
.table-report tr.is-voided td.qty-out { color: var(--text-3); }
.table-report .table-total td { font-weight: 600; background: var(--surface-2); border-top: 1px solid var(--border-strong); border-bottom: 0; }

@media (max-width: 767.98px) {
  .table-report tr { display: flex; flex-direction: column; }
  .table-report td, .table-report td.cell-wrap { max-width: none; min-width: 0; white-space: normal; overflow-wrap: anywhere; }
  .table-report td.cell-primary { order: -1; }
  .table-report td.is-empty { display: none; }
  .table-report tfoot { display: block; }
  .table-report .table-total { background: var(--surface-2); }
  .table-report .table-total td { background: transparent; border-top: 0; }
}
@media (min-width: 768px) {
  .chart-box { height: 260px; }
  .chart-box-h { height: auto; }
}
@media (min-width: 1024px) {
  .dash-panels, .report-groups { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 374.98px) {
  .stats-4 .stat-value { font-size: 19px; }
}
@media (min-width: 1024px) {
  /* El período no se parte en dos líneas y los selectores no se estiran a su alto. */
  .toolbar .period { flex-wrap: nowrap; }
  .toolbar .period ~ .select { align-self: center; }
}
/* En las rejillas el espacio lo da el gap; sin margen extra entre paneles vecinos. */
.dash-panels > .panel + .panel, .report-groups > .panel + .panel { margin-top: 0; }
