/* ============================================================
   Design Tokens
   ============================================================ */
:root {
  /* Colours — Light */
  --bg:          #F2F2F7;
  --bg-2:        #FFFFFF;
  --bg-3:        #E5E5EA;
  --card:        #FFFFFF;
  --text:        #1D1D1F;
  --text-2:      #6E6E73;
  --text-3:      #AEAEB2;
  --accent:      #4F46E5;
  --accent-soft: #EEF2FF;
  --danger:      #FF3B30;
  --border:      rgba(0,0,0,0.12);
  --shadow-sm:   0 1px 3px rgba(0,0,0,0.04), 0 4px 16px rgba(0,0,0,0.08);
  --shadow:      0 4px 20px rgba(0,0,0,0.12);
  --shadow-lg:   0 12px 40px rgba(0,0,0,0.16);

  /* Status */
  --s-wishlist:    #AEAEB2;
  --s-in-progress: #FF9F0A;
  --s-on-hold:     #5AC8FA;
  --s-dropped:     #FF375F;
  --s-done:        #30D158;

  /* Type colours */
  --t-place:    #34C759;
  --t-website:  #5AC8FA;
  --t-event:    #FF6B6B;
  --t-activity: #30D158;
  --t-group:    #FF9F0A;
  --t-book:     #FF9F0A;
  --t-movie:    #BF5AF2;
  --t-tv_show:  #BF5AF2;
  --t-manga:    #FF375F;
  --t-anime:    #FF375F;
  --t-music:    #0A84FF;
  --t-podcast:  #0A84FF;

  /* Typography */
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', Arial, sans-serif;

  /* Spacing */
  --s4:  4px;
  --s8:  8px;
  --s12: 12px;
  --s16: 16px;
  --s20: 20px;
  --s24: 24px;
  --s32: 32px;

  /* Radius */
  --r-sm:   8px;
  --r:      14px;
  --r-lg:   20px;
  --r-full: 9999px;

  /* Layout */
  --sidebar-w: 220px;
  --nav-h:     60px;
  --fab-size:  56px;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  :root { --theme: dark; }
}
[data-theme="dark"] {
  --bg:          #000000;
  --bg-2:        #1C1C1E;
  --bg-3:        #2C2C2E;
  --card:        #1C1C1E;
  --text:        #F2F2F7;
  --text-2:      #8E8E93;
  --text-3:      #6E6E73;
  --accent:      #6366F1;
  --accent-soft: rgba(99,102,241,0.18);
  --danger:      #FF453A;
  --border:      rgba(255,255,255,0.12);
  --shadow-sm:   0 1px 3px rgba(0,0,0,0.60), 0 4px 16px rgba(0,0,0,0.40);
  --shadow:      0 4px 20px rgba(0,0,0,0.70);
  --shadow-lg:   0 16px 48px rgba(0,0,0,0.85);
}

/* Dark mode surface overrides */
[data-theme="dark"] .view-header {
  background: rgba(0,0,0,0.82);
}
[data-theme="dark"] .bottom-nav {
  background: rgba(0,0,0,0.85);
  border-top-color: rgba(255,255,255,0.12);
}
[data-theme="dark"] .sidebar {
  background: rgba(10,10,10,0.98);
  border-right-color: rgba(255,255,255,0.07);
}
[data-theme="dark"] .item-card,
[data-theme="dark"] .collection-card,
[data-theme="dark"] .settings-group,
[data-theme="dark"] .profile-card,
[data-theme="dark"] .usage-bar-wrap {
  border-color: rgba(255,255,255,0.08);
  box-shadow: 0 1px 3px rgba(0,0,0,0.40);
}
[data-theme="dark"] .auth-form input {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.08);
}
[data-theme="dark"] .auth-form input:focus {
  background: rgba(255,255,255,0.08);
  border-color: var(--accent);
}
[data-theme="dark"] .auth-tabs {
  background: rgba(255,255,255,0.07);
}
[data-theme="dark"] .auth-tab.active {
  background: rgba(255,255,255,0.12);
}
[data-theme="light"] {
  --bg:          #FFFFFF;
  --bg-2:        #F5F5F7;
  --bg-3:        #E8E8ED;
  --card:        #FFFFFF;
  --text:        #1D1D1F;
  --text-2:      #6E6E73;
  --text-3:      #AEAEB2;
  --accent:      #4F46E5;
  --accent-soft: #EEF2FF;
  --border:      rgba(0,0,0,0.08);
  --shadow-sm:   0 1px 4px rgba(0,0,0,0.06);
  --shadow:      0 4px 16px rgba(0,0,0,0.10);
  --shadow-lg:   0 12px 40px rgba(0,0,0,0.14);
}

/* ============================================================
   Reset & Base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  height: 100%;
}

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  transition: background 0.2s, color 0.2s;
}

img { display: block; width: 100%; height: 100%; object-fit: cover; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, textarea { font-family: inherit; outline: none; border: none; background: none; }
a { color: inherit; text-decoration: none; }
ul { list-style: none; }

/* ============================================================
   Screens
   ============================================================ */
.screen { display: none; }
.screen.active { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* Auth can scroll if form is taller than viewport (small phones) */
#screen-auth.active { height: auto; min-height: 100vh; min-height: 100dvh; overflow-y: auto; }

/* ============================================================
   Auth Screen
   ============================================================ */
#screen-auth {
  align-items: center;
  justify-content: center;
  padding: var(--s24);
  background: var(--bg);
}

.auth-box {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: var(--s24);
}

.auth-theme-btn {
  position: fixed;
  top: var(--s16);
  right: var(--s16);
  width: 36px;
  height: 36px;
  border-radius: var(--r-full);
  background: var(--bg-2);
  color: var(--text-2);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  transition: background 0.15s, color 0.15s;
  z-index: 5;
}
.auth-theme-btn:hover { background: var(--bg-3); color: var(--text); }

/* Show sun in dark mode, moon in light mode */
[data-theme="dark"]  .auth-theme-btn .icon-sun  { display: none; }
[data-theme="dark"]  .auth-theme-btn .icon-moon { display: block; }
[data-theme="light"] .auth-theme-btn .icon-sun  { display: block; }
[data-theme="light"] .auth-theme-btn .icon-moon { display: none; }

.auth-logo {
  text-align: center;
  margin-bottom: var(--s8);
}

.auth-logo h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text);
}

.auth-logo p {
  font-size: 15px;
  color: var(--text-2);
  margin-top: var(--s4);
}

.auth-tabs {
  display: flex;
  background: var(--bg-2);
  border-radius: var(--r);
  padding: 3px;
}

.auth-tab {
  flex: 1;
  padding: var(--s8) var(--s12);
  border-radius: calc(var(--r) - 3px);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
  transition: all 0.2s;
  text-align: center;
}

.auth-tab.active {
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: var(--s12);
}

.auth-form input {
  width: 100%;
  padding: var(--s14, 14px) var(--s16);
  background: var(--bg-2);
  border-radius: var(--r);
  font-size: 15px;
  color: var(--text);
  border: 1.5px solid transparent;
  transition: border-color 0.2s;
}

.auth-form input::placeholder { color: var(--text-3); }
.auth-form input:focus { border-color: var(--accent); background: var(--bg); }

.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--r);
  font-size: 15px;
  font-weight: 600;
  transition: opacity 0.15s, transform 0.15s;
}

.btn-primary:active { opacity: 0.85; transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.auth-error {
  font-size: 13px;
  color: var(--danger);
  text-align: center;
  min-height: 18px;
}

.field-wrap {
  display: flex;
  flex-direction: column;
  gap: var(--s4);
}

.field-hint {
  font-size: 12px;
  color: var(--text-3);
  padding-left: var(--s4);
  transition: color 0.2s;
}

.field-hint.valid { color: var(--s-done); }
.field-hint.invalid { color: var(--danger); }

.password-reqs {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-left: var(--s4);
  list-style: none;
}

.req {
  font-size: 12px;
  color: var(--text-3);
  display: flex;
  align-items: center;
  gap: var(--s4);
  transition: color 0.2s;
}

.req::before {
  content: '○';
  font-size: 10px;
  flex-shrink: 0;
  transition: color 0.2s;
}

.req.met {
  color: var(--s-done);
}

.req.met::before {
  content: '●';
  color: var(--s-done);
}

.auth-link {
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  padding: var(--s4) 0;
  transition: opacity 0.15s;
}
.auth-link:hover { opacity: 0.75; }

.auth-subtitle {
  font-size: 14px;
  color: var(--text-2);
  text-align: center;
  padding-bottom: var(--s4);
}

.auth-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s8);
  padding: var(--s24) 0 var(--s8);
  text-align: center;
}
.auth-message-icon { font-size: 40px; line-height: 1; }
.auth-message-title { font-size: 18px; font-weight: 700; color: var(--text); }
.auth-message-body { font-size: 14px; color: var(--text-2); }

/* ============================================================
   App Shell (sidebar + main)
   ============================================================ */
#screen-app {
  flex-direction: row;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  display: none;
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  padding: var(--s24) var(--s16);
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh; height: 100dvh;
  z-index: 10;
}

.sidebar-logo {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text);
  padding: var(--s8) var(--s8);
  margin-bottom: var(--s16);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: var(--s8);
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--s12);
  padding: var(--s8) var(--s12);
  border-radius: var(--r-sm);
  font-size: 15px;
  font-weight: 500;
  color: var(--text-2);
  transition: all 0.15s;
  cursor: pointer;
}

.nav-item:hover { background: var(--bg-3); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-item svg { width: 22px; height: 22px; flex-shrink: 0; }

.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--s12);
  width: 100%;
  border-radius: var(--r-sm);
  padding: var(--s12);
  margin-top: auto;
  transition: background 0.15s;
  text-align: left;
}
.sidebar-user:hover { background: var(--bg-3); }
.sidebar-user:active { background: var(--bg-3); }

.sidebar-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--r-full);
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  flex-shrink: 0;
}

.sidebar-user-info { flex: 1; overflow: hidden; }
.sidebar-user-name { font-size: 14px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-plan { font-size: 12px; color: var(--text-3); }

/* Main content area */
.main-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 16px);
}

/* Views */
.view { display: none; }
.view.active { display: block; }

/* ============================================================
   Home View
   ============================================================ */
.view-header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(242,242,247,0.82);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  padding: var(--s32) var(--s16) 0;
  border-bottom: 1px solid var(--border);
}

[data-theme="dark"] .view-header {
  background: rgba(0,0,0,0.85);
}

#view-profile .view-header {
  border-bottom: none;
  padding-bottom: var(--s16);
}

.view-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text);
  padding-bottom: var(--s12);
}

/* Mobile header: title + avatar row */
.view-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: var(--s12);
}
.view-title-row .view-title { padding-bottom: 0; }

.header-avatar {
  width: 42px;
  height: 42px;
  border-radius: var(--r-full);
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s;
}
.header-avatar:active { opacity: 0.7; }

@media (min-width: 768px) {
  .header-avatar { display: none; }
}

.filter-row {
  display: flex;
  gap: var(--s8);
  overflow-x: auto;
  padding-bottom: var(--s12);
  scrollbar-width: none;
}

.filter-row::-webkit-scrollbar { display: none; }

.filter-pill {
  flex-shrink: 0;
  padding: 9px 16px;
  background: var(--bg-2);
  border-radius: var(--r-full);
  font-size: 15px;
  font-weight: 500;
  color: var(--text-2);
  transition: all 0.15s;
  white-space: nowrap;
}

.filter-pill.active {
  background: var(--accent);
  color: #fff;
}

.filter-pill:active { transform: scale(0.95); }

/* Cards grid */
.cards-grid {
  padding: var(--s16);
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--s12);
}

.item-card {
  background: var(--card);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}

.item-card:active {
  -webkit-transform: scale(0.97) translateZ(0);
  transform: scale(0.97) translateZ(0);
  box-shadow: var(--shadow-sm);
}

.card-image {
  width: 100%;
  aspect-ratio: 2/3;
  background: var(--bg-2);
  position: relative;
  overflow: hidden;
}

.card-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: opacity 0.3s;
}

.card-image-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
}

.card-status {
  position: absolute;
  top: var(--s8);
  right: var(--s8);
  padding: 3px var(--s8);
  border-radius: var(--r-full);
  font-size: 10px;
  font-weight: 600;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.card-body {
  padding: var(--s12);
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: var(--s4);
}

.card-meta {
  display: flex;
  align-items: center;
  gap: var(--s4);
}

.type-dot {
  width: 7px;
  height: 7px;
  border-radius: var(--r-full);
  flex-shrink: 0;
}

.card-type-label {
  font-size: 11px;
  color: var(--text-3);
  font-weight: 500;
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--s32) var(--s24);
  text-align: center;
  min-height: 40vh;
}

.empty-icon { font-size: 48px; margin-bottom: var(--s16); }
.empty-title { font-size: 17px; font-weight: 600; color: var(--text); margin-bottom: var(--s8); }
.empty-desc { font-size: 14px; color: var(--text-2); max-width: 260px; }

.load-more-btn {
  display: block;
  width: 100%;
  padding: var(--s12) var(--s16);
  background: var(--bg-2);
  color: var(--text-2);
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.load-more-btn:hover { background: var(--bg-3); color: var(--text); }
.load-more-btn:disabled { opacity: 0.5; cursor: default; }

/* Skeleton loader */
.skeleton {
  background: linear-gradient(90deg, var(--bg-2) 25%, var(--bg-3) 50%, var(--bg-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--r-sm);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-card {
  background: var(--card);
  border-radius: var(--r-lg);
  overflow: hidden;
  border: 1px solid var(--border);
}

.skeleton-img {
  aspect-ratio: 2/3;
  width: 100%;
}

.skeleton-body { padding: var(--s12); display: flex; flex-direction: column; gap: var(--s8); }
.skeleton-title { height: 13px; width: 80%; }
.skeleton-sub { height: 11px; width: 50%; }

/* ============================================================
   Collections View
   ============================================================ */
.collections-grid {
  padding: var(--s16);
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--s12);
}

.collection-card {
  background: var(--card);
  border-radius: var(--r-lg);
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.15s;
}

.collection-card:active { transform: scale(0.97); }

.collection-covers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  aspect-ratio: 1;
  background: var(--bg-2);
  overflow: hidden;
}

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

.collection-cover-placeholder {
  background: var(--bg-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.collection-body {
  padding: var(--s12);
}

.collection-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.collection-count {
  font-size: 12px;
  color: var(--text-3);
  margin-top: var(--s4);
}

/* ============================================================
   Profile View
   ============================================================ */
.profile-view {
  padding: var(--s16);
  display: flex;
  flex-direction: column;
  gap: var(--s24);
}

.profile-card {
  background: var(--card);
  border-radius: var(--r-lg);
  padding: var(--s20);
  display: flex;
  align-items: center;
  gap: var(--s16);
  border: 1px solid var(--border);
}

.profile-avatar {
  width: 56px;
  height: 56px;
  border-radius: var(--r-full);
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  flex-shrink: 0;
}

.profile-name { font-size: 17px; font-weight: 700; color: var(--text); }
.profile-email { font-size: 13px; color: var(--text-2); margin-top: 2px; }

.usage-bar-wrap {
  background: var(--card);
  border-radius: var(--r-lg);
  padding: var(--s20);
  border: 1px solid var(--border);
}

.usage-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-2);
}

.usage-label + .usage-track { margin-top: var(--s8); }

.usage-label strong { color: var(--text); }

.usage-track {
  height: 6px;
  background: var(--bg-2);
  border-radius: var(--r-full);
  overflow: hidden;
}

.usage-fill {
  height: 100%;
  background: var(--accent);
  border-radius: var(--r-full);
  transition: width 0.6s ease;
}

.usage-fill.near { background: var(--s-in-progress); }
.usage-fill.full { background: var(--danger); }

/* Upgrade CTA */
.upgrade-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--accent);
  border-radius: var(--r-lg);
  padding: var(--s20);
  gap: var(--s16);
}

.upgrade-card-title {
  font-size: 15px;
  font-weight: 600;
  color: #FFFFFF;
}

.upgrade-card-sub {
  font-size: 13px;
  color: rgba(255,255,255,0.72);
  margin-top: 2px;
}

.btn-upgrade {
  flex-shrink: 0;
  background: #FFFFFF;
  color: var(--accent);
  border: none;
  border-radius: var(--r-full);
  padding: var(--s8) var(--s16);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: opacity 0.15s;
}

.btn-upgrade:disabled { opacity: 0.6; cursor: default; }

.settings-group {
  background: var(--card);
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  overflow: hidden;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s16) var(--s20);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}

.settings-row:last-child { border-bottom: none; }
.settings-row:active { background: var(--bg-2); }
.settings-row-label { font-size: 15px; color: var(--text); }
.settings-row-value { font-size: 15px; color: var(--text-2); }
.settings-row-danger .settings-row-label { color: var(--danger); }

/* Theme toggle */
.theme-toggle {
  display: flex;
  gap: var(--s8);
}

.theme-btn {
  flex: 1;
  padding: var(--s8);
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
  border: 1.5px solid transparent;
}

/* Light button — always looks like light mode */
.theme-btn[data-theme="light"] {
  background: #F5F5F7;
  color: #1D1D1F;
}

/* Dark button — always looks like dark mode */
.theme-btn[data-theme="dark"] {
  background: #1C1C1E;
  color: #F2F2F7;
}

/* Active state: accent border to show selection */
.theme-btn.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

/* ============================================================
   Bottom Nav (mobile)
   ============================================================ */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  background: rgba(242,242,247,0.85);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-around;
  padding-top: calc((var(--nav-h) - 48px) / 2);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 50;
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: var(--s4) var(--s16);
  color: var(--text-3);
  transition: color 0.15s;
  cursor: pointer;
}

.nav-btn.active { color: var(--accent); }
.nav-btn svg { width: 24px; height: 24px; }
.nav-btn span { font-size: 10px; font-weight: 500; }

/* ============================================================
   FAB
   ============================================================ */
.fab {
  position: fixed;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + var(--s16));
  right: var(--s24);
  width: var(--fab-size);
  height: var(--fab-size);
  border-radius: var(--r-full);
  background: var(--accent);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(79,70,229,0.4);
  z-index: 40;
  transition: transform 0.2s, box-shadow 0.2s;
  padding-bottom: 1px;
}

.fab:active {
  transform: scale(0.92);
  box-shadow: 0 2px 10px rgba(79,70,229,0.3);
}

.fab.open { transform: rotate(45deg); }

/* ============================================================
   Overlay
   ============================================================ */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 60;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: fadeIn 0.2s ease;
}

.overlay.active { display: block; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ============================================================
   Sheet (slide-up panel)
   ============================================================ */
.sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  z-index: 70;
  max-height: 92vh; max-height: 92dvh;
  overflow: hidden;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32,0.72,0,1);
}

.sheet-scroll {
  overflow-y: auto;
  overscroll-behavior: contain;
  max-height: inherit;
  padding-bottom: env(safe-area-inset-bottom);
  scrollbar-width: thin;
  scrollbar-color: var(--bg-3) transparent;
}

.sheet-scroll::-webkit-scrollbar {
  width: 6px;
}
.sheet-scroll::-webkit-scrollbar-track {
  background: transparent;
}
.sheet-scroll::-webkit-scrollbar-thumb {
  background: var(--bg-3);
  border-radius: var(--r-full);
  border: 2px solid transparent;
  background-clip: padding-box;
}

.sheet.open { transform: translateY(0); }

/* Detail sheet renders above other sheets (e.g. collection sheet) */
#sheet-detail { z-index: 80; }

/* Collection sheet has fixed height on desktop so it doesn't collapse when switching grid/list */
@media (min-width: 768px) {
  #sheet-collection {
    height: 75vh;
    height: 75dvh;
  }
}
#sheet-pick-collection { z-index: 90; min-height: 50vh; }
#pick-collection-list { padding: var(--s8) var(--s16) var(--s16); }

/* Collection detail toolbar */
.coll-toolbar {
  display: flex;
  align-items: center;
  gap: var(--s8);
  padding: 0 var(--s16) var(--s16);
}

.coll-search-input {
  flex: 1;
  padding: 10px var(--s12);
  background: var(--bg-2);
  border-radius: var(--r);
  font-size: 15px;
  color: var(--text);
  border: 1.5px solid transparent;
  transition: border-color 0.2s;
}
.coll-search-input::placeholder { color: var(--text-3); }
.coll-search-input:focus { border-color: var(--accent); background: var(--bg); }

.coll-view-toggle {
  display: flex;
  background: var(--bg-2);
  border-radius: var(--r-sm);
  padding: 3px;
  gap: 2px;
  flex-shrink: 0;
}

.coll-view-btn {
  width: 34px;
  height: 34px;
  border-radius: calc(var(--r-sm) - 3px);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  transition: all 0.15s;
}

.coll-view-btn.active {
  background: var(--card);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

/* Collection list view */
.coll-list {
  display: flex;
  flex-direction: column;
  gap: var(--s12);
  margin: 0 var(--s16) var(--s16);
  padding: var(--s8);
  background: var(--bg-2);
  border-radius: var(--r);
}

.card-list-body {
  display: flex;
  align-items: center;
  gap: var(--s12);
  padding: var(--s12) var(--s16);
}

.card-list-icon {
  font-size: 26px;
  flex-shrink: 0;
  width: 36px;
  text-align: center;
}

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

.card-list-status {
  padding: 3px var(--s8);
  border-radius: var(--r-full);
  font-size: 10px;
  font-weight: 600;
  flex-shrink: 0;
}

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--bg-3);
  border-radius: var(--r-full);
  margin: var(--s12) auto var(--s4);
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s16) var(--s20) var(--s12);
}

.sheet-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.sheet-close {
  width: 36px;
  height: 36px;
  border-radius: var(--r-full);
  background: var(--bg-3);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
  transition: background 0.1s;
}

.sheet-close:active { background: var(--bg-3); opacity: 0.7; }

/* ============================================================
   Add Item Sheet
   ============================================================ */
.step { display: none; }
.step.active { display: block; }

/* ============================================================
   Mobile sheet — stable height + internal scroll
   ============================================================ */
@media (max-width: 767px) {
  /* No scrollbars anywhere on mobile — mimic native app behaviour */
  * {
    scrollbar-width: none;
  }
  *::-webkit-scrollbar {
    display: none;
  }

  /* Add sheet only expands to 90vh when search step is active */
  #sheet-add.is-search {
    height: 90vh;
    max-height: 90vh;
  }

  /* Flex layout only needed when in search mode */
  #sheet-add.is-search .sheet-scroll {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow-y: hidden;
  }

  /* Search step fills remaining space after handle + header */
  #step-search.active {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
  }

  /* Search wrap fills the step */
  #sheet-add .search-wrap {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    padding-bottom: 0;
  }

  /* Results scroll within the container — search input stays pinned above */
  #sheet-add .search-results {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
  }

  /* Any sheet with an active input expands to 90vh — prevents background shift when keyboard appears */
  .sheet.keyboard-open {
    height: 90vh;
    max-height: 90vh;
  }

  /* Collection sheet always 90vh on mobile — has sticky toolbar + scrollable items */
  #sheet-collection {
    height: 90vh;
    max-height: 90vh;
  }

  #sheet-collection .sheet-scroll {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow-y: hidden;
  }

  /* Collection items scroll within the sheet, toolbar stays pinned */
  #coll-items-container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
  }
}

.type-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--s12);
  padding: 0 var(--s20) var(--s24);
}

.type-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s8);
  padding: var(--s12) var(--s4);
  border-radius: var(--r);
  transition: all 0.15s;
  cursor: pointer;
}

.type-btn:active { transform: scale(0.92); }

.type-icon {
  width: 58px;
  height: 58px;
  border-radius: var(--r);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  border: 1px solid var(--border);
}

.type-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  text-align: center;
  line-height: 1.2;
}

/* Search step */
.search-wrap {
  padding: 0 var(--s20) var(--s16);
}

.search-input-wrap {
  display: flex;
  align-items: center;
  background: var(--bg-2);
  border-radius: var(--r);
  padding: var(--s12) var(--s16);
  gap: var(--s8);
  border: 1.5px solid transparent;
  transition: border-color 0.2s;
  margin-bottom: var(--s16);
}

.search-input-wrap:focus-within { border-color: var(--accent); background: var(--bg); }

.search-input-wrap svg { color: var(--text-3); flex-shrink: 0; width: 18px; height: 18px; }

.search-input {
  flex: 1;
  font-size: 15px;
  color: var(--text);
}

.search-input::placeholder { color: var(--text-3); }

.search-results { display: flex; flex-direction: column; }

.search-result {
  display: flex;
  align-items: center;
  gap: var(--s12);
  padding: var(--s12) var(--s16);
  cursor: pointer;
  transition: background 0.1s;
  border-radius: var(--r);
  margin-bottom: var(--s4);
}

.search-result:active { background: var(--bg-2); }

.result-thumb {
  width: 44px;
  height: 60px;
  border-radius: var(--r-sm);
  background: var(--bg-2);
  overflow: hidden;
  flex-shrink: 0;
  object-fit: cover;
}

.result-thumb img { width: 100%; height: 100%; object-fit: cover; }
.result-thumb-placeholder { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-size: 20px; }

.result-info { flex: 1; overflow: hidden; }
.result-title { font-size: 14px; font-weight: 600; color: var(--text); line-height: 1.3; }
.result-sub { font-size: 12px; color: var(--text-2); margin-top: 2px; }

.search-loading {
  display: flex;
  justify-content: center;
  padding: var(--s32);
  color: var(--text-3);
  font-size: 14px;
}

/* Confirm step */
.confirm-wrap { padding: 0 var(--s20) var(--s24); }

.confirm-preview {
  display: flex;
  gap: var(--s16);
  align-items: flex-start;
  margin-bottom: var(--s24);
  padding: var(--s16);
  background: var(--bg-2);
  border-radius: var(--r);
}

.confirm-thumb {
  width: 60px;
  height: 84px;
  border-radius: var(--r-sm);
  background: var(--bg-3);
  overflow: hidden;
  flex-shrink: 0;
}

.confirm-info { flex: 1; }
.confirm-title { font-size: 16px; font-weight: 700; color: var(--text); line-height: 1.3; }
.confirm-sub { font-size: 13px; color: var(--text-2); margin-top: var(--s4); }

.status-label { font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: var(--s8); }

.status-pills {
  display: flex;
  gap: var(--s8);
  flex-wrap: wrap;
  margin-bottom: var(--s20);
}

.status-pill {
  padding: 6px var(--s12);
  border-radius: var(--r-full);
  font-size: 13px;
  font-weight: 500;
  border: 1.5px solid var(--border);
  color: var(--text-2);
  transition: all 0.15s;
}

.status-pill.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.notes-input {
  width: 100%;
  padding: var(--s12) var(--s16);
  background: var(--bg-2);
  border-radius: var(--r);
  font-size: 14px;
  color: var(--text);
  resize: none;
  min-height: 80px;
  border: 1.5px solid transparent;
  transition: border-color 0.2s;
  margin-bottom: var(--s20);
}

.notes-input::placeholder { color: var(--text-3); }
.notes-input:focus { border-color: var(--accent); background: var(--bg); }

/* ============================================================
   Item Detail Sheet
   ============================================================ */
.detail-hero {
  width: 100%;
  aspect-ratio: 16/9;
  background: var(--bg-2);
  overflow: hidden;
  position: relative;
}

.detail-hero img { width: 100%; height: 100%; object-fit: contain; }
.detail-hero-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 64px;
}

.detail-body { padding: var(--s20); }

.detail-type-row {
  display: flex;
  align-items: center;
  gap: var(--s8);
  margin-bottom: var(--s8);
}

.detail-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text);
  line-height: 1.2;
  margin-bottom: var(--s4);
}

.detail-sub {
  font-size: 15px;
  color: var(--text-2);
  margin-bottom: var(--s20);
}

.detail-status-row {
  display: flex;
  gap: var(--s8);
  margin-bottom: var(--s24);
  overflow-x: auto;
  padding-bottom: var(--s4);
}

.detail-status-row::-webkit-scrollbar { display: none; }

.detail-section-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-3);
  margin-bottom: var(--s8);
}

.detail-notes {
  font-size: 15px;
  color: var(--text);
  line-height: 1.6;
  width: 100%;
  min-height: 60px;
  resize: none;
  background: var(--bg-2);
  border-radius: var(--r);
  padding: var(--s12) var(--s16);
  border: 1.5px solid transparent;
  margin-bottom: var(--s24);
  transition: border-color 0.2s;
}

.detail-notes:focus { border-color: var(--accent); background: var(--bg); }
.detail-notes::placeholder { color: var(--text-3); }

.detail-metadata {
  background: var(--bg-2);
  border-radius: var(--r);
  overflow: hidden;
  margin-bottom: var(--s24);
}

.metadata-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--s12) var(--s16);
  border-bottom: 1px solid var(--border);
}

.metadata-row:last-child { border-bottom: none; }
.metadata-key { font-size: 13px; color: var(--text-2); }
.metadata-val { font-size: 13px; font-weight: 500; color: var(--text); }

.detail-link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s8);
  padding: 12px;
  background: var(--bg-2);
  border-radius: var(--r);
  font-size: 15px;
  font-weight: 500;
  color: var(--accent);
  margin-bottom: var(--s12);
  transition: background 0.1s;
}

.detail-link:active { background: var(--bg-3); }

.btn-action {
  width: 100%;
  padding: 12px;
  background: var(--bg-2);
  color: var(--text);
  border-radius: var(--r);
  font-size: 15px;
  font-weight: 500;
  transition: background 0.1s;
}

.btn-action:active { background: var(--bg-3); }

.btn-danger {
  width: 100%;
  padding: 12px;
  background: var(--bg-2);
  color: var(--danger);
  border-radius: var(--r);
  font-size: 15px;
  font-weight: 500;
  transition: background 0.1s;
}

.btn-danger:active { background: var(--bg-3); }

/* ============================================================
   Status badge colours
   ============================================================ */
.s-wishlist    { background: rgba(174,174,178,0.15); color: #8E8E93; }
.s-in_progress { background: rgba(255,159,10,0.15);  color: #FF9F0A; }
.s-on_hold     { background: rgba(90,200,250,0.15);  color: #5AC8FA; }
.s-dropped     { background: rgba(255,55,95,0.15);   color: #FF375F; }
.s-done        { background: rgba(48,209,88,0.15);   color: #30D158; }

/* ============================================================
   Toast
   ============================================================ */
/* Loading overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.loading-overlay.hidden { display: none; }

.loading-box {
  background: rgba(255,255,255,0.88);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-radius: 18px;
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}

[data-theme="dark"] .loading-box {
  background: rgba(44,44,46,0.88);
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid rgba(0,0,0,0.12);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}

[data-theme="dark"] .loading-spinner {
  border-color: rgba(255,255,255,0.12);
  border-top-color: var(--accent);
}

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

#toast-container {
  position: fixed;
  top: var(--s16);
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: var(--s8);
  pointer-events: none;
}

.toast {
  background: var(--text);
  color: var(--bg);
  padding: var(--s12) var(--s20);
  border-radius: var(--r-full);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  animation: toastIn 0.25s ease, toastOut 0.25s ease 2.5s forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes toastOut {
  from { opacity: 1; }
  to   { opacity: 0; }
}

/* ============================================================
   Desktop (≥768px)
   ============================================================ */
@media (min-width: 768px) {
  .sidebar { display: flex; }
  .bottom-nav { display: none; }
  .fab { bottom: var(--s32); right: var(--s32); }

  .main-content {
    margin-left: var(--sidebar-w);
    padding-bottom: var(--s32);
  }

  .cards-grid,
  .collections-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .sheet {
    bottom: auto;
    top: 50%;
    left: 50%;
    right: auto;
    transform: translate(-50%, -40%);
    width: 560px;
    max-height: 85vh; max-height: 85dvh;
    border-radius: var(--r-lg);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
  }

  .sheet.open {
    transform: translate(-50%, -50%);
    opacity: 1;
    pointer-events: auto;
  }

  .sheet-handle { display: none; }

  /* Inner scroll container must fill the fixed-height sheet on desktop */
  .sheet-scroll {
    max-height: inherit;
    height: 100%;
    scrollbar-gutter: stable; /* desktop only — mobile scrollbars are overlay */
  }

  /* Sheet grids stay at 3 cols inside the fixed-width modal */
  .sheet .cards-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 1200px) {
  .cards-grid,
  .collections-grid { grid-template-columns: repeat(auto-fill, minmax(170px, 170px)); }

  /* Sheet grid stays 2-col regardless of screen width */
  .sheet .cards-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ============================================================
   View header row (title + action button)
   ============================================================ */
.view-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: var(--s12);
}

.view-header-row .view-title { padding-bottom: 0; }

.btn-header-action {
  padding: 9px var(--s16);
  background: var(--accent);
  color: #fff;
  border-radius: var(--r-full);
  font-size: 15px;
  font-weight: 600;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

.btn-header-action:active { opacity: 0.8; }

/* ============================================================
   Sheet back button
   ============================================================ */
.sheet-back {
  width: 28px;
  height: 28px;
  border-radius: var(--r-full);
  background: var(--bg-2);
  color: var(--text-2);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s;
  flex-shrink: 0;
}

.sheet-back:active { background: var(--bg-3); }

/* ============================================================
   Detail hero close button
   ============================================================ */
.detail-close-btn {
  position: absolute;
  top: var(--s12);
  right: var(--s12);
  background: rgba(0,0,0,0.45) !important;
  color: #fff !important;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

/* ============================================================
   Collection cover — single letter tile
   ============================================================ */
.collection-cover-single {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  font-weight: 800;
  color: rgba(255,255,255,0.9);
  letter-spacing: -1px;
}

/* ============================================================
   Confirm thumb placeholder
   ============================================================ */
.confirm-thumb-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  background: var(--bg-3);
}

/* ============================================================
   New collection input
   ============================================================ */
.new-coll-input {
  width: 100%;
  padding: 14px var(--s16);
  background: var(--bg-2);
  border-radius: var(--r);
  font-size: 15px;
  color: var(--text);
  border: 1.5px solid transparent;
  transition: border-color 0.2s;
  font-family: inherit;
  margin-bottom: var(--s12);
}

.new-coll-input::placeholder { color: var(--text-3); }
.new-coll-input:focus { border-color: var(--accent); background: var(--bg); outline: none; }

/* ============================================================
   Utilities
   ============================================================ */
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* ============================================================
   iOS: prevent auto-zoom on input focus (requires font-size ≥ 16px)
   ============================================================ */
@supports (-webkit-touch-callout: none) {
  input, textarea, select {
    font-size: 16px !important;
  }
}
