/* Layout: flex-column full-height shell — header / search / virtual-list / statusbar */
:root {
  --bg:        #0c1420;
  --surface:   #131f2e;
  --surface2:  #1a2840;
  --surface3:  #21334f;
  --border:    #263347;
  --border2:   #32445e;
  --text:      #c5cedd;
  --text2:     #6e849e;
  --text3:     #3e5068;
  --accent:    #4a8fd4;
  --accent-bg: rgba(74,143,212,.1);
  --accent-br: rgba(74,143,212,.3);
  --match:     #d49b4a;
  --match-bg:  rgba(212,155,74,.16);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg:        #eef2f7;
    --surface:   #ffffff;
    --surface2:  #eef2f7;
    --surface3:  #e0e8f2;
    --border:    #cdd8e6;
    --border2:   #b5c6d8;
    --text:      #1b2b3e;
    --text2:     #526a84;
    --text3:     #96afbf;
    --accent:    #2868b8;
    --accent-bg: rgba(40,104,184,.08);
    --accent-br: rgba(40,104,184,.25);
    --match:     #a85e18;
    --match-bg:  rgba(168,94,24,.12);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
    --bg:        #eef2f7;
    --surface:   #ffffff;
    --surface2:  #eef2f7;
    --surface3:  #e0e8f2;
    --border:    #cdd8e6;
    --border2:   #b5c6d8;
    --text:      #1b2b3e;
    --text2:     #526a84;
    --text3:     #96afbf;
    --accent:    #2868b8;
    --accent-bg: rgba(40,104,184,.08);
    --accent-br: rgba(40,104,184,.25);
    --match:     #a85e18;
    --match-bg:  rgba(168,94,24,.12);
    color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 13px;
  line-height: 1.5;
}

/* ── Animations ── */
@keyframes fadeUp  { from { opacity:0; transform:translateY(10px) } to { opacity:1; transform:none } }
@keyframes popIn   { from { opacity:0; transform:scale(.96) translateY(4px) } to { opacity:1; transform:none } }
@keyframes spin    { to   { transform:rotate(360deg) } }
@keyframes pulse   { 0%,100%{opacity:.45} 50%{opacity:.9} }

/* ── Shell ── */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  animation: fadeUp .3s ease both;
}

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  height: 50px;
  min-height: 50px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: .2px;
  white-space: nowrap;
}

.logo-mark {
  width: 24px; height: 24px;
  background: var(--accent);
  color: var(--bg);
  border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 800; letter-spacing: -.5px;
  flex-shrink: 0;
  box-shadow: 0 1px 6px rgba(74,143,212,.35);
}

.hdr-sep { width:1px; height:18px; background:var(--border2); flex-shrink:0; }

#file-pill {
  display: flex; align-items: center; gap: 7px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px 3px 8px;
  animation: popIn .2s ease;
  min-width: 0; max-width: 420px;
}
#file-pill.hidden { display:none; }

.pill-ico  { flex-shrink:0; color:var(--text3); }
.pill-name { font-size:12px; font-weight:500; color:var(--text); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; min-width:0; max-width:200px; }
.pill-meta { font-size:11px; color:var(--text2); white-space:nowrap; flex-shrink:0; }
.pill-meta b { color:var(--accent); font-weight:600; }

.btn-change {
  margin-left:3px; flex-shrink:0;
  background:none; border:1px solid var(--border2);
  color:var(--text2); padding:2px 8px; border-radius:10px;
  cursor:pointer; font-size:11px; font-family:inherit;
  transition: border-color .15s, color .15s;
}
.btn-change:hover { border-color:var(--accent); color:var(--accent); }

/* ── Main ── */
main { flex:1; overflow:hidden; display:flex; flex-direction:column; }

/* ── Drop zone ── */
#drop-zone {
  flex:1;
  display:flex; align-items:center; justify-content:center;
  padding: 40px max(16px, env(safe-area-inset-left,0px));
}
#drop-zone.hidden { display:none; }

.drop-card {
  width:100%; max-width:440px;
  background:var(--surface);
  border:2px dashed var(--border2);
  border-radius:14px;
  padding:60px 44px 52px;
  text-align:center;
  cursor:pointer;
  transition: border-color .2s, transform .15s;
  position:relative; overflow:hidden;
}
.drop-card::before {
  content:'';
  position:absolute; inset:0;
  background:radial-gradient(ellipse at 50% 0%, var(--accent-bg) 0%, transparent 68%);
  opacity:0; transition:opacity .2s; pointer-events:none;
}
.drop-card:hover, .drop-card.over { border-color:var(--accent); transform:translateY(-2px); }
.drop-card:hover::before, .drop-card.over::before { opacity:1; }

.drop-glyph { color:var(--text3); transition:color .2s; margin-bottom:16px; }
.drop-card:hover .drop-glyph, .drop-card.over .drop-glyph { color:var(--accent); }

.drop-h { font-size:16px; font-weight:600; color:var(--text); margin-bottom:6px; text-wrap:balance; }
.drop-p { font-size:12.5px; color:var(--text2); line-height:1.65; margin-bottom:24px; text-wrap:balance; }

.btn-open {
  display:inline-flex; align-items:center; gap:7px;
  background:var(--accent); color:#fff;
  border:none; border-radius:7px; padding:8px 20px;
  font-size:13px; font-weight:500; font-family:inherit;
  cursor:pointer; transition:filter .15s, transform .1s;
}
.btn-open:hover { filter:brightness(1.14); transform:translateY(-1px); }

.drop-formats { margin-top:14px; font-size:11px; color:var(--text3); letter-spacing:.3px; }

/* ── Workspace ── */
#workspace { flex:1; display:flex; flex-direction:column; overflow:hidden; animation:fadeUp .2s ease; }
#workspace.hidden { display:none; }

/* ── Search ── */
.search-panel {
  display:flex; align-items:center; gap:10px;
  padding:8px max(16px,env(safe-area-inset-right,0px)) 8px max(16px,env(safe-area-inset-left,0px));
  background:var(--surface);
  border-bottom:1px solid var(--border);
  flex-shrink:0;
}

.search-wrap {
  flex:1; display:flex; align-items:center; gap:7px;
  background:var(--bg);
  border:1px solid var(--border2);
  border-radius:8px;
  padding:0 10px;
  transition: border-color .15s, box-shadow .15s;
  min-width:0;
}
.search-wrap:focus-within {
  border-color:var(--accent);
  box-shadow:0 0 0 3px var(--accent-bg);
}

.s-ico { color:var(--text3); display:flex; align-items:center; flex-shrink:0; transition:color .15s; }
.search-wrap:focus-within .s-ico { color:var(--accent); }

#search-input {
  flex:1; background:none; border:none; outline:none;
  color:var(--text); font-size:13px;
  font-family:'JetBrains Mono', monospace;
  padding:7px 0; min-width:0;
}
#search-input::placeholder { color:var(--text3); font-family:'Inter',sans-serif; font-size:13px; }

.tog {
  background:none; border:1px solid transparent; border-radius:4px;
  color:var(--text2); padding:2px 6px;
  font-size:11px; font-weight:700; font-family:inherit;
  cursor:pointer; transition:all .15s; white-space:nowrap; flex-shrink:0;
}
.tog:hover { border-color:var(--border2); color:var(--text); }
.tog.on    { background:var(--accent-bg); border-color:var(--accent-br); color:var(--accent); }

.btn-x {
  background:none; border:none; color:var(--text3);
  font-size:18px; line-height:1; cursor:pointer;
  padding:0 1px; flex-shrink:0; transition:color .15s;
}
.btn-x:hover { color:var(--text); }
.btn-x.hidden { visibility:hidden; }

.s-info { font-size:12px; color:var(--text2); white-space:nowrap; min-width:175px; flex-shrink:0; }
.s-info .hi  { color:var(--match); font-weight:600; font-variant-numeric:tabular-nums; }
.s-info .dim { color:var(--text3); }

/* ── Results header ── */
.res-hdr {
  display:flex; align-items:center;
  padding:0 max(14px,env(safe-area-inset-left,0px));
  height:26px;
  background:var(--surface2);
  border-bottom:1px solid var(--border);
  font-size:10px; font-weight:600;
  color:var(--text3);
  text-transform:uppercase; letter-spacing:.6px;
  flex-shrink:0; user-select:none;
}
.rh-n { width:46px; flex-shrink:0; text-align:right; padding-right:12px; }
.rh-l { width:72px; flex-shrink:0; padding:0 10px; border-left:1px solid var(--border); }
.rh-c { flex:1; padding:0 10px; border-left:1px solid var(--border); min-width:0; }

/* ── List ── */
#list-wrap {
  flex:1; overflow-y:scroll; overflow-x:hidden;
  position:relative; background:var(--bg);
}
#list-wrap::-webkit-scrollbar { width:10px; }
#list-wrap::-webkit-scrollbar-track { background:var(--bg); }
#list-wrap::-webkit-scrollbar-thumb {
  background:var(--border2); border-radius:5px; border:2px solid var(--bg);
}
#list-wrap::-webkit-scrollbar-thumb:hover { background:var(--text3); }

#phantom { position:relative; width:100%; }

.row {
  position:absolute; left:0; right:0; height:28px;
  display:flex; align-items:center;
  padding:0 max(14px,env(safe-area-inset-left,0px));
  border-bottom:1px solid color-mix(in srgb, var(--border) 60%, transparent);
  transition:background .07s; cursor:default;
}
.row:hover { background:var(--surface2); }

.row-n {
  width:46px; flex-shrink:0; text-align:right; padding-right:12px;
  color:var(--text3); font-size:11px;
  font-variant-numeric:tabular-nums; user-select:none;
}
.row-l {
  width:72px; flex-shrink:0; padding:0 10px;
  color:var(--accent); font-size:11px;
  font-family:'JetBrains Mono',monospace;
  font-variant-numeric:tabular-nums;
  border-left:1px solid var(--border); user-select:none; overflow:hidden;
}
.row-c {
  flex:1; padding:0 10px;
  border-left:1px solid var(--border);
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
  font-size:12.5px; font-family:'JetBrains Mono',monospace;
  color:var(--text); min-width:0;
}
mark {
  background:var(--match-bg); color:var(--match);
  border-radius:2px; padding:0 1px;
  font-weight:600; font-style:normal;
}

/* ── Empty state ── */
#empty {
  position:absolute; inset:0;
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  gap:10px; pointer-events:none; animation:fadeUp .2s ease;
}
#empty.hidden { display:none; }
.e-ico  { font-size:30px; opacity:.2; }
.e-msg  { font-size:14px; color:var(--text2); }
.e-hint { font-size:11.5px; color:var(--text3); }

/* ── Loading ── */
#loading {
  position:fixed; inset:0;
  background:rgba(12,20,32,.88);
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  gap:14px; z-index:50;
  backdrop-filter:blur(3px);
  animation:fadeUp .15s ease;
}
#loading.hidden { display:none; }
.spinner {
  width:30px; height:30px;
  border:2.5px solid var(--border2); border-top-color:var(--accent);
  border-radius:50%; animation:spin .65s linear infinite;
}
.ld-msg { color:var(--text2); font-size:13px; animation:pulse 1.4s ease infinite; }

/* ── Status bar ── */
#statusbar {
  display:flex; align-items:center;
  padding:0 max(16px,env(safe-area-inset-left,0px));
  height:22px; min-height:22px;
  background:var(--surface);
  border-top:1px solid var(--border);
  flex-shrink:0; font-size:10.5px; color:var(--text3);
  gap:0; overflow:hidden;
}
#statusbar.hidden { display:none; }
.st     { white-space:nowrap; }
.st b   { color:var(--text2); font-weight:500; font-variant-numeric:tabular-nums; }
.st-sep { padding:0 8px; color:var(--border2); flex-shrink:0; }

.hidden { display:none !important; }

.back-link { margin-left: auto; flex-shrink: 0; font-size: 12px; color: var(--text2); text-decoration: none; border: 1px solid var(--border2); padding: 4px 10px; border-radius: 14px; transition: .15s; }
.back-link:hover { color: var(--accent); border-color: var(--accent); }

/* ── Multi-archivo ── */
#list-outer { flex: 1; position: relative; display: flex; flex-direction: column; overflow: hidden; }
#sticky { position: absolute; top: 0; left: 0; right: 10px; z-index: 5; box-shadow: 0 6px 14px rgba(0,0,0,.25); }
#sticky .sec { position: relative; }
.sec {
  position: absolute; left: 0; right: 0; height: 34px;
  display: flex; align-items: center; gap: 10px;
  padding: 0 max(14px, env(safe-area-inset-left, 0px));
  background: var(--surface3); border-top: 1px solid var(--border2); border-bottom: 1px solid var(--border2);
  cursor: pointer; user-select: none; transition: background .1s;
}
.sec:hover { background: color-mix(in srgb, var(--surface3) 80%, var(--accent) 20%); }
.sec .chev { width: 14px; color: var(--accent); font-size: 11px; transition: transform .15s; }
.sec.collapsed .chev { transform: rotate(-90deg); }
.sec .sec-ico { color: var(--text2); display: flex; }
.sec .sec-name { font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.sec .sec-count { font-size: 11.5px; color: var(--text2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.sec .sec-count b { color: var(--match); font-weight: 600; }
.sec .sec-size { font-size: 11px; color: var(--text3); white-space: nowrap; margin-left: auto; }
.sec .sec-rm { background: none; border: 1px solid transparent; border-radius: 5px; color: var(--text3); font-size: 16px; line-height: 1; padding: 1px 6px; cursor: pointer; }
.sec .sec-rm:hover { color: #e5566e; border-color: var(--border2); }
.sec.zero { opacity: .55; }
.sec-empty {
  position: absolute; left: 0; right: 0; height: 28px; display: flex; align-items: center;
  padding: 0 max(14px, env(safe-area-inset-left, 0px)) 0 calc(max(14px, env(safe-area-inset-left, 0px)) + 24px);
  color: var(--text3); font-size: 12px; font-style: italic;
}
.tog.fold { font-weight: 500; padding: 5px 10px; border-color: var(--border2); }
.btn-change + .btn-change { margin-left: 0; }
@media (max-width: 700px) { .s-info { min-width: 0; } .sec .sec-size { display: none; } }

/* ── Detalle de línea ── */
.row { cursor: pointer; }
.row:active { background: var(--surface3); }
html:has(.lv[open]) { overflow: hidden; }
.lv {
  width: min(900px, 94vw); max-height: 86vh; margin: auto; padding: 0;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border2); border-radius: 16px;
  box-shadow: 0 30px 90px rgba(0,0,0,.55), 0 0 0 1px var(--accent-bg) inset;
  overflow: hidden;
}
.lv[open] { display: flex; flex-direction: column; animation: popIn .18s ease; }
.lv::backdrop { background: rgba(6,10,18,.62); backdrop-filter: blur(5px); }
.lv-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 16px 14px 20px; background: var(--surface2); border-bottom: 1px solid var(--border);
}
.lv-file { display: flex; align-items: center; gap: 8px; min-width: 0; font-weight: 600; font-size: 14px; }
.lv-file svg { color: var(--accent); flex-shrink: 0; }
.lv-file span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 340px; }
.lv-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.lv-chip {
  font: 11px 'JetBrains Mono', monospace; color: var(--text2);
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 3px 9px;
}
.lv-chip b { color: var(--accent); font-weight: 600; }
.lv-chip.match b { color: var(--match); }
.lv-x {
  width: 30px; height: 30px; flex-shrink: 0; border-radius: 8px; cursor: pointer;
  background: none; border: 1px solid var(--border2); color: var(--text2); font-size: 13px; transition: .15s;
}
.lv-x:hover { color: var(--text); border-color: var(--accent); }
.lv-body { padding: 18px 20px; overflow: auto; display: flex; flex-direction: column; gap: 4px; }
.lv-ctx, .lv-main { display: flex; gap: 14px; font-family: 'JetBrains Mono', monospace; }
.lv-ctx { font-size: 12px; line-height: 1.6; color: var(--text3); padding: 2px 15px; }
.lv-ctx .t { color: var(--text2); opacity: .75; }
.lv-ctx i { color: var(--text3); }
.lv-main {
  margin: 6px 0; padding: 14px 15px 14px 12px; font-size: 13.5px; line-height: 1.75;
  background: var(--bg); border: 1px solid var(--accent-br); border-left: 3px solid var(--accent); border-radius: 10px;
  box-shadow: 0 0 0 4px var(--accent-bg);
}
.lv-main .n { color: var(--accent); }
.lv-main .t { color: var(--text); }
.lv-main em { color: var(--text3); }
.lv .n { flex-shrink: 0; min-width: 52px; text-align: right; user-select: none; font-variant-numeric: tabular-nums; }
.lv .t { flex: 1; min-width: 0; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
.lv-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 12px 16px 12px 20px; background: var(--surface2); border-top: 1px solid var(--border);
}
.lv-nav { display: flex; align-items: center; gap: 10px; }
.lv-pos { font: 11.5px 'JetBrains Mono', monospace; color: var(--text2); min-width: 90px; text-align: center; font-variant-numeric: tabular-nums; }
.lv-btn {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  font: 500 12.5px 'Inter', sans-serif; color: var(--text); background: var(--bg);
  border: 1px solid var(--border2); border-radius: 8px; padding: 7px 13px; transition: .15s;
}
.lv-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.lv-btn:disabled { opacity: .4; cursor: default; }
.lv-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.lv-btn.primary:hover { filter: brightness(1.12); color: #fff; }
.lv-btn.primary.done { background: #2fa36b; border-color: #2fa36b; }
@media (max-width: 600px) {
  .lv { width: 100vw; max-height: 92vh; border-radius: 14px 14px 0 0; margin-bottom: 0; }
  .lv-chips { margin-left: 0; }
  .lv-nav { width: 100%; justify-content: space-between; }
  .lv-btn.primary { width: 100%; justify-content: center; }
}
