/* CTFd Tools plugin — styles
   Colours mirror the core theme (Bootstrap 4 dark navbar) so the panel reads
   as part of CTFd rather than a bolt-on. All rules are namespaced with
   .ctools- to avoid colliding with theme CSS. */

:root {
  --ctools-ink: #343a40;
  --ctools-ink-deep: #23272b;
  --ctools-paper: #ffffff;
  --ctools-paper-dim: #f8f9fa;
  --ctools-line: #dee2e6;
  --ctools-muted: #6c757d;
  --ctools-accent: #007bff;
  --ctools-on-ink: #ffffff;
  --ctools-on-ink-dim: rgba(255, 255, 255, 0.62);
  --ctools-radius: 6px;
  --ctools-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --ctools-z-button: 1040;  /* under Bootstrap modals (1050) so the challenge modal covers it */
  --ctools-z-panel: 1060;   /* above them so tools can be opened while reading a challenge */
}

/* ---------- Floating button ---------- */
.ctools-fab {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: var(--ctools-z-button);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  border: 0;
  border-radius: var(--ctools-radius);
  background: var(--ctools-ink);
  color: var(--ctools-on-ink);
  font: 600 0.95rem/1 inherit;
  font-family: inherit;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  transition: transform 120ms ease, background-color 120ms ease;
}
.ctools-fab:hover { background: var(--ctools-ink-deep); transform: translateY(-1px); }
.ctools-fab:focus-visible { outline: 3px solid var(--ctools-accent); outline-offset: 2px; }
.ctools-fab svg { width: 1em; height: 1em; fill: currentColor; }

/* ---------- Overlay + panel ---------- */
.ctools-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--ctools-z-panel);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2vh 2vw;
  background: rgba(0, 0, 0, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease;
}
.ctools-overlay.is-open { opacity: 1; pointer-events: auto; }

.ctools-panel {
  display: flex;
  flex-direction: column;
  width: min(1400px, 96vw);
  height: 92vh;
  background: var(--ctools-paper);
  border-radius: var(--ctools-radius);
  box-shadow: var(--ctools-shadow);
  overflow: hidden;
  transform: translateY(8px) scale(0.995);
  transition: transform 160ms ease;
}
.ctools-overlay.is-open .ctools-panel { transform: none; }

/* ---------- Header ---------- */
.ctools-header {
  display: flex;
  align-items: stretch;
  gap: 0.25rem;
  min-height: 48px;
  padding: 0 0.25rem 0 1rem;
  background: var(--ctools-ink);
  color: var(--ctools-on-ink);
}
.ctools-title {
  align-self: center;
  margin: 0 1rem 0 0;
  font-size: 1.05rem;
  font-weight: 600;
  white-space: nowrap;
}
.ctools-tabs {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
}
.ctools-tab {
  position: relative;
  flex: 0 0 auto;
  padding: 0 0.9rem;
  border: 0;
  background: transparent;
  color: var(--ctools-on-ink-dim);
  font: 500 0.9rem/48px inherit;
  font-family: inherit;
  white-space: nowrap;
  cursor: pointer;
}
.ctools-tab:hover { color: var(--ctools-on-ink); }
.ctools-tab[aria-selected="true"] { color: var(--ctools-on-ink); }
.ctools-tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 0.9rem;
  right: 0.9rem;
  bottom: 0;
  height: 3px;
  background: var(--ctools-paper);
  border-radius: 3px 3px 0 0;
}
.ctools-tab:focus-visible { outline: 2px solid var(--ctools-paper); outline-offset: -4px; }
.ctools-tab .ctools-ext {
  margin-left: 0.3rem;
  font-size: 0.75em;
  opacity: 0.7;
}

.ctools-actions { display: flex; align-items: center; gap: 0.15rem; }
.ctools-iconbtn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  height: 36px;
  padding: 0 0.7rem;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--ctools-on-ink-dim);
  font: 500 0.85rem/1 inherit;
  font-family: inherit;
  text-decoration: none;
  cursor: pointer;
}
.ctools-iconbtn:hover { color: var(--ctools-on-ink); background: rgba(255, 255, 255, 0.08); text-decoration: none; }
.ctools-iconbtn:focus-visible { outline: 2px solid var(--ctools-paper); outline-offset: -2px; }
.ctools-iconbtn svg { width: 1em; height: 1em; fill: currentColor; }
.ctools-close { font-size: 1.4rem; padding: 0 0.6rem; }

/* ---------- Body ---------- */
.ctools-body { position: relative; flex: 1 1 auto; min-height: 0; background: var(--ctools-paper-dim); }
.ctools-frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #fff; }
.ctools-frame[hidden] { display: none; }

.ctools-linkcard {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}
.ctools-linkcard[hidden] { display: none; }
.ctools-linkcard-inner {
  max-width: 34rem;
  padding: 2rem 2.25rem;
  background: var(--ctools-paper);
  border: 1px solid var(--ctools-line);
  border-radius: var(--ctools-radius);
  color: var(--ctools-ink);
}
.ctools-linkcard h3 { margin: 0 0 0.5rem; font-size: 1.35rem; font-weight: 600; }
.ctools-linkcard p { margin: 0 0 1.25rem; color: var(--ctools-muted); line-height: 1.5; }
.ctools-linkcard .ctools-url {
  display: block;
  margin: -0.75rem 0 1.25rem;
  font-family: SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  color: var(--ctools-muted);
  word-break: break-all;
}
.ctools-open {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.6rem 1.1rem;
  border: 0;
  border-radius: 4px;
  background: var(--ctools-accent);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
}
.ctools-open:hover { background: #0069d9; color: #fff; text-decoration: none; }
.ctools-open:focus-visible { outline: 3px solid rgba(0, 123, 255, 0.4); }
.ctools-open svg { width: 1em; height: 1em; fill: currentColor; }

.ctools-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--ctools-muted);
  text-align: center;
  padding: 2rem;
}

/* ---------- Small screens ---------- */
@media (max-width: 640px) {
  .ctools-overlay { padding: 0; }
  .ctools-panel { width: 100vw; height: 100vh; border-radius: 0; }
  .ctools-title { display: none; }
  .ctools-fab span { display: none; }         /* icon-only button */
  .ctools-fab { padding: 0.75rem; }
  .ctools-iconbtn span { display: none; }     /* icon-only "open in new tab" */
}

@media (prefers-reduced-motion: reduce) {
  .ctools-fab, .ctools-overlay, .ctools-panel { transition: none; }
}
