/* ═══════════════════════════════════════════════════════════════════════════
   GLOBAL INTELLIGENCE — War Chronicle RPG Theme
   Direction: ancient tome, ink + gold, corner-cut panels, rune accents
══════════════════════════════════════════════════════════════════════════ */

/* ── Page ── */
#countries-page {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 85;
  background: #2e2416;
  background-image:
    radial-gradient(ellipse at 25% 0%, rgba(220, 175, 80, 0.09) 0%, transparent 55%),
    radial-gradient(ellipse at 75% 100%, rgba(150, 100, 40, 0.08) 0%, transparent 50%);
  overflow-y: scroll;
  color: var(--parchment);
}

#countries-page::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='400' height='400' filter='url(%23n)' opacity='0.055'/%3E%3C/svg%3E");
  background-size: 300px 300px;
  mix-blend-mode: screen;
}

.ct-inner {
  position: relative;
  z-index: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 44px 80px;
  box-sizing: border-box;
}

/* ── Header Overrides ── */
#countries-page .nav-back {
  color: rgba(220, 192, 100, .8);
  border-color: rgba(196, 168, 74, .25);
  background: rgba(196, 168, 74, .06);
}

#countries-page .nav-back:hover {
  color: #faecc8;
  border-color: rgba(196, 168, 74, .6);
}

#countries-page .hdr-sigil {
  color: rgba(220, 192, 100, .8);
}

#countries-page .hdr-eye {
  color: rgba(220, 192, 100, .55);
}

#countries-page .hdr-title {
  color: #faecc8;
  text-shadow: 0 0 30px rgba(196, 168, 74, .25);
}

#countries-page .hdr-sub {
  color: rgba(250, 236, 200, .65);
}

#countries-page .hdr-rule::before,
#countries-page .hdr-rule::after {
  background: linear-gradient(to right, transparent, rgba(196, 168, 74, .35), transparent);
}

#countries-page .hdr-rule span {
  color: rgba(220, 192, 100, .65);
}

/* ── Action Bar ── */
.ct-action-bar {
  display: flex;
  justify-content: center;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(196, 168, 74, .15);
}

.ct-search-wrapper {
  display: flex;
  align-items: center;
  max-width: 420px;
  width: 100%;
}

.ct-search-input {
  flex: 1;
  background: rgba(0, 0, 0, .3);
  border: 1px solid rgba(196, 168, 74, .22);
  color: #faecc8;
  padding: 10px 16px;
  font-family: 'Cinzel', serif;
  font-size: 13px;
  letter-spacing: .05em;
  outline: none;
  border-radius: 4px 0 0 4px;
}

.ct-search-input::placeholder {
  color: rgba(250, 236, 200, .4);
}

.ct-search-input:focus {
  border-color: #d4b85a;
  box-shadow: 0 0 8px rgba(212, 184, 90, .2);
}

.ct-search-btn {
  background: rgba(196, 168, 74, .15);
  border: 1px solid rgba(196, 168, 74, .3);
  border-left: none;
  color: #d4b85a;
  padding: 10px 16px;
  font-family: 'Cinzel', serif;
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
  border-radius: 0 4px 4px 0;
}

.ct-search-btn:hover {
  background: rgba(196, 168, 74, .25);
  border-color: #d4b85a;
  color: #faecc8;
}

/* ── Nations List ── */
.ct-nations-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ct-loading {
  text-align: center;
  padding: 60px 20px;
  color: rgba(250, 236, 200, .4);
  font-family: 'Cinzel', serif;
  font-size: 14px;
  letter-spacing: .1em;
}

/* ── Nation Card (Horizontal) ── */
.ct-nation-card {
  background: linear-gradient(160deg, #362a16 0%, #2a2010 100%);
  border: 1px solid rgba(196, 168, 74, .3);
  box-shadow: inset 0 0 20px rgba(0, 0, 0, .35), 0 1px 8px rgba(0, 0, 0, .4);
  position: relative;
  cursor: pointer;
  transition: all .15s;
  overflow: hidden;
}

/* Corner ornaments */
.ct-nation-card::before,
.ct-nation-card::after {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  border-color: rgba(220, 192, 100, .65);
  border-style: solid;
  pointer-events: none;
}

.ct-nation-card::before {
  top: 3px;
  left: 3px;
  border-width: 1px 0 0 1px;
}

.ct-nation-card::after {
  bottom: 3px;
  right: 3px;
  border-width: 0 1px 1px 0;
}

.ct-nation-card:hover {
  border-color: rgba(220, 192, 100, .65);
  box-shadow: inset 0 0 20px rgba(0, 0, 0, .35), 0 2px 12px rgba(0, 0, 0, .6);
}

.ct-nation-card.active {
  border-color: #d4b85a;
  box-shadow: inset 0 0 20px rgba(0, 0, 0, .35), 0 0 20px rgba(212, 184, 90, .3);
}

.ct-nation-content {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  gap: 20px;
}

.ct-nation-rank {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  border-radius: 8px;
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 18px;
  flex-shrink: 0;
}

.ct-nation-rank.rank-1 {
  background: linear-gradient(135deg, #FFD700, #FFA500);
  color: #000;
  box-shadow: 0 2px 8px rgba(255, 215, 0, .4);
}

.ct-nation-rank.rank-2 {
  background: linear-gradient(135deg, #C0C0C0, #808080);
  color: #000;
  box-shadow: 0 2px 8px rgba(192, 192, 192, .4);
}

.ct-nation-rank.rank-3 {
  background: linear-gradient(135deg, #CD7F32, #8B4513);
  color: #FFF;
  box-shadow: 0 2px 8px rgba(205, 127, 50, .4);
}

.ct-nation-rank.rank-normal {
  background: rgba(196, 168, 74, .15);
  color: #d4b85a;
  border: 1px solid rgba(196, 168, 74, .3);
}

.ct-nation-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ct-nation-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ct-nation-flag {
  width: 32px;
  height: 24px;
  flex-shrink: 0;
  position: relative;
  border-radius: 2px;
  overflow: hidden;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.flag-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.flag-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  background: rgba(196, 168, 74, .1);
  border: 1px solid rgba(196, 168, 74, .3);
  border-radius: 2px;
}

.ct-nation-name {
  font-family: 'Cinzel Decorative', 'Cinzel', serif;
  font-size: 20px;
  font-weight: 700;
  color: #faecc8;
  letter-spacing: .05em;
  line-height: 1.2;
}

.ct-nation-stats {
  display: flex;
  gap: 32px;
  flex: 1;
}

.ct-stat-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ct-stat-label {
  font-family: 'Nunito', sans-serif;
  font-size: 10px;
  color: rgba(250, 236, 200, .5);
  text-transform: uppercase;
  letter-spacing: .1em;
}

.ct-stat-value {
  font-family: 'Cinzel', serif;
  font-size: 16px;
  font-weight: 600;
  color: #d4b85a;
}

/* ── Detail View ── */
.ct-detail-view {
  display: none;
}

.ct-detail-header {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid rgba(196, 168, 74, .15);
}

.ct-country-hero {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-top: 16px;
}

.ct-country-flag-large {
  width: 80px;
  height: 60px;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .4);
  flex-shrink: 0;
}

.flag-large-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.flag-large-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  background: rgba(196, 168, 74, .1);
  border: 1px solid rgba(196, 168, 74, .3);
}

.ct-country-info {
  flex: 1;
}

.ct-country-name {
  font-family: 'Cinzel Decorative', 'Cinzel', serif;
  font-size: 32px;
  font-weight: 700;
  color: #faecc8;
  letter-spacing: .05em;
  margin: 0 0 12px 0;
  text-shadow: 0 0 20px rgba(196, 168, 74, .3);
}

.ct-country-badges {
  display: flex;
  gap: 12px;
}

.ct-badge {
  padding: 4px 12px;
  border-radius: 16px;
  font-family: 'Cinzel', serif;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .05em;
  background: rgba(196, 168, 74, .15);
  color: #d4b85a;
  border: 1px solid rgba(196, 168, 74, .3);
}

.ct-badge.ghost {
  background: rgba(196, 168, 74, .05);
  color: rgba(220, 192, 100, .5);
  border-color: rgba(196, 168, 74, .15);
}

/* ── Detail Tabs ── */
.ct-detail-tabs {
  display: flex;
  gap: 32px;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(196, 168, 74, .15);
}

.ct-tab-btn {
  background: none;
  border: none;
  color: rgba(220, 192, 100, .6);
  font-family: 'Cinzel', serif;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .1em;
  cursor: pointer;
  transition: all .15s;
  padding: 8px 0;
  position: relative;
}

.ct-tab-btn::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background: #d4b85a;
  transform: scaleX(0);
  transition: transform .15s;
}

.ct-tab-btn.active {
  color: #faecc8;
}

.ct-tab-btn.active::after {
  transform: scaleX(1);
}

.ct-tab-btn:hover {
  color: #faecc8;
}

/* ── Tab Content ── */
.ct-tab-content {
  min-height: 400px;
}

.ct-tab-pane {
  display: none;
  animation: fade-in 0.3s ease;
}

.ct-tab-pane.active {
  display: block;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Stats Grid ── */
.ct-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.ct-stat-card {
  background: rgba(196, 168, 74, .08);
  border: 1px solid rgba(196, 168, 74, .18);
  border-radius: 8px;
  padding: 20px;
  backdrop-filter: blur(10px);
  transition: transform .15s;
}

.ct-stat-card:hover {
  transform: translateY(-2px);
}

.ct-stat-label {
  font-family: 'Nunito', sans-serif;
  font-size: 11px;
  color: rgba(250, 236, 200, .6);
  text-transform: uppercase;
  letter-spacing: .1em;
  margin-bottom: 8px;
}

.ct-stat-value {
  font-family: 'Cinzel', serif;
  font-size: 24px;
  font-weight: 700;
  color: #d4b85a;
}

.ct-stat-sub {
  font-family: 'Nunito', sans-serif;
  font-size: 12px;
  color: rgba(250, 236, 200, .4);
  margin-top: 4px;
}

/* ── Rankings Grid ── */
.ct-rankings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
}

.ct-rank-card {
  background: rgba(196, 168, 74, .08);
  border: 1px solid rgba(196, 168, 74, .18);
  border-radius: 8px;
  padding: 16px 20px;
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: transform .15s;
}

.ct-rank-card:hover {
  transform: translateY(-2px);
}

.ct-rank-info {
  display: flex;
  flex-direction: column;
}

.ct-rank-label {
  font-family: 'Nunito', sans-serif;
  font-size: 11px;
  color: rgba(250, 236, 200, .6);
  text-transform: uppercase;
  letter-spacing: .1em;
}

.ct-rank-value {
  font-family: 'Cinzel', serif;
  font-size: 16px;
  font-weight: 600;
  color: #faecc8;
}

.ct-rank-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 12px;
  font-family: 'Cinzel', serif;
  font-size: 14px;
  font-weight: 700;
}

/* ── Diplomacy Cards ── */
.ct-diplo-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
}

.ct-diplo-card {
  background: rgba(196, 168, 74, .08);
  border: 1px solid rgba(196, 168, 74, .18);
  border-radius: 8px;
  padding: 16px 20px;
  backdrop-filter: blur(4px);
}

.ct-diplo-card h3 {
  font-size: 16px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: rgba(220, 192, 100, .8);
}

.ct-diplo-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 250px;
  overflow-y: auto;
}

.ct-diplo-list::-webkit-scrollbar { width: 4px; }
.ct-diplo-list::-webkit-scrollbar-thumb { background: rgba(196, 168, 74, .3); border-radius: 2px; }

.ct-diplo-item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  background: rgba(0, 0, 0, .2);
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  transition: background .12s;
}

.ct-diplo-item:hover {
  background: rgba(0, 0, 0, .3);
}

.ct-diplo-item.pos {
  color: #3bc983;
}

.ct-diplo-item.neg {
  color: #f35050;
}

.ct-diplo-enemy {
  padding: 12px 16px;
  background: rgba(243, 80, 80, .1);
  border: 1px solid rgba(243, 80, 80, .3);
  border-radius: 4px;
  color: #f35050;
  font-weight: 600;
  cursor: pointer;
  transition: all .12s;
}

.ct-diplo-enemy:hover {
  background: rgba(243, 80, 80, .2);
}

.ct-diplo-policy {
  padding: 12px 16px;
  background: rgba(196, 168, 74, .05);
  border: 1px solid rgba(196, 168, 74, .15);
  border-radius: 4px;
  color: #faecc8;
  font-family: 'Nunito', sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.ct-diplo-info {
  padding: 12px 16px;
  background: rgba(196, 168, 74, .05);
  border: 1px solid rgba(196, 168, 74, .15);
  border-radius: 4px;
  color: #faecc8;
  font-family: 'Nunito', sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.ct-diplo-specialty {
  padding: 12px 16px;
  background: rgba(212, 184, 90, .1);
  border: 1px solid rgba(212, 184, 90, .3);
  border-radius: 4px;
  color: #d4b85a;
  font-family: 'Cinzel', serif;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
}

.ct-diplo-link {
  display: block;
  padding: 12px 16px;
  background: rgba(59, 201, 131, .1);
  border: 1px solid rgba(59, 201, 131, .3);
  border-radius: 4px;
  color: #3bc983;
  font-family: 'Cinzel', serif;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  transition: all .15s;
}

.ct-diplo-link:hover {
  background: rgba(59, 201, 131, .2);
  border-color: #3bc983;
  color: #faecc8;
}

.ct-rank-tier {
  font-size: 10px;
  color: rgba(250, 236, 200, .5);
  text-transform: uppercase;
  letter-spacing: .1em;
  margin-top: 2px;
}

/* ── Section Titles ── */
.ct-section-title {
  font-family: 'Cinzel', serif;
  font-size: 16px;
  font-weight: 600;
  color: rgba(220, 192, 100, .85);
  letter-spacing: .1em;
  text-transform: uppercase;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(196, 168, 74, .15);
}

/* ── Data Table ── */
.ct-data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-top: 16px;
}

.ct-data-table th {
  font-family: 'Cinzel', serif;
  font-weight: 600;
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(196, 168, 74, .2);
  color: rgba(220, 192, 100, .8);
}

.ct-data-table td {
  padding: 8px 12px;
  border-bottom: 1px solid rgba(196, 168, 74, .05);
  color: #faecc8;
}

.ct-data-table tr:hover {
  background: rgba(196, 168, 74, .04);
}

/* ── Color Classes ── */
.pos {
  color: #3bc983 !important;
}

.neutral {
  color: #d4b85a !important;
}

.neg {
  color: #f35050 !important;
}

#countries-page .loader-overlay.hidden {
  display: none;
}
#countries-page .spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(107, 76, 255, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* ── Citizens Tab ── */
.ct-citizens-loading {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 32px 0;
  color: rgba(250, 236, 200, .55);
  font-family: 'Nunito', sans-serif;
  font-size: 14px;
}

.ct-citizens-spinner {
  width: 22px;
  height: 22px;
  border: 2px solid rgba(196, 168, 74, .2);
  border-top-color: #d4b85a;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  flex-shrink: 0;
}

.ct-citizens-table td,
.ct-citizens-table th {
  vertical-align: middle;
}

.ct-citizen-center {
  text-align: center;
}

.ct-citizen-name-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ct-citizen-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid rgba(196, 168, 74, .25);
  flex-shrink: 0;
}

.ct-citizen-avatar-fallback {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid rgba(196, 168, 74, .2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  background: rgba(196, 168, 74, .06);
  flex-shrink: 0;
}

@media (max-width: 900px) {
  #countries-page .app-container {
    flex-direction: column;
  }
  #countries-page .sidebar {
    width: 100%;
    height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  #countries-page .diplomacy-grid {
    grid-template-columns: 1fr;
  }
}
