/* ── EJERCICIOS PAGE SPECIFIC ── */

#filter-toggle-btn {
  display: none;
  align-items: center;
  gap: .4rem;
  padding: .4rem .75rem;
  background: rgba(255, 255, 255, .15);
  border: 1px solid rgba(255, 255, 255, .25);
  color: #fff;
  border-radius: 7px;
  cursor: pointer;
  font-family: inherit;
  font-size: .82rem;
  font-weight: 500;
  transition: background .2s;
}

#filter-toggle-btn:hover {
  background: rgba(255, 255, 255, .22);
}

/* ── LAYOUT ── */
#layout {
  display: flex;
  min-height: calc(100vh - var(--header-h));
}

/* ── SIDEBAR ── */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--border);
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  scrollbar-width: thin;
  scrollbar-color: var(--border2) transparent;
}
 
#sidebar-close-btn {
  display: none;
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text3);
  cursor: pointer;
  padding: 0.5rem;
  line-height: 1;
}

.sidebar-section {
  margin-bottom: .25rem;
}

.sidebar-title {
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text3);
  margin-bottom: .5rem;
  padding-bottom: .35rem;
  border-bottom: 1px solid var(--border);
}

.filter-opt {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .28rem .3rem;
  border-radius: 5px;
  cursor: pointer;
  transition: background .15s;
  user-select: none;
}

.filter-opt:hover {
  background: var(--bg);
}

.filter-opt input[type=checkbox] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.filter-opt label {
  flex: 1;
  font-size: .82rem;
  color: var(--text2);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.filter-count {
  font-size: .7rem;
  color: var(--text3);
  background: var(--bg2);
  padding: 0 .35rem;
  border-radius: 10px;
  flex-shrink: 0;
}

.solved-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .4rem .3rem;
}

.solved-toggle-row label {
  font-size: .83rem;
  color: var(--text2);
  font-weight: 500;
}

.toggle-switch {
  position: relative;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--border2);
  border-radius: 10px;
  cursor: pointer;
  transition: background .2s;
}

.toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
}

.toggle-switch input:checked+.toggle-track {
  background: var(--accent);
}

.toggle-switch input:checked+.toggle-track::after {
  transform: translateX(16px);
}

#clear-btn {
  width: 100%;
  margin-top: .5rem;
  padding: .5rem;
  border: 1px solid var(--border2);
  background: var(--bg);
  color: var(--text2);
  border-radius: 7px;
  cursor: pointer;
  font-family: inherit;
  font-size: .8rem;
  font-weight: 500;
  transition: all .15s;
}

#clear-btn:hover {
  background: var(--bg2);
  border-color: var(--text3);
}

/* cat group toggle */
.cat-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  padding: .28rem .3rem;
  border-radius: 5px;
  margin-top: .35rem;
}

.cat-group-header:hover {
  background: var(--bg);
}

.cat-group-name {
  font-size: .78rem;
  font-weight: 600;
  color: var(--text);
}

.cat-group-arrow {
  font-size: .65rem;
  color: var(--text3);
  transition: transform .2s;
}

.cat-group-arrow.open {
  transform: rotate(90deg);
}

.cat-group-items {
  display: none;
  padding-left: .5rem;
}

.cat-group-items.open {
  display: block;
}

/* ── MAIN ── */
#main {
  flex: 1;
  padding: 1.25rem;
  min-width: 0;
}

#results-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: .5rem;
}

#results-count {
  font-size: .82rem;
  color: var(--text2);
}

#results-count strong {
  color: var(--text);
}

#sort-select {
  padding: .3rem .6rem;
  border: 1px solid var(--border2);
  background: var(--card);
  color: var(--text);
  border-radius: 7px;
  font-family: inherit;
  font-size: .8rem;
  cursor: pointer;
}

/* ── ACTIVE FILTERS ── */
#active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin-bottom: .75rem;
}

.active-tag {
  display: flex;
  align-items: center;
  gap: .3rem;
  padding: .2rem .6rem;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 500;
}

.active-tag button {
  border: none;
  background: none;
  color: var(--accent);
  cursor: pointer;
  font-size: .8rem;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
}

/* ── GRID ── */
#exercises-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  max-width: 900px;
  margin: 0 auto;
}

/* ── CARD ── */
.ex-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: cardIn .3s ease both;
  transition: box-shadow .2s, transform .2s;
}

.ex-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .65rem .9rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  gap: .5rem;
}

.card-id {
  font-size: .78rem;
  font-weight: 600;
  color: var(--primary);
  white-space: nowrap;
}

.badge-solved {
  display: flex;
  align-items: center;
  gap: .25rem;
  font-size: .68rem;
  font-weight: 600;
  color: var(--solved);
  background: #dcfce7;
  padding: .15rem .5rem;
  border-radius: 20px;
  white-space: nowrap;
}

.card-cats {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
  padding: .55rem .9rem .4rem;
}

.cat-tag {
  font-size: .68rem;
  font-weight: 500;
  padding: .15rem .55rem;
  border-radius: 20px;
  background: var(--violet-light);
  color: var(--violet);
  cursor: pointer;
  transition: background .15s;
}

.cat-tag:hover {
  background: #ddd6fe;
}

.cat-tag.primary-cat {
  background: var(--accent-light);
  color: var(--accent);
}

.cat-tag.primary-cat:hover {
  background: #bfdbfe;
}

.card-body {
  padding: .65rem .9rem;
  font-size: .88rem;
  line-height: 1.65;
  color: var(--text);
  min-height: 60px;
}

.card-body .skeleton {
  background: linear-gradient(90deg, var(--bg) 25%, var(--bg2) 50%, var(--bg) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  height: 14px;
  border-radius: 4px;
  margin-bottom: .4rem;
}

.card-body .skeleton:last-child {
  width: 70%;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }

  100% {
    background-position: -200% 0;
  }
}

.card-body img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  margin: .4rem 0;
  border: 1px solid var(--border);
}

.card-body ol,
.card-body ul {
  padding-left: 1.4rem;
}

.card-body li {
  margin-bottom: .25rem;
}

.card-footer {
  padding: .6rem .9rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}

.btn-solution {
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: .4rem .85rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 7px;
  font-family: inherit;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s;
}

.btn-solution:hover {
  background: #1d4ed8;
}

.btn-solution:active {
  transform: scale(.97);
}

.btn-solution.open {
  background: var(--text2);
}

.btn-report-error {
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: .4rem .85rem;
  background: transparent;
  color: var(--text2);
  border: 1px solid var(--border2);
  border-radius: 7px;
  font-family: inherit;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s, transform .1s;
}

.btn-report-error:hover {
  background: var(--fail-bg);
  border-color: var(--fail-bd);
  color: var(--fail);
}

.btn-report-error:active {
  transform: scale(.97);
}

.btn-report-error.open {
  background: var(--fail);
  border-color: var(--fail);
  color: #fff;
}

/* ── REPORT PANEL ── */
.report-panel {
  border-top: 2px solid var(--fail-bd);
  background: var(--fail-bg);
  padding: .9rem 1.1rem;
  font-size: .86rem;
  line-height: 1.7;
  display: none;
  animation: solutionIn .25s ease;
}

.report-panel.open {
  display: block;
}

.report-label {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--fail);
  margin-bottom: .4rem;
  display: block;
}

.report-desc {
  color: var(--text2);
  font-size: .82rem;
  margin-bottom: .75rem;
}

.report-textarea {
  width: 100%;
  min-height: 80px;
  padding: .6rem;
  border: 1px solid var(--border2);
  border-radius: 6px;
  font-family: inherit;
  font-size: .84rem;
  resize: vertical;
  background: var(--card);
  color: var(--text);
  margin-bottom: .6rem;
  transition: border-color .15s, box-shadow .15s;
}

.report-textarea:focus {
  outline: none;
  border-color: var(--fail);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.15);
}

.report-form-footer {
  display: flex;
  justify-content: flex-end;
}

.btn-report-submit {
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: .4rem 1rem;
  background: var(--fail);
  color: #fff;
  border: none;
  border-radius: 7px;
  font-family: inherit;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s;
}

.btn-report-submit:hover {
  background: #b91c1c;
}

.btn-report-submit:active {
  transform: scale(.97);
}

.btn-report-submit:disabled {
  background: var(--text3);
  cursor: not-allowed;
  transform: none;
}

/* ── SOLUTION PANEL ── */
.solution-panel {
  border-top: 2px solid var(--accent-light);
  background: #f0f7ff;
  padding: .75rem .9rem;
  font-size: .86rem;
  line-height: 1.7;
  display: none;
  animation: solutionIn .25s ease;
}

.solution-panel.open {
  display: block;
}

@keyframes solutionIn {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.solution-panel img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  margin: .4rem 0;
  border: 1px solid var(--border);
}

.solution-panel ol,
.solution-panel ul {
  padding-left: 1.4rem;
}

.solution-panel li {
  margin-bottom: .3rem;
}

.solution-label {
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: .4rem;
  display: block;
}

/* ── EMPTY STATE ── */
#empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text3);
  display: none;
  grid-column: 1/-1;
}

#empty-state svg {
  margin-bottom: .75rem;
  opacity: .4;
}

#empty-state p {
  font-size: .9rem;
}

/* ── AI RESOLVER ── */
.ai-resolver-container {
  position: relative;
  display: inline-block;
}

.btn-ai {
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: .4rem .85rem;
  background: var(--bg2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  font-family: inherit;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}

.btn-ai:hover {
  background: var(--card);
  border-color: var(--accent);
  color: var(--accent);
}

.ai-options-dropdown {
  position: absolute;
  bottom: calc(100% + 5px);
  left: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.15);
  padding: 0.4rem;
  min-width: 140px;
  display: none;
  flex-direction: column;
  gap: 2px;
  z-index: 100;
}

.ai-options-dropdown.open {
  display: flex;
  animation: dropdownIn .2s ease;
}

@keyframes dropdownIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.ai-option-btn {
  background: none;
  border: none;
  padding: .4rem .75rem;
  text-align: left;
  cursor: pointer;
  color: var(--text2);
  font-family: inherit;
  font-size: .8rem;
  font-weight: 500;
  border-radius: 5px;
  transition: background .15s, color .15s;
}

.ai-option-btn:hover {
  background: var(--bg2);
  color: var(--text);
}

.ai-option-icon {
  margin-right: 0.4rem;
}

/* ── MOBILE OVERLAY ── */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .4);
  z-index: 1050; /* Above header (1000) but below sidebar (1100) */
}

#sidebar-overlay.open {
  display: block;
}

@media (max-width: 768px) {
  #filter-toggle-btn {
    display: flex;
  }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1100; /* Above header and overlay */
    transform: translateX(-100%);
    transition: transform .3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 10px 0 30px rgba(0, 0, 0, .15);
  }

  #sidebar.open {
    transform: translateX(0);
  }

  #sidebar-close-btn {
    display: block;
  }

  #main {
    padding: 1rem;
  }
}

@media print {
  #sidebar,
  #filter-toggle-btn,
  #sidebar-overlay {
    display: none !important;
  }
}

/* ── LOAD MORE BUTTON ── */
.btn-load-more {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .65rem 1.8rem;
  background: var(--card);
  color: var(--text2);
  border: 1px solid var(--border2);
  border-radius: 9px;
  font-family: inherit;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.btn-load-more:hover {
  background: var(--bg);
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.15);
  transform: translateY(-2px);
}

.btn-load-more:active {
  transform: translateY(0);
}

/* ── RANDOM EXERCISE CARD ── */
.random-card {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  background: linear-gradient(135deg, #eff6ff 0%, #f5f3ff 100%);
  border: 1.5px solid var(--accent);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  box-shadow: 0 4px 20px rgba(37, 99, 235, 0.1);
  position: relative;
  animation: cardIn .35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.random-card-icon {
  font-size: 2rem;
  line-height: 1;
  flex-shrink: 0;
  animation: spin-once .5s ease .2s both;
}

@keyframes spin-once {
  from { transform: rotate(-20deg) scale(.8); opacity: 0; }
  to   { transform: rotate(0deg) scale(1);   opacity: 1; }
}

.random-card-body {
  flex: 1;
  min-width: 0;
}

.random-card-question {
  font-size: .95rem;
  font-weight: 500;
  color: var(--text);
  margin: 0 0 .9rem;
  line-height: 1.55;
}

.random-card-question strong {
  color: var(--accent);
}

.random-card-actions {
  display: flex;
  gap: .6rem;
  flex-wrap: wrap;
}

.btn-random-yes {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .45rem 1.1rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s, box-shadow .15s;
  box-shadow: 0 2px 8px rgba(37, 99, 235, .25);
}

.btn-random-yes:hover {
  background: #1d4ed8;
  box-shadow: 0 4px 14px rgba(37, 99, 235, .35);
  transform: translateY(-1px);
}

.btn-random-yes:active {
  transform: translateY(0);
}

.btn-random-no {
  display: inline-flex;
  align-items: center;
  padding: .45rem 1.1rem;
  background: transparent;
  color: var(--text2);
  border: 1px solid var(--border2);
  border-radius: 8px;
  font-family: inherit;
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
}

.btn-random-no:hover {
  background: var(--bg2);
  border-color: var(--text3);
  color: var(--text);
}

.random-card-close {
  position: absolute;
  top: .65rem;
  right: .65rem;
  background: none;
  border: none;
  font-size: .9rem;
  color: var(--text3);
  cursor: pointer;
  padding: .25rem;
  line-height: 1;
  border-radius: 4px;
  transition: color .15s, background .15s;
}

.random-card-close:hover {
  color: var(--text);
  background: var(--bg2);
}

/* ── RANDOM RESULT BANNER ── */
.random-result-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  background: linear-gradient(90deg, #eff6ff, #f5f3ff);
  border: 1.5px solid var(--accent);
  border-radius: var(--radius);
  padding: .7rem 1.1rem;
  box-shadow: 0 2px 12px rgba(37, 99, 235, .1);
  animation: cardIn .3s ease both;
}

.random-result-label {
  font-size: .85rem;
  font-weight: 600;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: .4rem;
}

.btn-random-reset {
  padding: .35rem .9rem;
  background: transparent;
  color: var(--text2);
  border: 1px solid var(--border2);
  border-radius: 7px;
  font-family: inherit;
  font-size: .8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}

.btn-random-reset:hover {
  background: var(--bg2);
  border-color: var(--accent);
  color: var(--accent);
}

.random-result-actions {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  align-items: center;
}

.btn-random-another {
  padding: .35rem .9rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 7px;
  font-family: inherit;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s;
  white-space: nowrap;
}

.btn-random-another:hover {
  background: #1d4ed8;
  transform: translateY(-1px);
}

.btn-random-another:active {
  transform: translateY(0);
}

@media (max-width: 768px) {
  .random-card {
    flex-direction: column;
    gap: .75rem;
  }

  .random-card-icon {
    font-size: 1.6rem;
  }

  .random-result-banner {
    flex-direction: column;
    align-items: flex-start;
  }
}
