:root {
  --primary-bg: #f4f6f8;
  --secondary-bg: #edf1f5;
  --tertiary-bg: #e4ebf2;
  --card-bg: #ffffff;
  --text-primary: #1f2937;
  --text-secondary: #4b5563;
  --text-muted: #6b7280;
  --accent: #4ecdc4;
  --accent-hover: #34b8ae;
  --accent-color: #4ecdc4;
  --border-color: #dbe3ea;
  --border-radius: 14px;
  --border-radius-lg: 18px;
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --box-shadow: var(--shadow-md);
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --transition-fast: all 0.2s ease;
  --page-max-width: 1400px;
  --section-gap: 20px;
  --content-pad: 20px;
  /* Legacy aliases used in page-specific CSS */
  --border: var(--border-color);
  --hover-bg: rgba(78, 205, 196, 0.09);
  --sidebar-bg: var(--secondary-bg);
  --accent-gradient: linear-gradient(135deg, #4ecdc4, #34b8ae);
  --shadow: var(--shadow-sm);
  --shadow-hover: var(--shadow-md);
}

html[data-theme="dark"] {
  --primary-bg: #0f141d;
  --secondary-bg: #151c27;
  --tertiary-bg: #1b2432;
  --card-bg: #141c26;
  --text-primary: #e6edf7;
  --text-secondary: #c3cedd;
  --text-muted: #96a2b6;
  --border-color: #263144;
  --box-shadow: 0 10px 30px rgba(2, 6, 23, 0.45);
  --border: var(--border-color);
  --hover-bg: rgba(78, 205, 196, 0.14);
  --sidebar-bg: #111925;
  --accent-gradient: linear-gradient(135deg, #4ecdc4, #2a9f98);
  --shadow: 0 8px 24px rgba(2, 6, 23, 0.4);
  --shadow-hover: 0 14px 34px rgba(2, 6, 23, 0.52);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  background: var(--primary-bg);
  color: var(--text-primary);
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  line-height: 1.45;
}

a {
  color: inherit;
}

img {
  max-width: 100%;
  height: auto;
}

button,
input,
select,
textarea {
  font: inherit;
}

input,
select,
textarea {
  color: var(--text-primary);
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(78, 205, 196, 0.15);
}

button {
  border: 1px solid transparent;
  border-radius: 12px;
}

.btn,
button.btn,
a.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  background: var(--card-bg);
  color: var(--text-primary);
  transition: var(--transition-fast);
}

.btn:hover,
button.btn:hover,
a.btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.btn-primary,
button.btn-primary,
a.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover,
button.btn-primary:hover,
a.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.card,
.panel,
.block-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-sm);
}

.badge,
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: rgba(78, 205, 196, 0.15);
  color: var(--text-primary);
}

.empty-state {
  color: var(--text-muted);
}

h1, h2, h3 {
  margin: 0;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

p {
  margin: 0;
  color: var(--text-secondary);
}

.main-content,
.profile-container,
.product-hero,
.catalog-page,
.chats-page {
  width: min(var(--page-max-width), 100%);
  margin-left: auto;
  margin-right: auto;
}

.profile-container,
.product-hero,
.catalog-page,
.chats-page {
  padding-left: var(--content-pad);
  padding-right: var(--content-pad);
}

.profile-container > * + *,
.catalog-page > * + *,
.product-hero > * + * {
  margin-top: var(--section-gap);
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-thumb {
  background: rgba(78, 205, 196, 0.45);
  border-radius: 99px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

/* ===== Unified Components Across Pages ===== */
.profile-container .card,
.profile-container .user-card,
.profile-container .product-card,
.profile-container .deal-card,
.product-hero .seller-compact-card,
.product-hero .product-card,
.catalog-page .category-section,
.catalog-page .filters-panel,
.catalog-page .product-card,
.chats-page .chats-container,
.chats-page .chats-sidebar,
.chats-page .chat-main {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-sm);
}

.profile-container .product-card:hover,
.catalog-page .product-card:hover,
.product-hero .product-card:hover,
.profile-container .deal-card:hover,
.catalog-page .category-section:hover {
  box-shadow: var(--shadow-md);
}

.profile-container .tab,
.profile-container .inner-tab,
.profile-container .settings-tab,
.profile-container .balance-tab,
.product-hero .tab-btn,
.catalog-page .category-tab,
.catalog-page .subtab,
.catalog-page .view-btn {
  min-height: 42px;
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: var(--card-bg);
  color: var(--text-secondary);
  transition: var(--transition-fast);
}

.profile-container .tab:hover,
.profile-container .inner-tab:hover,
.profile-container .settings-tab:hover,
.profile-container .balance-tab:hover,
.product-hero .tab-btn:hover,
.catalog-page .category-tab:hover,
.catalog-page .subtab:hover,
.catalog-page .view-btn:hover {
  border-color: rgba(78, 205, 196, 0.45);
  background: rgba(78, 205, 196, 0.09);
  color: var(--text-primary);
}

.profile-container .tab.active,
.profile-container .inner-tab.active,
.profile-container .settings-tab.active,
.profile-container .balance-tab.active,
.product-hero .tab-btn.active,
.catalog-page .category-tab.active,
.catalog-page .subtab.active,
.catalog-page .view-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.profile-container .tab-count,
.profile-container .profile-count-badge,
.catalog-page .product-badge,
.product-hero .views-chip,
.chats-page .unread-badge,
.mobile-nav .cart-counter,
.mobile-nav .notification-counter {
  font-weight: 700;
}

.profile-container .action-btn,
.profile-container .btn-deal,
.profile-container .btn-chat,
.profile-container .btn-details,
.profile-container .edit-btn,
.profile-container .finish-btn,
.profile-container .add-to-cart-btn,
.profile-container .add-to-favorites-btn,
.product-hero .btn,
.product-hero .icon-action-btn,
.catalog-page .btn-primary,
.catalog-page .btn-secondary,
.catalog-page .apply-filter-btn,
.catalog-page .reset-filter-btn,
.chats-page .btn-send,
.chats-page .btn-archive-toggle,
.chats-page .btn-deal-info,
.chats-page .btn-archive,
.chats-page .btn-attach,
.chats-page .btn-emoji {
  min-height: 40px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  box-shadow: none;
  transition: var(--transition-fast);
}

.profile-container .action-btn:hover,
.profile-container .btn-deal:hover,
.profile-container .btn-chat:hover,
.profile-container .btn-details:hover,
.profile-container .edit-btn:hover,
.profile-container .finish-btn:hover,
.profile-container .add-to-cart-btn:hover,
.profile-container .add-to-favorites-btn:hover,
.product-hero .btn:hover,
.product-hero .icon-action-btn:hover,
.catalog-page .btn-primary:hover,
.catalog-page .btn-secondary:hover,
.catalog-page .apply-filter-btn:hover,
.catalog-page .reset-filter-btn:hover,
.chats-page .btn-send:hover,
.chats-page .btn-archive-toggle:hover,
.chats-page .btn-deal-info:hover,
.chats-page .btn-archive:hover,
.chats-page .btn-attach:hover,
.chats-page .btn-emoji:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.profile-container .modal,
.product-hero .modal,
.catalog-page .modal {
  backdrop-filter: blur(3px);
}

.profile-container .modal-content,
.product-hero .modal-content,
.catalog-page .modal-content {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  box-shadow: var(--shadow-md);
  width: min(720px, calc(100vw - 24px));
}

.profile-container .tab-count,
.catalog-page .product-badge,
.product-hero .views-chip,
.chats-page .unread-badge {
  border-radius: 999px;
}

@media (max-width: 768px) {
  :root {
    --section-gap: 14px;
    --content-pad: 12px;
  }

  body {
    padding-bottom: max(90px, env(safe-area-inset-bottom));
  }

  .profile-container .product-card,
  .catalog-page .product-card,
  .product-hero .product-card {
    border-radius: 14px;
  }

  .profile-container .action-btn,
  .product-hero .btn,
  .catalog-page .btn-primary,
  .catalog-page .btn-secondary,
  .chats-page .btn-send {
    min-height: 38px;
    padding: 8px 12px;
  }

  .profile-container .tab,
  .profile-container .inner-tab,
  .profile-container .settings-tab,
  .product-hero .tab-btn,
  .catalog-page .category-tab,
  .catalog-page .subtab {
    min-width: 0;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .profile-container .tab,
  .profile-container .inner-tab,
  .profile-container .settings-tab,
  .product-hero .tab-btn,
  .catalog-page .category-tab,
  .catalog-page .subtab,
  .catalog-page .view-btn {
    font-size: 0.9rem;
  }

  .profile-container .modal-content,
  .product-hero .modal-content,
  .catalog-page .modal-content {
    border-radius: 14px;
    max-height: min(88vh, 760px);
    overflow: auto;
  }
}

/* ===== Dark Theme Normalization (legacy page CSS overrides) ===== */
html[data-theme="dark"] .chats-page,
html[data-theme="dark"] .catalog-page,
html[data-theme="dark"] .product-hero,
html[data-theme="dark"] .profile-container {
  background: var(--primary-bg);
  color: var(--text-primary);
}

html[data-theme="dark"] .chats-page .chats-container,
html[data-theme="dark"] .chats-page .chat-main,
html[data-theme="dark"] .chats-page .chat-header,
html[data-theme="dark"] .chats-page .message-input-container,
html[data-theme="dark"] .catalog-page .modal-content,
html[data-theme="dark"] .profile-container .modal-content,
html[data-theme="dark"] .product-hero .modal-content,
html[data-theme="dark"] .product-hero .seller-compact-card,
html[data-theme="dark"] .product-hero .icon-action-btn,
html[data-theme="dark"] .profile-container .mobile-profile-icon-btn,
html[data-theme="dark"] .profile-container .mobile-quick-item,
html[data-theme="dark"] .profile-container .ppe-section-card,
html[data-theme="dark"] .profile-container #profilePageEditModal .card,
html[data-theme="dark"] .profile-container .ppe-color-input,
html[data-theme="dark"] .profile-container .ppe-check-label {
  background: var(--card-bg) !important;
  color: var(--text-primary);
  border-color: var(--border-color) !important;
}

html[data-theme="dark"] .catalog-page .search-box input,
html[data-theme="dark"] .catalog-page .input-with-icon input,
html[data-theme="dark"] .catalog-page .styled-select,
html[data-theme="dark"] .product-hero .review-form select,
html[data-theme="dark"] .product-hero .review-form textarea,
html[data-theme="dark"] .profile-container .form-group input,
html[data-theme="dark"] .profile-container .form-group select,
html[data-theme="dark"] .profile-container .form-group textarea,
html[data-theme="dark"] .chats-page #chatInput {
  background: #101826 !important;
  color: var(--text-primary) !important;
  border-color: var(--border-color) !important;
}

html[data-theme="dark"] .catalog-page .search-box input:focus,
html[data-theme="dark"] .catalog-page .input-with-icon input:focus,
html[data-theme="dark"] .catalog-page .styled-select:focus,
html[data-theme="dark"] .product-hero .review-form select:focus,
html[data-theme="dark"] .product-hero .review-form textarea:focus,
html[data-theme="dark"] .profile-container .form-group input:focus,
html[data-theme="dark"] .profile-container .form-group select:focus,
html[data-theme="dark"] .profile-container .form-group textarea:focus,
html[data-theme="dark"] .chats-page #chatInput:focus {
  background: #0f1724 !important;
  border-color: var(--accent) !important;
}

html[data-theme="dark"] .product-hero .toast,
html[data-theme="dark"] .catalog-page .toast,
html[data-theme="dark"] .profile-container .toast {
  background: #101a28 !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border-color);
}

html[data-theme="dark"] .games-page,
html[data-theme="dark"] .apps-page,
html[data-theme="dark"] .deal-container,
html[data-theme="dark"] #cartContainer,
html[data-theme="dark"] #favoritesContainer {
  background: var(--primary-bg) !important;
  color: var(--text-primary);
}

html[data-theme="dark"] .games-page .search-box input,
html[data-theme="dark"] .apps-page .search-box input,
html[data-theme="dark"] .games-page .filters input,
html[data-theme="dark"] .apps-page .filters input,
html[data-theme="dark"] .games-page .filters select,
html[data-theme="dark"] .apps-page .filters select,
html[data-theme="dark"] .games-page .buttons .btn-view,
html[data-theme="dark"] .apps-page .buttons .btn-view {
  background: #101826 !important;
  color: var(--text-primary) !important;
  border-color: var(--border-color) !important;
}

html[data-theme="dark"] .games-page .search-box input:focus,
html[data-theme="dark"] .apps-page .search-box input:focus,
html[data-theme="dark"] .games-page .filters input:focus,
html[data-theme="dark"] .apps-page .filters input:focus,
html[data-theme="dark"] .games-page .filters select:focus,
html[data-theme="dark"] .apps-page .filters select:focus {
  background: #0f1724 !important;
}

html[data-theme="dark"] .deal-container,
html[data-theme="dark"] .deal-container .product-card,
html[data-theme="dark"] .deal-container .swipe-grip {
  background: var(--card-bg) !important;
  color: var(--text-primary) !important;
  border-color: var(--border-color) !important;
}

html[data-theme="dark"] .mobile-smart-search__box,
html[data-theme="dark"] .mobile-search-chip,
html[data-theme="dark"] .mobile-smart-search__suggestions,
html[data-theme="dark"] .quick-action-btn {
  background: #101826 !important;
  color: var(--text-primary) !important;
  border-color: var(--border-color) !important;
}

/* ===== Custom Confirm Modal ===== */
.app-confirm-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(10, 14, 22, 0.36);
  backdrop-filter: blur(3px);
  z-index: 12000;
}

.app-confirm-modal.is-open {
  display: flex;
}

.app-confirm-dialog {
  width: min(460px, calc(100vw - 24px));
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  box-shadow: var(--shadow-md);
  padding: 18px;
}

.app-confirm-title {
  font-size: 1.1rem;
  font-weight: 800;
  margin: 0 0 8px;
  color: var(--text-primary);
}

.app-confirm-message {
  margin: 0;
  color: var(--text-secondary);
  line-height: 1.45;
  white-space: pre-wrap;
}

.app-confirm-actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
