:root {
  color-scheme: dark;
  --bg: #12181f;
  --card-bg: #1b232d;
  --border: #2a3542;
  --text: #e8edf2;
  --muted: #8b98a7;
  --accent: #4fc3f7;
  --green: #4caf82;
  --red: #e5626f;
  --input-bg: #0f151b;
}

/* Step 7.5 of the build plan (light/dark display theme) - the customer's
   choice is stored on their profile for the future firmware to read too,
   but applying it here as well gives the toggle a real, immediately-
   visible effect in the companion app itself, not just a stored value
   with no observable result until real hardware exists. */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f7fa;
  --card-bg: #ffffff;
  --border: #dde3ea;
  --text: #1b2530;
  --muted: #6b7684;
  --accent: #0288b8;
  --green: #2f8f5f;
  --red: #c73f4d;
  --input-bg: #f0f3f6;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
}

.screen { min-height: 100vh; }

#auth-screen:not([hidden]) {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: fixed;
  inset: 0;
  z-index: 300;
  background: var(--bg);
}

#landing-screen:not([hidden]) {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: var(--bg);
  overflow-y: auto;
}

.landing-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  max-width: 720px;
  margin: 0 auto;
}
.landing-brand { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.landing-login-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 18px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
}
.landing-login-btn:hover { filter: none; border-color: var(--accent); color: var(--accent); }


.passkey-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.passkey-row:last-child { border-bottom: none; }

.auth-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 360px;
}

.auth-card h1 { margin: 0 0 4px; font-size: 24px; }
.auth-card .sub { margin: 0 0 24px; color: var(--muted); font-size: 13px; }

#auth-form { display: flex; flex-direction: column; gap: 14px; }
#auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }

input, select, button {
  font: inherit;
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button {
  background: var(--accent);
  color: #08131a;
  border: none;
  font-weight: 600;
  cursor: pointer;
}
button:hover { filter: brightness(1.08); }
button:disabled {
  background: var(--input-bg);
  color: var(--muted);
  cursor: default;
  filter: none;
}
button:disabled:hover { filter: none; }

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 500;
  padding: 4px 0;
  text-decoration: underline;
}

.error {
  color: var(--red);
  font-size: 13px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 17px; }

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 88px; /* clears the fixed bottom-nav */
}

.tab-panel:not([hidden]) {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  display: flex;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
}

.nav-btn {
  flex: 1 1 0;
  background: none;
  border: none;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 2px;
  font-size: 11px;
  border-radius: 10px;
  cursor: pointer;
}
.nav-btn svg { width: 22px; height: 22px; }
.nav-btn:hover { filter: none; background: var(--input-bg); }
.nav-btn.active { color: var(--accent); }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}
.card h2 { margin: 0 0 12px; font-size: 15px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }

#onboarding-banner {
  position: sticky;
  top: 0;
  z-index: 90;
  border-color: var(--accent);
  margin-bottom: 16px;
}
.onboarding-progress { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--accent); }
.onboarding-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

/* Keeps a tour-targeted card from scrolling in underneath the sticky
   onboarding banner - without this, scrollIntoView's default "align top
   edge with viewport top" would land the card exactly behind it. */
.scroll-target { scroll-margin-top: 180px; }

.totals-card #totals-body { font-size: 14px; line-height: 1.6; }
.totals-card .total-line { display: flex; justify-content: space-between; }
.totals-card .total-line .pos { color: var(--green); }
.totals-card .total-line .neg { color: var(--red); }

.position-row, .history-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.position-row:last-child, .history-row:last-child { border-bottom: none; }
.position-row .ticker { font-weight: 600; }
.position-row .muted, .history-row .muted { color: var(--muted); font-size: 12px; }
.position-row .change.pos, .history-row .amount.pos { color: var(--green); }
.position-row .change.neg, .history-row .amount.neg { color: var(--red); }

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.inline-form input, .inline-form select { flex: 1 1 120px; }
.inline-form button { flex: 0 0 auto; }
.inline-form .date-field {
  flex: 1 1 120px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
}
.inline-form .date-field input { flex: none; width: 100%; }

.ticker-search-wrap { position: relative; flex: 1 1 120px; }
.ticker-search-wrap input { width: 100%; }
.ticker-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 50;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 220px;
  overflow-y: auto;
  box-shadow: 0 8px 20px rgba(0,0,0,0.35);
}
.ticker-result-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  padding: 9px 12px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.ticker-result-item:last-child { border-bottom: none; }
.ticker-result-item:hover { background: var(--input-bg); }
.ticker-result-item .tr-symbol { font-weight: 700; flex-shrink: 0; }
.ticker-result-item .tr-name { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.ticker-result-item .tr-exchange { color: var(--muted); font-size: 11px; flex-shrink: 0; }

.hint { color: var(--muted); font-size: 12px; margin: 10px 0 14px; }
.hint:last-child { margin-bottom: 0; }

.setting-group {
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.setting-group:first-of-type { padding-top: 0; border-top: none; }
.setting-group-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  margin-bottom: 10px;
}

.slider-label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.slider-label input[type="range"] { padding: 0; }

.card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 14px;
}
.card label:last-child { margin-bottom: 0; }

.toggle-row {
  flex-direction: row !important;
  align-items: center;
  justify-content: space-between;
  gap: 10px !important;
  color: var(--text) !important;
  font-size: 14px !important;
  cursor: pointer;
}

.toggle-switch { position: relative; display: inline-block; width: 44px; height: 26px; flex-shrink: 0; }
.toggle-switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
  z-index: 1;
}
.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 13px;
  transition: background 0.15s ease;
}
.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: var(--muted);
  border-radius: 50%;
  transition: transform 0.15s ease, background 0.15s ease;
}
.toggle-switch input:checked ~ .toggle-track { background: var(--accent); border-color: var(--accent); }
.toggle-switch input:checked ~ .toggle-track .toggle-thumb { transform: translateX(18px); background: #08131a; }

#bg-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 4px;
}
.gallery-item {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid var(--border);
  aspect-ratio: 480 / 320;
  background: var(--input-bg);
}
.gallery-item.is-active { border-color: #f0b429; }
.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.gallery-item .gi-processing {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  padding: 8px;
}
.gallery-item .gi-actions {
  position: absolute;
  top: 4px;
  right: 4px;
  display: flex;
  gap: 4px;
}
.gallery-item .gi-btn {
  background: rgba(0,0,0,0.55);
  border: none;
  color: #fff;
  width: 26px;
  height: 26px;
  padding: 5px;
  border-radius: 6px;
  cursor: pointer;
}
.gallery-item .gi-btn svg { width: 100%; height: 100%; }
.gallery-item .gi-btn.gi-star.active { color: #f0b429; }
.gallery-item .gi-btn.gi-star.active svg { fill: currentColor; }
.gallery-item .gi-btn.gi-star:disabled { cursor: default; }
.gallery-item .gi-btn.gi-delete:hover { background: var(--red); }

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 4px 8px;
  font-size: 12px;
}
.icon-btn:hover { color: var(--red); border-color: var(--red); }

.card-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: none;
  border: none;
  padding: 0;
  margin: 0 0 12px;
  cursor: pointer;
}
.card-toggle h2 { margin: 0; }
.card-toggle .chevron {
  width: 18px;
  height: 18px;
  color: var(--muted);
  flex-shrink: 0;
  transition: transform 0.15s ease;
}
.card-toggle[aria-expanded="false"] .chevron { transform: rotate(-90deg); }
#positions-body:not([hidden]), #history-body:not([hidden]),
#photo-schedule-body:not([hidden]), #your-data-body:not([hidden]) { display: block; }

.danger-btn {
  width: 100%;
  background: none;
  border: 1px solid var(--red);
  color: var(--red);
  font-weight: 600;
}
.danger-btn:hover { background: var(--red); color: #fff; filter: none; }

.secondary-btn {
  width: 100%;
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 600;
}
.secondary-btn:hover { background: var(--input-bg); filter: none; }

/* ---- Overview grid (mirrors the frame's own Overview slide) ---- */
#overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.overview-card {
  position: relative;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.overview-card:hover { border-color: var(--accent); }
.overview-card .ov-top { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; }
.overview-card .ov-ticker { font-weight: 600; }
.overview-card .ov-price { font-size: 12px; color: var(--muted); }
.overview-card .ov-pct { font-size: 12px; font-weight: 600; }
.overview-card .ov-pct.pos { color: var(--green); }
.overview-card .ov-pct.neg { color: var(--red); }
.overview-card .ov-chart { height: 34px; }
.overview-card .ov-chart svg { display: block; width: 100%; height: 100%; }

.star-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: none;
  border: none;
  padding: 2px;
  width: 22px;
  height: 22px;
  color: var(--muted);
  cursor: pointer;
}
.star-btn svg { width: 100%; height: 100%; }
.star-btn.favorited { color: #f0b429; }
.star-btn.favorited svg { fill: currentColor; }

/* ---- Per-ticker detail overlay (mirrors visAktieSlide) ---- */
.detail-overlay:not([hidden]) {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
@media (min-width: 640px) {
  .detail-overlay { align-items: center; }
}
.detail-panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  padding: 20px;
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
}
@media (min-width: 640px) {
  .detail-panel { border-radius: 16px; }
}
.detail-header { display: flex; justify-content: space-between; align-items: center; margin: 8px 0 4px; }
.detail-header .dt-ticker { font-size: 22px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.detail-header .dt-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.detail-header .dt-pct { font-size: 14px; font-weight: 600; }
.detail-price { font-size: 26px; font-weight: 700; margin-bottom: 12px; }
.detail-chart { height: 130px; margin-bottom: 14px; }
.detail-chart svg { display: block; width: 100%; height: 100%; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; row-gap: 16px; }
.detail-grid .dt-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.detail-grid .dt-value { font-size: 16px; font-weight: 600; margin-top: 2px; }

#qr-video {
  width: 100%;
  border-radius: 10px;
  background: #000;
  margin-top: 10px;
  aspect-ratio: 1 / 1;
  object-fit: cover;
}

#scan-qr-btn {
  flex: 0 0 auto;
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--text);
  width: 44px;
  padding: 10px;
}
#scan-qr-btn svg { width: 100%; height: 100%; }

#pair-device-id:disabled {
  color: var(--muted);
  cursor: default;
}

#firmware-card {
  opacity: 0.55;
  filter: grayscale(0.6);
  transition: opacity 0.2s ease, filter 0.2s ease;
}
#firmware-card.update-available {
  opacity: 1;
  filter: none;
  border-color: var(--accent);
}
#firmware-accept-btn { margin-top: 12px; }

.status-line { display: flex; justify-content: space-between; font-size: 14px; padding: 4px 0; }
.status-line .muted { color: var(--muted); }
