/* Member Administrations — country cards & modals */

.country-grid {
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

.country-card {
  position: relative;
  padding: 18px 18px 14px;
  border: 1px solid rgba(18, 87, 158, 0.08);
  cursor: pointer;
}

.country-card:focus-visible {
  outline: 2px solid var(--tj-color-theme-primary, #12579e);
  outline-offset: 2px;
}

.country-card-edit {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: #fff;
  color: var(--tj-color-theme-primary, #12579e);
  box-shadow: 0 2px 10px rgba(18, 87, 158, 0.15);
  cursor: pointer;
  transition: background 0.2s, color 0.2s, transform 0.2s;
}

.country-card-edit:hover {
  background: var(--tj-color-theme-primary, #12579e);
  color: #fff;
  transform: scale(1.05);
}

.country-card-main {
  padding-right: 28px;
}

.country-card-cta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--tj-color-theme-primary, #12579e);
  opacity: 0.85;
  transition: gap 0.2s, opacity 0.2s;
}

.country-card:hover .country-card-cta {
  gap: 10px;
  opacity: 1;
}

/* Theme main.css sets .modal { background: rgba(0,0,0,.6) } — must not dim page when closed */
.modal.country-modal {
  background: transparent !important;
}

.modal.country-modal:not(.show) {
  display: none !important;
  pointer-events: none;
}

body:not(.modal-open) .modal-backdrop {
  display: none !important;
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* Modals above theme overlays (body-overlay z-index: 9999) */
.modal-backdrop.country-modal-backdrop {
  z-index: 10040 !important;
}

.country-modal {
  z-index: 10050 !important;
}

.country-modal .modal-dialog {
  margin: 1.25rem auto;
}

.country-modal .modal-content {
  border: none;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 24px 48px rgba(15, 23, 42, 0.18);
}

.country-modal .modal-header {
  align-items: flex-start;
  gap: 12px;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid #e8eef4;
  background: linear-gradient(180deg, #f8fafc 0%, #fff 100%);
}

.country-modal .modal-title-wrap {
  flex: 1;
  min-width: 0;
}

.country-modal .modal-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: #0f172a;
  margin: 0 0 4px;
  line-height: 1.3;
}

.country-modal .modal-subtitle {
  font-size: 0.875rem;
  color: #64748b;
  margin: 0;
}

.country-modal .btn-close {
  margin: 0;
  padding: 0.5rem;
  opacity: 0.7;
  flex-shrink: 0;
}

.country-modal .btn-close:hover {
  opacity: 1;
}

.country-modal .modal-body {
  padding: 1.25rem 1.5rem 1.5rem;
}

.country-modal .modal-footer {
  padding: 1rem 1.5rem 1.25rem;
  border-top: 1px solid #e8eef4;
  background: #f8fafc;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.country-modal-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0.55rem 1.25rem;
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}

.country-modal-btn--primary {
  background: var(--tj-color-theme-primary, #12579e);
  color: #fff;
}

.country-modal-btn--primary:hover {
  background: #0d4378;
  color: #fff;
}

.country-modal-btn--ghost {
  background: #fff;
  color: #475569;
  border: 1px solid #cbd5e1;
}

.country-modal-btn--ghost:hover {
  background: #f1f5f9;
  color: #0f172a;
}

/* View modal content */
.country-view-layout {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.country-view-hero {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 18px 20px;
  background: linear-gradient(135deg, #f0f6fc 0%, #f8fafc 100%);
  border: 1px solid #e8eef4;
  border-radius: 14px;
}

.country-view-flag {
  width: 80px;
  height: 56px;
  object-fit: cover;
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.1);
  flex-shrink: 0;
}

.country-view-flag-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  padding: 8px 12px;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--tj-color-theme-primary, #12579e);
  background: #fff;
  border-radius: 10px;
  border: 1px solid #dbeafe;
}

.country-view-hero-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  color: #0f172a;
  line-height: 1.35;
}

.country-view-card {
  display: block;
  padding: 16px 18px;
  background: #fff;
  border: 1px solid #e8eef4;
  border-radius: 12px;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
}

.country-view-card:hover {
  border-color: #cbd5e1;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.06);
}

.country-view-card-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--tj-color-theme-primary, #12579e);
  margin-bottom: 8px;
}

.country-view-card-body {
  font-size: 15px;
  line-height: 1.65;
  color: #334155;
}

.country-view-card--link {
  text-decoration: none;
  position: relative;
  padding-right: 40px;
}

.country-view-card--link:hover {
  transform: translateY(-1px);
}

.country-view-link-text {
  display: block;
  font-size: 14px;
  color: #1e293b;
  word-break: break-all;
}

.country-view-link-icon {
  position: absolute;
  top: 18px;
  right: 16px;
  color: var(--tj-color-theme-primary, #12579e);
  font-size: 14px;
}

.country-view-entries-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.country-view-section-heading {
  display: none !important;
}

.country-view-entries {
  display: grid;
  gap: 12px;
}

.country-view-entry {
  padding: 16px 18px;
  background: #f8fafc;
  border: 1px solid #e8eef4;
  border-radius: 12px;
  animation: country-entry-in 0.35s ease backwards;
  animation-delay: var(--entry-delay, 0ms);
}

@keyframes country-entry-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.country-view-entry-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.country-view-entry-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background: var(--tj-color-theme-primary, #12579e);
  border-radius: 50%;
}

.country-view-entry-label-title,
.country-view-entry-info-title {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #94a3b8;
  margin: 0 0 4px;
}

.country-view-entry-info-title {
  margin-top: 12px;
}

.country-view-entry-label-text {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: #0f172a;
  line-height: 1.45;
}

.country-view-entry-info-text {
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
  color: #475569;
}

.country-view-empty {
  text-align: center;
  padding: 2rem 1rem;
  color: #94a3b8;
  font-size: 15px;
}

.country-modal-loading {
  text-align: center;
  padding: 2.5rem 1rem;
  color: #64748b;
}

.country-modal-loading::after {
  content: '';
  display: block;
  width: 32px;
  height: 32px;
  margin: 1rem auto 0;
  border: 3px solid #e2e8f0;
  border-top-color: var(--tj-color-theme-primary, #12579e);
  border-radius: 50%;
  animation: country-modal-spin 0.7s linear infinite;
}

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

/* View modal — wide on desktop, edge-to-edge on mobile */
#countryViewModal .country-view-modal-dialog {
  --bs-modal-width: min(1140px, calc(100vw - 2rem));
  width: min(1140px, calc(100vw - 2rem)) !important;
  max-width: min(1140px, calc(100vw - 2rem)) !important;
  margin-left: auto;
  margin-right: auto;
}

#countryViewModal .modal-content {
  width: 100%;
}

#countryViewModal .modal-body {
  overflow-x: hidden;
}

/* Edit modal — wide on desktop, edge-to-edge on mobile */
#countryEditModal .country-edit-modal-dialog {
  --bs-modal-width: min(1140px, calc(100vw - 2rem));
  width: min(1140px, calc(100vw - 2rem)) !important;
  max-width: min(1140px, calc(100vw - 2rem)) !important;
  margin-left: auto;
  margin-right: auto;
}

#countryEditModal .modal-content {
  width: 100%;
}

#countryEditModal .modal-body {
  padding: 0 1.75rem 1.75rem;
  background: #f8fafc;
  overflow-x: hidden;
}

#countryEditModal .modal-header {
  padding-bottom: 1rem;
}

/* Edit form inside modal */
.country-edit-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.country-edit-tabs-wrap {
  position: sticky;
  top: 0;
  z-index: 2;
  margin: 0;
  padding: 1rem 0 0.75rem;
  background: linear-gradient(180deg, #f8fafc 85%, rgba(248, 250, 252, 0));
}

.country-edit-tabs-lead {
  margin: 0 0 10px;
  font-size: 13px;
  color: #64748b;
  line-height: 1.45;
}

.country-edit-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  padding: 4px;
  background: #e2e8f0;
  border-radius: 12px;
  border: 1px solid #cbd5e1;
}

.country-edit-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 700;
  color: #475569;
  background: transparent;
  border: none;
  border-radius: 9px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}

.country-edit-tab:hover {
  color: #0f172a;
}

.country-edit-tab.is-active {
  color: var(--tj-color-theme-primary, #12579e);
  background: #fff;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.1);
}

.country-edit-tab-code {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  padding: 2px 6px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.06);
  color: inherit;
}

.country-edit-tab.is-active .country-edit-tab-code {
  background: rgba(18, 87, 158, 0.12);
}

#countryOwnerEditForm.is-country-lang-en .country-field--ru,
#countryOwnerEditForm.is-country-lang-ru .country-field--en,
.country-edit-form[data-active-lang='en'] .country-field--ru,
.country-edit-form[data-active-lang='ru'] .country-field--en {
  display: none !important;
}

.country-field[hidden] {
  display: none !important;
}

.country-edit-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 20px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.country-edit-section-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: #0f172a;
}

.country-edit-section-hint {
  margin: -6px 0 0;
  font-size: 13px;
  color: #64748b;
  line-height: 1.45;
}

.country-edit-section-head {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.country-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.country-field .form-label {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #64748b;
}

.country-info-input {
  border-radius: 10px;
  border-color: #cbd5e1;
  font-size: 14px;
}

.country-info-input:focus {
  border-color: var(--tj-color-theme-primary, #12579e);
  box-shadow: 0 0 0 3px rgba(18, 87, 158, 0.1);
}

.country-info-formset-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.country-info-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 18px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
}

.country-info-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid #e2e8f0;
}

.country-info-card__badge {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--tj-color-theme-primary, #12579e);
}

.country-info-delete {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: #b91c1c;
  cursor: pointer;
}

.country-info-delete input {
  margin: 0;
}

.country-info-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.country-info-field .form-label {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #64748b;
}

.country-edit-form-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 12px;
  padding: 16px 20px;
  margin: 8px 0 0;
  background: #fff;
  border-top: 1px solid #e2e8f0;
  border-radius: 0 0 14px 14px;
  position: sticky;
  bottom: 0;
  z-index: 2;
}

.country-search-container {
  max-width: 1000px;
  margin: 0 auto 1rem;
  padding: 0 20px;
}

@media (max-width: 767px) {
  .country-grid {
    grid-template-columns: 1fr;
    padding: 12px;
    gap: 14px;
  }

  .country-card {
    padding: 16px;
  }

  #countryViewModal .country-view-modal-dialog {
    margin: 0.5rem auto;
    width: calc(100vw - 1rem);
    max-width: calc(100vw - 1rem);
  }

  #countryEditModal .country-edit-modal-dialog {
    margin: 0.5rem auto;
    width: calc(100vw - 1rem);
    max-width: calc(100vw - 1rem);
  }

  #countryEditModal .modal-body,
  #countryEditModal .modal-header {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  #countryViewModal .modal-header,
  #countryViewModal .modal-body,
  #countryViewModal .modal-footer {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .country-info-formset-row .col-md-6 {
    flex: 0 0 100%;
    max-width: 100%;
  }
}

@media (max-width: 575px) {
  #countryViewModal .country-view-modal-dialog {
    margin: 0;
    width: 100%;
    max-width: 100%;
    min-height: 100%;
    height: 100%;
  }

  #countryViewModal .modal-content {
    min-height: 100dvh;
    border-radius: 0;
  }

  #countryViewModal .modal-body,
  #countryViewModal .modal-header,
  #countryViewModal .modal-footer {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  #countryEditModal .country-edit-modal-dialog {
    margin: 0;
    width: 100%;
    max-width: 100%;
    min-height: 100%;
    height: 100%;
  }

  #countryEditModal .modal-content {
    min-height: 100dvh;
    border-radius: 0;
  }

  #countryEditModal .modal-body,
  #countryEditModal .modal-header {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  #countryViewModal .modal-footer {
    position: sticky;
    bottom: 0;
    z-index: 1;
  }
}
