:root {
  --bg: #0f1419;
  --panel: #1a222c;
  --text: #e8eef5;
  --muted: #8b9aab;
  --accent: #2aabee;
  --ok: #4caf50;
  --error: #e55;
  --border: #2a3542;
  --radius: 12px;
  font-family: "Segoe UI", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: linear-gradient(160deg, #0f1419 0%, #16202b 50%, #101820 100%);
  color: var(--text);
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 20, 25, 0.9);
  position: sticky;
  top: 0;
}
.brand { font-weight: 700; font-size: 1.15rem; }
.topbar nav { display: flex; gap: 18px; align-items: center; }
.container { max-width: 920px; margin: 0 auto; padding: 24px 16px 48px; }
.container:has(.apk-page),
.container:has(.cars-page),
.container:has(.car-detail-page) { max-width: 1100px; }

.apk-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 8px;
}
.apk-header h1 { margin-bottom: 4px; }
.upload-card.is-hidden { display: none; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.apk-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-top: 20px;
}
.apk-card {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 190px;
  overflow: hidden;
}
.apk-card-body {
  padding: 14px 14px 10px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.apk-top {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.apk-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  object-fit: cover;
  background: #121820;
  border: 1px solid var(--border);
  flex: 0 0 auto;
}
.apk-top-text {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.apk-title {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.apk-version { font-size: 0.95rem; }
.apk-package {
  font-size: 0.78rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.apk-meta {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  font-size: 0.78rem;
}
.apk-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border-top: 1px solid var(--border);
}
.apk-actions button {
  width: 100%;
  border: 0;
  border-radius: 0;
  padding: 11px 8px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-update {
  background: #1c3348;
  color: var(--accent);
}
.btn-update:hover { background: #24415a; }
.btn-delete {
  background: #2a1a1a;
  color: #ff8d8d;
  border-left: 1px solid var(--border) !important;
}
.btn-delete:hover { background: #3a2222; }
.apk-delete-form { margin: 0; }
.apk-empty { grid-column: 1 / -1; padding: 24px 0; }
button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
}
@media (max-width: 1100px) {
  .apk-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .apk-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: 1fr; }
  .apk-header { flex-direction: column; }
}
@media (max-width: 520px) {
  .apk-grid { grid-template-columns: 1fr; }
}
.login-card {
  max-width: 380px;
  margin: 12vh auto;
  background: var(--panel);
  padding: 28px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin: 16px 0;
}
.list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.list-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: inherit;
}
.list-item:hover { border-color: var(--accent); }
.list-item.static:hover { border-color: var(--border); }
.list-main { display: flex; flex-direction: column; gap: 4px; }
.list-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: 0.9rem; }
.muted { color: var(--muted); }
.ok { color: var(--ok); }
.error { color: var(--error); }
.badge {
  background: #243447;
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.8rem;
}
.status-done { color: var(--ok); }
.status-failed { color: var(--error); }
.status-pending { color: #f0c14b; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 0.92rem; }
input, select, textarea, button {
  font: inherit;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #121820;
  color: var(--text);
  padding: 10px 12px;
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #041018;
  font-weight: 600;
  cursor: pointer;
}
button.btn-danger {
  background: #8b2430;
  border-color: #c44555;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
button.linkish {
  background: transparent;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
}
.inline { display: inline; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; }
.kv dt { color: var(--muted); }
.plain { list-style: none; padding: 0; margin: 0; }
.plain li { padding: 6px 0; border-bottom: 1px solid var(--border); }
.hash { font-size: 0.8rem; color: var(--muted); }
h1 { margin: 0 0 8px; font-size: 1.6rem; }
h2 { margin: 0 0 12px; font-size: 1.1rem; }
.remote-toolbar { align-items: center; margin-bottom: 10px; }
.remote-toolbar .badge[data-state="pending"] { color: #f0c14b; }
.remote-toolbar .badge[data-state="live"] { color: var(--ok); }
.remote-canvas-wrap {
  margin-top: 12px;
  background: #0b1016;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  touch-action: none;
}
.remote-canvas-wrap canvas {
  display: block;
  width: 100%;
  height: auto;
  cursor: crosshair;
  background: #121820;
}

/* —— Cars page —— */
.cars-page,
.car-detail-page {
  max-width: 1040px;
}
.cars-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.cars-stats {
  display: flex;
  flex-direction: row;
  gap: 10px;
  flex-wrap: wrap;
}
.stat-pill {
  min-width: 110px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid #334455;
  background: #1a222c;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-pill.is-warn {
  border-color: #6b5320;
  background: #2a2316;
}
.stat-num {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.1;
  color: #e8eef5;
}
.stat-label {
  color: #8b9aab;
  font-size: 0.78rem;
}
.cars-search {
  display: flex;
  flex-direction: row;
  gap: 10px;
  align-items: center;
  margin: 8px 0 18px;
  flex-wrap: wrap;
}
.cars-search input[type="search"] {
  flex: 1 1 280px;
  max-width: 520px;
  min-width: 220px;
}
.ghost-link {
  color: #8b9aab;
  padding: 10px 8px;
}
.cars-filter-note {
  margin: 0 0 12px;
  color: #8b9aab;
  font-size: 0.92rem;
}
.cars-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.car-card {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  background: #1a222c;
  border: 1px solid #334455;
  border-radius: 14px;
  color: #e8eef5;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.03);
  transition: border-color 0.15s ease, transform 0.15s ease, background 0.15s ease;
}
.car-card:hover {
  border-color: #2aabee;
  background: #1e2833;
  transform: translateY(-1px);
}
.car-check-form {
  flex: 0 0 auto;
  margin: 0;
}
.car-check {
  width: 28px;
  height: 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1.5px solid #4a5a6c;
  background: #121820;
  color: transparent;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.car-check:hover {
  border-color: #2aabee;
}
.car-check.is-checked {
  border-color: #2aabee;
  background: #1a3347;
  color: #2aabee;
}
.car-check-mark {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
}
.car-card-link {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  flex: 1 1 auto;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}
.car-card-link:hover {
  color: #e8eef5;
}
.car-card-main {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.car-vin-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.car-vin {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  letter-spacing: 0.02em;
  font-size: 1.08rem;
  margin: 0;
  color: #e8eef5;
  font-weight: 700;
}
.car-sub {
  color: #8b9aab;
  font-size: 0.92rem;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.car-sub .dot { opacity: 0.5; }
.car-card-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 8px;
  flex: 0 0 auto;
  text-align: right;
  min-width: 160px;
}
.car-seen {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.car-seen-rel {
  font-size: 0.95rem;
  color: #e8eef5;
}
.car-seen-abs {
  font-size: 0.8rem;
  color: #8b9aab;
}
.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.tag-live {
  background: #1a3324;
  color: #7ddea0;
}
.tag-test {
  background: #33281a;
  color: #e0c07a;
}
.tag-pending {
  background: #243447;
  color: #2aabee;
}
.status-chip {
  display: inline-flex;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}
.status-chip.status-ok {
  background: #1a3324;
  color: #7ddea0;
}
.status-chip.status-pending {
  background: #33281a;
  color: #f0c14b;
}
.status-chip.status-off {
  background: #2a3038;
  color: #8b9aab;
}
.cars-empty {
  padding: 28px 18px;
  border: 1px dashed #334455;
  border-radius: 14px;
  text-align: center;
  background: #1a222c;
}
.notice-test {
  background: #2a2316;
  border: 1px solid #6b5320;
  color: #e0c07a;
  padding: 12px 14px;
  border-radius: 12px;
  margin: 0 0 16px;
}
.back-link { margin: 0 0 12px; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
@media (max-width: 720px) {
  .car-card {
    align-items: flex-start;
  }
  .car-card-link {
    flex-direction: column;
    align-items: stretch;
  }
  .car-card-side {
    align-items: flex-start;
    text-align: left;
    flex-direction: row;
    justify-content: space-between;
    flex-wrap: wrap;
    min-width: 0;
  }
}
