:root {
  --bg: #0b0e11;
  --bg-elev: #151a1f;
  --bg-elev2: #1c232a;
  --line: #262f38;
  --text: #eef2f5;
  --muted: #8a97a4;
  --accent: #e42237; /* Tesla red */
  --accent-press: #b81b2c;
  --ok: #22b573;
  --err: #ff5a5f;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}
/* The [hidden] attribute must always win, even over class-based display rules
   like .view { display: flex } used for our screens/cards. */
[hidden] {
  display: none !important;
}
html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans",
    "Noto Sans JP", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
}

/* ---- Topbar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  position: sticky;
  top: 0;
  background: linear-gradient(var(--bg), rgba(11, 14, 17, 0.85));
  backdrop-filter: blur(8px);
  z-index: 10;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand-logo {
  width: 26px;
  height: 26px;
}
.brand-name {
  font-weight: 700;
  letter-spacing: 0.3px;
}
.topbar-actions {
  display: flex;
  gap: 8px;
}
.ghost-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
}
.ghost-btn:active {
  background: var(--bg-elev);
}

/* ---- Content ---- */
.content {
  flex: 1;
  padding: 8px 16px 24px;
}
.view {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---- Login ---- */
.login {
  align-items: center;
  text-align: center;
  padding-top: 8vh;
  gap: 20px;
}
.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.hero-logo {
  width: 84px;
  height: 84px;
  filter: drop-shadow(0 6px 24px rgba(228, 34, 55, 0.35));
}
.hero-title {
  margin: 0;
  font-size: 30px;
  letter-spacing: 0.5px;
}
.hero-tagline {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
  max-width: 22em;
}
.primary-btn {
  width: 100%;
  max-width: 340px;
  border: none;
  border-radius: var(--radius);
  padding: 16px 20px;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease;
}
.primary-btn:active {
  background: var(--accent-press);
  transform: scale(0.99);
}
.primary-btn:disabled {
  background: var(--bg-elev2);
  color: var(--muted);
  cursor: not-allowed;
}
.setup-warning {
  background: #2a1c00;
  border: 1px solid #6b4d00;
  color: #ffd479;
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 14px;
  max-width: 340px;
}
.setup-warning p {
  margin: 6px 0 0;
}

/* ---- Vehicle selector ---- */
.vehicle-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 14px;
}
.field-label {
  font-size: 18px;
}
.vehicle-select {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 16px;
  padding: 10px 0;
  appearance: none;
  outline: none;
}
.vehicle-select option {
  color: #000;
}

/* ---- Search ---- */
.search-wrap {
  position: relative;
}
.search-input {
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 17px;
  padding: 16px 18px;
  outline: none;
}
.search-input:focus {
  border-color: var(--accent);
}
.search-input::placeholder {
  color: var(--muted);
}

/* ---- Results ---- */
.results {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.result {
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 13px 15px;
  cursor: pointer;
}
.result:active {
  background: var(--bg-elev2);
}
.result.typed {
  border-style: dashed;
}
.r-name {
  font-weight: 600;
  font-size: 15.5px;
}
.r-addr {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
}
.hint {
  color: var(--muted);
  font-size: 14px;
  padding: 10px 4px;
}
.hint.error {
  color: var(--err);
}

/* ---- Selected card ---- */
.selected-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 4px;
}
.sel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.sel-clear {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg-elev2);
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.sel-clear:active {
  background: #232c35;
}
.sel-label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.sel-name {
  font-size: 18px;
  font-weight: 700;
}
.sel-addr {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 8px;
}
.send {
  margin-top: 4px;
}

/* ---- Superchargers on the way ---- */
.sc-wrap {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
}
.sc-head {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.3px;
  padding: 2px 4px 8px;
}
.sc-ico {
  font-size: 15px;
}
.sc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sc-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
}
.sc-item:active {
  background: var(--bg-elev2);
}
.sc-item .sc-plug {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: rgba(43, 181, 115, 0.14);
  font-size: 17px;
}
.sc-item .sc-txt {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sc-name {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sc-addr {
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sc-dist {
  margin-left: auto;
  flex: none;
  color: var(--ok);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

/* ---- Ads ---- */
.ad-slot {
  min-height: 0;
  padding: 0 16px;
  text-align: center;
}
.ad-slot:empty {
  display: none;
}

/* ---- Footer ---- */
.footer {
  padding: 12px 16px calc(14px + var(--safe-bottom));
  text-align: center;
}
.muted {
  color: var(--muted);
}
.small {
  font-size: 12px;
}
.footer a {
  color: var(--muted);
}

/* ---- Toast ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-elev2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 13px 18px;
  border-radius: 12px;
  font-size: 14px;
  max-width: 88%;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.success {
  border-color: var(--ok);
}
.toast.error {
  border-color: var(--err);
}

@media (prefers-color-scheme: light) {
  /* Keep the dark, Tesla-like look regardless of OS theme for brand consistency. */
}
