/* Importar extracto */
.im-panel[hidden], .im-history[hidden], .im-source[hidden], .im-body[hidden], .im-foot[hidden] { display: none; }

.im-source, .im-map, .im-preview, .im-body, .im-applybox, .im-sample, .im-result, .im-history, .im-history-list { grid-template-columns: minmax(0, 1fr); }

/* Paso 1: fichero */
.im-source { display: grid; gap: 16px; }
.im-source .panel-title { margin-bottom: 0; }
.im-drop {
  position: relative; display: grid; justify-items: center; gap: 6px; padding: 30px 18px; text-align: center; cursor: pointer;
  border: 2px dashed color-mix(in srgb, var(--muted) 50%, transparent); border-radius: var(--radius); background: var(--input-bg);
  transition: border-color 0.15s, background 0.15s;
}
.im-drop:hover { border-color: var(--violet); }
.im-drop .icon { width: 30px; height: 30px; color: var(--violet); }
:root[data-theme='light'] .im-drop .icon { color: #6D3FD9; }
.im-drop b { font-family: var(--font-display); font-size: 16px; letter-spacing: -0.02em; }
.im-drop small { color: var(--muted); font-size: 13px; max-width: 46ch; }
.im-drop:focus-within { border-color: var(--cyan); box-shadow: 0 0 0 4px rgba(34, 211, 238, 0.22); }
.im-drop.is-over { border-style: solid; border-color: var(--violet); background: color-mix(in srgb, var(--violet) 14%, transparent); }
.im-file { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.im-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; min-width: 0; font-size: 14px; color: var(--muted); }
.im-meta:empty { display: none; }
.im-meta .icon { width: 18px; height: 18px; }
.im-meta-name { color: var(--text); font-weight: 600; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.im-meta .pill-soft { margin-left: 0; }
.im-error { color: var(--neg); font-size: 14px; font-weight: 600; }
.im-error:empty { display: none; }

/* Paso 2: columnas */
.im-map { display: grid; gap: 20px; }
.im-map-grid { display: grid; gap: 18px; grid-template-columns: minmax(0, 1fr); }
.im-group { display: grid; gap: 14px; align-content: start; min-width: 0; padding: 16px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface-2); }
.im-group h3 { font-size: 14px; color: var(--muted); font-family: var(--font-body); font-weight: 650; letter-spacing: 0; }
.im-group-next { margin-top: 4px; }
.im-add { justify-self: start; }
.im-desc-cols { display: grid; gap: 8px; }
.im-desc-col { display: flex; align-items: center; gap: 6px; }
.im-desc-col select { flex: 1; min-width: 0; }
.im-amount-grid { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
.im-group .seg { width: 100%; }
.im-group .seg button { flex: 1; justify-content: center; padding: 0 8px; height: auto; min-height: 36px; white-space: normal; line-height: 1.2; text-align: center; }
@media (min-width: 760px) {
  .im-map-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .im-group-wide { grid-column: 1 / -1; }
  .im-amount-grid { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
}

.im-sample { display: grid; gap: 8px; min-width: 0; }
.im-sample-title { font-size: 13px; font-weight: 600; color: var(--muted); }
.im-table-wrap { overflow-x: auto; max-width: 100%; border: 1px solid var(--line); border-radius: 14px; }
.im-raw { border-collapse: collapse; width: max-content; min-width: 100%; font-size: 12.5px; }
.im-raw th, .im-raw td { padding: 6px 10px; text-align: left; border-bottom: 1px solid var(--line); max-width: 230px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.im-raw tbody tr:last-child td { border-bottom: 0; }
.im-tags th { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.im-head-row th { font-weight: 650; color: var(--text); background: var(--surface-3); }
.im-raw .is-date { background: color-mix(in srgb, var(--cyan) 15%, transparent); }
.im-raw .is-desc { background: color-mix(in srgb, var(--violet) 16%, transparent); }
.im-raw .is-amount { background: color-mix(in srgb, var(--mint) 16%, transparent); }
.im-tags .is-date, .im-tags .is-desc, .im-tags .is-amount { color: var(--text); }

/* Paso 3: vista previa */
.im-preview { display: grid; gap: 16px; }
.im-preview > .panel-title { margin-bottom: 0; }
.im-body { display: grid; gap: 16px; min-width: 0; }
.im-wait { display: flex; align-items: center; gap: 12px; padding: 18px 4px; color: var(--muted); }
.im-wait .spinner { width: 22px; height: 22px; border-width: 2.5px; }
.im-fail { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.im-info { padding: 12px 14px; border-radius: var(--radius-sm); background: color-mix(in srgb, var(--amber) 16%, transparent); color: var(--text); font-size: 14px; }
.im-summary { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.im-summary .stat b { font-size: clamp(18px, 3.4vw, 24px); }
.im-stat-sub { display: flex; flex-wrap: wrap; gap: 0 10px; margin-top: 2px; font-size: 12.5px; font-weight: 650; font-variant-numeric: tabular-nums; }
.im-stat-sub .pos { color: var(--pos); }
.im-stat-sub .neg { color: var(--neg); }
.im-applybox { display: grid; gap: 6px; }
.im-apply { font-weight: 600; width: fit-content; }
.im-apply-note { color: var(--muted); font-size: 13.5px; max-width: 78ch; }
.im-apply-note b { color: var(--text); }
.im-apply-note b.pos { color: var(--pos); }
.im-apply-note b.neg { color: var(--neg); }
.im-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px 18px; flex-wrap: wrap; }
.im-all { font-weight: 600; }

.im-rows { container-type: inline-size; display: grid; min-width: 0; }
.im-rows-head { display: none; }
.im-row {
  display: grid; align-items: center; gap: 6px 10px; padding: 12px 4px; border-bottom: 1px solid var(--line); min-width: 0;
  grid-template-columns: 28px auto minmax(0, 1fr) auto;
  grid-template-areas: 'chk desc desc amt' 'chk date stat stat' 'chk cat cat act';
}
.im-c-chk { grid-area: chk; display: grid; align-self: start; padding-top: 2px; }
.im-c-date { grid-area: date; font-size: 13px; color: var(--muted); white-space: nowrap; }
.im-c-desc { grid-area: desc; min-width: 0; display: grid; gap: 1px; }
.im-c-cat { grid-area: cat; display: flex; align-items: center; gap: 8px; min-width: 0; }
.im-c-cat select { flex: 1; min-width: 0; }
.im-c-amt { grid-area: amt; justify-self: end; font-family: var(--font-display); font-size: 15px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.im-c-amt.pos { color: var(--pos); }
.im-c-amt.neg { color: var(--neg); }
.im-c-stat { grid-area: stat; display: flex; flex-wrap: wrap; gap: 4px 6px; min-width: 0; }
.im-c-act { grid-area: act; justify-self: end; }
.im-desc { font-weight: 650; font-size: 14.5px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.im-bank { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.im-row.is-off .im-desc { color: var(--muted); }
.im-row select { min-height: 38px; padding: 0 30px 0 10px; font-size: 13.5px; border-radius: 11px; background-position: calc(100% - 17px) 15px, calc(100% - 11px) 15px; }
.im-row .pill { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.im-row .pill-soft { margin-left: 0; height: 26px; font-size: 12.5px; }
.im-similar { background: color-mix(in srgb, var(--amber) 20%, transparent); color: var(--text); }
:root[data-theme='light'] .im-similar { color: #7A4C00; }
.im-err { color: var(--neg); font-size: 13px; font-weight: 600; }
.im-cat-ico { width: 28px; height: 28px; border-radius: 9px; flex: none; display: grid; place-items: center; background: color-mix(in srgb, var(--c) 22%, transparent); color: var(--c); }
.im-cat-ico .icon { width: 15px; height: 15px; }
.im-empty { padding: 26px 6px; text-align: center; color: var(--muted); }
.im-more { display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap; }
.im-more:empty { display: none; }
.im-more-count { color: var(--muted); font-size: 13px; }

@container (min-width: 760px) {
  .im-rows-head, .im-row {
    display: grid; gap: 12px; align-items: center;
    grid-template-columns: 28px 76px minmax(0, 1fr) minmax(140px, 180px) 112px minmax(110px, 170px) 40px;
    grid-template-areas: 'chk date desc cat amt stat act';
  }
  .im-rows-head { padding: 0 4px 8px; border-bottom: 1px solid var(--line); font-size: 12.5px; font-weight: 600; color: var(--muted); }
  .im-h-amt { text-align: right; }
  .im-row { padding: 10px 4px; }
  .im-c-chk { align-self: center; padding-top: 0; }
}

.im-foot {
  position: sticky; bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 5; display: flex; gap: 10px; flex-wrap: wrap;
  padding: 12px; border: 1px solid var(--line); border-radius: 20px; background: var(--glass); box-shadow: var(--shadow);
  backdrop-filter: blur(18px) saturate(160%); -webkit-backdrop-filter: blur(18px) saturate(160%);
}
.im-foot .btn-primary { flex: 1 1 220px; min-width: max-content; justify-content: center; }
.im-foot .btn-ghost { flex: 0 1 auto; }
@media (min-width: 960px) { .im-foot { bottom: 14px; } }

/* Resultado */
.im-result { display: grid; gap: 18px; }
.im-result-head { display: flex; align-items: center; gap: 16px; }
.im-result-head h2 { font-size: 22px; }
.im-result-ico { width: 52px; height: 52px; border-radius: 18px; flex: none; display: grid; place-items: center; background: rgba(24, 227, 160, 0.16); color: var(--pos); }
.im-result-ico .icon { width: 28px; height: 28px; }
.im-result-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* Importaciones recientes */
.im-history { display: grid; gap: 4px; }
.im-history .panel-title { margin-bottom: 8px; }
.im-history-list { display: grid; gap: 2px; }
.im-hist { flex-wrap: wrap; row-gap: 8px; }
.im-hist .grow b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.im-hist .grow span.wrap { overflow-wrap: anywhere; }
.im-hist.is-undone .grow, .im-hist.is-undone .im-hist-side b { opacity: 0.6; }
.im-hist-side { display: grid; justify-items: end; gap: 4px; }
.im-hist-side .pill-soft { margin-left: 0; }
.im-hist-net { font-family: var(--font-display); font-size: 14.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.im-hist-net.pos { color: var(--pos); }
.im-hist-net.neg { color: var(--neg); }
.im-hist .btn[aria-disabled='true'] { opacity: 0.55; }

/* Reglas */
.im-rules-intro { color: var(--muted); font-size: 14px; }
.im-rules { display: grid; gap: 8px; max-height: min(52vh, 460px); overflow-y: auto; }
.im-rule { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-2); }
.im-rule-main { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; min-width: 0; }
.im-rule-pattern { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.im-rule-arrow { color: var(--muted); }
.im-rule-cat { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; }
.im-rule-desc { flex-basis: 100%; color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.im-rule-tools { display: inline-flex; flex: none; }
.im-rule-tools .icon-btn:disabled { opacity: 0.3; pointer-events: none; }

@media (max-width: 560px) {
  .im-summary { grid-template-columns: 1fr 1fr; }
  .im-source select, .im-map select, .im-toolbar .seg { width: 100%; }
  .im-toolbar .seg button { flex: 1; justify-content: center; padding: 0 6px; }
  .im-drop { padding: 24px 14px; }
  .im-hist-side { justify-items: start; }
  .im-foot .btn-primary { flex: 1 1 100%; }
  .im-foot .btn-ghost { flex: 1 1 100%; justify-content: center; }
  .im-result-head { align-items: flex-start; }
  .im-result-actions .btn { flex: 1 1 100%; justify-content: center; }
}

/* Pantallas muy estrechas: la categoría y la regla pasan a su propia línea y la descripción tiene más sitio */
@media (max-width: 380px) {
  .im-row { grid-template-areas: 'chk desc desc amt' 'chk date stat stat' 'chk cat cat cat' 'chk act act act'; }
  .im-c-act { justify-self: start; }
  .im-desc { -webkit-line-clamp: 3; }
}
