@import url('../components/tooltip.css');
:root {
  --sidebar-w: 270px;
  --legend-w: 195px;
  --landing-panel-w: 480px;
}
@media (max-width: 1400px) {
  :root {
    --landing-panel-w: 380px;
  }
}
@media (max-width: 1100px) {
  :root {
    --landing-panel-w: 300px;
  }
}

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

/* ── vis-network tooltip ──────────────────────────────────────── */

.vis-tooltip {
  background: #1f2937 !important;
  border: 1px solid #374151 !important;
  border-radius: 7px !important;
  color: #d1d5db !important;
  font-family: 'Segoe UI', system-ui, sans-serif !important;
  font-size: 0.82rem !important;
  padding: 0.45rem 0.75rem !important;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5) !important;
  white-space: nowrap !important;
}

/* ── Main screen ──────────────────────────────────────────────── */

#main-screen {
  display: flex;
  height: 100vh;
  background-size: cover;
  background-position: center;
  background-position-y: 50%;
  background-repeat: no-repeat;
}

#sidebar {
  width: 270px;
  min-width: 270px;
  background: rgba(31, 41, 55, 0.45);
  border-right: 1px solid #374151;
  display: flex;
  flex-direction: column;
  padding: 0.9rem 0.5rem;
  gap: 0.9rem;
  overflow: hidden;
  position: relative;
  transition:
    width 0.25s ease,
    min-width 0.25s ease,
    padding 0.25s ease,
    border-width 0.25s ease;
}

/* Hide stale sidebar content until the loaded book has rendered. */
.sidebar-loading {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: #1f2937;
  color: #9ca3af;
  font-size: 0.9rem;
}
body.sidebar-collapsed #sidebar {
  width: 0;
  min-width: 0;
  padding: 0;
  border-right-width: 0;
}

/* Floating elements reposition when sidebar collapses */
body.sidebar-collapsed #run-trail-float {
  left: 12px;
}
body.sidebar-collapsed #play-btns-bar {
  left: 50vw;
}

#graph-container {
  flex: 1;
  background-color: transparent;
}

/* vis.Network replaces the graph loading indicator when initialized. */
.graph-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  height: 100%;
  color: #9ca3af;
  font-size: 0.9rem;
}

.graph-load-error {
  margin: 1rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid #7f1d1d;
  border-radius: 8px;
  background: rgba(127, 29, 29, 0.18);
  color: #fecaca;
  font-size: 0.9rem;
}

/* ── Buttons ──────────────────────────────────────────────────── */

.primary-btn {
  background: #f5a623;
  color: #111827;
  border: none;
  border-radius: 7px;
  padding: 0.4rem 0.75rem;
  font-weight: 700;
  font-size: 0.88rem;
  font-family: inherit;
  cursor: pointer;
  width: 100%;
  transition: background 0.15s;
}
.primary-btn:hover {
  background: #e09518;
}
#record-btn {
  padding: 0.2rem 0.75rem;
}

.record-btn-row {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: wrap;
}

.add-portal-btn {
  padding: 0.2rem 0.6rem;
  background: #0e7490;
  color: #e0f2fe;
  border: 1px solid #0891b2;
  border-radius: 4px;
  font-size: 0.75rem;
  cursor: pointer;
  white-space: nowrap;
}
.add-portal-btn:hover {
  background: #0891b2;
}

.portal-destinations {
  background: rgba(14, 116, 144, 0.12);
  border: 1px solid rgba(8, 145, 178, 0.35);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.portal-dest-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #7dd3fc;
  margin-bottom: 0.1rem;
}
.portal-dest-item {
  display: flex;
  gap: 0.3rem;
  align-items: center;
}
.portal-travel-btn {
  flex: 1;
  font-size: 0.78rem;
  padding: 0.2rem 0.5rem;
  background: #0e7490;
  border-color: #0891b2;
}
.portal-travel-btn:hover {
  background: #0891b2;
}
.portal-edit-btn,
.portal-del-btn {
  padding: 0.15rem 0.4rem;
  font-size: 0.75rem;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  cursor: pointer;
  color: #94a3b8;
}
.portal-edit-btn:hover {
  color: #e2e8f0;
  border-color: rgba(255, 255, 255, 0.35);
}
.portal-del-btn:hover {
  color: #f87171;
  border-color: rgba(248, 113, 113, 0.5);
}

/* ── Inputs ───────────────────────────────────────────────────── */

/* Publication type selector + identifier fields */
.series-row {
  display: flex;
  gap: 0.4rem;
  width: 100%;
}
.series-row input[type='text'] {
  flex: 1;
  min-width: 0;
}
/* Split selector/order fields 75:25 at every modal width. */
.series-row .app-select:has(+ .order-num-input) {
  flex: 3 1 0%;
}
.series-row .order-num-input {
  flex: 1 1 0%;
  min-width: 0;
}

.series-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.7rem;
  color: #a78bfa;
  background: rgba(167, 139, 250, 0.1);
  border: 1px solid rgba(167, 139, 250, 0.3);
  border-radius: 4px;
  padding: 0.05em 0.45em;
  margin-top: 0.2rem;
  white-space: nowrap;
}

.also-appears-list {
  display: grid;
  gap: 0.35rem;
  margin-top: 0.4rem;
  width: 100%;
}
.also-appears-chip {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 1fr);
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  min-height: 2.1rem;
  font-size: 0.7rem;
  color: #a78bfa;
  background: rgba(167, 139, 250, 0.1);
  border: 1px solid rgba(167, 139, 250, 0.3);
  border-radius: 6px;
  box-sizing: border-box;
}
.also-appears-chip-name {
  min-width: 0;
  padding: 0.45rem 0.6rem;
  overflow-wrap: normal;
}
.also-appears-chip button {
  position: absolute;
  right: 0.55rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 0.85em;
  line-height: 1;
  padding: 0;
  opacity: 0.7;
}
.also-appears-chip button:hover {
  opacity: 1;
}
.also-appears-chip .also-appears-chip-order {
  width: 100%;
  height: 100%;
  min-width: 0;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(167, 139, 250, 0.3);
  border-radius: 6px;
  color: inherit;
  font-size: 0.82rem;
  font-family: inherit;
  padding: 0.45rem 1.55rem 0.45rem 0.6rem;
  text-align: center;
}
.also-appears-chip-order:focus {
  outline: none;
  border-color: #a78bfa;
}

.book-item--container {
  border-color: rgba(167, 139, 250, 0.75);
  border-left: 3px solid rgba(167, 139, 250, 0.9);
  background: rgba(167, 139, 250, 0.04);
}
.book-item--container[data-expanded='1'],
.book-item--container[data-search-expanded='1'] {
  border-radius: 8px;
}
.book-item--container[data-expanded='1']:has(+ .book-children-group:not(:empty)),
.book-item--container[data-search-expanded='1']:has(+ .book-children-group:not(:empty)) {
  border-radius: 8px 8px 0 0;
  border-bottom: none;
}

.book-children-group {
  margin: 0;
  padding: 0;
  border: 1px solid rgba(167, 139, 250, 0.65);
  border-left: 3px solid rgba(167, 139, 250, 0.9);
  border-top: none;
  border-radius: 0 0 8px 8px;
  background: rgba(167, 139, 250, 0.03);
}
.book-children-group:empty {
  display: none;
}
#books-list > .book-item--container[data-expanded='1'] + .book-children-group,
#books-list > .book-item--container[data-search-expanded='1'] + .book-children-group {
  margin-top: -0.5rem;
}
.series-books-group > .book-item--container[data-expanded='1'] + .book-children-group,
.series-books-group > .book-item--container[data-search-expanded='1'] + .book-children-group {
  margin-top: -1px;
}
.book-item--container {
  cursor: pointer;
  /* Avoid text-selection flashes when clicking to expand the card. */
  user-select: none;
}
.book-item--container .book-secondary-actions {
  cursor: default;
}
.book-item--container .book-name-text::before {
  content: '▶';
  display: inline-block;
  margin-right: 0.35rem;
  vertical-align: middle;
  font-size: 0.6rem;
  color: #a78bfa;
  transition: transform 0.15s;
  transform: rotate(0deg);
  line-height: 1;
}
.book-item--container[data-expanded='1'] .book-name-text::before,
.book-item--container[data-search-expanded='1'] .book-name-text::before {
  transform: rotate(90deg);
}

.book-item--child {
  margin-left: 1.2rem;
  border-left: 2px solid rgba(167, 139, 250, 0.3);
  padding-left: 0.5rem;
  font-size: 0.92em;
}
.book-item--child .book-sections {
  font-size: 0.72rem;
}

/* Use a compound selector to beat the later base card border regardless of load order. */
.book-item.book-item--party {
  /* Keep borders opaque enough that cover art cannot make them look patchy. */
  border-color: rgba(52, 211, 153, 0.9);
  border-left: 3px solid rgba(52, 211, 153, 0.95);
}

.pub-type-row {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  width: 100%;
}

.app-select,
.pub-type-select {
  background: #111827;
  border: 1px solid #374151;
  border-radius: 6px;
  color: #d1d5db;
  padding: 0.45rem 1.7rem 0.45rem 0.6rem;
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%236b7280' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.45rem center;
  transition: border-color 0.15s;
}
.app-select:focus,
.pub-type-select:focus {
  outline: none;
  border-color: #f5a623;
}
.pub-type-select {
  flex-shrink: 0;
}
.app-select {
  flex: 1;
  min-width: 0;
}

/* Keep membership choices compact, with the same gray highlight as other lists. */
.series-row .app-select {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.series-row .app-select option {
  white-space: normal;
}
.series-row .app-select option:checked {
  background: #374151;
  color: #f9fafb;
}
@supports (appearance: base-select) {
  .series-row .app-select,
  .series-row .app-select::picker(select) {
    appearance: base-select;
  }
  .series-row .app-select::picker-icon,
  .series-row .app-select option::checkmark {
    display: none;
  }
  .series-row .app-select::picker(select) {
    background: #111827;
    border: 1px solid #374151;
    border-radius: 4px;
    color: #d1d5db;
    font: inherit;
    margin: 0;
    padding: 0;
    max-height: 200px;
    overflow-y: auto;
  }
  .series-row .app-select option {
    background: #111827;
    color: #d1d5db;
    border: 0;
    border-radius: 0;
    padding: 0.15rem 0.5rem;
    min-block-size: 0;
    font: inherit;
    line-height: 1.35;
  }
  .series-row .app-select option:is(:hover, :focus, :checked) {
    background: #374151;
    color: #f9fafb;
  }
}

.pub-id-fields {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 0;
}

.pub-id-fields input {
  width: 100%;
}

input[type='text'],
input[type='number'],
input[type='password'],
input[type='email'] {
  background: #111827;
  border: 1px solid #374151;
  border-radius: 6px;
  color: #d1d5db;
  padding: 0.45rem 0.75rem;
  font-size: 0.88rem;
  width: 100%;
  transition: border-color 0.15s;
}
input[type='text']:focus,
input[type='number']:focus,
input[type='password']:focus,
input[type='email']:focus {
  outline: none;
  border-color: #f5a623;
}
input[type='text']:disabled,
input[type='password']:disabled,
input[type='email']:disabled {
  opacity: 0.6;
  cursor: default;
  background: #1f2937;
  color: #9ca3af;
}

/* ── Custom scrollbars (global) ───────────────────────────────── */

* {
  scrollbar-width: thin;
  scrollbar-color: #374151 transparent;
}
*::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}
*::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background: #374151;
  border-radius: 3px;
}
*::-webkit-scrollbar-thumb:hover {
  background: #4b5563;
}

/* ── vis.js tooltip ──────────────────────────────────────────── */

.vis-tooltip {
  background: #1f2937 !important;
  border: 1px solid #4b5563 !important;
  border-radius: 6px !important;
  color: #d1d5db !important;
  font-family: 'Segoe UI', system-ui, sans-serif !important;
  font-size: 0.78rem !important;
  padding: 0.4rem 0.65rem !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5) !important;
  max-width: 260px !important;
  line-height: 1.5 !important;
  white-space: normal !important;
  word-break: break-word !important;
  overflow-wrap: break-word !important;
}
.vis-tooltip div {
  white-space: normal !important;
  word-break: break-word !important;
  overflow-wrap: break-word !important;
  max-width: 260px !important;
}

/* ── PDF link ─────────────────────────────────────────────────── */

.pdf-link {
  color: #60a5fa;
  font-size: 0.82rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.pdf-link:hover {
  text-decoration: underline;
}
.inline-svg-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
.inline-svg-icon svg {
  display: block;
}
.pdf-svg-icon svg {
  width: 0.92rem;
  height: 0.92rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.modal-upload-progress {
  margin-top: 0.35rem;
  width: 100%;
  height: 3px;
  background: transparent;
  border-radius: 999px;
  overflow: hidden;
}
.modal-upload-progress-bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #0891b2, #67e8f9);
  transition: width 0.12s linear;
}

.book-pdf-btn {
  font-size: 0.75rem;
  color: #60a5fa;
  background: none;
  border: 1px solid #374151;
  border-radius: 5px;
  padding: 0.15rem 0.45rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.book-pdf-btn:hover {
  background: #1f2937;
}

/* ── Admin badge ──────────────────────────────────────────────── */

.admin-badge,
.author-badge,
.moderator-badge,
.squire-badge,
.contributor-badge {
  display: inline-flex;
  font-size: 0.5em;
  width: 1em;
  height: 1em;
  line-height: 1;
  margin-left: 0.2em;
  vertical-align: super;
  cursor: default;
  user-select: none;
}
:is(.admin-badge, .author-badge, .contributor-badge, .moderator-badge, .squire-badge)
  + :is(.admin-badge, .author-badge, .contributor-badge, .moderator-badge, .squire-badge) {
  margin-left: 0;
}
.admin-badge {
  color: #60a5fa;
}
.author-badge {
  color: #fbbf24;
}
.contributor-badge {
  color: #34d399;
}
.moderator-badge {
  color: #c084fc;
}
.squire-badge {
  color: #fb923c;
}
:is(.admin-badge, .author-badge, .contributor-badge, .moderator-badge, .squire-badge) svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* ── Responsive: compact sidebar for short viewports (e.g. 1366×768) ── */

@media (max-height: 750px) {
  #sidebar {
    padding: 0.5rem;
    gap: 0.45rem;
  }

  #stats {
    padding: 0.35rem 0.6rem;
    gap: 0.15rem;
    margin: -0.25rem -0.5rem -0.4rem -0.5rem;
  }

  .stats-row {
    font-size: 0.76rem;
  }

  .section-display {
    font-size: 1.35rem;
  }

  .section-label {
    font-size: 0.68rem;
  }

  .undo-run-btn,
  .fasttravel-btn,
  .battle-death-btn {
    padding: 0.1rem 0.4rem;
  }

  .choices-label {
    font-size: 0.72rem;
  }

  .choice-btn {
    padding: 0.2rem 0.5rem;
    font-size: 0.72rem;
  }

  #sidebar .primary-btn {
    padding: 0.4rem 0.75rem;
  }

  .input-group {
    gap: 0.2rem;
  }

  .runs-section {
    margin-top: 0.25rem;
    padding-top: 0.35rem;
  }

  #data-controls {
    padding-top: 0.25rem;
    gap: 0.2rem;
  }

  #data-controls button {
    padding: 0.3rem;
  }
}

/* ── Sidebar book info (>1920px only) ────────────────────────────────────── */

#sidebar-book-info {
  display: none;
}

@media (min-width: 1921px) {
  #sidebar-book-info {
    display: block;
    margin: -0.75rem -0.5rem 0 -0.5rem;
    padding: 0 0.4rem;
  }

  #sidebar-cover-img {
    display: block;
    width: 100%;
    aspect-ratio: 2/3;
    object-fit: cover;
    border-radius: 3px;
    background: #1f2937;
    margin-bottom: 0.2rem;
  }

  #sidebar-cover-img[src=''] {
    display: none;
  }

  .stats-row {
    font-size: 0.8rem;
  }
}
