/* ============================================================
   style.css — KHO APP CHUM — Mobile-friendly App Catalog
   Reference: horizontal card rows, category sections, smooth mobile
   ============================================================ */

/* ---------- RESET & VARIABLES ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0
}

:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-card-h: #22263a;
  --bg-topbar: #14161e;
  --surface: #252836;
  --border: #2e3144;
  --text: #e8eaf0;
  --text-dim: #8d90a0;
  --accent: #6c63ff;
  --accent-h: #857dff;
  --accent-glow: rgba(108, 99, 255, .35);
  --danger: #ff5a5a;
  --success: #3dd68c;
  --focus-ring: #6c63ff;
  --toast-bg: #252836;
  --skeleton: #252836;
  --skeleton-shine: #2e3144;
  --radius: 12px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --topbar-h: 60px;
  --tabs-h: 48px;
  --card-gap: 12px;
  --transition: .2s cubic-bezier(.4, 0, .2, 1);
}

[data-theme="light"] {
  --bg: #f3f8fb;
  --bg-card: #ffffff;
  --bg-card-h: #f0f4ff;
  --bg-topbar: #ffffff;
  --surface: #eaedf3;
  --border: #d8dbe5;
  --text: #1a1d27;
  --text-dim: #6b6e80;
  --accent: #5046e5;
  --accent-h: #6c63ff;
  --accent-glow: rgba(80, 70, 229, .22);
  --focus-ring: #5046e5;
  --toast-bg: #ffffff;
  --skeleton: #e0e3ea;
  --skeleton-shine: #f0f2f5;
}

html {
  font-family: 'Inter', 'Poppins', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: none;
  overflow-x: hidden;
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  background: var(--bg);
  -webkit-overflow-scrolling: touch;
}

a {
  text-decoration: none;
  color: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0
}

/* ---------- FOCUS SYSTEM ---------- */
.focusable:focus {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px var(--accent-glow);
  z-index: 5;
  transition: transform var(--transition), box-shadow var(--transition);
}

.focusable:focus:not(:focus-visible) {
  outline: none;
  box-shadow: none;
}

.focusable:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px var(--accent-glow);
}

/* ---------- TOP BAR ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-h);
  padding: 0 16px;
  background: var(--bg-topbar);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.topbar__left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar__logo {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
}

.topbar__title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: .3px;
  white-space: nowrap;
}

.topbar__right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Search */
.search-wrap {
  position: relative;
}

.search-input {
  width: 200px;
  height: 38px;
  padding: 0 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: .88rem;
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  outline: none;
}

.search-input::placeholder {
  color: var(--text-dim);
}

/* Topbar Buttons */
.topbar-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  text-decoration: none;
  transition: all var(--transition);
}

.topbar-btn:hover,
.topbar-btn:focus-visible {
  background: var(--bg-card-h);
}

.topbar-btn svg {
  width: 18px;
  height: 18px;
}

/* Theme toggle icon visibility */
[data-theme="dark"] .icon-sun {
  display: none
}

[data-theme="light"] .icon-moon {
  display: none
}

/* ---------- STATUS LINE ---------- */
.status-line {
  padding: 5px 16px;
  font-size: .72rem;
  color: var(--text-dim);
  background: var(--bg);
  min-height: 24px;
}

/* ---------- TABS ---------- */
.tabs-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: var(--topbar-h);
  z-index: 90;
}

.tab-btn {
  flex-shrink: 0;
  padding: 7px 16px;
  border-radius: 50px;
  border: none;
  font-size: .8rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
  color: #fff;
  opacity: .7;
  -webkit-tap-highlight-color: transparent;
}

.tab-btn:hover {
  opacity: 1;
}

.tab-btn[aria-selected="true"] {
  opacity: 1;
  box-shadow: 0 3px 12px rgba(0, 0, 0, .25);
  transform: scale(1.05);
}

/* Per-tab colors */
.tab-btn:nth-child(1) {
  background: #6c63ff
}

.tab-btn:nth-child(2) {
  background: #e85d75
}

.tab-btn:nth-child(3) {
  background: #2ecc71
}

.tab-btn:nth-child(4) {
  background: #e67e22
}

.tab-btn:nth-child(5) {
  background: #3498db
}

.tab-btn:nth-child(6) {
  background: #9b59b6
}

.tab-btn:nth-child(7) {
  background: #1abc9c
}

.tab-btn:nth-child(8) {
  background: #e74c3c
}

.tab-btn:nth-child(n+9) {
  background: #34495e
}

/* ---------- MAIN / CONTENT ---------- */
.main-content {
  padding: 12px 16px 60px;
}

.cards-grid {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ---------- CATEGORY SECTION ---------- */
.category-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.category-title {
  position: relative;
  padding: 0 4px;
}

.category-title h3 {
  font-size: .9rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text);
  letter-spacing: .5px;
  padding-left: 12px;
  border-left: 3px solid var(--accent);
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--card-gap);
}

/* ---------- APP CARD (horizontal row like reference) ---------- */
.app-card {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 10px;
  transition: all var(--transition);
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overflow: hidden;
}

.app-card:hover,
.app-card:active {
  background: var(--bg-card-h);
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .15);
}

.app-card:active {
  transform: scale(0.98);
}

.app-card__icon-wrap {
  flex-shrink: 0;
}

.app-card__icon {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--surface);
  display: block;
}

.app-card__icon-placeholder {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 1.3rem;
  flex-shrink: 0;
}

.app-card__info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.app-card__name {
  font-weight: 700;
  font-size: .92rem;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.app-card__desc {
  font-size: .78rem;
  color: var(--text-dim);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.app-card__meta {
  font-size: .7rem;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- SKELETON ---------- */
.skeleton-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--card-gap);
}

.skeleton-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 12px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
}

.sk-icon {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  background: var(--skeleton);
  animation: skPulse 1.4s ease-in-out infinite;
  flex-shrink: 0;
}

.sk-line {
  height: 12px;
  border-radius: 4px;
  background: var(--skeleton);
  animation: skPulse 1.4s ease-in-out .2s infinite;
}

.sk-line.w80 {
  width: 80%
}

.sk-line.w60 {
  width: 60%
}

.sk-line.w40 {
  width: 40%
}

@keyframes skPulse {

  0%,
  100% {
    opacity: .45
  }

  50% {
    opacity: .85
  }
}

/* ---------- EMPTY / ERROR STATE ---------- */
.empty-state,
.error-state {
  text-align: center;
  padding: 60px 20px;
}

.empty-state__text,
.error-state__text {
  font-size: 1rem;
  color: var(--text-dim);
  margin-bottom: 18px;
}

.error-state .btn-primary {
  display: inline-block;
  padding: 12px 32px;
  width: auto;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-xs);
  font-size: .85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.error-state .btn-primary:hover {
  background: var(--accent-h);
}

/* ---------- TOAST ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--toast-bg);
  color: var(--text);
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: .85rem;
  font-weight: 600;
  box-shadow: 0 8px 32px rgba(0, 0, 0, .35);
  opacity: 0;
  pointer-events: none;
  transition: all .3s ease;
  z-index: 200;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

/* ---------- RESPONSIVE ---------- */

/* Tablet */
@media (max-width: 1080px) {

  .category-grid,
  .skeleton-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Mobile landscape / small tablet */
@media (max-width: 768px) {
  .topbar {
    padding: 0 12px;
    height: 52px;
  }

  .topbar__title {
    font-size: .92rem;
  }

  .topbar__logo {
    width: 32px;
    height: 32px;
  }

  .topbar-btn {
    width: 34px;
    height: 34px;
  }

  .topbar-btn svg {
    width: 16px;
    height: 16px;
  }

  .search-input {
    width: 150px;
    height: 34px;
    font-size: .82rem;
    padding: 0 12px;
  }

  .tabs-bar {
    padding: 6px 12px;
    top: 52px;
  }

  .tab-btn {
    padding: 6px 14px;
    font-size: .75rem;
  }

  .main-content {
    padding: 10px 12px 40px;
  }

  .category-grid,
  .skeleton-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .app-card {
    padding: 8px;
    gap: 10px;
  }

  .app-card__icon,
  .app-card__icon-placeholder {
    width: 56px;
    height: 56px;
  }

  .app-card__name {
    font-size: .85rem;
  }

  .app-card__desc {
    font-size: .74rem;
    -webkit-line-clamp: 1;
    line-clamp: 1;
  }
}

/* Mobile portrait */
@media (max-width: 480px) {
  .topbar {
    padding: 0 10px;
    height: 48px;
    gap: 6px;
  }

  .topbar__left {
    gap: 8px;
  }

  .topbar__logo {
    width: 28px;
    height: 28px;
  }

  .topbar__title {
    font-size: .85rem;
  }

  .topbar__right {
    gap: 5px;
  }

  .topbar-btn {
    width: 30px;
    height: 30px;
  }

  .topbar-btn svg {
    width: 14px;
    height: 14px;
  }

  .search-input {
    width: 110px;
    height: 30px;
    font-size: .78rem;
    padding: 0 10px;
    border-radius: 15px;
  }

  .tabs-bar {
    padding: 5px 10px;
    gap: 5px;
    top: 48px;
  }

  .tab-btn {
    padding: 5px 12px;
    font-size: .72rem;
  }

  .main-content {
    padding: 8px 10px 30px;
  }

  .category-grid,
  .skeleton-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .category-title h3 {
    font-size: .82rem;
  }

  .app-card {
    padding: 10px;
    gap: 12px;
    border-radius: 10px;
  }

  .app-card__icon,
  .app-card__icon-placeholder {
    width: 60px;
    height: 60px;
    border-radius: 8px;
  }

  .app-card__name {
    font-size: .88rem;
  }

  .app-card__desc {
    font-size: .76rem;
    -webkit-line-clamp: 2;
    line-clamp: 2;
  }

  .sk-icon {
    width: 60px;
    height: 60px;
  }

  .status-line {
    padding: 3px 10px;
    font-size: .68rem;
  }
}

/* ---------- SCROLLBAR ---------- */
::-webkit-scrollbar {
  width: 5px
}

::-webkit-scrollbar-track {
  background: var(--bg)
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim)
}