/* TechAdvisor Mini App — Apple/iOS "Liquid Glass" inspired dark UI.
   Design language ported by hand from open-glass-ui (github.com/moekoelueker/
   open-glass-ui, MIT) — same technique already used in Moneyflow
   (family-budget-webapp/static/css/style.css): backdrop-filter blur +
   translucent tinted surface + hairline border + soft shadow, three "frost"
   tiers (clear/regular/frosted). We did NOT install the npm package (it's a
   React component library, this stack is vanilla JS + FastAPI) — only the
   CSS technique and tier naming were reused. Unlike Moneyflow's navy-blue
   fintech palette, this product explicitly targets an Apple/iOS visual
   register (true-black background, iOS system accent colours, large
   rounded corners, big confident type) — see project memory for the
   Artem's own framing ("особенно оценят пользователи техники Apple"). */

:root {
  --primary: #0A84FF;       /* iOS system blue */
  --primary-light: #409CFF;
  --accent: #30D158;        /* iOS system green — confirmed price / compatible */
  --destructive: #FF453A;   /* iOS system red — unconfirmed / incompatible */
  --warning: #FF9F0A;       /* iOS system orange */
  --yellow: #FFD60A;

  --bg: #000000;
  --fg: #FFFFFF;
  --card: #1C1C1E;          /* iOS "systemGray6" dark, used as glass tint base */
  --card-fg: #FFFFFF;
  --muted-fg: #98989D;      /* iOS "systemGray" dark */
  --border: rgba(255, 255, 255, 0.08);

  --radius: 20px;
  --radius-sm: 14px;

  /* Glass material tokens — same names/technique as Moneyflow's style.css,
     tint rebased onto this product's near-black card colour (#1C1C1E)
     instead of Moneyflow's navy (#192134). Alpha tiers kept identical
     (24/62/86%) so the "frost" naming means the same thing across the
     fleet. */
  --glass-blur-clear: 8px;
  --glass-blur-regular: 20px;
  --glass-blur-frosted: 32px;
  --glass-clear-bg: rgba(28, 28, 30, 0.30);
  --glass-regular-bg: rgba(28, 28, 30, 0.66);
  --glass-frosted-bg: rgba(18, 18, 20, 0.88);
  --glass-border: rgba(255, 255, 255, 0.14);
  --glass-shadow: 0 10px 32px -16px rgba(0, 0, 0, 0.75);
  --glass-sheen: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Inter', sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}

/* Fixed decorative backdrop, colourful blurred "blobs" reminiscent of iOS
   Control Center / Liquid Glass — purely visual, non-interactive, doesn't
   affect layout. Without this the glass cards below would have nothing
   colourful to actually blur against a flat black background. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(55% 38% at 12% 6%, rgba(10, 132, 255, 0.32), transparent 70%),
    radial-gradient(48% 34% at 92% 14%, rgba(191, 90, 242, 0.24), transparent 70%),
    radial-gradient(50% 32% at 50% 100%, rgba(48, 209, 88, 0.16), transparent 70%);
}

#app {
  min-height: 100vh;
  padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px));
}

.page { display: none; }
.page.active { display: block; }

/* ── Header ─────────────────────────────────────────── */

.header {
  padding: calc(18px + env(safe-area-inset-top, 0px)) 20px 16px;
}

.header-top { display: flex; align-items: center; justify-content: space-between; }

.brand { display: flex; align-items: center; gap: 9px; }
.brand-icon { font-size: 26px; }
.brand-name { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }

.header-sub { margin-top: 6px; font-size: 14px; color: var(--muted-fg); line-height: 1.4; }

/* ── Content ────────────────────────────────────────── */

.content { padding: 4px 16px 24px; display: flex; flex-direction: column; gap: 14px; }

.loading { display: flex; justify-content: center; padding: 60px 0; }
.spinner {
  width: 30px; height: 30px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Glass surfaces (three frost tiers) ────────────────── */

.glass-card {
  border-radius: var(--radius);
  padding: 16px;
  position: relative;
  overflow: hidden;
}

.tier-clear {
  background: var(--glass-clear-bg);
  backdrop-filter: blur(var(--glass-blur-clear));
  -webkit-backdrop-filter: blur(var(--glass-blur-clear));
  border: 1px solid var(--glass-border);
}

.tier-regular {
  background: var(--glass-regular-bg);
  backdrop-filter: blur(var(--glass-blur-regular)) saturate(160%);
  -webkit-backdrop-filter: blur(var(--glass-blur-regular)) saturate(160%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow), var(--glass-sheen);
}

.tier-frosted {
  background: var(--glass-frosted-bg);
  backdrop-filter: blur(var(--glass-blur-frosted)) saturate(160%);
  -webkit-backdrop-filter: blur(var(--glass-blur-frosted)) saturate(160%);
  border: 1px solid var(--glass-border);
}

/* ── Form fields ────────────────────────────────────── */

.field-block { margin-bottom: 18px; }
.field-block:last-of-type { margin-bottom: 0; }

.field-row-between { display: flex; align-items: center; justify-content: space-between; }

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted-fg);
  margin: 0 0 8px;
}

.budget-value { font-size: 20px; font-weight: 800; color: var(--primary-light); letter-spacing: -0.02em; }

.range-input {
  width: 100%;
  accent-color: var(--primary);
  margin: 6px 0 8px;
}

.field-input {
  width: 100%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--fg);
  font-size: 15px;
  font-family: inherit;
  padding: 12px 14px;
  outline: none;
}
.field-input:focus { border-color: var(--primary); }
textarea.field-input { resize: vertical; min-height: 64px; }
.compact-input { max-width: 160px; }

.field-error { color: var(--destructive); font-size: 13px; margin-top: 10px; min-height: 0; }

/* ── Chip / segmented buttons (purpose, resolution, upgrade, quick-start) ── */

.chip-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.chip-grid.three-col { grid-template-columns: 1fr 1fr 1fr; }
.chip-grid.two-col { grid-template-columns: 1fr 1fr; }

.chip-btn {
  padding: 12px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--fg);
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.chip-btn.selected { border-color: var(--primary); background: rgba(10, 132, 255, 0.22); color: #fff; }

.chip-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  -ms-overflow-style: none;
  scrollbar-width: none;
}
.chip-scroll::-webkit-scrollbar { display: none; }
.quick-chip { white-space: nowrap; flex-shrink: 0; }

.submit-btn {
  width: 100%;
  margin-top: 4px;
  padding: 15px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}
.submit-btn:disabled { opacity: 0.5; cursor: default; }
.secondary-btn { background: rgba(255, 255, 255, 0.08); }

/* ── Build: loading / result ────────────────────────── */

.build-loading, .support-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 36px 20px;
  text-align: center;
}
.build-loading-text { font-size: 14px; color: var(--muted-fg); line-height: 1.5; }

.component-card { margin-bottom: 10px; display: flex; gap: 12px; align-items: flex-start; }
.component-card:last-child { margin-bottom: 0; }
.component-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.component-body { flex: 1; min-width: 0; }
.component-label { font-size: 11px; color: var(--muted-fg); text-transform: uppercase; letter-spacing: 0.03em; font-weight: 700; }
.component-model { font-size: 14.5px; font-weight: 600; margin-top: 2px; line-height: 1.35; }
.component-price-row { margin-top: 6px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.price-badge {
  font-size: 13px;
  font-weight: 800;
  color: var(--accent);
}
.shop-badge {
  font-size: 11px;
  color: var(--muted-fg);
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 7px;
  border-radius: 999px;
}
.component-link {
  font-size: 12px;
  color: var(--primary-light);
  text-decoration: none;
}
.unconfirmed-badge {
  font-size: 11px;
  font-weight: 700;
  color: var(--destructive);
  background: rgba(255, 69, 58, 0.14);
  padding: 3px 8px;
  border-radius: 999px;
}
.component-image {
  width: 100%;
  max-width: 220px;
  border-radius: 12px;
  margin-top: 8px;
  display: block;
}

.build-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 0;
  border-top: 1px solid var(--border);
  font-size: 14px;
}
.build-summary-row:first-child { border-top: none; }
.summary-total { font-size: 19px; font-weight: 800; }
.summary-total.over { color: var(--destructive); }

.status-line {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  line-height: 1.45;
  padding: 8px 0;
}
.status-line.ok { color: var(--accent); }
.status-line.warn { color: var(--warning); }
.status-line.error { color: var(--destructive); }

.build-list { font-size: 13px; color: var(--muted-fg); line-height: 1.6; margin: 4px 0 0; padding-left: 18px; }

.build-note-box {
  margin-top: 10px;
  background: var(--glass-clear-bg);
  border: 1px dashed var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 12.5px;
  color: var(--muted-fg);
  line-height: 1.5;
}

/* ── Support: dropzone + answer ─────────────────────── */

.dropzone {
  border: 1px dashed var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 18px;
  text-align: center;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.03);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.dropzone.drag-over { border-color: var(--primary); background: rgba(10, 132, 255, 0.1); }
.dropzone-hint { font-size: 13px; color: var(--muted-fg); }
.dropzone-preview { max-width: 100%; max-height: 180px; border-radius: 10px; display: block; margin: 0 auto; }
.dropzone-remove {
  margin-top: 10px;
  background: rgba(255, 69, 58, 0.14);
  color: var(--destructive);
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}

.answer-card { white-space: normal; }
.answer-body { font-size: 14.5px; line-height: 1.55; }
.answer-body b, .answer-body strong { font-weight: 700; }
.answer-body a { color: var(--primary-light); }
.answer-body code { background: rgba(255, 255, 255, 0.08); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.answer-body pre { background: rgba(255, 255, 255, 0.06); padding: 10px; border-radius: 10px; overflow-x: auto; font-size: 13px; }

/* ── Profile page ───────────────────────────────────── */

.profile-empty-text { font-size: 14px; color: var(--muted-fg); line-height: 1.55; text-align: center; padding: 8px 4px; }

.profile-list { display: flex; flex-direction: column; }
.profile-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  border-top: 1px solid var(--border);
  font-size: 14px;
}
.profile-row:first-child { border-top: none; }
.profile-row-label { color: var(--muted-fg); flex-shrink: 0; }
.profile-row-value { font-weight: 600; text-align: right; }

/* ── Bottom nav (iOS tab bar) ───────────────────────── */

.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  border-radius: 0;
  padding: 10px 0 calc(8px + env(safe-area-inset-bottom, 0px));
  z-index: 20;
  border-left: none;
  border-right: none;
  border-bottom: none;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--muted-fg);
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  padding: 4px;
  cursor: pointer;
}
.nav-btn.active { color: var(--primary); }
.nav-icon { font-size: 21px; }

/* ── Modals ─────────────────────────────────────────── */

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 50;
  align-items: flex-end;
}
.overlay.open { display: flex; }

.modal {
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--glass-frosted-bg);
  backdrop-filter: blur(var(--glass-blur-frosted)) saturate(160%);
  -webkit-backdrop-filter: blur(var(--glass-blur-frosted)) saturate(160%);
  border: 1px solid var(--glass-border);
  border-bottom: none;
  border-radius: 24px 24px 0 0;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  animation: slide-up 0.22s ease-out;
}
@keyframes slide-up { from { transform: translateY(24px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 18px 10px;
  font-size: 16px;
  font-weight: 700;
}
.modal-close {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: var(--fg);
  width: 28px; height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 13px;
}
.modal-body { padding: 4px 18px 18px; display: flex; flex-direction: column; gap: 4px; }

.modal-banner {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  margin-bottom: 8px;
}
.modal-banner.info {
  background: rgba(10, 132, 255, 0.14);
  border: 1px solid rgba(10, 132, 255, 0.4);
  color: var(--primary-light);
}

/* ── Toast ──────────────────────────────────────────── */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 12px);
  background: rgba(28, 28, 30, 0.95);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  z-index: 100;
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── Accessibility fallbacks for the glass material ────────────────────
   Same policy as Moneyflow: don't assume the user wants translucency,
   don't assume they want motion. Both roll the UI back to a fully
   opaque/static look while keeping all content and layout intact. */

@media (prefers-reduced-transparency: reduce) {
  .tier-clear, .tier-regular, .tier-frosted, .bottom-nav, .modal {
    background: var(--card);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border-color: var(--border);
    box-shadow: none;
  }
  .build-note-box { background: rgba(255, 255, 255, 0.04); }
  body::before { display: none; }
}

@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;
  }
}
