/*******************************************************************************
  1. THEME CONFIGURATION VARIABLES (LIGHT & DARK SYSTEM MATRICES)
*******************************************************************************/
:root, [data-theme="light"] {
  color-scheme: light;
  --bg: #f9fafb;
  --text: #111827;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-soft: #c7d2fe;
  --card-bg: #ffffff;
  --border: #e5e7eb;
  --shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
  --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.08);
  --radius: 12px;
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0f19;
  --text: #f3f4f6;
  --muted: #9ca3af;
  --accent: #6366f1;
  --accent-soft: #312e81;
  --card-bg: #111827;
  --border: #1f2937;
  --shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.5);
}

/*******************************************************************************
  2. BASE LAYOUT & TYPOGRAPHY RESETS
*******************************************************************************/
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background 0.3s ease, color 0.3s ease;
}

/*******************************************************************************
  3. COMPONENT NAVIGATION: SITE HEADER
*******************************************************************************/
.site-header {
  /* FIXED FOR ANDROID 15: Adapts top padding to seamlessly clear hardware status bars */
  padding: calc(16px + env(safe-area-inset-top, 0px)) 20px 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--card-bg);
  box-shadow: var(--shadow);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  position: relative;
  z-index: 100;
  transition: background 0.3s ease, border-color 0.3s ease;
}

.site-header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.025em;
}

.site-header .subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  margin-right: auto;
}

.last-updated {
  font-size: 0.8rem;
  color: var(--muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/*******************************************************************************
  4. INTERACTIVE DECENTRALIZED TOGGLE NAVIGATION (MOBILE CORES)
*******************************************************************************/
.menu-toggle-bar {
  display: none;
  background: var(--card-bg);
  /* FIXED FOR ANDROID 15: Protects navigation elements in landscape/portrait scenarios */
  padding: calc(12px + env(safe-area-inset-top, 0px)) calc(16px + env(safe-area-inset-right, 0px)) 12px calc(16px + env(safe-area-inset-left, 0px));
  border-bottom: 1px solid var(--border);
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 90;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
  transition: background 0.3s ease, border-color 0.3s ease;
}

.hamburger-btn {
  background: transparent;
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  color: var(--text);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.hamburger-btn:active, .hamburger-btn:hover {
  background: var(--border);
}

/*******************************************************************************
  5. SYSTEM LAYOUT PANELS (3-COLUMN ENGINE)
*******************************************************************************/
.hub-main {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  /* FIXED FOR ANDROID 15: Injects physical window safe-area boundary configurations */
  padding: 16px calc(16px + env(safe-area-inset-right, 0px)) 16px calc(16px + env(safe-area-inset-left, 0px));
  flex: 1;
}

.sidebar {
  display: block;
}

.filter-group h3 {
  margin: 0 0 12px 0;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.filter-chips {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-chip {
  appearance: none;
  background: transparent;
  border: none;
  text-align: left;
  padding: 10px 14px;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.filter-chip:hover {
  background: var(--border);
}

.filter-chip.active {
  background: var(--accent-soft);
  color: var(--accent);
}

/*******************************************************************************
  6. DIRECTORY APPS GRID LAYOUT
*******************************************************************************/
.apps-section {
  position: relative;
  width: 100%;
}

.apps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

/*******************************************************************************
  7. INDEPENDENT APP CARDS MATRIX STYLING
*******************************************************************************/
.app-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.3s ease, border-color 0.3s ease;
  position: relative;
}

.app-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}

.card-completed {
  opacity: 0.85;
  border-style: dashed;
}

.app-icon {
  border: 1px solid var(--border);
  background: var(--bg);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
  flex-shrink: 0;
}

.app-title {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.25;
}

.app-meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 4px;
}

/* Custom Data Fields Meta chips */
.dir-category {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
}

.dir-price {
  color: #047857;
  font-weight: 600;
}

[data-theme="dark"] .dir-price {
  color: #34d399;
}

.app-description {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 14px 0;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.app-timing {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text);
}

.app-actions {
  display: flex;
  gap: 6px;
}

/*******************************************************************************
  8. STATUS BADGES & TAG CHIPS
*******************************************************************************/
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 9999px;
  background: var(--border);
  color: var(--text);
  white-space: nowrap;
}

.badge-status-active {
  background: #d1fae5;
  color: #065f46;
}

[data-theme="dark"] .badge-status-active {
  background: #064e3b;
  color: #a7f3d0;
}

.badge-status-joined {
  background: #eff6ff;
  color: #1e40af;
}

[data-theme="dark"] .badge-status-joined {
  background: #1e3a8a;
  color: #bfdbfe;
}

.badge-status-completed {
  background: #f3e8ff;
  color: #6b21a8;
}

[data-theme="dark"] .badge-status-completed {
  background: #581c87;
  color: #e9d5ff;
}

.badge-status-expired {
  background: #fee2e2;
  color: #991b1b;
}

[data-theme="dark"] .badge-status-expired {
  background: #7f1d1d;
  color: #fca5a5;
}

/*******************************************************************************
  9. SYSTEM TYPOGRAPHY BUTTONS
*******************************************************************************/
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
}

.btn-primary:hover {
  background: #4338ca;
}

[data-theme="dark"] .btn-primary:hover {
  background: #4f46e5;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover {
  background: var(--border);
}

/*******************************************************************************
  10. RUNTIME UI LOADING STATE HANDLERS
*******************************************************************************/
.loading, .empty {
  padding: 40px;
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
  grid-column: 1 / -1;
  width: 100%;
}

.hidden {
  display: none !important;
}

/*******************************************************************************
  11. SYSTEM WIDGET CARDS: PRO-TIPS MODULE
*******************************************************************************/
.pro-tip-card {
  background: var(--card-bg);
  border: 1px solid #f59e0b;
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

[data-theme="light"] .pro-tip-card {
  background: linear-gradient(135deg, #ffffff 0%, #fdfbf7 100%);
}

.pro-tip-header {
  font-size: 0.9rem;
  font-weight: 700;
  color: #d97706;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.pro-tip-content {
  font-size: 0.85rem;
  line-height: 1.45;
  color: var(--text);
}

/*******************************************************************************
  12. FLOATING OVERLAYS MODALS LAYERS
*******************************************************************************/
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(11, 15, 25, 0.5);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 90%;
  max-width: 500px;
  padding: 24px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3);
  z-index: 1010;
  transition: background 0.3s ease, border-color 0.3s ease;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--muted);
}

/*******************************************************************************
  13. STRUCTURAL CONTENT PAGES CLOSURES (ABOUT, DETAILS)
*******************************************************************************/
.app-page-container {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
  transition: background 0.3s ease, border-color 0.3s ease;
}

.app-info p {
  margin: 10px 0;
  font-size: 0.9rem;
  line-height: 1.4;
}

.site-footer {
  width: 100%;
  max-width: 1400px;
  margin: auto auto 0 auto;
  /* FIXED FOR ANDROID 15: Extends padding below text bounding lines to shield gesture pill intersections */
  padding: 24px calc(20px + env(safe-area-inset-right, 0px)) calc(24px + env(safe-area-inset-bottom, 0px)) calc(20px + env(safe-area-inset-left, 0px));
  border-top: 1px solid var(--border);
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  transition: border-color 0.3s ease;
}

.site-footer a {
  color: var(--accent);
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

/*******************************************************************************
  14. HIGH DESKTOP SCREEN LAYOUT OVERRIDES (3-COLUMNS RUNNER)
*******************************************************************************/
@media (min-width: 992px) {
  .hub-main {
    grid-template-columns: 240px 1fr 280px;
    gap: 24px;
    align-items: start;
    padding: 24px 20px;
  }
  
  #daily-pro-tip-container {
    position: sticky;
    top: 24px;
  }
}

/*******************************************************************************
  15. MOBILE NAVIGATION SYSTEM INTERFACES (HAMBURGER BREAKPOINTS)
*******************************************************************************/
@media (max-width: 991px) {
  .menu-toggle-bar {
    display: flex;
  }

  .sidebar {
    display: none;
    background: var(--card-bg);
    border: 1px solid var(--border);
    padding: 16px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    width: 100%;
    animation: slideDown 0.2s ease-out;
  }

  .sidebar.active {
    display: block;
  }

  .filter-chips {
    flex-direction: column;
    gap: 4px;
  }

  .filter-chip {
    padding: 12px 14px;
  }
}

/*******************************************************************************
  16. SMALL DEVICE MEDIA RESPONSIVENESS MATRIX
*******************************************************************************/
@media (max-width: 768px) {
  .site-header {
    text-align: center;
    justify-content: center;
    flex-direction: column;
    /* FIXED FOR ANDROID 15: Safeguards responsive mobile header from top overlays */
    padding: calc(20px + env(safe-area-inset-top, 0px)) 16px 20px 16px;
  }
  
  .site-header .subtitle {
    margin: 6px 0 12px 0;
  }

  .apps-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .btn {
    width: 100%;
    text-align: center;
  }

  .app-footer {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .app-actions {
    flex-direction: column;
    gap: 8px;
  }

  .app-page-container {
    padding: 16px;
  }

  .app-header {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 12px;
  }
}

/*******************************************************************************
  17. RUNTIME UI RENDERER SYSTEM ANIMATIONS
*******************************************************************************/
@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}