/* =============================================================================
   CODEX PANEL - Realm Statistics Display
   ============================================================================= */

.codex-panel {
    width: 961px;
    height: 640px;
    background: var(--bg-panel);
    border-radius: 0;
    box-shadow: var(--shadow-popup);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.codex-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 2px 24px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-control-light);
}

.codex-header h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}

.codex-close {
    background: none;
    border: none;
    font-size: 28px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.codex-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.codex-content {
    flex: 1;
    display: flex;
    min-height: 0;
}

/* =============================================================================
   LEFT COLUMN - Realm List
   ============================================================================= */

.codex-left {
    width: 272px;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    background: var(--bg-control-light);
}

.codex-controls {
    padding: 8px 12px 12px 12px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.codex-search,
.codex-sort {
    width: 100%;
}

.codex-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.codex-realm-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.codex-realm-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
    background: var(--bg-panel);
    border: 1px solid transparent;
}

.codex-realm-item:hover {
    background: var(--bg-hover);
    border-color: var(--border-color);
}

.codex-realm-item.selected {
    background: #4a90e2;
    color: #fff;
    border-color: #3a80d2;
}

.realm-item-icon {
    width: 36px;
    height: 36px;
    border: 3.5px solid #888888;
    border-radius: 4px;
    background: #fafafa;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    box-shadow: 0 0 0 1px white;
}

.realm-item-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.realm-item-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.realm-item-name {
    font-weight: 600;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.realm-item-meta {
    font-size: 10px;
    opacity: 0.7;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.realm-item-meta .realm-race {
    font-weight: 500;
}

.realm-item-meta .realm-gov {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.realm-item-pop {
    font-size: 11px;
    font-weight: 500;
    opacity: 0.8;
    text-align: right;
    flex-shrink: 0;
}

.codex-realm-item.selected .realm-item-name,
.codex-realm-item.selected .realm-item-meta,
.codex-realm-item.selected .realm-item-pop {
    color: #fff;
}

.codex-summary {
    padding: 10px 12px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-panel);
    font-size: 11px;
    color: var(--text-secondary);
}

/* =============================================================================
   RIGHT COLUMN - Realm Detail
   ============================================================================= */

.codex-right {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: #f5f6f7;
    box-shadow: inset -2px 0 8px rgba(0, 0, 0, 0.04);
}

.codex-detail {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #ffffff;
    margin: 12px;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
    overflow: hidden;
}

.codex-no-selection {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
    font-size: 14px;
}

/* =============================================================================
   REALM DETAIL VIEW
   ============================================================================= */

.codex-realm-detail {
    font-size: 12px;
    line-height: 1.4;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.realm-detail-fixed {
    flex-shrink: 0;
    padding: 20px 24px 0 24px;
    background: #ffffff;
}

.realm-detail-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 0 24px 24px 24px;
}

.realm-detail-header {
    margin-bottom: 16px;
    padding-bottom: 0;
    border-bottom: none;
}

/* =============================================================================
   TABS - History/Stats Toggle
   ============================================================================= */

.realm-detail-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.realm-tab {
    padding: 10px 12px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-control-light);
    border: 1px solid var(--border-color);
    border-radius: 6px 6px 0 0;
    cursor: pointer;
    transition: all 0.15s ease;
    margin-bottom: -1px;
    white-space: nowrap;
    min-width: 100px;
}

.realm-tab:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.realm-tab.active {
    color: var(--accent-color);
    background: #ffffff;
    border-bottom-color: #ffffff;
    font-weight: 700;
}

.realm-tab-content {
    /* Content sections controlled by JS display property */
}

.tab-content-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-top: 4px;
    margin-bottom: 12px;
}

.tab-content-heading {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

.tab-content-meta {
    font-size: 11px;
    color: var(--text-muted);
}

.realm-detail-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.realm-detail-name {
    margin: 0 0 4px 0;
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
}

.realm-detail-subtitle {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.codex-export-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-control);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.codex-export-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent-color);
}

.codex-export-btn svg {
    flex-shrink: 0;
}

.realm-detail-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.realm-detail-section {
    margin-bottom: 16px;
}

.realm-detail-section+.realm-detail-section {
    margin-top: 24px;
}

.realm-detail-section h3 {
    margin: 0 0 10px 0;
    font-size: 13px;
    font-weight: 600;
    color: #4a90e2;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 6px;
}

/* =============================================================================
   OVERVIEW ROW (Overview + Region Map side by side)
   ============================================================================= */

.realm-overview-row {
    display: flex;
    gap: 16px;
}

.realm-overview-column {
    flex: 1;
}

.realm-map-column {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 200px;
}

.realm-map-loading,
.realm-map-error {
    padding: 20px;
    color: var(--text-secondary);
    font-size: 12px;
}

.realm-map-error {
    color: #a83232;
}

/* =============================================================================
   STATS GRID
   ============================================================================= */

.realm-stats-grid {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stat-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 3px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.stat-row:last-child {
    border-bottom: none;
}

.stat-label {
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 100px;
    font-size: 10px;
    text-transform: uppercase;
    flex-shrink: 0;
}

.stat-value {
    color: var(--text-primary);
    flex: 1;
}

.nowrap {
    white-space: nowrap;
}

.stat-value-gov {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Government styling */
.gov-standard {
    color: var(--text-primary);
    font-weight: 600;
}

.gov-unusual {
    color: #d63384;
    font-weight: 700;
}

.gov-foreign {
    color: #e67e22;
    font-weight: 700;
}

.gov-origin {
    font-size: 10px;
    color: var(--text-secondary);
    font-style: italic;
    font-weight: normal;
}

.gov-desc {
    font-size: 11px;
    color: var(--text-secondary);
    font-style: italic;
}

/* =============================================================================
   POPULATION TABLE
   ============================================================================= */

.pop-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
    margin-top: 8px;
}

.pop-table th {
    text-align: right;
    border-bottom: 1px solid var(--border-color);
    padding: 4px 6px;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 10px;
    text-transform: uppercase;
}

.pop-table th:first-child {
    text-align: left;
}

.pop-table td {
    padding: 5px 6px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.pop-table td.pop-num {
    text-align: right;
}

.pop-table td:first-child {
    text-align: left;
    font-weight: 500;
}

.pop-table tr:last-child td {
    border-bottom: none;
}

.pop-num {
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 11px;
}

.pop-dim {
    color: var(--text-secondary);
    opacity: 0.6;
}

.pop-total {
    font-weight: 600;
    color: var(--text-primary);
}

/* =============================================================================
   PROFESSIONS
   ============================================================================= */

.professions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 8px;
    margin-bottom: 8px;
}

.profession-group {
    padding: 0;
}

.prof-header {
    font-weight: 600;
    font-size: 11px;
    color: var(--text-primary);
    margin-bottom: 4px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 3px;
}

.prof-list {
    font-size: 11px;
    color: var(--text-primary);
    padding-left: 8px;
    margin-top: 4px;
    line-height: 1.5;
}

.prof-label {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 10px;
    margin-right: 3px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.prof-highlight {
    color: #a83232;
}

/* =============================================================================
   GUILDS
   ============================================================================= */

.realm-guilds {
    font-size: 11px;
    color: var(--text-primary);
    margin-top: 4px;
    line-height: 1.5;
}

/* =============================================================================
   EMPTY & LOADING STATES
   ============================================================================= */

.codex-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--text-secondary);
    padding: 40px;
}

.codex-empty-state .empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.codex-empty-state h3 {
    margin: 0 0 8px 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.codex-empty-state p {
    margin: 0;
    font-size: 13px;
}

.codex-empty {
    padding: 20px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
}

.codex-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 12px;
    color: var(--text-secondary);
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: #4a90e2;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* =============================================================================
   REALM CARD (Compact View)
   ============================================================================= */

.realm-card {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    margin-bottom: 12px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    font-size: 12px;
    line-height: 1.3;
}

.realm-header {
    background: var(--bg-control-light);
    border-bottom: 1px solid var(--border-color);
    padding: 8px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-left: 4px solid #4a90e2;
}

.realm-title {
    font-weight: 700;
    font-size: 14px;
    color: var(--text-primary);
}

.realm-stats-summary {
    font-size: 11px;
    color: var(--text-secondary);
    text-align: right;
}

.realm-body {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 16px;
    padding: 12px;
}

.realm-column-left {
    border-right: 1px solid var(--border-color);
    padding-right: 12px;
}

.realm-column-right h4 {
    margin: 0 0 8px 0;
    font-size: 12px;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 4px;
    color: #4a90e2;
    text-transform: uppercase;
}

.param-list {
    list-style-type: none;
    padding: 0;
    margin: 0;
}

.param-list li {
    padding: 3px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
}

.param-list li:last-child {
    border-bottom: none;
}

.param-label {
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 80px;
    font-size: 10px;
    text-transform: uppercase;
}

.param-value {
    color: var(--text-primary);
    flex: 1;
}

/* =============================================================================
   SCROLLBAR STYLING
   ============================================================================= */

.codex-list::-webkit-scrollbar,
.realm-detail-scroll::-webkit-scrollbar {
    width: 8px;
}

.codex-list::-webkit-scrollbar-track,
.realm-detail-scroll::-webkit-scrollbar-track {
    background: var(--bg-control-light);
}

.codex-list::-webkit-scrollbar-thumb,
.realm-detail-scroll::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.codex-list::-webkit-scrollbar-thumb:hover,
.realm-detail-scroll::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* =============================================================================
   REALM HISTORY SECTION
   ============================================================================= */

.realm-history-section {
    /* Uses shared .realm-detail-section styling */
}

.realm-history-summary p {
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-secondary);
    margin: 0 0 16px 0;
}

.realm-history-timeline-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.realm-history-event {
    display: flex;
    gap: 10px;
    padding: 6px 10px;
    border-bottom: 1px solid rgba(178, 184, 189, 0.3);
    align-items: flex-start;
}

.realm-history-header {
    border-bottom: 1px solid var(--border-color);
    padding: 0px 10px 8px 10px;
    align-items: center;
}

.realm-history-header .realm-history-event-year,
.realm-history-header .realm-history-event-name,
.realm-history-header .realm-history-event-type {
    font-size: 11px !important;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    font-family: inherit;
    padding-top: 0;
}

.realm-history-event-type {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    white-space: nowrap;
    margin-left: auto;
    padding-top: 2px;
}

.realm-history-event:last-child {
    border-bottom: 2px solid rgba(178, 184, 189, 0.3);
}

.realm-history-event-year {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    min-width: 36px;
    font-family: 'Consolas', 'Monaco', monospace;
    text-align: right;
    padding-right: 12px;
}

.realm-history-event-content {
    flex: 1;
    min-width: 0;
    padding-left: 8px;
}

.realm-history-event-name {
    margin-bottom: 2px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
}

.realm-history-event-desc {
    font-size: 11px;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* Founding event */
.realm-history-event.event-founding .realm-history-event-name {
    color: #d4af37;
    font-weight: 600;
}

.realm-history-event.event-founding .realm-history-event-year {
    color: #d4af37;
    font-weight: 700;
}


/* History Stats */
.realm-history-stats {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.realm-history-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.realm-history-stat-label {
    font-size: 9px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.realm-history-stat-value {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

/* Empty/placeholder states */
.realm-history-empty {
    text-align: center;
    padding: 20px;
}

.realm-history-placeholder {
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
}

.realm-history-no-events {
    font-size: 11px;
    color: var(--text-muted);
    font-style: italic;
    padding: 8px 0;
}

/* Compact view */
.realm-history-compact {
    display: flex;
    gap: 8px;
    font-size: 10px;
    color: var(--text-muted);
}

/* Timeline scrollbar */
.realm-history-timeline-list::-webkit-scrollbar {
    width: 6px;
}

.realm-history-timeline-list::-webkit-scrollbar-track {
    background: var(--bg-control-light);
    border-radius: 3px;
}

.realm-history-timeline-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.realm-history-timeline-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}