/* GM Forge - Minimal styles using existing app conventions */

/* Table row highlight for edit mode */
tr.is-highlighted {
  background: rgba(var(--color-character-accent-rgb), 0.16);
}

/* ===========================================
   Inline Editable Title
   =========================================== */

.gm-forge-editable-title {
  position: relative;
}

.gm-forge-title-display {
  cursor: pointer;
  transition: opacity 0.15s;
}

.gm-forge-title-display:hover {
  opacity: 0.7;
}

.gm-forge-title-display:hover .ph {
  opacity: 0.8;
}

.gm-forge-title-input {
  /* Match h2 styling exactly */
  font-size: 1.5em;
  font-weight: bold;
  font-family: var(--font-stack-sans-serif);
  line-height: 1.25;
  height: auto;
  margin: 0;
  padding: 0;
  border: none;
  border-bottom: 2px solid var(--color-primary);
  border-radius: 0;
  background: transparent;
  color: inherit;
  width: 100%;
  min-width: 200px;
  outline: none;
  box-shadow: none;
}

.gm-forge-title-input:focus {
  border-bottom-color: var(--color-primary);
}

@media (prefers-color-scheme: dark) {
  .gm-forge-title-input {
    color: inherit;
    border-bottom-color: rgba(255, 255, 255, 0.3);
  }
  
  .gm-forge-title-input:focus {
    border-bottom-color: var(--color-character-accent);
  }
}

/* ===========================================
   Wide Layout for GM Forge (show page only)
   Uses body controller-action class for page-specific layouts
   Index page uses default width for a more focused list view
   =========================================== */

body.gm_forge-show main,
body.gm_forge-show #main-nav section {
  width: 95%;
  max-width: 95%;
}

/* Layout with side-by-side sticky notebook */
.gm-forge-layout {
  display: flex;
  align-items: flex-start;
  gap: calc(var(--base-spacing) * 1.5);
}

.gm-forge-main {
  flex: 1;
  min-width: 0;
}

/* ===========================================
   Sidebar Panel (Shared by all panels)
   =========================================== */

.gm-forge-sidebar-panel {
  width: 450px;
  flex-shrink: 0;
  background: var(--color-box);
  border: 1px solid rgba(128, 128, 128, 0.2);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 10px;
  height: calc(100vh - 70px);
  max-height: calc(100vh - 70px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
  overflow: hidden;
  z-index: 10;
}

@media (max-width: 1400px) {
  .gm-forge-sidebar-panel {
    width: 380px;
  }
}

@media (max-width: 1100px) {
  .gm-forge-layout {
    flex-direction: column;
  }
  .gm-forge-sidebar-panel {
    position: static;
    width: 100%;
    height: 500px;
    box-shadow: none;
    order: -1;
  }
}

.gm-forge-sidebar-panel .gm-forge-sidebar-header {
  padding: calc(var(--base-spacing) / 1.5) var(--base-spacing);
  border-bottom: 1px solid rgba(128, 128, 128, 0.2);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.gm-forge-sidebar-panel .gm-forge-sidebar-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.gm-forge-sidebar-panel .gm-forge-sidebar-content {
  flex: 1;
  overflow-y: auto;
}

.gm-forge-sidebar-panel .gm-forge-sidebar-footer {
  padding: var(--base-spacing);
  border-top: 1px solid rgba(128, 128, 128, 0.2);
}

/* ===========================================
   Notebook Panel (Notebook-specific styles)
   =========================================== */

.gm-forge-notebook-panel form {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.gm-forge-notebook-panel textarea {
  border: none;
  padding: var(--base-spacing);
  font-family: var(--font-stack-monospace);
  font-size: 0.9rem;
  line-height: 1.5;
  resize: none;
  width: 100%;
  height: 100%;
}

/* ===========================================
   Unified Chip System
   Base component for tags, filters, selections
   =========================================== */

.gm-forge-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  font-family: var(--font-stack-monospace);
  font-size: 0.75rem;
  font-weight: 400;
  border-radius: 12px;
  border: 2px solid transparent;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
  background: rgba(128, 128, 128, 0.12);
  color: inherit;
  transition: transform 0.1s ease-out, border-color 0.1s, background 0.1s;
  max-height: 24px;
}

/* Size variants */
.gm-forge-chip-sm { padding: 2px 8px; font-size: 0.7rem; border-radius: 10px; }
.gm-forge-chip-lg { padding: 6px 14px; font-size: 0.85rem; border-radius: 14px; }

/* Interactive chips */
.gm-forge-chip-interactive {
  cursor: pointer;
  text-decoration: none;
}

.gm-forge-chip-interactive:hover {
  transform: scale(1.03);
  background: rgba(128, 128, 128, 0.2);
}

.gm-forge-chip-interactive:active {
  transform: scale(0.98);
}

/* Selectable chips (with hidden checkbox) */
.gm-forge-chip-selectable {
  cursor: pointer;
}

.gm-forge-chip-selectable input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.gm-forge-chip-check {
  display: none;
  font-size: 0.65em;
}

.gm-forge-chip-selectable.is-selected,
.gm-forge-chip-selectable:has(input:checked) {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

.gm-forge-chip-selectable.is-selected .gm-forge-chip-check,
.gm-forge-chip-selectable:has(input:checked) .gm-forge-chip-check {
  display: inline;
}

.gm-forge-chip-selectable:hover:not(.is-selected):not(:has(input:checked)) {
  background: rgba(128, 128, 128, 0.2);
}

/* Removable chips (with × button) */
.gm-forge-chip-removable {
  padding-right: 4px;
}

.gm-forge-chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  padding: 0;
  margin-left: 2px;
  border: none;
  background: rgba(0, 0, 0, 0.15);
  color: inherit;
  border-radius: 50%;
  cursor: pointer;
  font-size: 11px;
  opacity: 0.7;
  transition: opacity 0.1s, background 0.1s;
}

.gm-forge-chip-remove:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.3);
}

/* Active state - border highlight */
.gm-forge-chip-interactive.is-active {
  border-color: currentColor;
}

/* Chip containers */
.gm-forge-chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.gm-forge-chip-scroll {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px;
  border: 1px solid rgba(128, 128, 128, 0.2);
  border-radius: 6px;
  background: rgba(128, 128, 128, 0.05);
  align-content: flex-start;
}

/* System picker uses larger chips */
.gm-forge-system-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.gm-forge-system-picker .gm-forge-chip {
  padding: 10px 16px;
  font-size: 0.9rem;
  border-radius: 6px;
}


/* Entity cards in session view */
.gm-forge-entity-list {
  display: flex;
  flex-direction: column;
  gap: calc(var(--base-spacing) / 2);
}

/* Entity card state classes only - base styling uses Tachyons utilities */

/* Expand/collapse indicator at bottom of card */
.gm-forge-expand-toggle {
  width: 100%;
  padding: 6px 0;
  margin-top: calc(var(--base-spacing) / 2);
  border-top: 1px solid rgba(128, 128, 128, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
}

.gm-forge-expand-arrow {
  font-size: 10px;
  opacity: 0.6;
  transition: transform 0.2s ease;
}

.gm-forge-expand-toggle:hover .gm-forge-expand-arrow {
  opacity: 1;
}

.gm-forge-expand-toggle[aria-expanded="true"] .gm-forge-expand-arrow {
  transform: rotate(180deg);
}

/* Summary stats (always visible) */
.gm-forge-entity-summary {
  margin-top: calc(var(--base-spacing) / 2);
}

.gm-forge-summary-stats {
  display: flex;
  flex-wrap: wrap;
  gap: calc(var(--base-spacing) / 2);
}

.gm-forge-summary-stat {
  padding: 2px 6px;
  background: rgba(128, 128, 128, 0.15);
  border-radius: 3px;
}

.gm-forge-summary-stat strong {
  font-weight: 600;
  margin-right: 4px;
}

/* Detailed stats (collapsible) */
.gm-forge-entity-details {
  display: none;
  margin-top: var(--base-spacing);
  padding-top: var(--base-spacing);
  border-top: 1px solid rgba(128, 128, 128, 0.2);
}

.gm-forge-entity-details.is-expanded {
  display: block;
}

/* Stat block for D&D-style entities */
.gm-forge-stat-block {
  display: flex;
  justify-content: space-between;
  text-align: center;
  margin: calc(var(--base-spacing) / 2) 0;
  padding: calc(var(--base-spacing) / 2);
  border-radius: 4px;
  background: rgba(128, 128, 128, 0.08);
}

.gm-forge-stat-item {
  flex: 1;
}

.gm-forge-stat-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.6;
  font-family: var(--font-stack-sans-serif);
}

.gm-forge-stat-value {
  font-size: 1.1rem;
  font-weight: 600;
}

.gm-forge-stat-modifier {
  font-size: 0.75rem;
  opacity: 0.7;
}

/* Key-value pairs */
.gm-forge-kv-row {
  display: flex;
  flex-wrap: wrap;
  gap: calc(var(--base-spacing) / 2);
  margin: calc(var(--base-spacing) / 4) 0;
}

/* Wrapping kv-row for many items */
.gm-forge-kv-wrap {
  flex-wrap: wrap;
  row-gap: calc(var(--base-spacing) / 4);
}

/* Key-value list (readable, one per line; used in procedural entity details) */
.gm-forge-kv-list {
  margin: 0;
}

.gm-forge-kv-list-item {
  display: grid;
  grid-template-columns: minmax(140px, 220px) 1fr;
  gap: calc(var(--base-spacing) / 2);
  padding: calc(var(--base-spacing) / 6) 0;
}

.gm-forge-kv-term {
  font-weight: 600;
  opacity: 0.8;
}

.gm-forge-kv-def {
  margin: 0; /* override default dd margin */
}

@media (max-width: 640px) {
  .gm-forge-kv-list-item {
    grid-template-columns: 1fr;
    gap: 2px;
  }
}

/* Bullet lists for simple arrays */
.gm-forge-bullet-list {
  margin: 0;
  padding-left: 1.2rem;
}

.gm-forge-bullet-list li {
  margin: calc(var(--base-spacing) / 4) 0;
}

/* Sections */
.gm-forge-section {
  margin: var(--base-spacing) 0;
}

.gm-forge-section-title {
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: calc(var(--base-spacing) / 2);
  padding-bottom: calc(var(--base-spacing) / 4);
  border-bottom: 1px solid rgba(128, 128, 128, 0.25);
  opacity: 0.8;
  font-family: var(--font-stack-sans-serif);
}

/* Ability/Action entries */
.gm-forge-entry {
  margin: calc(var(--base-spacing) / 2) 0;
  font-size: 0.85rem;
}

.gm-forge-entry strong {
  font-style: italic;
}

/* Sidebar/Modal for generation and editing */
.gm-forge-sidebar {
  position: fixed;
  top: 0;
  right: 0;
  width: 400px;
  max-width: 90vw;
  height: 100vh;
  background: var(--color-box);
  z-index: 1001;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
}

.gm-forge-sidebar.is-open {
  transform: translateX(0);
}

.gm-forge-sidebar-header {
  padding: calc(var(--base-spacing) / 2) var(--base-spacing);
  border-bottom: 1px solid rgba(128, 128, 128, 0.2);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.gm-forge-sidebar-header h3 {
  margin: 0;
  font-size: 1rem;
}

/* Container for dynamically loaded edit form */
.gm-forge-sidebar-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.gm-forge-sidebar-body > form {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.gm-forge-sidebar-body .gm-forge-sidebar-content {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: var(--base-spacing);
}

.gm-forge-sidebar-footer {
  padding: var(--base-spacing);
  border-top: 1px solid rgba(128, 128, 128, 0.2);
}

/* Sticky footer inside edit form's scrollable content */
.gm-forge-sidebar-content .gm-forge-sidebar-footer {
  position: sticky;
  bottom: calc(-1 * var(--base-spacing));
  background: var(--color-box);
  /* Extend to edges of parent despite parent padding */
  margin-left: calc(-1 * var(--base-spacing));
  margin-right: calc(-1 * var(--base-spacing));
  margin-bottom: calc(-1 * var(--base-spacing));
  margin-top: var(--base-spacing);
  
  /* Shadow to cover any content peeking through */
  box-shadow: 0 -4px 8px rgba(0, 0, 0, 0.05);
}

@media (prefers-color-scheme: dark) {
  .gm-forge-sidebar-content .gm-forge-sidebar-footer {
    background: #444;
    box-shadow: 0 -4px 8px rgba(0, 0, 0, 0.2);
  }
}

/* Section columns for session view */
.gm-forge-session-columns {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--base-spacing);
}

@media (max-width: 1024px) {
  .gm-forge-session-columns {
    grid-template-columns: 1fr;
  }
}

.gm-forge-column {
  min-height: 200px;
}

.gm-forge-column-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--base-spacing);
  padding-bottom: calc(var(--base-spacing) / 2);
  border-bottom: 1px solid rgba(128, 128, 128, 0.2);
}

.gm-forge-column-header h3 {
  margin: 0;
  font-size: 1rem;
}

/* DM Notes section */
.gm-forge-notes {
  padding: calc(var(--base-spacing) / 2);
  border-radius: 4px;
  font-size: 0.85rem;
  margin-top: var(--base-spacing);
  background: rgba(128, 128, 128, 0.08);
}

.gm-forge-notes-edit {
  width: 100%;
  min-height: 100px;
  font-family: var(--font-stack-sans-serif);
  font-size: 0.85rem;
  padding: calc(var(--base-spacing) / 2);
  border-radius: 4px;
  resize: vertical;
}

/* Scrollable aspects container */
.gm-forge-aspects-scroll {
  overflow-y: auto;
  min-height: 60px;
}

/* Checkbox label for optional features */
.gm-forge-checkbox-label {
  display: flex;
  align-items: center;
  gap: var(--base-spacing);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 8px 10px;
  border-radius: 6px;
  background: rgba(128, 128, 128, 0.08);
  border: 1px solid rgba(128, 128, 128, 0.15);
  transition: background 0.15s, border-color 0.15s;
}

.gm-forge-checkbox-label:hover {
  background: rgba(128, 128, 128, 0.15);
}

.gm-forge-checkbox-label:has(input:checked) {
  background: rgba(var(--color-character-accent-rgb), 0.16);
  border-color: var(--color-character-accent);
}

.gm-forge-checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  cursor: pointer;
}

/* Aspects section (collapsible panel) */
.gm-forge-aspects-section {
  position: fixed;
  top: 0;
  right: 0;
  width: 450px;
  max-width: 95vw;
  height: 100vh;
  background: var(--color-box);
  z-index: 1001;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
  transform: translateX(100%);
  display: flex;
  flex-direction: column;
}

.gm-forge-aspects-section.is-open {
  transform: translateX(0);
}

.gm-forge-aspects-header {
  padding: calc(var(--base-spacing) / 2) var(--base-spacing);
  border-bottom: 1px solid rgba(128, 128, 128, 0.2);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.gm-forge-aspects-header h3 {
  margin: 0;
  font-size: 1rem;
}

.gm-forge-aspects-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: var(--base-spacing);
  min-height: 0;
}

.gm-forge-aspects-list {
  flex: 1;
  overflow-y: auto;
  min-height: 200px;
  margin-bottom: var(--base-spacing);
}

.gm-forge-new-aspect-form {
  flex-shrink: 0;
  padding-top: var(--base-spacing);
  border-top: 1px solid rgba(128, 128, 128, 0.2);
}

/* Empty state */
.gm-forge-empty {
  text-align: center;
  padding: calc(var(--base-spacing) * 2);
  opacity: 0.5;
  font-style: italic;
}

/* Dynamic Edit Form */
.gm-forge-edit-section {
  margin-bottom: var(--base-spacing);
  padding-bottom: var(--base-spacing);
  border-bottom: 1px solid rgba(128, 128, 128, 0.2);
}

.gm-forge-edit-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.gm-forge-edit-section-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-primary);
  margin: 0 0 calc(var(--base-spacing) / 2) 0;
}

.gm-forge-edit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: calc(var(--base-spacing) / 2);
}

.gm-forge-edit-grid .field {
  margin-bottom: 0;
}

.gm-forge-edit-grid .field label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  opacity: 0.7;
  margin-bottom: 2px;
}

.gm-forge-edit-grid .field input {
  padding: 4px 8px;
  font-size: 0.9rem;
}

/* Array items in edit form */
.gm-forge-edit-array-item {
  border-radius: 4px;
  padding: calc(var(--base-spacing) / 2);
  margin-bottom: calc(var(--base-spacing) / 2);
  background: rgba(128, 128, 128, 0.08);
}

.gm-forge-edit-array-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: calc(var(--base-spacing) / 2);
}

.gm-forge-edit-array-item .field {
  margin-bottom: calc(var(--base-spacing) / 2);
}

.gm-forge-edit-array-item .field:last-child {
  margin-bottom: 0;
}

/* Ensure textareas in edit form have proper height */
.gm-forge-sidebar-body textarea,
.gm-forge-edit-section textarea {
  min-height: 60px;
  resize: vertical;
}

.gm-forge-edit-section textarea[rows="2"] {
  min-height: 50px;
}

.gm-forge-edit-section textarea[rows="3"] {
  min-height: 72px;
}

.gm-forge-edit-section textarea[rows="4"] {
  min-height: 96px;
}

/* Aspect item (details/summary in session view overlay) */
.gm-forge-aspect-item {
  border-bottom: 1px solid rgba(128, 128, 128, 0.15);
  margin: 0;
}

.gm-forge-aspect-item:last-child {
  border-bottom: none;
}

.gm-forge-aspect-summary {
  padding: calc(var(--base-spacing) / 2) 0;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: calc(var(--base-spacing) / 2);
}

.gm-forge-aspect-summary::-webkit-details-marker {
  display: none;
}

.gm-forge-aspect-summary > div:first-child::before {
  content: '▸ ';
  font-size: 0.7rem;
  opacity: 0.5;
  transition: transform 0.15s ease;
  display: inline-block;
}

.gm-forge-aspect-item[open] .gm-forge-aspect-summary > div:first-child::before {
  transform: rotate(90deg);
}

.gm-forge-aspect-details {
  p:only-child {
    margin: 0;
    margin-bottom: var(--base-spacing);
  }
}

/* Prevent clicks on action buttons from toggling details */
.gm-forge-aspect-actions {
  display: flex;
  gap: 4px;
}

/* ===========================================
   Tags - Colored chips
   =========================================== */

/* Tiny tag color dots next to entity name */
.gm-forge-tag-dots {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding-left: 6px;
}

.gm-forge-tag-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Entity footer row (tags + actions) */
.gm-forge-entity-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--base-spacing);
  margin-top: var(--base-spacing);
  padding-top: calc(var(--base-spacing) / 2);
  border-top: 1px solid rgba(128, 128, 128, 0.15);
}

.gm-forge-entity-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.gm-forge-entity-actions .is-copied {
  color: var(--color-success, #28a745);
  background: rgba(40, 167, 69, 0.15);
}

/* Container for entity tags */
.gm-forge-entity-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

/* Filter chip - interactive with × on hover */
.gm-forge-filter-chip {
  cursor: pointer;
  text-decoration: none;
}

.gm-forge-filter-chip:hover {
  transform: scale(1.03);
}

.gm-forge-filter-chip .gm-forge-chip-remove {
  opacity: 0;
  background: transparent;
}

.gm-forge-filter-chip:hover .gm-forge-chip-remove {
  opacity: 0.8;
  background: rgba(0, 0, 0, 0.15);
}

/* ===========================================
   Tag Management Page
   =========================================== */

.gm-forge-tags-list {
  display: flex;
  flex-direction: column;
  gap: calc(var(--base-spacing) / 2);
}

.gm-forge-tag-row {
  display: flex;
  align-items: center;
  gap: var(--base-spacing);
  padding: calc(var(--base-spacing) * 0.75) var(--base-spacing);
  background: var(--color-box);
  border-radius: 6px;
  border: 1px solid rgba(128, 128, 128, 0.15);
}

.gm-forge-tag-row-actions {
  margin-left: auto;
}

/* Expandable tag with session breakdown */
.gm-forge-tag-expandable {
  background: var(--color-box);
  border-radius: 6px;
  border: 1px solid rgba(128, 128, 128, 0.15);
  overflow: hidden;
}

.gm-forge-tag-expandable-header {
  display: flex;
  align-items: center;
  gap: var(--base-spacing);
  padding: calc(var(--base-spacing) * 0.75) var(--base-spacing);
}

.gm-forge-tag-expandable-header .gm-forge-tag-row-actions {
  margin-left: auto;
}

.gm-forge-tag-sessions {
  border-top: 1px solid rgba(128, 128, 128, 0.1);
  background: rgba(128, 128, 128, 0.03);
}

.gm-forge-tag-session-link {
  display: flex;
  align-items: center;
  gap: var(--base-spacing);
  padding: calc(var(--base-spacing) / 2) var(--base-spacing);
  padding-left: calc(var(--base-spacing) * 2);
  text-decoration: none;
  color: inherit;
  border-bottom: 1px solid rgba(128, 128, 128, 0.08);
  transition: background 0.1s;
}

.gm-forge-tag-session-link:last-child {
  border-bottom: none;
}

.gm-forge-tag-session-link:hover {
  background: rgba(128, 128, 128, 0.08);
}

/* Add tag form in edit sidebar */
.gm-forge-add-tag-form {
  margin-top: calc(var(--base-spacing) / 2);
}

.gm-forge-entity-tags-editor .gm-forge-entity-tags {
  margin-top: 0;
}

/* Search & Filter Bar */
.gm-forge-search-filter-bar {
  margin-bottom: var(--base-spacing);
  display: flex;
  flex-direction: column;
  gap: calc(var(--base-spacing) / 2);
}

.gm-forge-search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.gm-forge-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0.5;
  pointer-events: none;
  font-size: 1rem;
  z-index: 1;
  display: inline-block;
  line-height: 1;
}

.gm-forge-search-wrapper input {
  width: 100%;
  padding-left: 36px;
  padding-right: 36px;
}

.gm-forge-search-clear {
  position: absolute;
  right: 8px;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  background: rgba(128, 128, 128, 0.2);
  color: inherit;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  opacity: 0.6;
  transition: opacity 0.15s, background 0.15s;
}

.gm-forge-search-clear:hover {
  opacity: 1;
  background: rgba(128, 128, 128, 0.35);
}

/* Filter bar */
.gm-forge-filter-bar {
  display: flex;
  align-items: center;
  gap: var(--base-spacing);
  padding: calc(var(--base-spacing) / 1.5) var(--base-spacing);
  background: var(--color-box);
  border-radius: 6px;
  border: 2px solid var(--color-primary);
  flex-wrap: wrap;
  background-color: rgba(0, 0, 0, 0.05)
}

.gm-forge-filter-label {
  font-size: 0.85rem;
  font-weight: 600;
  opacity: 0.7;
  font-family: var(--font-stack-sans-serif);
}

.gm-forge-active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
}

/* Search text filter chip */
.gm-forge-filter-chip-search {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  font-size: 0.8rem;
  border-radius: 10px;
  background: rgba(128, 128, 128, 0.15);
  text-decoration: none;
  color: inherit;
}

.gm-forge-filter-chip-search:hover {
  background: rgba(128, 128, 128, 0.25);
}

/* Empty state when filtered */
.gm-forge-empty-filtered {
  font-style: italic;
  opacity: 0.6;
}

/* Notebook - collapsible section */
.gm-forge-notebook {
  border-bottom: 1px solid rgba(128, 128, 128, 0.2);
  padding-bottom: var(--base-spacing);
}

.gm-forge-notebook > summary {
  cursor: pointer;
  list-style: none;
}

.gm-forge-notebook > summary::-webkit-details-marker {
  display: none;
}

/* Notebook Markdown Content - scaled down to fit page hierarchy */
.gm-forge-notebook-content {
  font-size: 0.9rem;
  line-height: 1.6;
}

.gm-forge-notebook-content h1 { font-size: 1.1rem; }
.gm-forge-notebook-content h2 { font-size: 1rem; }
.gm-forge-notebook-content h3 { font-size: 0.95rem; }
.gm-forge-notebook-content h4 { font-size: 0.9rem; }

.gm-forge-notebook-content h1,
.gm-forge-notebook-content h2,
.gm-forge-notebook-content h3,
.gm-forge-notebook-content h4 {
  margin-top: 1em;
  margin-bottom: 0.4em;
  font-weight: 600;
}

.gm-forge-notebook-content h1:first-child,
.gm-forge-notebook-content h2:first-child,
.gm-forge-notebook-content h3:first-child {
  margin-top: 0;
}

.gm-forge-notebook-content ul,
.gm-forge-notebook-content ol {
  padding-left: 1.5em;
  margin-bottom: 0.75em;
}

.gm-forge-notebook-content p {
  margin-bottom: 0.6em;
}

.gm-forge-notebook-content p:last-child {
  margin-bottom: 0;
}

/* ===========================================
   Building State - Async Entity Generation
   =========================================== */

@keyframes gm-forge-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.gm-forge-spinner {
  animation: gm-forge-spin 1s linear infinite;
  display: inline-block;
}


.gm-forge-entity-card.is-building {
  opacity: 0.7;
  border-style: dashed;
}

.gm-forge-loading-bar-container {
  width: 100%;
  height: 6px;
  background-color: rgba(0, 0, 0, 0.1);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 0.5rem;
}

.gm-forge-loading-bar {
  height: 100%;
  background-color: rgba(0, 0, 0, 0.1);
  width: 0%;
  animation: gm-forge-loading-progress 7s ease-in-out forwards;
}

@keyframes gm-forge-loading-progress {
  0% { width: 0%; }
  10% { width: 15%; }
  20% { width: 18%; }
  30% { width: 35%; }
  40% { width: 42%; }
  50% { width: 55%; }
  60% { width: 63%; }
  70% { width: 75%; }
  80% { width: 82%; }
  90% { width: 92%; }
  100% { width: 98%; }
}

.gm-forge-entity-card.has-error {
  border-color: var(--color-danger);
}

.gm-forge-error-title {
  color: var(--color-danger);
}

.gm-forge-error-message {
  color: var(--color-danger);
  font-size: 0.85em;
}

/* ===========================================
   Entity Images
   =========================================== */

.gm-forge-entity-thumbnail {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  border: 1px solid rgba(128, 128, 128, 0.2);
  margin-right: 8px;
  background-position: center;
  background-repeat: no-repeat;
}

.gm-forge-entity-thumbnail.is-generating {
  opacity: 0.4;
}

/* Image generation error indicator */
.gm-forge-image-error {
  color: var(--color-warning, #e67e22) !important;
}
.gm-forge-image-error:hover {
  color: var(--color-warning-dark, #d35400) !important;
}

/* ===========================================
   Dice Roller
   =========================================== */

.gm-forge-dice-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.gm-forge-dice-result {
  background: rgba(128, 128, 128, 0.1);
}

.gm-forge-dice-result.is-animating {
  opacity: 0.5;
}

.gm-forge-dice-history {
  border-top: 1px solid rgba(128, 128, 128, 0.2);
}

/* Dark mode - only for elements that need explicit overrides */
@media (prefers-color-scheme: dark) {
  .gm-forge-sidebar,
  .gm-forge-aspects-section,
  .gm-forge-sidebar-panel {
    background: #444;
  }

  .gm-forge-edit-section-title {
    color: var(--color-character-accent);
  }

  .gm-forge-tag-row,
  .gm-forge-tag-expandable {
    background: #333;
  }
  
  .gm-forge-chip-remove {
    background: rgba(255, 255, 255, 0.15);
  }
  
  .gm-forge-chip-remove:hover {
    background: rgba(255, 255, 255, 0.25);
  }
}

/* ===========================================
   Spark AI Assistant Panel
   =========================================== */

.spark-panel {
  width: 400px;
}

.spark-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.spark-threads-section {
  flex-shrink: 0;
  border-bottom: 1px solid rgba(128, 128, 128, 0.2);
  max-height: 25%;
  overflow-y: auto;
}

.spark-threads-header {
  padding: 0.375rem 0.75rem;
  background: rgba(128, 128, 128, 0.05);
  border-bottom: 1px solid rgba(128, 128, 128, 0.1);
}

.spark-thread-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid rgba(128, 128, 128, 0.1);
  transition: background 0.15s;
}

.spark-thread-item:hover {
  background: rgba(128, 128, 128, 0.05);
}

.spark-thread-item.is-active {
  background: rgba(var(--color-character-accent-rgb), 0.12);
  border-left: 3px solid var(--color-character-accent);
  padding-left: calc(0.75rem - 3px);
}

.spark-thread-link {
  flex: 1;
  text-decoration: none;
  color: inherit;
  display: block;
  min-width: 0;
}

.spark-thread-title {
  font-weight: 600;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.spark-thread-meta {
  font-size: 0.7rem;
  opacity: 0.5;
  margin-top: 0.125rem;
}

.spark-thread-delete {
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s;
  padding: 0.25rem 0.5rem;
}

.spark-thread-item:hover .spark-thread-delete {
  opacity: 0.6;
}

.spark-thread-delete:hover {
  opacity: 1 !important;
}

.spark-conversation {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.spark-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.spark-message {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  &:not(:first-of-type) {
    margin-top: calc(var(--base-spacing) / 2);
  }
}

.spark-message-role {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  opacity: 0.7;
}

.spark-message-role i {
  font-size: 1rem;
}

.spark-message-content {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  line-height: 1.5;

  p:only-child { margin: 0; }
  p:last-child { margin-bottom: 0; }
  p:first-child { margin-top: 0; }
}

.spark-message-user .spark-message-content {
  background: rgba(var(--color-character-accent-rgb), 0.12);
  border: 1px solid rgba(var(--color-character-accent-rgb), 0.24);
}

.spark-message-assistant .spark-message-content {
  background: rgba(128, 128, 128, 0.05);
  border: 1px solid rgba(128, 128, 128, 0.1);
}

.spark-message-entities {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.spark-entity-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.5rem;
  background: rgba(128, 128, 128, 0.1);
  border: 1px solid rgba(128, 128, 128, 0.2);
  border-radius: 4px;
  font-size: 0.75rem;
}

.spark-entity-chip i {
  font-size: 0.9rem;
  opacity: 0.6;
}

.spark-input-form {
  flex-shrink: 0;
  border-top: 1px solid rgba(128, 128, 128, 0.2);
  padding: 0.75rem;
}

.spark-input-container {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.spark-input {
  width: 100%;
  min-height: 60px;
  max-height: 120px;
  resize: vertical;
  border: 1px solid rgba(128, 128, 128, 0.2);
  border-radius: 6px;
  padding: 0.5rem;
  font-size: 0.9rem;
  font-family: var(--font-stack-sans-serif);
}

.spark-input:focus {
  outline: none;
  border-color: var(--color-primary);
}

.spark-input-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.spark-cost {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  opacity: 0.6;
}

.spark-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
}

.spark-thinking {
  opacity: 0.7;
}

.spark-thinking .spark-message-content {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.spark-error-flash {
  background: var(--color-danger, #e74c3c);
  color: white;
  padding: 0.75rem;
  border-radius: 4px;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
  transition: opacity 0.3s;
}

.spark-tool-call {
  background: rgba(128, 128, 128, 0.08);
  border: 1px solid rgba(128, 128, 128, 0.1);
}

.spark-tool-call-args {
  color: rgba(0, 0, 0, 0.6);
}

.spark-tool-call-key {
  color: rgba(0, 0, 0, 0.4);
}

/* Dark mode overrides for Spark */
@media (prefers-color-scheme: dark) {
  .spark-panel {
    background: #444;
  }

  .spark-tool-call {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
  }

  .spark-tool-call-args {
    color: rgba(255, 255, 255, 0.7);
  }

  .spark-tool-call-key {
    color: rgba(255, 255, 255, 0.4);
  }
  
  .spark-message-user .spark-message-content {
    background: rgba(var(--color-character-accent-rgb), 0.18);
    border-color: rgba(var(--color-character-accent-rgb), 0.32);
  }
  
  .spark-message-assistant .spark-message-content {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
  }
  
  .spark-input {
    background: rgba(0, 0, 0, 0.2);
    border-color: rgba(255, 255, 255, 0.2);
    color: inherit;
  }
  
  .spark-input:focus {
    border-color: rgba(255, 255, 255, 0.4);
  }
}
