/* Apple Human Interface Guidelines Design Tokens */
:root {
  --bg-primary: #F2F2F7;
  --bg-card: #FFFFFF;
  --bg-card-hover: #F8F8FA;
  --text-primary: #1C1C1E;
  --text-secondary: #8E8E93;
  --text-tertiary: #AEAEB2;
  --accent: #007AFF;
  --accent-hover: #0056B3;
  --accent-bg: #E5F1FF;
  --border: rgba(60, 60, 67, 0.12);
  --glass-bg: rgba(255, 255, 255, 0.85);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.08);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --radius-full: 9999px;
  --transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #000000;
    --bg-card: #1C1C1E;
    --bg-card-hover: #2C2C2E;
    --text-primary: #FFFFFF;
    --text-secondary: #8E8E93;
    --text-tertiary: #636366;
    --accent: #0A84FF;
    --accent-hover: #409CFF;
    --accent-bg: rgba(10, 132, 255, 0.15);
    --border: rgba(255, 255, 255, 0.1);
    --glass-bg: rgba(28, 28, 30, 0.85);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.6);
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", Helvetica, Arial, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(40px + env(safe-area-inset-bottom));
}

/* Navbar */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.navbar-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 26px;
  height: 26px;
  color: var(--accent);
}

.brand-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.4px;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-name {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-btn {
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  padding: 6px;
  border-radius: var(--radius-full);
  transition: var(--transition);
  text-decoration: none;
}

.logout-btn:hover {
  background: var(--border);
  color: var(--text-primary);
}

/* Main Content Layout */
.main-content {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px;
}

.hero-section {
  margin-bottom: 24px;
}

.hero-title {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.6px;
  margin-bottom: 6px;
}

.hero-subtitle {
  font-size: 15px;
  color: var(--text-secondary);
}

/* Search & Categories */
.controls-section {
  margin-bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.search-bar {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 14px;
  width: 18px;
  height: 18px;
  color: var(--text-secondary);
}

.search-bar input {
  width: 100%;
  padding: 12px 38px 12px 42px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 16px;
  color: var(--text-primary);
  outline: none;
  transition: var(--transition);
}

.search-bar input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

.clear-btn {
  position: absolute;
  right: 12px;
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text-secondary);
  cursor: pointer;
}

.category-pills {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}

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

.pill {
  padding: 8px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition);
}

.pill.active {
  background: var(--accent);
  color: #FFFFFF;
  border-color: var(--accent);
}

/* App Grid */
.app-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.app-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.app-card:active {
  transform: scale(0.985);
}

.app-icon-wrapper {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-md);
  flex-shrink: 0;
  overflow: hidden;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.app-icon-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.app-info {
  flex: 1;
  min-width: 0;
}

.app-name {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 3px;
}

.app-category {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-device {
  font-size: 10px;
  font-weight: 700;
  background: rgba(52, 199, 89, 0.15);
  color: #34C759;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

@media (prefers-color-scheme: dark) {
  .badge-device {
    background: rgba(48, 209, 88, 0.2);
    color: #30D158;
  }
}

.app-name {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-description {
  font-size: 13px;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.app-developer {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-action {
  flex-shrink: 0;
}

.btn-get {
  background: var(--bg-primary);
  color: var(--accent);
  border: none;
  font-size: 14px;
  font-weight: 700;
  padding: 8px 20px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: var(--transition);
  text-transform: uppercase;
}

.btn-get:active {
  background: var(--accent);
  color: #FFFFFF;
}

.btn-update {
  background: rgba(52, 199, 89, 0.12);
  color: #34C759;
}

.btn-update:active {
  background: #34C759;
  color: #FFFFFF;
}

@media (prefers-color-scheme: dark) {
  .btn-update {
    background: rgba(48, 209, 88, 0.18);
    color: #30D158;
  }
  .btn-update:active {
    background: #30D158;
    color: #FFFFFF;
  }
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
  font-size: 15px;
}

/* Skeleton Loading */
.skeleton-card {
  height: 96px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  animation: pulse 1.5s infinite ease-in-out;
}

@keyframes pulse {
  0% { opacity: 0.6; }
  50% { opacity: 1; }
  100% { opacity: 0.6; }
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  max-width: 340px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
  from { transform: translateY(20px) scale(0.95); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

.modal-icon-container {
  margin: 0 auto 16px;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.success-icon {
  width: 44px;
  height: 44px;
  color: #34C759;
}

.modal-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 8px;
}

.modal-message {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 16px;
  line-height: 1.4;
}

.modal-tip {
  font-size: 12px;
  background: var(--bg-primary);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.modal-btn {
  background: var(--accent);
  color: #FFFFFF;
  border: none;
  width: 100%;
  padding: 12px;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
