/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d0d0d;
  --bg2:       #141414;
  --bg3:       #242424;
  --bg4:       #1e1e1e;
  --border:    #383838;
  --border2:   #303030;
  --border3:   #282828;
  --red:       #e31937;
  --red-dim:   #2a1515;
  --red-zone:  rgba(200,50,50,0.40);
  --green:     #5cc896;
  --green-dim: #1a3328;
  --green-zone:rgba(40,160,90,0.45);
  --text1:     #ffffff;
  --text2:     #f0f0f0;
  --text3:     #d8d8d8;
  --text4:     #c0c0c0;
  --text5:     #aaaaaa;
  --text6:     #888888;
  --text7:     #aaaaaa;
  --kwh-trip:  #e07878;
  --kwh-charge:#5cc896;
  --font:      -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', sans-serif;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text2);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

button { font-family: var(--font); cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:active { opacity: 0.75; }

/* ── App shell ── */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  max-width: 430px;
  margin: 0 auto;
  background: var(--bg);
}

/* ── Header ── */
#header {
  flex-shrink: 0;
  padding: env(safe-area-inset-top, 12px) 20px 10px;
  background: var(--bg);
}

.header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 10px;
}

.header-brand {
  display: flex;
  flex-direction: column;
}

.brand-label {
  color: var(--red);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-bottom: 2px;
}

.brand-name {
  color: var(--text1);
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -0.3px;
}

.header-km {
  text-align: right;
  padding-top: 2px;
}

.header-km-label {
  color: var(--text6);
  font-size: 9px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  margin-bottom: 1px;
}

.header-km-value {
  color: var(--text1);
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.5px;
}

.header-km-value em {
  font-size: 11px;
  color: var(--text5);
  font-weight: 400;
  font-style: normal;
}

/* ── Voyage button ── */
#voyage-btn {
  background: var(--bg2);
  border: 0.5px solid var(--border);
  border-radius: 9px;
  color: var(--text4);
  font-size: 11px;
  padding: 7px 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  float: right;
  clear: both;
}

#voyage-btn.active {
  background: var(--red-dim);
  border-color: var(--red);
  color: var(--red);
}

#voyage-btn svg { flex-shrink: 0; }

/* ── Content area ── */
#content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 6px 14px 16px;
  background: var(--bg);
}

#content::-webkit-scrollbar { display: none; }

/* ── Day separator ── */
.day-sep {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 0 7px;
}

.day-sep:first-child { margin-top: 4px; }

.day-sep-label {
  color: var(--red);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  white-space: nowrap;
}

.day-sep-line {
  flex: 1;
  height: 0.5px;
  background: var(--border2);
}

/* ── Base card ── */
.card {
  border-radius: 12px;
  padding: 9px 12px;
  margin-bottom: 7px;
  border: 0.5px solid var(--border);
  position: relative;
  transition: border-color 0.15s;
  font-size: 13px;
}

.card-charge { background: #0d1e14; border-color: #1a3520; }
.card-trip   { background: #1a140d; border-color: #302010; }

.card.selectable { cursor: pointer; }
.card.selected { border: 1px solid var(--red); }
.card.in-voyage { border-radius: 10px; opacity: 0.92; }
.card.in-voyage.card-charge { background: #0a1810; }
.card.in-voyage.card-trip   { background: #150f08; }
.card.dimmed { opacity: 0.27; pointer-events: none; }

/* ── Card rows ── */
.card-row1 {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 3px;
}

.card-row1-right {
  margin-left: auto;
  color: var(--text6);
  font-size: 10px;
  white-space: nowrap;
  padding-left: 6px;
}

.card-row2 {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0;
  margin-bottom: 2px;
  font-size: 10px;
}

.card-row3 {
  color: #666666;
  font-size: 10px;
  margin-bottom: 2px;
}

.dot { color: #555555; margin: 0 4px; font-size: 10px; }

.time { color: var(--text2); font-size: 13px; font-weight: 500; }
.trip-label { color: var(--text2); font-size: 13px; font-weight: 500; }
.trip-label.in-v { color: var(--text3); font-size: 12px; }
.trip-dist { color: var(--text3); font-size: 14px; font-weight: 500; margin-left: 8px; }
.trip-dist.in-v { font-size: 13px; }

.loc-home { color: var(--green); font-size: 11px; font-weight: 500; }
.loc-sc   { color: #e87070;       font-size: 11px; font-weight: 500; }

.meta-dim  { color: var(--text5); font-size: 10px; }
.meta-trip-avg { color: var(--kwh-trip); font-size: 10px; font-weight: 500; }
.meta-kwh-trip { color: var(--text7); font-size: 10px; margin-left: auto; }
.meta-kwh-charge { color: var(--kwh-charge); font-size: 10px; font-weight: 500; }

/* ── Check circle (voyage mode) ── */
.check-circle {
  position: absolute;
  top: 10px; right: 10px;
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 1.5px solid #303030;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.1s, border-color 0.1s;
}

.check-circle.checked {
  background: var(--red);
  border-color: var(--red);
}

.check-circle span {
  color: #fff;
  font-size: 9px;
  font-weight: 700;
}

/* ── Battery bar (SVG wrapper) ── */
.batt-wrap {
  width: 100%;
  overflow: visible;
  display: block;
  margin-top: 2px;
}

/* ── Voyage card ── */
.voyage-card {
  background: var(--bg4);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 9px;
  border: 0.5px solid #2e1818;
}

.voyage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
}

.voyage-title-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.voyage-title {
  color: var(--text1);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.voyage-toggle-btn {
  background: none;
  border: none;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0;
  flex-shrink: 0;
  margin-left: 8px;
}

.voyage-toggle-label { color: var(--text5); font-size: 10px; white-space: nowrap; }

.voyage-meta {
  color: #888888;
  font-size: 10px;
  margin-bottom: 7px;
}

/* ── Stats grid ── */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin-top: 8px;
}

.sbox {
  background: #111;
  border-radius: 8px;
  padding: 6px 9px;
  border: 0.5px solid #1e1e1e;
}

.sbox.wide { grid-column: 1 / -1; }

.sbox-label {
  color: #777777;
  font-size: 8.5px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.sbox-value {
  color: #e0e0e0;
  font-size: 12px;
  font-weight: 500;
}

.sbox-value em {
  color: #888888;
  font-size: 9.5px;
  font-weight: 400;
  font-style: normal;
}

/* ── Voyage expanded children ── */
.voyage-children {
  margin-top: 8px;
  padding-top: 0;
  border-top: none;
}

.voyage-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 9px;
}

.btn-icon {
  background: none;
  border-radius: 7px;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon-edit  { border: 0.5px solid #252525; }
.btn-icon-trash { border: 0.5px solid #3a1515; }

/* ── Voyage mode banner ── */
#voyage-banner {
  display: none;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding: 8px 12px;
  background: #161616;
  border-radius: 11px;
  border: 0.5px solid var(--border2);
}

#voyage-banner.visible { display: flex; }

.banner-text {
  color: var(--text5);
  font-size: 11px;
  line-height: 1.5;
}

.banner-actions { display: flex; gap: 7px; }

.btn-cancel {
  background: none;
  border: 0.5px solid #282828;
  border-radius: 7px;
  color: var(--text5);
  font-size: 11px;
  padding: 5px 10px;
}

.btn-create {
  border: none;
  border-radius: 7px;
  font-size: 11px;
  font-weight: 600;
  padding: 5px 12px;
  background: var(--red-dim);
  color: #553333;
  transition: background 0.15s, color 0.15s;
}

.btn-create.ready {
  background: var(--red);
  color: #fff;
}

/* ── Bottom bar ── */
#bottom-bar {
  flex-shrink: 0;
  background: var(--bg);
  border-top: 0.5px solid #1c1c1c;
  display: flex;
  align-items: stretch;
  height: 56px;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 4px 0;
}

.tab-btn .tab-label {
  font-size: 9.5px;
  transition: color 0.15s;
}

.tab-btn.on  .tab-label { color: var(--red); font-weight: 600; }
.tab-btn.off .tab-label { color: var(--text6); font-weight: 400; }

#btn-sync {
  flex: 1;
  background: none;
  border: none;
  border-left: 0.5px solid #1a1a1a;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 0;
}

#sync-time {
  font-size: 8.5px;
  color: var(--text6);
  text-align: center;
}

/* ── Spinner ── */
@keyframes spin { to { transform: rotate(360deg); } }
.spinning { animation: spin 0.8s linear infinite; }

/* ── Empty state ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  gap: 10px;
  color: var(--text6);
  font-size: 13px;
  text-align: center;
}
