/* ==========================================================================
   1. VARIABLES & GLOBAL RESETS
   ========================================================================== */

:root {
  /* Colors - Dark Mode (Default) */
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-sidebar: #0f172a;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --accent: #38bdf8;
  --accent-hover: #0ea5e9;
  --border: #334155;
  --card-bg: #1e293b;
  --card-hover: #334155;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #fbbf24;

  /* Shadows & Transitions */
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --transition-speed: 0.2s;
  --transition: all var(--transition-speed) ease;

  /* Layout Constants */
  --header-height: 64px;
  --sidebar-width: 280px;
  --z-header: 100;
  --z-overlay: 998;
  --z-sidebar: 999;
}

body.light-mode {
  --bg-primary: #f1f5f9;
  --bg-secondary: #ffffff;
  --bg-sidebar: #f8fafc;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --accent: #0284c7;
  --accent-hover: #0369a1;
  --border: #e2e8f0;
  --card-bg: #ffffff;
  --card-hover: #f1f5f9;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* ==========================================================================
   2. LAYOUT STRUCTURE
   ========================================================================== */

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

header {
  height: var(--header-height);
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: var(--z-header);
}

main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

aside {
  width: var(--sidebar-width);
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 24px;
  overflow-y: auto;
  position: relative;
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
}

#content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  background-color: var(--bg-primary);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: var(--z-overlay);
  opacity: 0;
  transition: opacity 0.3s ease;
}

body.sidebar-active .sidebar-overlay {
  display: block;
  opacity: 1;
}

/* ==========================================================================
   3. COMPONENTS
   ========================================================================== */

/* Header Components */
.header-left {
  display: flex;
  align-items: baseline;
}

.logo-link {
  text-decoration: none;
  color: inherit;
  transition: var(--transition);
}

.logo-link:hover {
  opacity: 0.8;
}

h1 {
  font-size: 1.5rem;
  font-weight: 700;
}

.logo-heavy {
  font-weight: 700;
}

.logo-light {
  font-weight: 300;
  color: var(--accent);
}

.stats {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-left: 12px;
}

.search-container {
  position: relative;
  width: 300px;
  margin-left: auto;
  margin-right: 18px;
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* Sidebar Components */
.sidebar-header {
  margin-bottom: 24px;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.filter-group {
  margin-bottom: 32px;
}

.filter-group h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.sidebar-search-container {
  margin-bottom: 12px;
  position: relative;
  display: flex;
  align-items: center;
}

.search-clear-btn {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.2rem;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.search-clear-btn:hover {
  color: var(--text-primary);
  background: none;
}

.checkbox-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--border);
  padding: 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.05);
}

.checkbox-list.active-list {
  max-height: none;
  background: rgba(56, 189, 248, 0.05);
  border-color: var(--accent);
  padding: 8px;
  margin-bottom: 8px;
  border-radius: 8px;
  overflow-y: visible;
}

.checkbox-list.active-list label {
  font-weight: 600;
  color: var(--accent);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.footer-link {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-decoration: none;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 6px;
}

.footer-link:hover {
  color: var(--accent);
}

.footer-link i {
  font-style: normal;
  font-size: 0.875rem;
}

.copyright {
  font-size: 0.7rem;
  color: var(--text-secondary);
  opacity: 0.5;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  cursor: pointer;
}

.checkbox-item.disabled {
  opacity: 0.3;
  filter: grayscale(1);
}

/* Grid & Cards */
.grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

#grid-header {
  margin-bottom: 24px;
}

.card {
  background-color: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  transition: var(--transition);
  position: relative;
}

.card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.card-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.flag {
  width: 24px;
  height: 18px;
  border-radius: 2px;
  object-fit: cover;
}

.paywall-badge {
  font-size: 10px;
  background-color: var(--danger);
  color: white;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: bold;
  text-transform: uppercase;
}

.card-body .name {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text-primary);
}

.card-body .meta {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.card-body .domain {
  font-family: monospace;
  opacity: 0.6;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

.card-footer {
  margin-top: 12px;
  display: flex;
  gap: 8px;
}

/* Buttons & Inputs */
input[type="text"] {
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.875rem;
  transition: var(--transition);
}

#search {
  padding-left: 32px;
}

input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

button {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  transition: var(--transition);
}

button:hover {
  background-color: var(--card-hover);
}

.reset-btn {
  width: 100%;
  padding: 8px;
  background-color: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 8px;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.reset-btn:hover:not(:disabled) {
  background-color: var(--border);
  border-color: var(--accent);
}

.reset-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  filter: grayscale(1);
}

.visit-btn {
  flex: 1;
  background-color: var(--accent);
  color: white;
  text-decoration: none;
  text-align: center;
  padding: 6px;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  transition: var(--transition);
}

.visit-btn:hover {
  background-color: var(--accent-hover);
}

.favorite-btn {
  background: none;
  border: none;
  padding: 4px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.favorite-btn:hover {
  color: var(--accent);
}

.favorite-btn.active {
  color: var(--warning);
}

.favorite-btn.active svg {
  fill: var(--warning);
}

.copy-btn {
  width: 38px;
  height: 38px;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  position: relative;
}

.copy-btn:hover {
  color: var(--accent);
}

.copy-btn.copy-success {
  background-color: var(--success) !important;
  border-color: var(--success) !important;
  color: white !important;
}

/* Filter Chips */
#active-filters {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background-color: var(--card-bg);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.75rem;
  color: var(--text-primary);
}

.chip-remove {
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 1rem;
  line-height: 1;
}

.chip-remove:hover {
  color: var(--danger);
}

/* ==========================================================================
   4. STATE & THEMES
   ========================================================================== */

/* Favorites / Zen Mode */
.mode-favorites #section-countries,
.mode-favorites #section-languages,
.mode-favorites #section-display,
.mode-favorites #search-container,
.mode-favorites #active-filters {
  display: none !important;
}

.favorites-toggle.active {
  background-color: var(--accent);
  color: white;
  border-color: var(--accent);
}

.favorites-toggle svg {
  transition: var(--transition);
}

.favorites-toggle.active svg {
  fill: white;
}

.btn-back {
  background-color: var(--card-hover) !important;
  border-color: var(--accent) !important;
}

/* Toggle Switch */
.toggle {
  display: flex;
  align-items: center;
  cursor: pointer;
  gap: 10px;
}

.slider {
  position: relative;
  width: 36px;
  height: 20px;
  background-color: var(--border);
  border-radius: 20px;
  transition: 0.4s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  border-radius: 50%;
  transition: 0.4s;
}

input:checked+.slider {
  background-color: var(--accent);
}

input:checked+.slider:before {
  transform: translateX(16px);
}

.toggle input {
  display: none;
}

/* Mobile Utilities */
.mobile-toggle-btn {
  display: none;
  border: none;
  font-size: 1.5rem;
}

.close-sidebar-btn {
  display: none;
  border: none;
  font-size: 1.5rem;
}

/* Empty States */
.hidden {
  display: none !important;
}

.empty-state {
  text-align: center;
  padding: 80px 24px;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.empty-state span {
  font-size: 4rem;
  display: block;
  margin-bottom: 24px;
  line-height: 1;
}

.empty-state p {
  margin-bottom: 32px;
  font-size: 1.125rem;
  max-width: 400px;
}

.empty-state .reset-btn {
  width: auto;
  min-width: 220px;
  padding: 12px 32px;
  font-size: 0.9375rem;
  background-color: var(--accent);
  color: white;
  border: none;
}

.empty-state .reset-btn:hover {
  background-color: var(--accent-hover);
  transform: translateY(-1px);
}

/* ==========================================================================
   5. RESPONSIVE DESIGN
   ========================================================================== */

@media (max-width: 1024px) {
  aside {
    width: 240px;
    padding: 16px;
  }
}

@media (max-width: 768px) {

  .mobile-toggle-btn,
  .close-sidebar-btn {
    display: block;
  }

  aside {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 300px;
    z-index: var(--z-sidebar);
    transform: translateX(-100%);
    box-shadow: 20px 0 50px rgba(0, 0, 0, 0.3);
    border-right: none;
  }

  body.sidebar-active aside {
    transform: translateX(0);
  }

  header {
    height: auto;
    padding: 12px 16px;
    flex-wrap: wrap;
    gap: 12px;
  }

  .header-left {
    flex: 1;
    order: 1;
  }

  .header-right {
    flex-shrink: 0;
    order: 2;
  }

  .search-container {
    order: 3;
    width: 100% !important;
    margin: 8px 0 0 0;
  }
}

/* ==========================================================================
   6. UTILITIES & ANIMATIONS
   ========================================================================== */

@keyframes fadeOut {
  0% {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }

  100% {
    opacity: 0;
    transform: translateX(-50%) translateY(-10px);
  }
}

.copy-btn.copy-success::after {
  content: "Copied!";
  position: absolute;
  top: -24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--success);
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: bold;
  pointer-events: none;
  animation: fadeOut 1s forwards;
  white-space: nowrap;
}

::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}