/* ==========================================================================
   Rouf's Recommendations - Modern Light iOS & Slip Phone Optimized System
   Zero fluff, instant app tiles, touch-first responsive design
   ========================================================================== */

:root {
  /* Colors */
  --bg-page: #f8fafc;
  --bg-surface: #ffffff;
  --bg-subtle: #f1f5f9;
  --bg-pressed: #e2e8f0;

  --border-subtle: #e2e8f0;
  --border-strong: #cbd5e1;
  --border-focus: #0284c7;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-tertiary: #94a3b8;

  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-light: #e0f2fe;

  /* Badges */
  --badge-foss-bg: #ecfdf5;
  --badge-foss-text: #065f46;
  --badge-foss-border: #a7f3d0;

  --badge-free-bg: #f0f9ff;
  --badge-free-text: #0369a1;
  --badge-free-border: #bae6fd;

  --badge-freemium-bg: #fffbeb;
  --badge-freemium-text: #92400e;
  --badge-freemium-border: #fde68a;

  /* Radii */
  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-squircle: 20px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-tile: 0 1px 3px rgba(0, 0, 0, 0.05), 0 4px 6px -1px rgba(0, 0, 0, 0.03);
  --shadow-tile-hover: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);
  --shadow-sheet: 0 -4px 20px rgba(0, 0, 0, 0.12);

  /* Fonts */
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  /* Layout */
  --max-w: 1280px;
}

/* Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-family: var(--font-sans);
  background-color: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  padding-bottom: env(safe-area-inset-bottom, 1rem);
}

img, svg {
  display: block;
  max-width: 100%;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

/* ==========================================================================
   Header & Sticky Filter Bar
   ========================================================================== */

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0.6rem 0.85rem 0.5rem;
}

.header-container {
  max-width: var(--max-w);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  min-height: 40px;
}

.brand-icon {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-xs);
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}

.brand-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  min-height: 36px;
  transition: all 150ms ease;
}

.action-btn:hover {
  background: var(--bg-pressed);
  color: var(--text-primary);
}

.action-btn-github {
  background: #0f172a;
  color: #fff !important;
  border-color: #0f172a;
  padding: 0.35rem 0.6rem;
}

.action-btn-github:hover {
  background: #1e293b;
}

/* Compact Search Bar */
.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.search-icon {
  position: absolute;
  left: 0.85rem;
  color: var(--text-tertiary);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 0.55rem 2.2rem 0.55rem 2.4rem;
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-subtle);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  outline: none;
  min-height: 42px;
  transition: all 150ms ease;
}

.search-input:focus {
  background: var(--bg-surface);
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

.search-clear-btn {
  position: absolute;
  right: 0.6rem;
  color: var(--text-tertiary);
  padding: 0.25rem;
  border-radius: var(--radius-full);
  display: none;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  min-height: 32px;
}

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

/* Category Filter Tabs (Horizontally Scrollable) */
.category-tabs {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 0.15rem;
}

.category-tabs::-webkit-scrollbar {
  display: none;
}

.category-pill {
  white-space: nowrap;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  min-height: 36px;
  transition: all 150ms ease;
  flex-shrink: 0;
}

.category-pill:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.category-pill.active {
  background: var(--text-primary);
  color: #fff;
  border-color: var(--text-primary);
  font-weight: 600;
}

.pill-count {
  font-size: 0.7rem;
  padding: 0.05rem 0.35rem;
  background: rgba(0, 0, 0, 0.06);
  border-radius: var(--radius-full);
}

.category-pill.active .pill-count {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
}

/* ==========================================================================
   Main Content Layout
   ========================================================================== */

.main-wrapper {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0.85rem 0.85rem 3rem;
  width: 100%;
  flex: 1;
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.85rem;
  font-size: 0.8rem;
  color: var(--text-tertiary);
  font-weight: 500;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.platform-chips {
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.platform-chips::-webkit-scrollbar {
  display: none;
}

.platform-chip {
  font-size: 0.78rem;
  font-weight: 500;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  min-height: 36px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  transition: all 150ms ease;
}

.platform-chip:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.platform-chip.active {
  background: var(--primary-light);
  color: var(--primary);
  border-color: #bae6fd;
  font-weight: 600;
}

/* ==========================================================================
   App Tiles Grid (Optimized for iOS Slip Phone & All Viewports)
   ========================================================================== */

.tiles-grid {
  display: grid;
  /* Adaptive grid: 2 columns on slip/mobile screens, 3-6 on larger screens */
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.85rem;
}

/* Individual App Tile */
.app-tile {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1rem 0.85rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  box-shadow: var(--shadow-tile);
  cursor: pointer;
  transition: transform 150ms cubic-bezier(0.4, 0, 0.2, 1), box-shadow 150ms ease, border-color 150ms ease;
  user-select: none;
  min-height: 180px;
  position: relative;
}

.app-tile:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-tile-hover);
  border-color: var(--border-strong);
}

.app-tile:active {
  transform: scale(0.97);
  background: var(--bg-subtle);
}

/* Native-feel Squircle App Icon */
.tile-icon-wrap {
  width: 64px;
  height: 64px;
  margin-bottom: 0.75rem;
  position: relative;
  flex-shrink: 0;
}

.tile-icon {
  width: 100%;
  height: 100%;
  border-radius: var(--radius-squircle);
  object-fit: cover;
  background: var(--bg-subtle);
  border: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.08);
}

.tile-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  flex: 1;
}

.tile-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.25;
  margin-bottom: 0.25rem;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile-category {
  font-size: 0.72rem;
  color: var(--text-tertiary);
  font-weight: 500;
  margin-bottom: 0.5rem;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile-badges {
  margin-top: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  justify-content: center;
}

.badge {
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
}

.badge-foss {
  background: var(--badge-foss-bg);
  color: var(--badge-foss-text);
  border: 1px solid var(--badge-foss-border);
}

.badge-free {
  background: var(--badge-free-bg);
  color: var(--badge-free-text);
  border: 1px solid var(--badge-free-border);
}

.badge-freemium {
  background: var(--badge-freemium-bg);
  color: var(--badge-freemium-text);
  border: 1px solid var(--badge-freemium-border);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  background: var(--bg-surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  margin-top: 1rem;
}

.empty-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.3rem;
}

.empty-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.btn-reset-filters {
  display: inline-flex;
  align-items: center;
  padding: 0.5rem 1.1rem;
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  min-height: 40px;
}

/* ==========================================================================
   Embedded Setup Guides (Inside App / Service Popup)
   ========================================================================== */

.modal-guide-section {
  margin-top: 1.25rem;
  padding: 1rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}

.modal-guide-badge {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-light);
  border: 1px solid #bae6fd;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-full);
  display: inline-block;
  margin-bottom: 0.4rem;
  text-transform: uppercase;
}

.modal-guide-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.35rem;
  line-height: 1.3;
}

.modal-guide-summary {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
  line-height: 1.45;
}

.modal-guide-steps {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.modal-guide-step {
  display: flex;
  gap: 0.65rem;
  font-size: 0.82rem;
  color: var(--text-primary);
  line-height: 1.45;
}

.guide-step-number {
  width: 20px;
  height: 20px;
  border-radius: var(--radius-full);
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 0.1rem;
}

.code-block-wrapper {
  margin-top: 0.4rem;
  position: relative;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: var(--radius-xs);
  padding: 0.65rem 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  line-height: 1.4;
  overflow-x: auto;
}

.copy-code-btn {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border-radius: var(--radius-xs);
  padding: 0.25rem 0.5rem;
  font-size: 0.68rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  min-height: 30px;
}

.copy-code-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* ==========================================================================
   Modal / Bottom Sheet (Native iOS Sheet Feel)
   ========================================================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 50;
  display: flex;
  align-items: flex-end; /* Bottom sheet on mobile */
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 200ms ease, visibility 200ms ease;
  padding: 0;
}

.modal-backdrop.open {
  opacity: 1;
  visibility: visible;
}

.modal-card {
  background: var(--bg-surface);
  border-top-left-radius: var(--radius-md);
  border-top-right-radius: var(--radius-md);
  box-shadow: var(--shadow-sheet);
  width: 100%;
  max-width: 600px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(100%);
  transition: transform 260ms cubic-bezier(0.32, 0.72, 0, 1);
  border: 1px solid var(--border-subtle);
  border-bottom: none;
}

.modal-backdrop.open .modal-card {
  transform: translateY(0);
}

/* iOS Sheet Drawer Handle */
.drawer-handle {
  width: 36px;
  height: 4px;
  border-radius: var(--radius-full);
  background: var(--border-strong);
  margin: 0.6rem auto 0.2rem;
  flex-shrink: 0;
}

.modal-header {
  padding: 0.85rem 1.15rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
}

.modal-header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.modal-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-subtle);
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.modal-title-wrap h2 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.modal-title-wrap p {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  font-weight: 500;
}

.modal-close-btn {
  color: var(--text-tertiary);
  padding: 0.35rem;
  border-radius: var(--radius-full);
  min-height: 40px;
  min-width: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close-btn:hover {
  color: var(--text-primary);
  background: var(--bg-subtle);
}

.modal-body {
  padding: 1.15rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.55;
}

.modal-section-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 1rem;
  margin-bottom: 0.4rem;
}

.modal-features-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.modal-feature-item {
  position: relative;
  padding-left: 1.15rem;
  font-size: 0.84rem;
  color: var(--text-primary);
}

.modal-feature-item::before {
  content: "";
  position: absolute;
  left: 0.2rem;
  top: 0.5rem;
  width: 5px;
  height: 5px;
  border-radius: var(--radius-full);
  background: var(--primary);
}

.modal-footer {
  padding: 0.85rem 1.15rem;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.modal-footer-links {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.btn-modal-link {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-xs);
  background: var(--primary);
  color: #fff !important;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 40px;
}

.btn-modal-link:hover {
  background: var(--primary-hover);
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 100;
  pointer-events: none;
}

.toast {
  background: #0f172a;
  color: #fff;
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  opacity: 0;
  transform: translateY(10px);
  transition: all 150ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* Back to Top */
.back-to-top {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-tile);
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 35;
  opacity: 0;
  visibility: hidden;
  transition: all 200ms ease;
}

.back-to-top.visible {
  opacity: 1;
  visibility: visible;
}

.back-to-top:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* Footer */
.app-footer {
  border-top: 1px solid var(--border-subtle);
  padding: 1.5rem 0.85rem;
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-tertiary);
  margin-top: auto;
}

.app-footer a {
  color: var(--text-secondary);
  padding: 0.35rem 0.45rem;
  display: inline-block;
  min-height: 38px;
  line-height: 26px;
}

.app-footer a:hover {
  color: var(--primary);
}

/* ==========================================================================
   Responsive Viewport Optimizations (iOS Slip Phone, Foldable & Desktop)
   ========================================================================== */

/* Slip / Flip Phone (< 360px width) */
@media (max-width: 360px) {
  .app-header {
    padding: 0.5rem 0.6rem;
  }

  .brand-title {
    font-size: 0.95rem;
  }

  .btn-text {
    display: none;
  }

  .main-wrapper {
    padding: 0.65rem 0.6rem 2.5rem;
  }

  .tiles-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
  }

  .app-tile {
    padding: 0.75rem 0.45rem;
    min-height: 160px;
  }

  .tile-icon-wrap {
    width: 52px;
    height: 52px;
    margin-bottom: 0.5rem;
  }

  .tile-title {
    font-size: 0.85rem;
  }

  .tile-category {
    font-size: 0.68rem;
  }
}

/* Standard Mobile & iOS (360px to 640px) */
@media (min-width: 361px) and (max-width: 640px) {
  .tiles-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.65rem;
  }

  .app-tile {
    padding: 0.85rem 0.6rem;
  }
}

/* Desktop View (> 640px) */
@media (min-width: 641px) {
  .modal-backdrop {
    padding: 1.5rem;
    align-items: center;
  }

  .modal-card {
    border-radius: var(--radius-md);
    transform: scale(0.96);
    border-bottom: 1px solid var(--border-subtle);
  }

  .drawer-handle {
    display: none;
  }

  .modal-backdrop.open .modal-card {
    transform: scale(1);
  }

  .tiles-grid {
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 1rem;
  }

  .tile-icon-wrap {
    width: 68px;
    height: 68px;
  }
}
