:root {
  --bg: #121212;
  --card-bg: #1e1e1e;
  --border: #2a2a2a;
  --text: #f3f4f6;
  --text-muted: #9ca3af;
  --green: #10b981;
  --green-bg: rgba(16, 185, 129, 0.15);
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.15);
  --orange: #f59e0b;
  --orange-bg: rgba(245, 158, 11, 0.15);
  --blue: #3b82f6;
  --blue-bg: rgba(59, 130, 246, 0.15);
  --purple: #8b5cf6;
  --purple-bg: rgba(139, 92, 246, 0.15);
  --gray: #9ca3af;
  --gray-bg: rgba(156, 163, 175, 0.15);
}

* { 
  box-sizing: border-box; 
  margin: 0; 
  padding: 0; 
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; 
  -webkit-tap-highlight-color: transparent; 
}

html, body {
  max-width: 100vw;
  overflow-x: hidden;
}

body { 
  background-color: var(--bg); 
  color: var(--text); 
  padding-bottom: calc(100px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

header {
  position: sticky; 
  top: 0; 
  z-index: 30;
  background: rgba(18, 18, 18, 0.95);
  backdrop-filter: blur(10px);
  padding: calc(12px + env(safe-area-inset-top)) 12px 12px 12px;
  display: flex; 
  align-items: center; 
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  gap: 6px;
}

.brand { 
  display: flex; 
  align-items: center; 
  gap: 6px; 
  font-weight: 700; 
  font-size: 1.15rem; 
  flex-shrink: 0;
}

.header-actions { 
  display: flex; 
  align-items: center; 
  gap: 6px; 
  flex-shrink: 0;
}

.lang-switcher-app {
  display: inline-flex; 
  background: rgba(255, 255, 255, 0.05); 
  border: 1px solid var(--border);
  border-radius: 999px; 
  padding: 2px; 
  gap: 2px;
}

.btn-lang {
  background: transparent; 
  border: none; 
  color: var(--text-muted);
  padding: 4px 8px; 
  border-radius: 999px; 
  font-size: 0.72rem; 
  font-weight: 700;
  cursor: pointer;
}
.btn-lang.active { background: var(--blue); color: #fff; }

.btn-header {
  background: rgba(255, 255, 255, 0.08); 
  border: 1px solid var(--border);
  color: var(--text); 
  text-decoration: none; 
  font-size: 0.75rem; 
  font-weight: 600;
  padding: 5px 9px; 
  border-radius: 999px; 
  display: inline-flex; 
  align-items: center; 
  gap: 4px;
  cursor: pointer;
}
.btn-header:active { background: rgba(255, 255, 255, 0.2); }

.btn-yt-header {
  background: rgba(255, 0, 0, 0.1);
  border-color: rgba(255, 0, 0, 0.3);
  padding: 5px 8px;
}
.btn-yt-header:active { background: rgba(255, 0, 0, 0.25); }

.dashboard {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 12px 6px;
}

.stat-card {
  flex: 1 1 calc(20% - 6px);
  min-width: 60px;
  background: var(--card-bg); 
  border: 1px solid var(--border);
  padding: 6px 2px; 
  border-radius: 10px; 
  text-align: center;
}

@media (max-width: 380px) {
  .stat-card { flex: 1 1 calc(33.33% - 6px); }
}

.stat-label { 
  font-size: 0.62rem; 
  color: var(--text-muted); 
  margin-bottom: 2px; 
  white-space: nowrap; 
  overflow: hidden; 
  text-overflow: ellipsis; 
}
.stat-val { font-size: 1rem; font-weight: 700; }

.controls-bar {
  display: flex; 
  gap: 6px; 
  padding: 6px 12px; 
  align-items: center;
}

.search-input {
  flex: 1; 
  min-width: 0; 
  background: var(--card-bg); 
  border: 1px solid var(--border);
  border-radius: 10px; 
  color: var(--text); 
  padding: 8px 10px;
  font-size: 0.8rem; 
  outline: none;
}

.select-sort {
  background: var(--card-bg); 
  border: 1px solid var(--border);
  border-radius: 10px; 
  color: var(--text-muted); 
  padding: 8px 6px;
  font-size: 0.75rem; 
  outline: none; 
  font-weight: 600; 
  max-width: 125px;
}

.filters-row {
  display: flex; 
  justify-content: space-between; 
  align-items: center;
  padding: 4px 12px 10px; 
  gap: 6px;
}

.filters {
  display: flex; 
  gap: 5px; 
  overflow-x: auto; 
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}

.filter-btn {
  background: var(--card-bg); 
  border: 1px solid var(--border);
  color: var(--text-muted); 
  padding: 5px 9px; 
  border-radius: 999px;
  font-size: 0.72rem; 
  font-weight: 600; 
  cursor: pointer; 
  white-space: nowrap;
}
.filter-btn.active {
  background: var(--green-bg); 
  border-color: var(--green); 
  color: var(--green);
}

.btn-batch-storage {
  background: var(--orange-bg); 
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: var(--orange); 
  padding: 5px 8px; 
  border-radius: 999px;
  font-size: 0.7rem; 
  font-weight: 700; 
  cursor: pointer; 
  white-space: nowrap; 
  flex-shrink: 0;
}

.battery-list { 
  padding: 0 12px; 
  display: flex; 
  flex-direction: column; 
  gap: 10px; 
  min-height: 180px; 
}

.card {
  background: var(--card-bg); 
  border: 1px solid var(--border);
  border-radius: 14px; 
  padding: 12px; 
  display: flex; 
  flex-direction: column; 
  gap: 8px;
}
.card.is-retired { opacity: 0.75; border-style: dashed; }

.card-head { 
  display: flex; 
  justify-content: space-between; 
  align-items: flex-start; 
  gap: 6px; 
}
.title-wrapper { 
  display: flex; 
  align-items: center; 
  gap: 6px; 
  flex-wrap: wrap; 
  flex: 1; 
  min-width: 0; 
}
.card-title { font-size: 0.98rem; font-weight: 700; word-break: break-word; }

.cycle-badge {
  font-size: 0.65rem; 
  font-weight: 700; 
  padding: 2px 6px; 
  border-radius: 999px;
  background: var(--purple-bg); 
  color: var(--purple); 
  white-space: nowrap;
}
.cycle-badge.zero { background: rgba(255, 255, 255, 0.05); color: var(--text-muted); }

.ir-badge {
  font-size: 0.65rem; 
  font-weight: 700; 
  padding: 2px 6px; 
  border-radius: 6px; 
  white-space: nowrap;
}
.ir-good { background: var(--green-bg); color: var(--green); border: 1px solid rgba(16, 185, 129, 0.3); }
.ir-warn { background: var(--orange-bg); color: var(--orange); border: 1px solid rgba(245, 158, 11, 0.3); }
.ir-bad { background: var(--red-bg); color: var(--red); border: 1px solid rgba(239, 68, 68, 0.3); }

.model-tag {
  font-size: 0.65rem; 
  font-weight: 700; 
  padding: 2px 6px; 
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.07); 
  color: #d1d5db; 
  border: 1px solid rgba(255,255,255,0.1);
  white-space: nowrap;
}

.storage-alert-badge {
  font-size: 0.7rem; 
  font-weight: 700; 
  padding: 3px 6px; 
  border-radius: 6px;
  background: rgba(245, 158, 11, 0.18); 
  color: var(--orange); 
  border: 1px solid var(--orange);
  display: inline-flex; 
  align-items: center; 
  gap: 4px; 
  align-self: flex-start;
}

.status-badge {
  font-size: 0.72rem; 
  font-weight: 700; 
  padding: 4px 8px; 
  border-radius: 999px;
  cursor: pointer; 
  text-transform: capitalize; 
  user-select: none; 
  flex-shrink: 0;
}
.status-badge.charged { background: var(--green-bg); color: var(--green); }
.status-badge.discharged { background: var(--red-bg); color: var(--red); }
.status-badge.storage { background: var(--orange-bg); color: var(--orange); }
.status-badge.retired { background: var(--gray-bg); color: var(--gray); border: 1px solid rgba(156, 163, 175, 0.3); }

.specs { 
  display: flex; 
  align-items: center; 
  gap: 6px; 
  font-size: 0.8rem; 
  color: var(--text-muted); 
  flex-wrap: wrap; 
}
.type-chip {
  background: var(--blue-bg); 
  color: var(--blue);
  font-size: 0.68rem; 
  font-weight: 700; 
  padding: 2px 5px; 
  border-radius: 4px;
}

.card-footer {
  border-top: 1px solid var(--border); 
  padding-top: 8px;
  display: flex; 
  justify-content: space-between; 
  align-items: center; 
  font-size: 0.78rem; 
  gap: 4px; 
  flex-wrap: wrap;
}
.date-info { color: var(--text-muted); display: flex; flex-direction: column; }
.date-info strong { color: var(--text); font-weight: 600; margin-top: 1px; }

.card-actions { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.action-btn {
  background: rgba(255, 255, 255, 0.05); 
  border: 1px solid var(--border);
  color: var(--text); 
  border-radius: 6px; 
  padding: 5px 7px;
  font-size: 0.72rem; 
  font-weight: 600; 
  cursor: pointer; 
  display: flex; 
  align-items: center; 
  gap: 3px;
}
.btn-del { color: var(--red); border-color: rgba(239, 68, 68, 0.2); }

.details-drawer {
  border-top: 1px dashed var(--border); 
  padding-top: 5px; 
  margin-top: 2px;
  font-size: 0.72rem; 
  color: var(--text-muted);
}
.details-drawer summary {
  cursor: pointer; 
  user-select: none; 
  font-weight: 600; 
  color: var(--blue);
}

.ir-cell-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 6px;
  border: 1px solid var(--border);
}
.ir-cell-pill {
  font-size: 0.68rem;
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 5px;
  border-radius: 4px;
  color: var(--text);
}

.ir-history-section {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}
.ir-history-title {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.ir-history-entry {
  font-size: 0.68rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}
.ir-history-entry:last-child {
  border-bottom: none;
}
.ir-history-date {
  color: var(--text-muted);
}
.ir-history-metrics {
  color: var(--text);
  font-weight: 600;
}

.history-list { margin-top: 4px; padding-left: 16px; list-style-type: circle; }

.bottom-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 24px 12px 10px;
}
.btn-guide-footer {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  color: var(--text-muted);
  text-decoration: none;
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}
.btn-guide-footer:active {
  background: rgba(255, 255, 255, 0.15);
  color: var(--text);
}

.btn-yt-footer {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 0, 0, 0.08);
  border: 1px solid rgba(255, 0, 0, 0.25);
  color: var(--text);
  text-decoration: none;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}
.btn-yt-footer:active {
  background: rgba(255, 0, 0, 0.2);
}

.yt-channel-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.85rem;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
}
.yt-channel-link:hover, .yt-channel-link:active {
  background: rgba(255, 0, 0, 0.12);
  border-color: rgba(255, 0, 0, 0.35);
}

.fab {
  position: fixed; 
  bottom: calc(16px + env(safe-area-inset-bottom)); 
  right: 16px;
  width: 52px; 
  height: 52px; 
  border-radius: 26px;
  background: var(--blue); 
  color: white; 
  border: none;
  font-size: 1.6rem; 
  cursor: pointer; 
  display: flex; 
  align-items: center; 
  justify-content: center;
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.4);
  z-index: 40;
}

.modal {
  position: fixed; 
  inset: 0; 
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(4px); 
  display: none; 
  align-items: flex-end; 
  z-index: 100;
}
.modal.active { display: flex; }

.sheet {
  background: var(--card-bg); 
  border-radius: 18px 18px 0 0;
  width: 100%; 
  max-height: 90vh; 
  overflow-y: auto; 
  padding: 16px 14px calc(20px + env(safe-area-inset-bottom));
  display: flex; 
  flex-direction: column; 
  gap: 10px;
}
.sheet h3 { font-size: 1.1rem; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 0.72rem; color: var(--text-muted); font-weight: 600; }
.field input, .field select {
  background: #121212; 
  border: 1px solid var(--border);
  color: var(--text); 
  padding: 9px 10px; 
  border-radius: 8px; 
  font-size: 0.9rem;
  outline: none; 
  -webkit-appearance: none; 
  width: 100%;
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.ir-section {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ir-section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.ir-section-head label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text);
}
.ir-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(65px, 1fr));
  gap: 6px;
}
.ir-cell-input-box {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.ir-cell-input-box span {
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--text-muted);
  text-align: center;
}
.ir-cell-input-box input {
  text-align: center;
  padding: 6px 4px;
  font-size: 0.85rem;
}

.voltage-guide-box {
  background: rgba(59, 130, 246, 0.1); 
  border: 1px dashed rgba(59, 130, 246, 0.3);
  border-radius: 8px; 
  padding: 7px 9px; 
  font-size: 0.72rem; 
  color: #93c5fd;
  display: flex; 
  justify-content: space-between; 
  align-items: center; 
  flex-wrap: wrap; 
  gap: 4px;
}

.charge-rate-box {
  background: rgba(16, 185, 129, 0.1); 
  border: 1px dashed rgba(16, 185, 129, 0.35);
  border-radius: 8px; 
  padding: 7px 9px; 
  font-size: 0.72rem; 
  color: #6ee7b7;
  display: flex; 
  flex-direction: column; 
  gap: 3px;
}
.charge-rate-line { display: flex; justify-content: space-between; align-items: center; }

.btn-save {
  background: var(--blue); 
  color: white; 
  border: none;
  padding: 12px; 
  border-radius: 10px; 
  font-size: 0.95rem; 
  font-weight: 700; 
  cursor: pointer; 
  margin-top: 4px;
}
.btn-cancel {
  background: transparent; 
  border: 1px solid var(--border);
  color: var(--text-muted); 
  padding: 10px; 
  border-radius: 10px; 
  font-size: 0.85rem; 
  cursor: pointer;
}