/* ============================================================
   Tokens
   ============================================================ */
:root {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --surface-2: #e9e9ef;
  --text: #0b0b0f;
  --text-2: #6b6b76;
  --text-3: #a1a1aa;
  --sep: rgba(60, 60, 67, 0.16);
  --accent: #2457f5;
  --accent-press: #1c45c9;
  --accent-soft: rgba(36, 87, 245, 0.12);
  --danger: #e5322d;
  --warn: #d97706;
  --ok: #16a34a;
  --bar: rgba(242, 242, 247, 0.82);
  --tabbar: rgba(249, 249, 251, 0.86);
  --press: rgba(0, 0, 0, 0.055);
  --shadow-layer: -10px 0 30px rgba(0, 0, 0, 0.10);
  --clear-x: #f2f2f7;

  /* status colors: fg / bg */
  --st-nuevo: #a16207;      --st-nuevo-bg: #fef3c7;
  --st-sin: #52525b;        --st-sin-bg: #ececf0;
  --st-aproc: #1d4ed8;      --st-aproc-bg: #dbe6ff;
  --st-proc: #0f766e;       --st-proc-bg: #d5f3ee;
  --st-ganado: #15803d;     --st-ganado-bg: #d9f7e1;
  --st-perdido: #b91c1c;    --st-perdido-bg: #fde0e0;
  --st-noproc: #6b6b76;     --st-noproc-bg: #ececf0;
  --st-noprocdo: #7e22ce;   --st-noprocdo-bg: #f1e5fc;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --tabbar-h: 54px;
  --navbar-h: 48px;
  --radius: 14px;
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, "Roboto Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --text: #f5f5f7;
    --text-2: #98989f;
    --text-3: #636366;
    --sep: rgba(84, 84, 88, 0.6);
    --accent: #5b8cff;
    --accent-press: #7aa2ff;
    --accent-soft: rgba(91, 140, 255, 0.18);
    --danger: #ff5a52;
    --warn: #fbbf24;
    --ok: #34d058;
    --bar: rgba(0, 0, 0, 0.78);
    --tabbar: rgba(22, 22, 24, 0.86);
    --press: rgba(255, 255, 255, 0.07);
    --shadow-layer: -10px 0 30px rgba(0, 0, 0, 0.5);
    --clear-x: #1c1c1e;

    --st-nuevo: #fcd34d;      --st-nuevo-bg: rgba(252, 211, 77, 0.16);
    --st-sin: #c7c7cc;        --st-sin-bg: rgba(199, 199, 204, 0.14);
    --st-aproc: #93b4ff;      --st-aproc-bg: rgba(91, 140, 255, 0.2);
    --st-proc: #5eead4;       --st-proc-bg: rgba(94, 234, 212, 0.15);
    --st-ganado: #4ade80;     --st-ganado-bg: rgba(74, 222, 128, 0.16);
    --st-perdido: #fca5a5;    --st-perdido-bg: rgba(248, 113, 113, 0.18);
    --st-noproc: #a1a1aa;     --st-noproc-bg: rgba(161, 161, 170, 0.14);
    --st-noprocdo: #d8b4fe;   --st-noprocdo-bg: rgba(216, 180, 254, 0.16);
    color-scheme: dark;
  }
}

/* ============================================================
   Base: behave like an app, not a web page
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }
html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior-y: none;          /* custom pull-to-refresh instead of rubber band */
  -webkit-tap-highlight-color: transparent;
}
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 400 17px/1.35 var(--font);
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  touch-action: manipulation;
}
button, input, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { background: none; border: 0; padding: 0; margin: 0; cursor: pointer; text-align: inherit; touch-action: manipulation; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin: 0; }
button, .row, .tab, .chip, .kv, .file, .option, summary, .navbar { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.icon { flex: none; display: block; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }

/* Keep content readable on tablets/desktop */
.main, .detail-content, .login-card { max-width: 760px; margin-left: auto; margin-right: auto; }

/* ============================================================
   Shell
   ============================================================ */
.statusbar-bg {
  position: fixed; top: 0; left: 0; right: 0; height: var(--safe-top); z-index: 15;
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
}
.main {
  padding: 0 calc(16px + var(--safe-right)) calc(var(--tabbar-h) + var(--safe-bottom) + 24px) calc(16px + var(--safe-left));
  padding-top: var(--safe-top);
  transition: transform 380ms var(--ease);
}
body.pushed .main, body.pushed .tabbar { transform: translateX(-28%); }
body.detail-shown .main { pointer-events: none; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  background: var(--tabbar);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--sep);
  transition: transform 380ms var(--ease);
}
.tab {
  flex: 1; max-width: 180px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--text-3);
  transition: color 0.15s;
}
.tab.active { color: var(--accent); }
.tab:active .tab-icon { transform: scale(0.88); }
.tab-icon { position: relative; transition: transform 0.12s; }
.tab-label { font-size: 10.5px; font-weight: 600; letter-spacing: 0.01em; }
.badge {
  position: absolute; top: -4px; left: 15px;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
  box-shadow: 0 0 0 2px var(--tabbar);
}
.badge-dot {
  position: absolute; top: -1px; right: -3px; width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 2px var(--surface);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.35; } }

.scrim {
  position: fixed; inset: 0; z-index: 18; pointer-events: none;
  background: rgba(0, 0, 0, 0.16); opacity: 0;
  transition: opacity 380ms var(--ease);
}
body.pushed .scrim { opacity: 1; }

/* ============================================================
   Headers / toolbar
   ============================================================ */
.large-title { padding: 14px 4px 10px; }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.header-logo { display: block; width: 92px; height: auto; flex: none; margin-right: 2px; }
.large-title h1 { font-size: 34px; font-weight: 750; letter-spacing: -0.025em; line-height: 1.1; }
.subtitle { margin-top: 2px; color: var(--text-2); font-size: 15px; }

.toolbar {
  position: sticky; top: var(--safe-top); z-index: 5;
  margin: 0 -16px; padding: 8px 16px 10px;
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
}
.search {
  display: flex; align-items: center; gap: 6px;
  height: 38px; padding: 0 8px 0 10px; border-radius: 11px;
  background: var(--surface-2); color: var(--text-2);
}
.search input {
  flex: 1; min-width: 0; height: 100%;
  border: 0; outline: 0; background: transparent; color: var(--text);
  font-size: 17px;                       /* >=16px: iOS won't zoom on focus */
  -webkit-appearance: none; appearance: none;
}
.search input::placeholder { color: var(--text-2); }
.search input::-webkit-search-cancel-button { display: none; }
.search-clear { color: var(--text-3); display: grid; place-items: center; width: 28px; height: 28px; }

.chips {
  display: flex; gap: 8px; margin: 10px -16px 0; padding: 0 16px;
  overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px; border-radius: 16px;
  background: var(--surface); color: var(--text);
  font-size: 15px; font-weight: 550;
  box-shadow: inset 0 0 0 0.5px var(--sep);
  transition: background 0.15s, color 0.15s, transform 0.1s;
}
.chip:active { transform: scale(0.96); }
.chip.on { background: var(--text); color: var(--bg); box-shadow: none; }
.chip-count { font-size: 13px; font-weight: 600; opacity: 0.55; font-variant-numeric: tabular-nums; }

/* ============================================================
   Banners
   ============================================================ */
.banner {
  display: flex; align-items: center; gap: 10px; width: 100%;
  margin: 10px 0 0; padding: 11px 14px; border-radius: 12px;
  font-size: 14px; font-weight: 550;
}
.banner.offline { background: var(--surface-2); color: var(--text-2); justify-content: center; }
.banner.running { background: var(--accent-soft); color: var(--accent); }
.banner.running:active { opacity: 0.7; }
.banner.error { background: var(--st-perdido-bg); color: var(--st-perdido); font-weight: 500; }
.banner.inset { margin: 12px 16px 0; width: auto; }
.banner-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.banner .muted { color: inherit; opacity: 0.75; font-weight: 450; }

/* ============================================================
   Grouped lists
   ============================================================ */
.section { margin-top: 18px; }
.section-title, .group-title {
  display: flex; align-items: baseline; gap: 6px;
  padding: 0 4px 7px;
  font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-2);
}
.section-title span, .group-title span:not(.save-state) { color: var(--text-3); font-weight: 600; }
.group-title { margin-top: 26px; }
.group {
  background: var(--surface); border-radius: var(--radius); overflow: hidden;
}
.group > * + * { box-shadow: inset 0 0.5px 0 var(--sep); }
.group-note { padding: 7px 16px 0; font-size: 13px; color: var(--text-2); line-height: 1.4; }

.row {
  position: relative; display: block; width: 100%;
  padding: 12px 16px 13px 18px;
  transition: background 0.12s;
}
.row:active { background: var(--press); transition: none; }
.unread {
  position: absolute; left: 6px; top: 19px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
}
.row-top { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; min-height: 22px; }
.row-title {
  font-size: 16px; font-weight: 590; line-height: 1.3; letter-spacing: -0.012em;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.row-sub { display: flex; gap: 10px; margin-top: 4px; font-size: 14px; color: var(--text-2); }
.row-sub .ellipsis { flex: 1; }
.row-money { flex: none; font-variant-numeric: tabular-nums; color: var(--text); font-weight: 500; }
.row-note { margin-top: 6px; font-size: 12.5px; color: var(--warn); }

.pill {
  display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 6px;
  font-size: 12.5px; font-weight: 650; letter-spacing: 0;
  color: var(--pill-fg); background: var(--pill-bg);
}
.tag {
  height: 22px; line-height: 22px; padding: 0 7px; border-radius: 6px;
  font-size: 12px; font-weight: 600; color: var(--text-2); box-shadow: inset 0 0 0 1px var(--sep);
}
.when { margin-left: auto; font-size: 13.5px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--text-2); white-space: nowrap; }
.tone-urgent { color: var(--danger); }
.tone-soon { color: var(--warn); }
.tone-past, .tone-none { color: var(--text-3); }

.st-nuevo    { --pill-fg: var(--st-nuevo);    --pill-bg: var(--st-nuevo-bg); }
.st-sin      { --pill-fg: var(--st-sin);      --pill-bg: var(--st-sin-bg); }
.st-aproc    { --pill-fg: var(--st-aproc);    --pill-bg: var(--st-aproc-bg); }
.st-proc     { --pill-fg: var(--st-proc);     --pill-bg: var(--st-proc-bg); }
.st-ganado   { --pill-fg: var(--st-ganado);   --pill-bg: var(--st-ganado-bg); }
.st-perdido  { --pill-fg: var(--st-perdido);  --pill-bg: var(--st-perdido-bg); }
.st-noproc   { --pill-fg: var(--st-noproc);   --pill-bg: var(--st-noproc-bg); }
.st-noprocdo { --pill-fg: var(--st-noprocdo); --pill-bg: var(--st-noprocdo-bg); }

.list-end { height: 8px; }

/* Skeleton */
.skel { pointer-events: none; }
.skel-text, .skel-pill {
  display: block; height: 14px; border-radius: 6px; margin-top: 8px;
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--bg) 50%, var(--surface-2) 100%);
  background-size: 200% 100%; animation: shimmer 1.3s linear infinite;
}
.skel-pill { width: 70px; height: 22px; margin: 0; }
.section-title.skel-text { height: 12px; margin: 0 4px 9px; }
@keyframes shimmer { to { background-position: -200% 0; } }

.empty { padding: 56px 24px; text-align: center; color: var(--text-2); font-size: 15px; line-height: 1.45; }
.empty-title { color: var(--text); font-size: 20px; font-weight: 650; margin-bottom: 6px; }
.empty .btn { margin-top: 18px; }

/* ============================================================
   Key/value rows, links, files
   ============================================================ */
.kv {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 46px;
  padding: 11px 16px; font-size: 16px;
}
.kv .k { flex: 1 0 auto; max-width: 100%; display: flex; flex-direction: column; }
.kv .v { flex: 0 1 auto; min-width: 0; text-align: right; color: var(--text-2); overflow-wrap: anywhere; }
.kv .icon-cell + .k { flex-shrink: 1; min-width: 0; }
.kv .icon:last-child { color: var(--text-3); }
button.kv, a.kv { transition: background 0.12s; }
button.kv:active, a.kv:active { background: var(--press); transition: none; }
.kv.copy .v { color: var(--text); }
.mono { font-family: var(--mono); font-size: 14px; }
.icon-cell { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.icon-cell .icon { width: 19px; height: 19px; }
.danger-text { color: var(--danger); }
.danger-text .icon-cell { background: var(--st-perdido-bg); color: var(--danger); }
.link .k { color: var(--text); }

.file {
  display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 9px 16px; transition: background 0.12s;
}
.file:active { background: var(--press); transition: none; }
.file-ext {
  flex: none; width: 38px; height: 38px; border-radius: 9px; display: grid; place-items: center;
  font-size: 10.5px; font-weight: 800; letter-spacing: 0.02em;
  background: var(--surface-2); color: var(--text-2);
}
.ext-pdf { background: #fde3e1; color: #c2271f; }
.ext-doc { background: #dde8ff; color: #1d4ed8; }
.ext-xls { background: #daf5e2; color: #157f3c; }
@media (prefers-color-scheme: dark) {
  .ext-pdf { background: rgba(255, 90, 82, 0.18); color: #ff8a84; }
  .ext-doc { background: rgba(91, 140, 255, 0.2); color: #93b4ff; }
  .ext-xls { background: rgba(52, 208, 88, 0.18); color: #6ee7a0; }
}
.file-name { flex: 1; min-width: 0; font-size: 15.5px; line-height: 1.3; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.file-size { flex: none; font-size: 13px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.file > .icon { color: var(--text-3); }

/* ============================================================
   Detail (pushed screen)
   ============================================================ */
.detail-layer {
  position: fixed; inset: 0; z-index: 20;
  background: var(--bg);
  box-shadow: var(--shadow-layer);
  transform: translateX(100%);
  transition: transform 380ms var(--ease);
  will-change: transform;
}
.detail-layer.enter { transition: none; }
.detail-layer.open { transform: none; }
.detail-layer.leaving { transform: translateX(100%); }
.detail {
  position: absolute; inset: 0;
  overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
.detail-content {
  min-height: calc(100% + 1px);          /* always scrollable: stops scroll chaining to the page below */
  padding: 0 calc(16px + var(--safe-right)) calc(32px + var(--safe-bottom)) calc(16px + var(--safe-left));
}

.navbar {
  position: sticky; top: 0; z-index: 3;
  display: flex; align-items: center; gap: 4px;
  height: calc(var(--navbar-h) + var(--safe-top)); padding: var(--safe-top) calc(6px + var(--safe-right)) 0 calc(4px + var(--safe-left));
  background: var(--bg);
  transition: background 0.2s, box-shadow 0.2s;
}
.navbar.compact {
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  box-shadow: 0 0.5px 0 var(--sep);
}
.nav-back {
  display: flex; align-items: center; gap: 0; height: 44px; padding: 0 8px 0 4px;
  color: var(--accent); font-size: 17px; flex: none; max-width: 40%;
}
.nav-back .icon { margin-right: 1px; }
.nav-back:active, .nav-action:active { opacity: 0.4; }
.nav-title {
  flex: 1; min-width: 0; text-align: center; font-size: 16px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  opacity: 0; transform: translateY(4px); transition: opacity 0.2s, transform 0.2s;
}
.navbar.compact .nav-title { opacity: 1; transform: none; }
.nav-action { width: 44px; height: 44px; display: grid; place-items: center; color: var(--accent); flex: none; }

.hero { padding: 6px 4px 0; }
.status-button {
  display: inline-flex; align-items: center; gap: 7px;
  height: 34px; padding: 0 11px 0 12px; border-radius: 17px;
  background: var(--pill-bg); color: var(--pill-fg);
  font-size: 15px; font-weight: 650;
  transition: transform 0.1s, filter 0.1s;
}
.status-button:active { transform: scale(0.96); filter: brightness(0.95); }
.status-button .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.detail-title { margin-top: 14px; font-size: 24px; font-weight: 700; line-height: 1.22; letter-spacing: -0.02em; overflow-wrap: anywhere; }
.detail-inst { margin-top: 6px; font-size: 16px; color: var(--text-2); }
.detail-inst.muted { margin-top: 2px; font-size: 14px; }

.countdown {
  display: flex; align-items: center; gap: 10px; margin-top: 16px; padding: 13px 14px; border-radius: var(--radius);
  background: var(--surface); font-size: 15.5px; font-weight: 600;
}
.countdown.tone-urgent { background: var(--st-perdido-bg); color: var(--danger); }
.countdown.tone-soon { background: var(--st-nuevo-bg); color: var(--st-nuevo); }
.countdown.tone-normal { color: var(--text); }
.countdown.tone-normal .icon { color: var(--accent); }

.cond summary {
  display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 11px 16px; font-size: 16px; cursor: pointer;
  list-style: none; transition: background 0.12s;
}
.cond summary::-webkit-details-marker { display: none; }
.cond summary:active { background: var(--press); transition: none; }
.cond summary span { flex: 1; }
.cond summary .icon { color: var(--text-3); transition: transform 0.2s var(--ease); }
.cond[open] summary .icon { transform: rotate(90deg); }
.cond-text {
  padding: 0 16px 16px; font-size: 14.5px; line-height: 1.55; color: var(--text-2);
  white-space: pre-wrap; overflow-wrap: anywhere; -webkit-user-select: text; user-select: text;
}

.notes {
  display: block; width: 100%; min-height: 64px; padding: 13px 16px; resize: none; overflow: hidden;
  border: 0; outline: 0; background: transparent; font-size: 17px; line-height: 1.4;
}
.notes::placeholder { color: var(--text-3); }
.save-state { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 500; font-size: 13px; color: var(--text-3); }
.save-state.saved { color: var(--ok); }
.save-state.error { color: var(--danger); }

.hist { display: flex; gap: 12px; padding: 11px 16px; font-size: 14.5px; line-height: 1.35; color: var(--text-2); }
.hist > span:first-child { flex: 1; }
.hist b { color: var(--text); font-weight: 600; }
.hist-time { flex: none; font-size: 13px; color: var(--text-3); white-space: nowrap; }

.footnote { margin: 22px 4px 0; font-size: 13px; color: var(--text-3); text-align: center; }
.center-spinner { display: grid; place-items: center; padding: 80px 0; }

/* ============================================================
   Bottom sheet
   ============================================================ */
.sheet-host { position: fixed; inset: 0; z-index: 40; }
.sheet-backdrop {
  position: absolute; inset: 0; background: rgba(0, 0, 0, 0.32);
  opacity: 0; transition: opacity 300ms var(--ease);
}
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-width: 560px; margin: 0 auto; max-height: calc(100% - var(--safe-top) - 24px);
  display: flex; flex-direction: column;
  padding: 0 calc(12px + var(--safe-right)) calc(12px + var(--safe-bottom)) calc(12px + var(--safe-left));
  background: var(--bg); border-radius: 18px 18px 0 0;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.18);
  transform: translateY(100%);
  transition: transform 340ms var(--ease);
}
.sheet-host.open .sheet-backdrop { opacity: 1; }
.sheet-host.open .sheet { transform: none; }
.sheet-host.enter .sheet { transition: none; }
.sheet-host.leaving .sheet { transform: translateY(100%); transition-duration: 260ms; }
.sheet-handle { width: 38px; height: 5px; border-radius: 3px; background: var(--text-3); opacity: 0.5; margin: 7px auto 2px; flex: none; }
.sheet-header { padding: 10px 6px 12px; text-align: center; flex: none; }
.sheet-header h3 { font-size: 17px; font-weight: 650; }
.sheet-header p { margin-top: 3px; font-size: 13.5px; }
.sheet-scroll { overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; min-height: 0; }
.options { background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.options > * + * { box-shadow: inset 0 0.5px 0 var(--sep); }
.option {
  display: flex; align-items: center; gap: 13px; width: 100%; min-height: 60px; padding: 10px 16px;
  transition: background 0.12s;
}
.option:active { background: var(--press); transition: none; }
.option .dot { flex: none; width: 14px; height: 14px; border-radius: 50%; background: var(--pill-fg); box-shadow: 0 0 0 4px var(--pill-bg); }
.option-text { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.option-label { font-size: 17px; font-weight: 550; }
.option-hint { font-size: 13px; color: var(--text-2); line-height: 1.3; }
.option-check { color: var(--accent); }
.option.current .option-label { font-weight: 700; }
.sheet-actions { display: flex; flex-direction: column; gap: 10px; padding-top: 4px; }
.log {
  margin: 0; padding: 12px; border-radius: 12px; background: var(--surface);
  font: 12px/1.5 var(--mono); color: var(--text-2);
  white-space: pre-wrap; overflow-wrap: anywhere; max-height: 65vh;
  -webkit-user-select: text; user-select: text;
}

/* ============================================================
   Buttons, cards, spinner
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 50px; padding: 0 22px; border-radius: 13px;
  font-size: 17px; font-weight: 650;
  transition: transform 0.1s, background 0.15s, opacity 0.15s;
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; }
.btn.block { width: 100%; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:active:not(:disabled) { background: var(--accent-press); }
.btn.secondary { background: var(--surface); color: var(--accent); }
.btn.danger { background: var(--danger); color: #fff; }

.card { margin-top: 14px; padding: 16px; border-radius: var(--radius); background: var(--surface); }
.card-foot { margin-top: 12px; font-size: 13px; text-align: center; }
.run-state { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; min-height: 48px; }
.run-headline { font-size: 17px; font-weight: 650; }
.run-state .muted { font-size: 14px; margin-top: 2px; }
.run-icon { flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; }
.run-icon.ok { background: var(--st-ganado-bg); color: var(--ok); }
.run-icon.error { background: var(--st-perdido-bg); color: var(--danger); }
.run-row .k { gap: 1px; }
.run-dot { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--ok); }
.run-dot.error { background: var(--danger); }
.run-dot.running { background: var(--accent); animation: pulse 1.4s infinite; }
.run-row .v { font-size: 15px; font-variant-numeric: tabular-nums; }
.err { color: var(--danger); font-weight: 600; }

.spinner {
  display: inline-block; flex: none; width: 26px; height: 26px; border-radius: 50%;
  border: 2.5px solid var(--accent-soft); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
.spinner.small { width: 16px; height: 16px; border-width: 2px; }
.spinner.light { border-color: rgba(255, 255, 255, 0.35); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   Pull to refresh, toast
   ============================================================ */
.ptr {
  position: fixed; left: 50%; top: calc(var(--safe-top) + 8px); z-index: 16;
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface); color: var(--text-3);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.14);
  transform: translate(-50%, -64px); opacity: 0;
  transition: transform 300ms var(--ease), opacity 200ms;
  pointer-events: none;
}
.ptr.armed { color: var(--accent); }
.ptr.refreshing { transform: translate(-50%, 46px); opacity: 1; color: var(--accent); }
.ptr.refreshing .icon { animation: spin 0.8s linear infinite; }

.toast {
  position: fixed; left: 50%; z-index: 50;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 14px);
  display: flex; align-items: center; gap: 14px;
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 14px;
  background: rgba(30, 30, 34, 0.94); color: #fff;
  font-size: 15px; font-weight: 550; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  transform: translate(-50%, 0); animation: toast-in 320ms var(--ease);
}
body.detail-shown .toast { bottom: calc(var(--safe-bottom) + 18px); }
.toast.out { opacity: 0; transform: translate(-50%, 12px); transition: opacity 220ms, transform 220ms; }
.toast button { color: #8fb0ff; font-weight: 700; white-space: nowrap; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 16px) scale(0.96); } }
@media (prefers-color-scheme: dark) { .toast { background: rgba(58, 58, 62, 0.95); } }

/* ============================================================
   Login
   ============================================================ */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom)); }
.login-card { width: 100%; max-width: 380px; text-align: center; }
.login-logo { display: block; width: 240px; max-width: 70%; height: auto; margin: 0 auto; }
.login-card h1 { margin-top: 22px; font-size: 22px; font-weight: 650; letter-spacing: -0.01em; color: var(--text-2); }
.login-fields { margin: 28px 0 14px; text-align: left; }
.login-fields input {
  display: block; width: 100%; height: 52px; padding: 0 16px; border: 0; outline: 0; background: transparent;
  font-size: 17px;
}
.login-fields input::placeholder { color: var(--text-3); }
.login-error { margin: -2px 0 14px; color: var(--danger); font-size: 14.5px; }
.shake-0, .shake-1 { animation: shake 0.4s; }
.shake-1 { animation-name: shake2; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
@keyframes shake2 { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

/* ============================================================
   Motion preferences
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
  .spinner, .ptr.refreshing .icon { animation-duration: 0.8s !important; }
}

/* ============================================================
   Histórico
   ============================================================ */
.segmented {
  display: flex; margin-top: 12px; padding: 2px; border-radius: 10px; background: var(--surface-2);
}
.segmented button {
  flex: 1; min-width: 0; height: 32px; border-radius: 8px;
  font-size: 14.5px; font-weight: 600; color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background 0.18s, color 0.18s, box-shadow 0.18s;
}
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }

.hist-summary { padding: 14px 16px 16px; }
.hs-stats { display: flex; }
.hs-stat { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; }
.hs-stat + .hs-stat { box-shadow: inset 0.5px 0 0 var(--sep); }
.hs-num { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.hs-num.tone-won { color: var(--st-ganado); }
.hs-num.tone-lost { color: var(--st-perdido); }
.hs-label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.hs-bar { display: flex; gap: 2px; height: 6px; margin-top: 14px; border-radius: 3px; overflow: hidden; background: var(--surface-2); }
.hs-seg { background: var(--pill-fg); opacity: 0.85; min-width: 4px; }

.hist-line { margin-top: 6px; gap: 5px; font-size: 13.5px; }
.hist-line .row-money { font-weight: 600; }
.lost-why { color: var(--st-perdido); }

.status-button.static:active { transform: none; filter: none; }
.result-text { padding: 13px 16px; font-size: 16px; line-height: 1.4; font-weight: 550; }
.reason { display: flex; gap: 10px; padding: 12px 16px 14px; font-size: 15px; line-height: 1.45; color: var(--text); }
.reason > .icon { flex: none; color: var(--text-3); margin-top: 2px; }
.reason-label { font-size: 12.5px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 3px; }
.reason p:last-child { white-space: pre-line; overflow-wrap: anywhere; }
.group.others { margin-top: 10px; }
.other { display: flex; flex-direction: column; gap: 6px; padding: 11px 16px; }
.other-name { font-size: 15.5px; font-weight: 590; }
.other-res { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.reason-body { min-width: 0; flex: 1; }
.reason .clamped { display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.reason .more { margin-top: 6px; color: var(--accent); font-size: 15px; font-weight: 600; }

.offer { display: flex; align-items: center; gap: 12px; padding: 10px 16px; }
.offer.own { background: var(--accent-soft); }
.offer.tracked { box-shadow: inset 3px 0 0 var(--st-noprocdo); }
.group > .offer.tracked + *, .group > * + .offer.tracked { box-shadow: inset 3px 0 0 var(--st-noprocdo), inset 0 0.5px 0 var(--sep); }
.offer-pos {
  flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  font-size: 13px; font-weight: 700; color: var(--text-2); background: var(--surface-2); font-variant-numeric: tabular-nums;
}
.offer-pos.won { background: var(--st-ganado-bg); color: var(--st-ganado); }
.offer-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.offer-name { font-size: 15.5px; font-weight: 590; line-height: 1.25; overflow-wrap: anywhere; }
.offer-sub { font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.offer-bad { font-size: 13px; color: var(--st-perdido); }
.offer-price { flex: none; display: flex; flex-direction: column; align-items: flex-end; font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.offer-usd { font-size: 12px; font-weight: 500; color: var(--text-3); }
.own-tag { margin-left: 4px; height: 18px; line-height: 18px; padding: 0 5px; font-size: 11px; color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); vertical-align: 1px; }

.ext-html { background: var(--accent-soft); color: var(--accent); }
.file.disabled { color: var(--text-2); }
.file.disabled .file-ext { color: var(--text-3); }
.file-why { display: block; font-size: 12.5px; color: var(--text-3); margin-top: 2px; }
.center-spinner.small { padding: 32px 0; }

@media (max-width: 360px) { .tab-label { font-size: 9.5px; } }

.sheet-form { padding: 0 16px; }
.sheet-form .login-fields { margin: 6px 0 14px; }
.sheet-form .sheet-actions { padding-left: 0; padding-right: 0; }

/* Precalificación switches */
.kv.precalif { cursor: pointer; }
.kv.precalif .k { flex: 1 1 auto; min-width: 0; }
.precalif-name { font-size: 15.5px; line-height: 1.3; }
.switch {
  -webkit-appearance: none; appearance: none; flex: none; position: relative;
  width: 51px; height: 31px; border-radius: 16px; background: var(--surface-2);
  transition: background 0.2s; cursor: pointer;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25); transition: transform 0.22s var(--ease);
}
.switch:checked { background: var(--ok); }
.switch:checked::after { transform: translateX(20px); }

/* Palabras clave */
.kv.keyword .k { flex: 1 1 auto; min-width: 0; }
.icon-btn { flex: none; width: 36px; height: 36px; margin: -4px -8px -4px 0; border-radius: 10px; display: grid; place-items: center; }
.icon-btn:active:not(:disabled) { background: var(--press); }
.icon-btn:disabled { opacity: 0.35; }
.icon-btn.accent { color: var(--accent); }
.keyword-add input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text);
  font-size: 17px; -webkit-appearance: none; appearance: none;
}
.keyword-add input::placeholder { color: var(--text-3); }
.group-note.err { color: var(--danger); }
