/* ikompare -- premium dark comparison UI (uispec.md).
   A fixed dark theme by deliberate product design, not a light/dark
   toggle: the visual reference is a dark, premium international price
   comparison interface, adapted into a responsive product page. */

:root {
  color-scheme: dark;
  --background: #090d14;
  --sidebar: #0d131d;
  --panel: #121a26;
  --panel-hover: #172131;
  --border: #263244;
  --text: #f4f7fb;
  --muted: #94a3b8;
  --accent: #8b5cf6;
  --accent-secondary: #38bdf8;
  --success: #34d399;
  --success-bg: rgba(52, 211, 153, 0.12);
  --warning: #fbbf24;
  --warning-bg: rgba(251, 191, 36, 0.12);
  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, 0.12);

  /* Aliases so the pre-existing admin rules (written against the old
     token names) keep working unchanged against the new palette. */
  --fg: var(--text);
  --bg: var(--background);
  --surface: var(--panel);
  --accent-contrast: #0b0410;
}

* {
  box-sizing: border-box;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

html,
body {
  min-height: 100%;
}

body {
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: var(--background);
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

img {
  max-width: 100%;
}

a {
  color: var(--accent-secondary);
}

:focus-visible {
  outline: 2px solid var(--accent-secondary);
  outline-offset: 2px;
  border-radius: 4px;
}

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

/* ---------------------------------------------------------------------
   Header
   ------------------------------------------------------------------- */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  row-gap: 0.5rem;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: var(--sidebar);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

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

.wordmark,
.site-title {
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.01em;
}

.header-tagline {
  color: var(--muted);
  font-size: 0.8125rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 40rem) {
  .header-tagline {
    display: none;
  }
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  flex: 0 1 auto;
}

.verified-badge {
  font-size: 0.75rem;
  color: var(--success);
  background: var(--success-bg);
  border: 1px solid var(--success);
  border-radius: 999px;
  padding: 0.25rem 0.625rem;
  white-space: nowrap;
}

@media (max-width: 40rem) {
  .verified-badge {
    display: none;
  }
}

.menu-button {
  display: none;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

.has-js .menu-button {
  display: inline-flex;
}

@media (min-width: 61rem) {
  .has-js .menu-button {
    display: none;
  }
}

.currency-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.currency-select {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--panel);
  color: var(--text);
  font-size: 0.8125rem;
  width: 100%;
  max-width: 11rem;
  min-width: 0;
}

@media (max-width: 26rem) {
  .currency-select {
    max-width: 7.5rem;
  }
}

.currency-apply {
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--accent);
  border-radius: 0.5rem;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

/* ---------------------------------------------------------------------
   App shell: sidebar + main
   ------------------------------------------------------------------- */

.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  align-items: start;
  max-width: 90rem;
  margin: 0 auto;
}

@media (max-width: 60rem) {
  .app-shell {
    grid-template-columns: 1fr;
  }
}

.sidebar-backdrop {
  display: none;
}

.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  padding: 1.25rem 1rem;
  min-height: calc(100vh - 3.5rem);
}

.sidebar-head {
  display: none;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.sidebar-close {
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0.25rem;
}

.sidebar-section-label {
  display: block;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

.sidebar-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 0.75rem;
  border-radius: 0.625rem;
  border: 1px solid transparent;
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
}

.sidebar-item:hover {
  background: var(--panel-hover);
  color: var(--text);
}

.sidebar-item.is-active {
  background: var(--panel);
  border-color: var(--accent);
  color: var(--text);
  box-shadow: inset 3px 0 0 var(--accent);
}

.sidebar-item-icon {
  display: inline-flex;
  color: inherit;
}

.sidebar-muted {
  margin-top: 1rem;
  color: var(--muted);
  font-size: 0.75rem;
}

/* Mobile drawer: only takes effect once JavaScript has added .has-js to
   <html> (see layout.html) -- without JavaScript, the sidebar above
   simply stays in normal document flow, never an unopenable drawer. */
@media (max-width: 60rem) {
  .has-js .sidebar {
    position: fixed;
    inset: 0 25% 0 0;
    z-index: 40;
    min-height: 100vh;
    transform: translateX(-100%);
    transition: transform 180ms ease;
    box-shadow: 8px 0 24px rgba(0, 0, 0, 0.4);
  }

  .has-js .sidebar.is-open {
    transform: translateX(0);
  }

  .has-js .sidebar-head {
    display: flex;
  }

  .has-js .sidebar-backdrop:not([hidden]) {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(2, 4, 8, 0.6);
    z-index: 30;
  }
}

/* ---------------------------------------------------------------------
   Main area / hero
   ------------------------------------------------------------------- */

.main-area {
  padding: 1.5rem 1.25rem 3rem;
  min-width: 0;
}

.hero {
  max-width: 46rem;
  margin-bottom: 1.5rem;
}

.hero h1 {
  font-size: 1.75rem;
  margin: 0 0 0.5rem;
  letter-spacing: -0.01em;
}

.hero-sub {
  color: var(--muted);
  margin: 0;
}

.last-updated {
  color: var(--muted);
  font-size: 0.8125rem;
  margin: 0 0 1rem;
}

.htmx-indicator {
  opacity: 0;
  transition: opacity 120ms ease;
  color: var(--muted);
  font-size: 0.8125rem;
  margin-bottom: 0.5rem;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  opacity: 1;
}

/* ---------------------------------------------------------------------
   Model cards
   ------------------------------------------------------------------- */

.model-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: 0.875rem;
  margin-bottom: 1.75rem;
}

@media (max-width: 40rem) {
  .model-cards {
    display: flex;
    max-width: 100%;
    overflow-x: auto;
    padding-bottom: 0.25rem;
  }

  .model-card {
    flex: 0 0 10rem;
  }
}

.model-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.375rem;
  padding: 1.25rem 1rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
}

.model-card:hover {
  background: var(--panel-hover);
}

.model-card.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
  background: var(--panel-hover);
}

.model-card-image {
  width: 5rem;
  height: 5rem;
  object-fit: contain;
  aspect-ratio: 1 / 1;
}

.model-card-image-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 5rem;
  height: 5rem;
  border-radius: 0.75rem;
  background: var(--panel-hover);
  color: var(--muted);
}

.model-card-name {
  font-weight: 600;
}

.model-card-descriptor,
.model-card-storage {
  color: var(--muted);
  font-size: 0.8125rem;
}

/* ---------------------------------------------------------------------
   Storage selector
   ------------------------------------------------------------------- */

.storage-selector {
  border: none;
  margin: 0 0 1.5rem;
  padding: 0;
}

.storage-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.storage-option {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.625rem;
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}

.storage-option:hover {
  background: var(--panel-hover);
}

.storage-option.is-selected {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

/* ---------------------------------------------------------------------
   Country list
   ------------------------------------------------------------------- */

.country-list {
  list-style: none;
  margin: 0 0 1.75rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.country-row {
  border: 1px solid var(--border);
  border-radius: 0.875rem;
  background: var(--panel);
}

.country-row-unavailable {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.875rem 1.125rem;
  opacity: 0.75;
}

.country-summary {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1.125rem;
  cursor: pointer;
  list-style: none;
}

.country-summary::-webkit-details-marker {
  display: none;
}

.country-summary:hover {
  background: var(--panel-hover);
  border-radius: 0.875rem;
}

.country-rank {
  flex: 0 0 auto;
  width: 1.5rem;
  height: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--panel-hover);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
}

.country-flag {
  flex: 0 0 auto;
  display: inline-flex;
  border-radius: 0.25rem;
  overflow: hidden;
  border: 1px solid var(--border);
}

.flag-icon {
  display: block;
  width: 1.5rem;
  height: 1rem;
}

.country-heading {
  flex: 1 1 6rem;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.country-name {
  font-weight: 600;
}

.viewer-badge {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--accent-secondary);
  border: 1px solid var(--accent-secondary);
  border-radius: 999px;
  padding: 0.0625rem 0.5rem;
  margin-left: 0.375rem;
}

.country-price-line {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.country-price {
  font-weight: 700;
  font-size: 1.0625rem;
}

.country-approx,
.country-retailer-line {
  color: var(--muted);
  font-size: 0.8125rem;
}

.country-toggle {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.375rem;
  color: var(--muted);
  font-size: 0.8125rem;
  white-space: nowrap;
}

.chevron {
  transition: transform 160ms ease;
}

details[open] .chevron {
  transform: rotate(180deg);
}

@media (max-width: 30rem) {
  .country-toggle-text {
    display: none;
  }
}

.unavailable {
  color: var(--muted);
  margin: 0.125rem 0 0;
}

.conversion-disclaimer {
  color: var(--muted);
  font-size: 0.75rem;
  margin: -0.5rem 0 1.5rem;
}

/* ---------------------------------------------------------------------
   Offer list (inside an expanded country row)
   ------------------------------------------------------------------- */

.offer-list {
  list-style: none;
  margin: 0;
  padding: 0 1.125rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.offer {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 0.5rem 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.625rem;
  background: var(--background);
}

@media (max-width: 34rem) {
  .offer {
    grid-template-columns: 1fr;
  }
}

.offer.is-cheapest {
  border-color: var(--success);
}

.offer.is-out-of-stock {
  opacity: 0.65;
}

.offer-retailer {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  min-width: 0;
}

.retailer-logo {
  border-radius: 0.25rem;
  object-fit: contain;
  aspect-ratio: 1 / 1;
}

.retailer-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  font-size: 0.6875rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 0.125rem 0.5rem;
  white-space: nowrap;
}

.badge-success {
  color: var(--success);
  background: var(--success-bg);
}

.badge-warning {
  color: var(--warning);
  background: var(--warning-bg);
}

.offer-price {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.125rem;
}

.native-price {
  font-weight: 700;
  font-size: 1.0625rem;
}

.original-price {
  color: var(--muted);
  font-size: 0.75rem;
  text-decoration: line-through;
}

.discount-badge {
  color: var(--success);
  font-size: 0.75rem;
  font-weight: 600;
}

.approx-price {
  color: var(--muted);
  font-size: 0.75rem;
}

.offer-meta {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  color: var(--muted);
  font-size: 0.75rem;
}

.availability-IN_STOCK {
  color: var(--success);
}

.availability-OUT_OF_STOCK {
  color: var(--danger);
}

.availability-PREORDER {
  color: var(--warning);
}

.deal-button {
  grid-column: 3;
  justify-self: end;
  padding: 0.5rem 1rem;
  border: 1px solid var(--accent);
  border-radius: 0.5rem;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.deal-button:hover {
  filter: brightness(1.1);
}

.deal-button.is-disabled {
  grid-column: 3;
  border-color: var(--border);
  background: var(--panel-hover);
  color: var(--muted);
  cursor: not-allowed;
  pointer-events: none;
}

@media (max-width: 34rem) {
  .deal-button,
  .deal-button.is-disabled {
    grid-column: 1;
    justify-self: start;
  }
}

/* ---------------------------------------------------------------------
   Summary cards
   ------------------------------------------------------------------- */

.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.summary-card {
  padding: 1rem 1.125rem;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.summary-label {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.summary-value {
  font-weight: 700;
  font-size: 1.0625rem;
}

.summary-detail {
  color: var(--muted);
  font-size: 0.8125rem;
}

.summary-disclaimer {
  color: var(--muted);
  font-size: 0.75rem;
  margin: 0.5rem 0 1.5rem;
}

/* ---------------------------------------------------------------------
   Newsletter footer
   ------------------------------------------------------------------- */

.site-footer {
  max-width: 90rem;
  margin: 0 auto;
  padding: 0 1.25rem 2.5rem;
  color: var(--muted);
  font-size: 0.875rem;
}

.newsletter-form {
  margin-bottom: 1rem;
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: 0.875rem;
  background: var(--panel);
}

.newsletter-form label {
  display: block;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.newsletter-fields {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.newsletter-fields input[type="email"] {
  flex: 1 1 16rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--background);
  color: var(--text);
}

.newsletter-fields button {
  padding: 0.5rem 1rem;
  border: 1px solid var(--accent);
  border-radius: 0.5rem;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.newsletter-message {
  margin: 0.5rem 0 0;
}

.newsletter-success {
  color: var(--success);
}

.newsletter-error {
  color: var(--danger);
}

.newsletter-result {
  max-width: 32rem;
  padding: 1.5rem 1.25rem;
}

/* ---------------------------------------------------------------------
   Empty / error states, privacy page
   ------------------------------------------------------------------- */

.empty-state,
.error-state,
.privacy {
  max-width: 40rem;
  padding: 1.5rem 0;
  color: var(--muted);
}

.error-state h1,
.empty-state h1,
.privacy h1 {
  color: var(--text);
}

.error-state[role="alert"] {
  color: var(--text);
}

/* ---------------------------------------------------------------------
   Public users page
   ------------------------------------------------------------------- */

.users-page {
  max-width: 40rem;
  padding: 1.5rem 0 2rem;
}

.users-page h2 {
  margin-top: 2rem;
  font-size: 1.125rem;
}

.users-summary-table,
.users-country-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  overflow: hidden;
}

.users-summary-table th,
.users-summary-table td,
.users-country-table th,
.users-country-table td {
  padding: 0.625rem 1rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.users-summary-table tr:last-child th,
.users-summary-table tr:last-child td,
.users-country-table tr:last-child td {
  border-bottom: none;
}

.users-summary-table th {
  font-weight: 500;
  color: var(--muted);
}

.users-summary-table td,
.users-country-table td:last-child {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.users-country-table thead th {
  background: var(--panel);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ---------------------------------------------------------------------
   Admin (unchanged rules; now themed via the tokens/aliases above)
   ------------------------------------------------------------------- */

.admin-nav {
  display: flex;
  gap: 1rem;
}

.admin-nav a {
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.875rem;
}

.admin-nav a:hover {
  color: var(--fg);
}

.admin-product-thumb {
  border-radius: 0.375rem;
  object-fit: contain;
  background: var(--panel-hover);
  aspect-ratio: 1 / 1;
}

.admin-product-thumb-empty {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  color: var(--muted);
}

.admin-product-preview {
  display: block;
  margin: 0.75rem 0;
  border-radius: 0.5rem;
  object-fit: contain;
  background: var(--panel-hover);
  aspect-ratio: 1 / 1;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 72rem;
  margin: 0 auto;
  padding: 1rem;
}

.admin-logout-form {
  margin: 0;
}

.admin-logout-button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  padding: 0.375rem 0.75rem;
  color: var(--fg);
  cursor: pointer;
}

.admin-login,
.admin-offers,
.admin-offer-edit {
  max-width: 40rem;
  margin: 0 auto;
  padding: 0 1rem;
}

.admin-offers {
  max-width: 64rem;
}

.admin-form label,
.admin-filter-form label {
  display: block;
  font-weight: 600;
  margin: 1rem 0 0.25rem;
}

.admin-form input,
.admin-form select,
.admin-filter-form input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  background: var(--bg);
  color: var(--fg);
}

.admin-checkbox {
  display: flex !important;
  align-items: center;
  gap: 0.5rem;
  font-weight: 400 !important;
}

.admin-checkbox input {
  width: auto;
}

.admin-form button,
.admin-filter-form button {
  margin-top: 1rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--accent);
  border-radius: 0.375rem;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
  cursor: pointer;
}

.admin-filter-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: end;
  margin-bottom: 1.5rem;
}

.admin-filter-form > * {
  flex: 1 1 10rem;
}

.admin-error {
  color: var(--danger);
  font-weight: 600;
}

.admin-hint {
  color: var(--muted);
  font-size: 0.8125rem;
  margin: 0.25rem 0 0;
}

.admin-offers-table {
  width: 100%;
  border-collapse: collapse;
}

.admin-offers-table th,
.admin-offers-table td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.admin-row-disabled {
  opacity: 0.6;
}

.admin-inline-form {
  display: inline;
  margin-left: 0.5rem;
}

.admin-inline-form button {
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.25rem;
  background: none;
  color: var(--fg);
  cursor: pointer;
}

.admin-offer-context {
  color: var(--muted);
}
