/* ─── Main Layout ── Terminal Grid ─────────────────────── */
.layout {
  display: grid;
  grid-template-columns: minmax(200px, 260px) 1fr;
  grid-template-rows: 38px 1fr;
  height: 100vh;
}
.layout.no-sb { grid-template-columns: 1fr; }
@media (min-width: 1025px) {
  .layout.no-sb .sb { display: none; }
}

/* NAV — compact single row */
.nav {
  grid-column: 1 / -1;
  grid-row: 1;
  background: var(--nav-bg, var(--bg1));
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 6px;
  z-index: 20;
  position: relative;
  height: 40px;
  overflow: visible;
}
.brand { display: flex; align-items: center; gap: 7px; flex-shrink: 0; }
.bdot {
  width: 6px; height: 6px;
  background: var(--accent);
  border-radius: 2px;
  box-shadow: 0 0 4px rgba(232,168,0,.2);
  flex-shrink: 0;
}
.bname { font-family: var(--sans); font-size: 13px; font-weight: 600; letter-spacing: .3px; color: var(--text); }
.bsub { font-family: var(--mono); font-size: 7px; color: var(--text3); letter-spacing: .06em; text-transform: uppercase; }
.vsep { width: 1px; height: 16px; background: var(--line); flex-shrink: 0; margin: 0 4px; }

/* Tabs — YouTube Studio style */
.tabs {
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  flex-shrink: 1;
  min-width: 0;
  gap: 2px;
  /* hide scrollbar — la barra de scroll horizontal molesta visualmente
     en desktop; los tabs siguen scrolleando con shift+wheel o swipe. */
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 0 14px;
  height: 40px;
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  color: var(--text3);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color .18s ease;
  white-space: nowrap;
  position: relative;
  flex-shrink: 0;
}
.tab:hover { color: var(--text); }
.tab.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tc {
  font-family: var(--mono); font-size: 8px;
  background: transparent; border: none;
  border-radius: 10px; padding: 0 2px; color: var(--text3);
}
.tab.on .tc { color: var(--accent); }

/* Token bar */
.tokbar {
  display: flex; align-items: center; gap: 4px;
  background: transparent; border: 1px solid var(--line);
  border-radius: var(--radius); padding: 4px 10px; flex-shrink: 0;
}
.tok-lbl { font-family: var(--mono); font-size: 8px; color: var(--text3); }
.tv { font-family: var(--mono); font-size: 12px; font-weight: 700; }
.tch { font-family: var(--mono); font-size: 9px; color: var(--green); font-weight: 500; }
.tok-sep { color: var(--text3); font-size: 8px; }
.trst { font-family: var(--mono); font-size: 10px; color: var(--text3); cursor: pointer; margin-left: 2px; }
.trst:hover { color: var(--accent); }
.tok-bar-wrap {
  width: 38px; height: 3px; background: var(--bg3);
  border-radius: 2px; overflow: hidden; flex-shrink: 0;
}
.tok-bar-fill {
  height: 100%; border-radius: 2px;
  transition: width .3s, background .3s;
}

/* Status indicator */
.status-ind {
  display: flex; align-items: center; gap: 3px;
  font-family: var(--mono); font-size: 8px;
  padding: 3px 8px; border-radius: var(--radius);
  background: transparent; border: 1px solid var(--line);
  flex-shrink: 0;
}
.status-dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--text3); flex-shrink: 0;
}
.status-ind.online .status-dot { background: var(--green); box-shadow: 0 0 5px rgba(34,197,94,.4); }
.status-ind.online .status-txt { color: var(--green); }
.status-ind.offline .status-dot { background: var(--red); animation: blink .8s infinite; }
.status-ind.offline .status-txt { color: var(--red); }

/* Nav right */
.nr {
  margin-left: auto;
  display: flex; gap: 4px; align-items: center;
  flex-shrink: 0;
}

/* Buttons */
.btn {
  padding: 5px 12px; border-radius: var(--radius);
  font-family: var(--sans); font-size: 11px; font-weight: 600;
  cursor: pointer; border: none;
  display: flex; align-items: center; gap: 4px;
  transition: var(--transition); white-space: nowrap;
}
.btn-gold { background: var(--accent); color: #000; }
.btn-gold:hover { background: #f5c030; }
.btn-gold:disabled { opacity: .35; cursor: not-allowed; }
.btn-stop { background: var(--red); color: #fff; }
.btn-stop:hover { background: #dc2626; }
.btn-ghost { background: transparent; border: 1px solid var(--line2); color: var(--text2); }
.btn-ghost:hover { background: var(--bg3); color: var(--text); }
.btn-green { background: rgba(34,197,94,.08); border: 1px solid rgba(34,197,94,.2); color: var(--green); }
.btn-green:hover { background: rgba(34,197,94,.15); }

/* :active feedback global — sin esto los botones no daban feedback al
   tap en mobile (donde no hay :hover). Un scale+opacidad chico simula
   el "press" físico que esperamos los usuarios. */
.btn:active,
button:active:not(:disabled),
.tab:active,
.fchip:active,
.paBtn:active,
.btn-disc:active {
  transform: scale(.97);
  opacity: .85;
  transition: transform 80ms ease, opacity 80ms ease;
}
.btn:disabled, button:disabled { cursor: not-allowed; }
/* Focus visible para accesibilidad de teclado */
.btn:focus-visible,
button:focus-visible,
[role="button"]:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Save status */
.save-status {
  font-family: var(--mono); font-size: 8px; color: var(--text3);
  white-space: nowrap;
}
.save-status.saved { color: var(--green); }

/* Dropdown */
.ddrop { position: relative; }
.dmenu {
  display: none; position: absolute; right: 0; top: calc(100% + 4px);
  background: var(--bg2); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; z-index: 999; min-width: 140px;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
.ddrop.open .dmenu { display: block; }
.dopt { padding: 8px 14px; font-size: 11px; font-family: var(--sans); color: var(--text2); cursor: pointer; transition: var(--transition); }
.dopt:hover { background: var(--bg3); color: var(--text); }

/* SIDEBAR */
.sb {
  grid-column: 1;
  grid-row: 2;
  background: var(--sidebar-bg, var(--bg1));
  border-right: 1px solid var(--line);
  overflow-y: auto; overflow-x: hidden;
}
.sblk { border-bottom: 1px solid var(--line); padding: 12px 12px; word-break: break-word; }
.shd { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.stit {
  font-family: var(--sans); font-size: 10px; color: var(--text2);
  letter-spacing: .04em; text-transform: uppercase; font-weight: 600;
}
.sa {
  font-size: 9px; color: var(--text3); cursor: pointer;
  background: none; border: none; font-family: var(--mono); padding: 0;
  transition: color .18s;
}
.sa:hover { color: var(--text); }

/* Collapsible sidebar sections — SVG chevron toggle + state persistence */
.sblk-chev {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px; height: 14px;
  margin-right: 6px;
  color: var(--text3);
  cursor: pointer;
  transition: transform .15s, color .15s;
  user-select: none;
  vertical-align: -2px;
}
.sblk-chev svg {
  width: 12px; height: 12px;
  stroke-width: 2;
}
.sblk-chev:hover { color: var(--accent); }
.sblk.collapsed .sblk-chev { transform: rotate(-90deg); }
.sblk.collapsed { padding-bottom: 8px; }
.sblk.collapsed > *:not(.shd) { display: none !important; }
.sblk.collapsed .shd { margin-bottom: 0; }

/* MAIN */
.main {
  grid-column: 2;
  grid-row: 2;
  display: flex; flex-direction: column;
  overflow: hidden; position: relative;
  transition: padding-right .2s ease;
  min-height: 0;
}
.layout.no-sb .main { grid-column: 1; }
.main.popen { padding-right: 430px; }

/* Stats bar — HubSpot-style flat metrics */
.sbar {
  display: flex;
  background: var(--bg1);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  overflow-x: auto;
  flex-wrap: wrap;
}
.sc {
  padding: 10px 18px;
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 2px;
  flex-shrink: 0;
}
.sc:last-child { border-right: none; }
.sc-clickable { cursor: pointer; transition: background .18s; }
.sc-clickable:hover { background: rgba(255,255,255,.02); }
.sc-db { }
.sc-right {
  margin-left: auto; display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; flex-shrink: 0;
}
.sv { font-family: var(--sans); font-size: 18px; font-weight: 600; line-height: 1; }
.sv.gold { color: var(--accent); }
.sv.blue { color: var(--a2); }
.sv.green { color: var(--green); }
.sv.orange { color: var(--orange); }
.sv.teal { color: var(--teal); }
.sl { font-family: var(--sans); font-size: 9px; color: var(--text3); letter-spacing: .02em; text-transform: uppercase; font-weight: 500; }

/* Progress bar */
.pbar { height: 2px; background: var(--bg3); flex-shrink: 0; }
.pfill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--a2)); width: 0%; transition: width .3s; }

/* Toolbar */
.toolbar {
  display: flex; gap: 6px; align-items: center;
  padding: 8px 14px;
  background: var(--bg1);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.swrap { position: relative; flex: 1; }
.sico { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); color: var(--text3); font-size: 11px; pointer-events: none; }
.sin {
  width: 100%;
  background: var(--bg2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 6px 10px 6px 28px;
  color: var(--text); font-family: var(--sans); font-size: 11px; outline: none;
  transition: border-color .18s, background .18s;
}
.sin:focus { border-color: var(--accent); background: var(--bg3); }
.sin::placeholder { color: var(--text3); }

.achips { display: flex; gap: 3px; overflow-x: auto; flex-shrink: 0; }
.achip {
  display: flex; align-items: center; gap: 3px;
  padding: 3px 8px; border-radius: var(--radius);
  font-size: 9px; font-family: var(--mono); white-space: nowrap;
  background: rgba(59,130,246,.06); border: 1px solid rgba(59,130,246,.15); color: var(--a2);
  cursor: pointer; transition: var(--transition);
}
.achip:hover { background: rgba(239,68,68,.06); border-color: rgba(239,68,68,.2); color: var(--red); }

.pgctrls { display: flex; align-items: center; gap: 3px; flex-shrink: 0; }
.pglbl { font-family: var(--mono); font-size: 8px; color: var(--text3); white-space: nowrap; }
.pgsel {
  background: var(--bg2); border: 1px solid var(--line);
  border-radius: var(--radius); color: var(--text2); font-family: var(--mono);
  font-size: 9px; padding: 4px 6px; cursor: pointer; outline: none;
  transition: border-color .18s;
}
.pgsel:focus { border-color: var(--accent); }
.sortlbl { font-family: var(--mono); font-size: 8px; color: var(--text3); white-space: nowrap; }

/* Log bar */
.logbar {
  padding: 5px 14px;
  background: var(--bg1); border-top: 1px solid var(--line);
  font-family: var(--mono); font-size: 8px; color: var(--text3);
  display: flex; gap: 6px; align-items: center; flex-shrink: 0;
}
.ldot { width: 5px; height: 5px; border-radius: 50%; background: var(--text3); flex-shrink: 0; }
.ldot.on { background: var(--accent); animation: blink .8s infinite; }
.db-badge {
  margin-left: auto; font-size: 8px; padding: 1px 5px;
  border-radius: var(--radius); background: rgba(20,184,166,.08);
  border: 1px solid rgba(20,184,166,.18); color: var(--teal);
}

/* Blocked tab */
.blocked-header {
  padding: 6px 10px; border-bottom: 1px solid var(--line);
  background: var(--bg1); font-size: 9px; color: var(--text3);
  font-family: var(--mono);
}

/* Bulk bar */
.bulk-bar {
  display: flex; align-items: center; gap: 6px;
  background: rgba(59,130,246,.04);
  border: 1px solid rgba(59,130,246,.12);
  border-radius: var(--radius); padding: 4px 10px;
  flex-shrink: 0;
}
.bulk-count { font-family: var(--mono); font-size: 9px; color: var(--a2); white-space: nowrap; }

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 1400px) {
  .layout { grid-template-columns: 230px 1fr; }
}
@media (max-width: 1100px) {
  .layout { grid-template-columns: 200px 1fr; }
  .main.popen { padding-right: 360px; }
  .sc { padding: 5px 10px; }
  .sv { font-size: 14px; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; }
  .sb { grid-column: 1; grid-row: 2; border-right: none; border-bottom: 1px solid var(--line); max-height: 250px; overflow-y: auto; }
  .main { grid-column: 1; grid-row: 3; }
  .main.popen { padding-right: 0; }
  .panel { width: 100%; left: 0; }
  .nr { gap: 3px; }
  .btn { font-size: 9px; padding: 3px 7px; }
  .tokbar { display: none; }
}
@media (max-width: 600px) {
  .nav { padding: 0 6px; gap: 3px; }
  .brand { display: none; }
  .vsep { display: none; }
  .tab { padding: 0 6px; font-size: 10px; }
  .toolbar { padding: 4px 6px; flex-wrap: wrap; }
  .sbar { flex-wrap: wrap; }
  .sc { min-width: 70px; }
}
