:root {
  --red: #CC0000;
  --black: #0A0A0A;
  --green: #00CC00;
  --dark: #1A1A1A;
  --mid: #2A2A2A;
  --text: #ffffff;
  --muted: #888888;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: #050505;
  color: var(--text);
  font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 50% 0%, #1a0808 0%, #050505 55%, #000 100%);
}

.app-shell {
  width: min(1100px, 100vw);
  height: min(860px, 100vh);
  background: var(--black);
  position: relative;
  overflow: hidden;
  box-shadow: 0 0 0 1px #222, 0 24px 80px rgba(204, 0, 0, 0.18);
}

@media (max-width: 720px) {
  body { align-items: stretch; }
  .app-shell {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    box-shadow: none;
  }
}

/* ========== SPLASH ========== */
.splash {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--black) center/cover no-repeat;
  transition: opacity 0.45s ease, visibility 0.45s;
}

.splash.hide {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.splash-spacer-top { flex: 3; }
.splash-spacer-mid { flex: 2; }

.logo-circle {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 2px solid var(--red);
  display: grid;
  place-items: center;
  overflow: hidden;
  background: rgba(204, 0, 0, 0.08);
}

.logo-circle img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.logo-circle svg { width: 44px; height: 44px; fill: var(--red); }

.brand {
  margin-top: 24px;
  text-align: center;
}

.brand .autel {
  display: block;
  color: var(--red);
  font-size: 32px;
  font-weight: 900;
  letter-spacing: 4px;
  line-height: 1.1;
}

.brand .carservice {
  display: block;
  color: #fff;
  font-size: 22px;
  font-weight: 300;
  letter-spacing: 6px;
  margin-top: 4px;
}

.subtitle {
  margin-top: 16px;
  color: #777;
  font-size: 14px;
  letter-spacing: 1px;
}

.loading-line {
  width: 200px;
  height: 3px;
  margin-bottom: 48px;
  border-radius: 2px;
  background: var(--mid);
  position: relative;
  overflow: hidden;
}

.loading-line::after {
  content: "";
  position: absolute;
  top: 0;
  left: -35%;
  width: 35%;
  height: 100%;
  background: var(--red);
  border-radius: 2px;
  animation: loadslide 1.2s linear infinite;
}

@keyframes loadslide {
  from { left: -35%; }
  to { left: 100%; }
}

/* ========== HOME ========== */
.home {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.work {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: row;
}

.gauges-pane {
  width: 46%;
  min-width: 240px;
  overflow-y: auto;
  padding: 8px 10px 12px;
  background: #0d0d0d;
  border-right: 1px solid #222;
  -webkit-overflow-scrolling: touch;
}

.chat-pane {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.g-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 11px;
}

.g-bt { color: #777; font-weight: 700; letter-spacing: 0.4px; }
.g-bt.on { color: var(--green); }
.g-live { color: #666; font-size: 10px; }

.g-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px 4px;
}

.gauge { text-align: center; }
.gauge .g-fill {
  width: min(92px, 100%);
  aspect-ratio: 1 / 1;
  height: auto;
  margin: 0 auto;
  border-radius: 50%;
  background: conic-gradient(#2a2a2a 0 100%);
  display: grid;
  place-items: center;
}
.gauge .g-inner {
  width: 72%;
  height: 72%;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background: #111;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 0 0 1px #222;
}
.gauge .g-num {
  font-size: 16px;
  font-weight: 800;
  line-height: 1;
  color: #fff;
}
.gauge .g-unit {
  font-size: 9px;
  color: #888;
  margin-top: 2px;
}
.gauge .g-name {
  margin-top: 6px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: #9a9a9a;
}
.gauge.dead .g-num { color: #555; }
.gauge.dead .g-fill { opacity: 0.7; }
.gauge.hot .g-num { color: var(--red); }

.g-chips {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 10px;
}

.chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: #161616;
  border: 1px solid #2a2a2a;
  border-radius: 8px;
  padding: 7px 8px;
}
.chip .c-lbl { font-size: 9px; font-weight: 700; color: #777; letter-spacing: 0.4px; }
.chip .c-val { font-size: 13px; font-weight: 800; color: #fff; }
.chip.dead .c-val { color: #555; }
.chip.hot .c-val { color: var(--red); }

@media (max-width: 768px) {
  .work {
    flex-direction: column;
  }
  .gauges-pane {
    width: 100%;
    min-width: 0;
    max-height: 46vh;
    flex: 0 0 auto;
    padding: 8px 10px 10px;
    border-right: none;
    border-bottom: 1px solid #222;
  }
  .chat-pane {
    width: 100%;
    flex: 1 1 auto;
    min-height: 200px;
  }
  .g-grid { grid-template-columns: repeat(3, 1fr); gap: 10px 6px; }
  .g-chips { grid-template-columns: 1fr 1fr; }
  .bubble {
    max-width: 90%;
    font-size: 15px;
  }
  .bubble.assistant { margin-right: 10px; }
  .keyboard-row input { font-size: 16px; }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 8px;
  background: var(--black);
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.top-logo {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1.5px solid var(--red);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.top-logo img { width: 100%; height: 100%; object-fit: cover; }
.top-logo svg { width: 18px; height: 18px; fill: var(--red); }

.top-titles .name {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.top-titles .status {
  font-size: 11px;
  color: var(--green);
  margin-top: 1px;
}

.top-titles .status.critical { color: var(--red); }

.icon-btn {
  background: transparent;
  border: none;
  color: #ccc;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  display: grid;
  place-items: center;
}

.icon-btn:hover { background: var(--mid); color: #fff; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.bt-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1.5px solid #555;
  background: var(--mid);
  color: #bbb;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}

.bt-btn svg {
  width: 26px;
  height: 26px;
  fill: currentColor;
}

.bt-btn:hover { color: #fff; border-color: #888; }

.bt-btn.on {
  color: #0a0a0a;
  background: var(--green);
  border-color: var(--green);
  box-shadow: 0 0 12px rgba(0, 204, 0, 0.45);
}

.bt-btn.busy {
  border-color: #fa0;
  color: #fa0;
  animation: btpulse 1s ease-in-out infinite;
}

@keyframes btpulse {
  50% { box-shadow: 0 0 14px rgba(255, 170, 0, 0.55); }
}

.obd-bar[hidden] { display: none !important; }

/* OBD bar */
.obd-bar {
  display: flex;
  align-items: stretch;
  padding: 8px;
  background: var(--dark);
  border-bottom: 1px solid var(--mid);
}

.obd-bar.critical { border-bottom: 2px solid var(--red); }

.metric {
  flex: 1;
  text-align: center;
  padding: 2px 0;
}

.metric .ico { font-size: 12px; color: #888; line-height: 1; }
.metric.hot .ico { color: var(--red); }
.metric .lbl {
  font-size: 8px;
  color: #777;
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-top: 2px;
}
.metric .val {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  margin-top: 1px;
}
.metric.hot .val { color: var(--red); }
.metric .val span {
  font-size: 8px;
  color: #999;
  font-weight: 400;
}

.obd-sep {
  width: 1px;
  background: var(--mid);
  margin: 4px;
  align-self: stretch;
}

/* Chat */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0 12px;
  -webkit-overflow-scrolling: touch;
}

.bubble {
  max-width: 78%;
  margin: 4px 8px;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.bubble.assistant {
  margin-right: 48px;
  background: var(--mid);
  border-bottom-left-radius: 4px;
}

.bubble.user {
  margin-left: auto;
  margin-right: 8px;
  background: rgba(204, 0, 0, 0.85);
  border-bottom-right-radius: 4px;
}

.bubble .meta {
  margin-top: 4px;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.4);
}

.bubble .file {
  margin-top: 4px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.54);
}

.bubble.loading {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: rgba(255, 255, 255, 0.7);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Bottom bar */
.bottom {
  background: var(--dark);
  border-top: 1px solid var(--mid);
  padding: 8px 12px calc(8px + var(--safe-bottom));
  flex-shrink: 0;
}

.wave {
  display: none;
  height: 32px;
  align-items: flex-end;
  justify-content: center;
  gap: 4px;
  margin-bottom: 8px;
}

.wave.on { display: flex; }

.wave span {
  width: 4px;
  height: 10px;
  background: var(--red);
  border-radius: 2px;
  animation: wave 0.9s ease-in-out infinite;
}

.wave span:nth-child(2) { animation-delay: 0.1s; }
.wave span:nth-child(3) { animation-delay: 0.2s; }
.wave span:nth-child(4) { animation-delay: 0.3s; }
.wave span:nth-child(5) { animation-delay: 0.15s; }

@keyframes wave {
  0%, 100% { height: 8px; opacity: 0.5; }
  50% { height: 28px; opacity: 1; }
}

.voice-row {
  display: flex;
  align-items: center;
  justify-content: space-evenly;
}

.side-btn {
  background: transparent;
  border: none;
  color: #aaa;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  min-width: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.side-btn:hover { color: #fff; background: rgba(255, 255, 255, 0.05); }
.side-btn .ico { font-size: 22px; line-height: 1; }
.side-btn .lbl { font-size: 9px; color: #777; }

.mic-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  background: var(--red);
  color: #fff;
  font-size: 28px;
  cursor: pointer;
  box-shadow: 0 0 12px rgba(204, 0, 0, 0.4);
  transition: box-shadow 0.2s, transform 0.15s;
}

.mic-btn:active { transform: scale(0.96); }
.mic-btn.listening {
  box-shadow: 0 0 0 6px rgba(204, 0, 0, 0.25), 0 0 20px rgba(204, 0, 0, 0.55);
}

.keyboard-row {
  display: none;
  align-items: center;
  gap: 4px;
}

.keyboard-row.on { display: flex; }
.voice-row.off { display: none; }

.keyboard-row input {
  flex: 1;
  background: var(--mid);
  border: none;
  border-radius: 24px;
  color: #fff;
  padding: 10px 16px;
  font-size: 14px;
  outline: none;
}

.keyboard-row input::placeholder { color: #777; }

.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  background: var(--dark);
  border-radius: 16px 16px 0 0;
  padding: 16px 16px calc(16px + var(--safe-bottom));
  transform: translate3d(0, 100%, 0);
  visibility: hidden;
  pointer-events: none;
  transition: transform 0.28s ease, visibility 0.28s;
}

.sheet.open {
  transform: translate3d(0, 0, 0);
  visibility: visible;
  pointer-events: auto;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  z-index: 35;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.28s, visibility 0.28s;
}

.sheet-backdrop.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.sheet-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 14px 8px;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 15px;
  cursor: pointer;
  border-radius: 8px;
  text-align: left;
}

.sheet-item:hover { background: var(--mid); }
.sheet-item .ico { color: var(--red); font-size: 22px; width: 28px; text-align: center; }

.hidden-file { display: none; }
