/* ========================================
   CHARACTER MANAGER SPECIFIC STYLES
   Base terminal theme loaded from terminal-theme.css
   
   SCROLLBAR STRUCTURE:
   - Left panel (character grid): scrolls when content overflows
   - Right panel (character sheet): scrolls when content overflows
   - Splash content: scrolls if ASCII art is too large
   - Modal content: scrolls if form content is too large
   All scrollbars inherit from terminal-theme.css custom scrollbar styles
   ======================================== */

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.main-content.is-hidden {
    display: none;
}

/* Ensure splash content can scroll if needed */
.terminal-frame .splash-content {
    min-height: 0;
    height: 100%;
    box-sizing: border-box;
    overflow: auto;
}

/* ===== HEADER LAYOUT ===== */
.header-content {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--spacing-md);
    width: 100%;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    margin-left: auto;
}

.right-panel {
    display: flex;
    flex-direction: column;
}

/* Right panel uses teal scrollbars to match character sheet theme */
.right-panel {
    --scrollbar-track-color: hsl(var(--theme-teal-h), 70%, 7%);
    --scrollbar-thumb-color: hsla(var(--theme-teal-h), calc(var(--theme-teal-s) * 0.67), var(--theme-teal-l-dim), 0.5);
    --scrollbar-thumb-hover-color: hsla(var(--theme-teal-h), var(--theme-teal-s), var(--theme-teal-l-bright), 0.9);
}

/* ===== CONTROLS SECTION ===== */
.controls-section {
    margin-bottom: var(--spacing-lg);
}

.guest-notice {
    margin: 0 0 24px 0;
    padding: var(--spacing-sm) var(--spacing-md);
    border: 1px solid var(--modal-accent);
    background-color: hsla(var(--theme-yellow-h), var(--theme-yellow-s), var(--theme-yellow-l-bright), 0.12);
    font-size: var(--font-size-small);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.guest-notice .highlight {
    color: var(--modal-accent);
}

.guest-notice-icon {
    color: var(--modal-accent);
}

.guest-notice-close {
    margin-left: auto;
}

.search-bar {
    margin-bottom: var(--spacing-sm);
    display: flex;
    align-items: stretch;
    gap: var(--spacing-sm);
}

.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    flex: 1;
}

.search-input-wrapper .terminal-input {
    padding-right: 28px; /* make room for clear button */
    padding-left: 32px;  /* make room for leading search icon */
    /* Search field text should use dim terminal green so it feels subtle
       even when focused, while still using shared focus borders/shadows. */
    color: var(--terminal-dim);
    /* Match search input text size to small button text */
    font-size: var(--font-size-small);
}

/* Placeholder copy (e.g., "Search all 15 characters") should also use
   the dim terminal green token so it matches the input text color. */
.search-input-wrapper .terminal-input::placeholder {
    color: var(--terminal-dim);
    /* Keep placeholder the same size as the input/button text */
    font-size: var(--font-size-small);
}

/* Dim the search box when not focused so it feels secondary until active */
.search-input-wrapper .terminal-input:not(:focus) {
    border-color: var(--terminal-dim);
}

/* When focused, make the search field feel like a primary green input */
.search-input-wrapper .terminal-input:focus {
    /* Use bright terminal green (not teal accent) */
    border-color: var(--terminal-border);
    box-shadow: 0 0 8px var(--terminal-border);
    color: var(--terminal-fg);
}

.password-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.password-input-wrapper .terminal-input {
    padding-right: 64px; /* make room for toggle button */
}

.password-toggle-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--modal-accent);
    cursor: pointer;
    font-family: var(--font-family);
    font-size: var(--font-size-small);
    padding: 0;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.password-toggle-btn:hover {
    color: var(--terminal-accent);
}

.password-toggle-btn:focus {
    outline: 1px dashed var(--terminal-accent);
    outline-offset: 2px;
}

.search-clear-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--terminal-dim);
    cursor: pointer;
  font-size: 18px;
    line-height: 1;
    padding: 0;
    transition: color var(--transition-speed), transform var(--transition-speed);
}

.search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 18px;
    line-height: 1;
    color: var(--terminal-dim);
    pointer-events: none;
}

.search-clear-btn:hover {
    color: var(--terminal-accent);
    /* Match modal close spin: quarter turn on hover */
    transform: translateY(-50%) rotate(90deg);
}

.search-clear-btn.is-hidden {
    display: none;
}

.search-actions {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.sort-trigger-wrap {
    position: relative;
    display: inline-block;
}

.search-sort-btn {
    /* Inherit core visuals (border, colors, font, states) from .terminal-btn-small.
       This class now only handles layout tweaks specific to the sort control. */
    display: inline-flex;
    align-items: center;
    gap: 4px;
    justify-content: space-between;
    white-space: nowrap;
}

.search-sort-btn:hover {
    border-color: var(--terminal-accent);
    color: var(--terminal-accent);
}

.search-sort-btn.is-active {
    /* Dimmed look while listbox is open */
    border-color: var(--terminal-dim);
    color: var(--terminal-dim);
    background-color: rgba(0, 0, 0, 0.6);
}

/* Sort dropdown uses shared .selector-menu / .selector-option styles
   from terminal-theme.css; no additional manager-specific overrides. */

/* ===== CHARACTER COUNT ===== */
.character-count {
    margin-bottom: var(--spacing-md);
    font-size: var(--font-size-base);
    color: var(--terminal-dim);
}

/* ===== CHARACTER GRID ===== */
.character-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-xl);
}

/* ===== CHARACTER CARD ===== */
.character-card {
    background-color: var(--terminal-bg);
    /* Default/unselected: dim green outline */
    border: 1px solid var(--terminal-dim);
    padding: 0;
    transition: all var(--transition-speed);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    aspect-ratio: 3 / 4;
}

/* Hover and keyboard focus (unselected) - bright green outline, text, and ASCII */
.character-card:hover:not(.is-selected),
.character-card.is-keyboard-focused:not(.is-selected) {
    border-color: var(--terminal-border);
    background-color: hsla(var(--theme-terminal-h), var(--theme-terminal-s), var(--theme-terminal-l-bright), 0.08);
    box-shadow: 0 0 15px hsla(var(--theme-terminal-h), var(--theme-terminal-s), var(--theme-terminal-l-bright), 0.25);
}

.character-card:hover:not(.is-selected) .card-thumbnail,
.character-card.is-keyboard-focused:not(.is-selected) .card-thumbnail,
.character-card:hover:not(.is-selected) .card-name,
.character-card.is-keyboard-focused:not(.is-selected) .card-name,
.character-card:hover:not(.is-selected) .card-info,
.character-card.is-keyboard-focused:not(.is-selected) .card-info {
    color: var(--terminal-fg);
}
    
.card-thumbnail {
    width: 100%;
    aspect-ratio: 3 / 4;
    font-size: 2.2px;
    line-height: 1.1;
    /* Default/unselected: dim green ASCII */
    color: var(--terminal-dim);
    font-family: var(--font-mono);
    white-space: pre;
    overflow: hidden;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    background-color: rgba(0, 0, 0, 0.3);
    text-align: center;
    padding: 0;
    flex: 1 1 auto;
}

.card-details {
    padding: var(--spacing-md);
}

.card-name {
    /* Default/unselected: dim green text */
    color: var(--terminal-dim);
    font-size: var(--font-size-small);
    line-height: 1.2;
    margin-bottom: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card-info {
    color: var(--terminal-dim);
    /* Slightly smaller than other card text for hierarchy */
    font-size: 12px;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: var(--spacing-xl) var(--spacing-lg);
    display: none;
}

.empty-state.show {
    display: block;
}

.empty-icon {
    font-size: 4rem;
    margin-bottom: var(--spacing-md);
    opacity: 0.5;
}

.empty-title {
    font-size: var(--font-size-base);
    color: var(--terminal-accent);
    margin-bottom: var(--spacing-sm);
}

.empty-message {
    color: var(--terminal-dim);
    font-size: var(--font-size-base);
    margin-bottom: var(--spacing-lg);
}

.new-character-card {
    display: flex;
    align-items: center;
    justify-content: center;
}

.new-character-card .card-details {
    text-align: center;
}

/* ===== CHARACTER SHEET (Right Panel) ===== */
.sheet-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--terminal-dim);
}

.placeholder-icon {
    font-size: 4rem;
    margin-bottom: var(--spacing-md);
    opacity: 0.3;
}

.placeholder-text {
    font-size: var(--font-size-base);
}

/* ===== EDIT DETAILS MODAL ===== */
#editDetailsModal .terminal-textarea {
    min-height: 120px;
}

#editDetailsModal #editBackstory {
    min-height: 180px;
}

/* Remove border for sections with grid layouts */
.stat-grid + .sheet-header,
.ability-grid + .sheet-header,
.sheet-section:has(.stat-grid) .sheet-header,
.sheet-section:has(.ability-grid) .sheet-header {
    border-bottom: none;
    padding-bottom: 0;
}

.sheet-header-title {
    flex: 1;
}

.original-portrait {
    width: 100%;
    max-width: 100%;
    height: auto;
    display: block;
    object-fit: contain;
    text-align: center;
    margin: 0 auto;
    border: none;
}

/* Removed - using .text-dim from builder instead */

/* ===== WELCOME MODAL (BUILDER-STYLE SPLASH) ===== */
.welcome-modal {
    max-width: 960px;
}

.welcome-modal .modal-body {
    padding: 24px;
}

.welcome-body {
    display: flex;
    gap: var(--spacing-lg);
    align-items: center;
    justify-content: center;
}

.welcome-modal .splash-content {
    flex: 0 0 auto;
    max-height: 60vh;
    overflow: auto;
}

.welcome-modal .splash-art {
    color: var(--modal-accent);
}

.welcome-actions {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    min-width: 220px;
}

.welcome-actions .terminal-btn {
    display: flex;
    width: 100%;
    justify-content: center;
    border-color: var(--modal-accent);
    color: var(--modal-accent);
}

.welcome-actions .terminal-btn:hover {
    border-color: var(--modal-accent);
    background: hsla(var(--theme-yellow-h), var(--theme-yellow-s), var(--theme-yellow-l-bright), 0.18);
    box-shadow: 0 0 10px hsla(var(--theme-yellow-h), var(--theme-yellow-s), var(--theme-yellow-l-bright), 0.7);
}

.welcome-version {
    margin-top: var(--spacing-md);
    font-size: var(--font-size-small);
    color: var(--modal-accent-dim);
    text-align: center;
}

/* ===== UTILITY CLASSES ===== */
.is-hidden {
    display: none !important;
}

.file-input-hidden {
    display: none;
}

.fade-out {
    opacity: 0 !important;
    transition: opacity 0.3s ease-out;
}

.fade-in {
    opacity: 1 !important;
    transition: opacity 0.3s ease-in;
}

/* Inline-style replacements from HTML */
.file-name-label {
    margin-left: var(--spacing-sm);
}

.modal-body-question {
    margin-top: var(--spacing-md);
}

.modal-footer-centered {
    justify-content: center;
}

.modal-footer-end {
    justify-content: flex-end;
}

/* ===== AUTH UI / HEADER THEMING ===== */
/* Make the manager header content use the teal sheet theme:
   - Title: bright teal
   - User/local-storage label: dim teal
   - Buttons: use ui-theme-teal via HTML classes */
.terminal-header .terminal-title {
    color: var(--sheet-accent);
}

#userInfoDisplay {
    font-size: var(--font-size-small);
    white-space: nowrap;
    color: var(--sheet-accent-dim);
    display: inline-flex;
    align-items: center;
    gap: 0;
    /* Visually dim the account label so it doesn't compete with CTAs */
    opacity: 0.7;
}

.user-status-icon {
    display: none; /* hide cloud/local glyph; we only show the text label */
}

.user-status-text {
    line-height: 1.2;
}

/* Dim the header auth button (LOGIN / LOGOUT) so it reads as secondary */
.header-actions #authBtn {
    /* Use the dim teal tokens rather than the bright accent */
    border-color: var(--sheet-accent-dim);
    color: var(--sheet-accent-dim);
    opacity: 0.7;
}

.header-actions #authBtn:hover:not(:disabled) {
    /* On hover, brighten slightly but keep it softer than primary CTAs */
    border-color: var(--sheet-accent);
    color: var(--sheet-accent);
    opacity: 1;
}

/* Username + auth/log links in header should all be dim teal by default */
#userInfoDisplay .terminal-link {
    color: var(--sheet-accent-dim);
}

#userInfoDisplay .terminal-link:hover {
    color: var(--sheet-accent);
}

.terminal-text-error {
    color: var(--terminal-error);
    font-weight: bold;
    margin-top: var(--spacing-sm);
}

.terminal-link {
    text-decoration: none;
    cursor: pointer;
}

.terminal-link:hover {
    text-decoration: underline;
}

/* ===== MIGRATION STATUS ===== */
#migrationStatus {
    margin-top: var(--spacing-md);
    padding: var(--spacing-sm);
    border: 1px solid var(--ui-border-color);
    background: hsla(var(--theme-terminal-h), var(--theme-terminal-s), var(--theme-terminal-l-bright), 0.05);
}

.modal-section-label {
    margin-top: var(--spacing-lg);
}

/* Ability + combat grids inside Edit Details modal */
.modal-grid-abilities,
.modal-grid-combat {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--spacing-sm);
    margin-top: var(--spacing-sm);
}

.modal-grid-abilities label,
.modal-grid-combat label {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* ===== CARD SELECTION OVERRIDES (left panel) ===== */
/* Manager screen scrollbars keep teal theme for the right-hand sheet panel */
.manager-screen {
    --scrollbar-track-color: hsl(var(--theme-teal-h), 70%, 7%);
    --scrollbar-thumb-color: hsla(var(--theme-teal-h), calc(var(--theme-teal-s) * 0.67), var(--theme-teal-l-dim), 0.5);
    --scrollbar-thumb-hover-color: hsla(var(--theme-teal-h), var(--theme-teal-s), var(--theme-teal-l-bright), 0.9);
}

/* LEFT PANEL - Selected card uses bright terminal green (no teal) */
.character-card.is-selected {
    border-color: var(--terminal-border) !important;
    box-shadow: 0 0 15px hsla(var(--theme-terminal-h), var(--theme-terminal-s), var(--theme-terminal-l-bright), 0.5) !important;
    background-color: hsla(var(--theme-terminal-h), var(--theme-terminal-s), var(--theme-terminal-l-bright), 0.08);
}

.character-card.is-selected .card-thumbnail {
    /* Selected: bright green ASCII art */
    color: var(--terminal-border) !important;
}

.character-card.is-selected .card-name {
    /* Selected: reversed text area → bright green background, black text */
    color: #000000 !important;
}

.character-card.is-selected .card-info {
    color: #000000 !important;
}

.character-card.is-selected .card-details {
    background-color: var(--terminal-border);
    color: #000000;
}

/* Hover and keyboard focus for selected cards - keep bright green treatment */
.character-card.is-selected:hover,
.character-card.is-selected.is-keyboard-focused {
    border-color: var(--terminal-border) !important;
    background-color: hsla(var(--theme-terminal-h), var(--theme-terminal-s), var(--theme-terminal-l-bright), 0.14);
    box-shadow: 0 0 18px hsla(var(--theme-terminal-h), var(--theme-terminal-s), var(--theme-terminal-l-bright), 0.7) !important;
}

/* (All modal theming is now handled by terminal-theme.css so it can be shared across apps.) */

/* ===== ANIMATIONS ===== */
/* DEPRECATED: Old text-based spinner (↻ glyph). Replaced by .spinner-cube-* in terminal-theme.css.
   Keeping these rules for backward compatibility with any legacy code that hasn't been migrated yet. */
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.spinner {
  display: inline-block;
  animation: spin 1s linear infinite;
  font-size: 18px;
  color: currentColor;
  text-shadow: none;
  vertical-align: middle;
  margin-right: 8px;
}

.loading-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--spacing-xl);
}

.split-layout {
  position: relative;
}

.panel-loading-row {
  position: absolute;
  /* Fill the split layout and let CSS Grid handle centering so that
     parent transforms don't interfere with the cube's 3D axis. */
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  pointer-events: none; /* let clicks fall through to underlying UI */
}

.loading-text {
  color: var(--terminal-accent);
  font-family: var(--font-mono);
  font-size: calc(var(--font-size-base) * 1.1);
  text-shadow: 0 0 10px var(--terminal-accent);
}

/* Centered teal cube loaders for sheet + grid */
.panel-loading-row .loading-text {
  /* Match cube demo / narrator context so the cube spins on the same axis */
  font-size: var(--font-size-base);
  line-height: var(--line-height);
  white-space: normal;
  text-align: center;

  /* Match narrator spinner behavior: cube + text on one axis-aligned row */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35em;

  /* Use sheet teal tokens instead of terminal green */
  color: var(--sheet-accent);
  text-shadow: 0 0 10px var(--sheet-accent);

  /* Drive spinner-cube color via the shared UI foreground token */
  --ui-fg-color: var(--sheet-accent);
}

/* Ensure the cube + text wrapper behaves like the narrator context */
.panel-loading-row .narrator-spinner-shell {
  display: inline-flex;
  align-items: center;
  white-space: normal;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .header-content {
        gap: var(--spacing-sm);
    }
    
    .split-layout {
        flex-direction: column;
        overflow-y: auto;
    }
    
    .left-panel,
    .right-panel {
        flex: none;
        border-right: none;
        border-bottom: 1px solid var(--terminal-border);
        padding: var(--spacing-md);
        overflow-y: auto;
    }
    
    .right-panel {
        border-bottom: none;
    }
    
    .terminal-select {
        width: 100%;
    }
    
    .character-grid {
        grid-template-columns: 1fr;
    }
    
    .header-actions {
        width: 100%;
    }
    
    .header-actions button {
        flex: 1;
    }
    
    .stat-grid {
        grid-template-columns: 1fr;
    }
    
    .ability-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .sheet-title-buttons {
        flex-wrap: wrap;
    }
    
    .card-thumbnail {
        font-size: 1.5px;
        transform: scale(1.45);
    }
    
    .ascii-portrait {
        font-size: 4px;
    }
}
