:root {
  --brand-primary-light: #00345b;
  --brand-primary-dark: #4ea8de;
  --brand-accent-light: #0a7e6e;
  --brand-accent-dark: #2ec4b6;

  --bg-page-light: #f4f7f9;
  --bg-page-dark: #0f1419;
  --bg-surface-light: #ffffff;
  --bg-surface-dark: #19222b;
  --bg-elevated-light: #eef3f7;
  --bg-elevated-dark: #222e3a;

  --text-main-light: #111827;
  --text-main-dark: #f1f5f9;
  --text-muted-light: #52606d;
  --text-muted-dark: #94a3b8;

  --border-light: #dce3ea;
  --border-dark: #2b3947;

  --brand-primary: var(--brand-primary-light);
  --brand-accent: var(--brand-accent-light);
  --bg-page: var(--bg-page-light);
  --bg-surface: var(--bg-surface-light);
  --bg-elevated: var(--bg-elevated-light);
  --text-main: var(--text-main-light);
  --text-muted: var(--text-muted-light);
  --border-color: var(--border-light);

  color-scheme: light dark;
  accent-color: var(--brand-accent);
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand-primary: var(--brand-primary-dark);
    --brand-accent: var(--brand-accent-dark);
    --bg-page: var(--bg-page-dark);
    --bg-surface: var(--bg-surface-dark);
    --bg-elevated: var(--bg-elevated-dark);
    --text-main: var(--text-main-dark);
    --text-muted: var(--text-muted-dark);
    --border-color: var(--border-dark);
  }
}

@supports (color: light-dark(white, black)) {
  :root {
    --brand-primary: light-dark(var(--brand-primary-light), var(--brand-primary-dark));
    --brand-accent: light-dark(var(--brand-accent-light), var(--brand-accent-dark));
    --bg-page: light-dark(var(--bg-page-light), var(--bg-page-dark));
    --bg-surface: light-dark(var(--bg-surface-light), var(--bg-surface-dark));
    --bg-elevated: light-dark(var(--bg-elevated-light), var(--bg-elevated-dark));
    --text-main: light-dark(var(--text-main-light), var(--text-main-dark));
    --text-muted: light-dark(var(--text-muted-light), var(--text-muted-dark));
    --border-color: light-dark(var(--border-light), var(--border-dark));
  }
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  width: 100%;
  background-color: var(--bg-page);
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #00345b;
  color: #ffffff;
  padding: env(safe-area-inset-top, 0) 16px 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 60px;
  gap: 12px;
  max-width: 1120px;
  margin: 0 auto;
}

.desktop-nav {
  display: none;
}

.install-btn,
.lang-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 44px;
  min-height: 44px;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  cursor: pointer;
  padding: 6px 10px;
  font-size: 0.9rem;
  font-weight: 600;
}

.install-label {
  display: none;
}

.install-btn:hover,
.lang-btn:hover,
.portal-link:hover {
  background: rgba(255, 255, 255, 0.22);
}

.portal-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 44px;
  min-height: 44px;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.9);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 500;
}

.portal-label {
  display: none;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-logo {
  border-radius: 8px;
  flex-shrink: 0;
}

.brand-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.2;
}

.brand-subtitle {
  margin: 0;
  font-size: 0.78rem;
  opacity: 0.85;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn,
.lang-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  cursor: pointer;
  padding: 6px;
}

.icon-btn:hover,
.lang-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

/* Main */
.app-main {
  flex: 1;
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 14px 16px calc(84px + env(safe-area-inset-bottom, 0));
}

.catalog-heading {
  margin: 4px 0 12px;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-muted);
}

.app-shell.has-ad-banner .app-main {
  padding-bottom: calc(146px + env(safe-area-inset-bottom, 0));
}

/* Search */
.search-wrap {
  margin-bottom: 12px;
}

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

.search-icon {
  position: absolute;
  left: 14px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  min-height: 46px;
  padding: 10px 44px 10px 42px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background-color: var(--bg-surface);
  color: var(--text-main);
  font-size: 1rem;
}

.search-input:focus {
  outline: 2px solid var(--brand-accent);
  outline-offset: 1px;
}

.clear-search-btn {
  position: absolute;
  right: 4px;
  min-width: 40px;
  min-height: 40px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  border-radius: 8px;
}

.results-count {
  margin-top: 6px;
  padding-left: 4px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* List */
.items-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.list-section-header {
  padding: 10px 6px 4px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--brand-accent);
  text-transform: uppercase;
}

.list-item {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  overflow: hidden;
}

.list-item:nth-child(n+15) {
  content-visibility: auto;
  contain-intrinsic-size: auto 68px;
}

.list-item-btn {
  width: 100%;
  min-height: 56px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border: none;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.list-item-btn:hover {
  background-color: var(--bg-elevated);
}

.item-tube-wrap {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background-color: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.item-tube {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.item-text {
  flex: 1;
  min-width: 0;
}

.item-title {
  display: block;
  font-size: 0.98rem;
  font-weight: 600;
  line-height: 1.3;
  word-break: break-word;
}

.item-subtitle {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.item-star {
  color: #f59e0b;
  flex-shrink: 0;
}

.item-chevron {
  color: var(--text-muted);
  flex-shrink: 0;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
  font-size: 1rem;
}

/* Detail View */
.detail-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 8px;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 44px;
  padding: 8px 14px 8px 8px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background-color: var(--bg-surface);
  color: var(--text-main);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.detail-actions {
  display: flex;
  gap: 8px;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background-color: var(--bg-surface);
  color: var(--text-main);
  cursor: pointer;
}

.action-btn .star-icon {
  fill: none;
}

.action-btn[aria-pressed="true"] {
  border-color: #f59e0b;
  color: #f59e0b;
}

.action-btn[aria-pressed="true"] .star-icon {
  fill: #f59e0b;
}

.detail-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 18px 16px;
}

.detail-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--brand-accent);
  margin-bottom: 6px;
}

.detail-title {
  margin: 0 0 14px;
  font-size: 1.3rem;
  line-height: 1.25;
  color: var(--brand-primary);
}

.detail-body {
  font-size: 0.98rem;
  line-height: 1.6;
}

.detail-body ul {
  padding-left: 20px;
  margin: 10px 0;
}

.detail-body li {
  margin-bottom: 8px;
}

.detail-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
}

.detail-body th,
.detail-body td {
  border: 1px solid var(--border-color);
  padding: 8px 10px;
  text-align: left;
}

.alert-text {
  color: #dc2626;
  font-weight: 700;
}

/* Extra Menu */
.extra-section-title {
  margin: 16px 4px 8px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--brand-accent);
}

.extra-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* AdSense Banner (0px height & invisible unless filled by AdSense or local preview; keeps width > 0 so adsbygoogle never throws availableWidth=0) */
.ad-banner {
  position: fixed;
  bottom: calc(58px + env(safe-area-inset-bottom, 0));
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 860px;
  height: 0;
  max-height: 64px;
  overflow: hidden;
  visibility: hidden;
  pointer-events: none;
  z-index: 24;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: transparent;
  border-top: none;
  padding: 0;
}

.ad-banner:has(ins[data-ad-status="filled"]),
.ad-banner:has(.ad-placeholder) {
  height: auto;
  visibility: visible;
  pointer-events: auto;
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  padding: 4px 8px;
}

.ad-placeholder {
  width: 100%;
  max-width: 728px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--border-color);
  border-radius: 6px;
  background-color: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 0.78rem;
  text-align: center;
  padding: 0 8px;
}

@media (min-width: 768px) {
  .app-header {
    background-color: var(--bg-surface);
    color: var(--text-main);
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
    padding: 8px 24px 0;
  }

  .header-inner {
    min-height: 64px;
  }

  .brand-title {
    color: var(--brand-primary);
    font-size: 1.25rem;
  }

  .brand-subtitle {
    color: var(--text-muted);
    opacity: 1;
  }

  .install-btn,
  .lang-btn,
  .portal-link {
    background-color: var(--bg-surface);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    padding: 6px 14px;
  }

  .install-btn,
  .lang-btn {
    color: var(--text-main);
  }

  .install-label,
  .portal-label {
    display: inline;
  }

  .install-btn:hover,
  .lang-btn:hover,
  .portal-link:hover {
    background-color: var(--bg-elevated);
    color: var(--text-main);
  }

  .desktop-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 1120px;
    margin: 0 auto;
    padding: 4px 0 12px;
  }

  .desktop-tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 6px 16px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
  }

  .desktop-tab-btn:hover {
    background-color: var(--bg-elevated);
    color: var(--text-main);
  }

  .desktop-tab-btn.is-active {
    background-color: #00345b;
    color: #ffffff;
  }

  .tab-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 20px;
    padding: 0 7px;
    border-radius: 999px;
    background-color: var(--bg-elevated);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 700;
  }

  .desktop-tab-btn.is-active .tab-badge {
    background-color: rgba(255, 255, 255, 0.22);
    color: #ffffff;
  }

  .app-main {
    padding: 20px 24px 40px;
  }

  .items-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .list-section-header {
    grid-column: 1 / -1;
  }

  .extra-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .detail-toolbar,
  .detail-card {
    max-width: 820px;
    margin-left: auto;
    margin-right: auto;
  }

  .ad-banner {
    bottom: 0;
    max-width: 100%;
    max-height: 98px;
  }

  .ad-placeholder {
    height: 90px;
    font-size: 0.85rem;
  }

  .app-shell.has-ad-banner .app-main {
    padding-bottom: 120px;
  }
}

@media (min-width: 1024px) {
  .items-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* Remove Ads / Stripe Dialog */
.noads-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.noads-desc {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.5;
}

.btn-full {
  width: 100%;
}

.noads-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.noads-divider::before,
.noads-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background-color: var(--border-color);
}

.restore-form {
  display: flex;
  gap: 8px;
}

.email-input {
  flex: 1;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background-color: var(--bg-page);
  color: var(--text-main);
  font-size: 0.95rem;
}

/* Bottom Tab Bar */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 860px;
  z-index: 25;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.tab-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 58px;
  padding: 6px 4px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
}

.tab-btn.is-active {
  color: var(--brand-primary);
}

/* Dialogs */
dialog {
  width: min(92vw, 480px);
  max-height: 85dvh;
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 18px;
  background-color: var(--bg-surface);
  color: var(--text-main);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
}

dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  overflow: hidden;
  overscroll-behavior: contain;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.dialog-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.dialog-close-x {
  min-width: 44px;
  min-height: 44px;
  border: none;
  border-radius: 10px;
  background: var(--bg-elevated);
  color: var(--text-main);
  font-size: 1rem;
  cursor: pointer;
}

.lang-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lang-option-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background-color: var(--bg-elevated);
  color: var(--text-main);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.lang-option-btn.is-selected {
  border-color: var(--brand-accent);
  outline: 2px solid var(--brand-accent);
}

.notes-textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background-color: var(--bg-page);
  color: var(--text-main);
  font-family: inherit;
  font-size: 1rem;
  resize: vertical;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}

.btn-primary,
.btn-secondary {
  min-height: 44px;
  padding: 8px 18px;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
}

.btn-primary {
  background-color: #00345b;
  color: #ffffff;
}

.btn-secondary {
  background-color: var(--bg-elevated);
  color: var(--text-main);
  border-color: var(--border-color);
}

.policy-content {
  font-size: 0.92rem;
  line-height: 1.55;
  max-height: 55dvh;
  overflow-y: auto;
}

/* RGPD Consent Banner */
.consent-banner {
  position: fixed;
  bottom: 66px;
  left: 50%;
  transform: translateX(-50%);
  width: min(94vw, 820px);
  z-index: 30;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.consent-text {
  margin: 0;
  font-size: 0.85rem;
  flex: 1 1 260px;
}

.consent-actions {
  display: flex;
  gap: 8px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 76px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #111827;
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 40;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

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