:root {
  --nav: #24292f;
  --ink: #1f2328;
  --muted: #656d76;
  --line: #d0d7de;
  --line-soft: #eaeef2;
  --bg: #f6f8fa;
  --card: #fff;
  --blue: #0969da;
  --blue-soft: #ddf4ff;
  --green: #1f883d;
  --green-soft: #dafbe1;
  --red: #cf222e;
  --red-soft: #ffebe9;
  --amber: #9a6700;
  --amber-soft: #fff8c5;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
}
button { font: inherit; }
.field-page { padding-bottom: 24px; }

.field-header {
  height: 64px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--nav);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
}
.field-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  background: #fff;
  color: var(--blue);
}
.brand-mark svg { width: 20px; height: 20px; fill: currentColor; }
.field-brand > span:last-child { display: flex; flex-direction: column; min-width: 0; }
.field-brand strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.field-brand small { max-width: 72vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; color: #b7c0c8; }
.field-header[data-state=error] .field-brand small { color: #ffb7b7; }
.header-actions { display: flex; align-items: center; gap: 7px; }
.header-admin { height: 34px; padding: 0 10px; border: 1px solid #57606a; border-radius: 7px; display: flex; align-items: center; gap: 5px; background: #32383f; color: #fff; text-decoration: none; font-size: 10px; font-weight: 700; white-space: nowrap; }
.header-admin svg { width: 15px; height: 15px; fill: currentColor; }
.header-refresh {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid #57606a;
  border-radius: 7px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  background: #32383f;
  color: #fff;
}
.header-refresh svg { width: 18px; height: 18px; fill: currentColor; }
.header-refresh:active { transform: translateY(1px); }
.header-refresh:disabled { opacity: .5; }

main { width: min(1040px, 100%); margin: auto; padding: 14px 12px; }
.credential-alert {
  margin-bottom: 12px;
  padding: 13px;
  border: 1px solid #d4a72c;
  border-radius: 8px;
  background: var(--amber-soft);
  color: #7d4e00;
}
.credential-alert strong { font-size: 13px; }
.credential-alert p { margin: 5px 0 9px; font-size: 11px; }
.credential-alert button { min-height: 34px; border: 0; border-radius: 6px; background: var(--amber); color: #fff; padding: 0 12px; font-weight: 700; }

.site-switcher {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  overflow: hidden;
}
.site-switcher > header { padding: 8px 10px 7px 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.site-switcher > header > div { min-width: 0; }
.site-switcher > header strong { font-size: 13px; }
.site-switcher > header small { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; }
.site-switcher > header nav{display:flex;gap:6px}.site-switcher > header button,.site-switcher > header a { width: 32px; height: 32px; padding: 0; border: 1px solid var(--line); border-radius: 6px; display: grid; place-items: center; flex: 0 0 auto; background: #fff; color: var(--blue); }
.site-switcher > header button svg,.site-switcher > header a svg { width: 17px; height: 17px; fill: currentColor; }
.site-tabs {
  padding: 0 10px 10px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: thin;
  scroll-snap-type: x proximity;
}
.site-tabs button {
  min-width: 150px;
  min-height: 50px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  scroll-snap-align: start;
  text-align: left;
  background: #fff;
  color: var(--ink);
}
.site-tabs button strong, .site-tabs button small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-tabs button strong { font-size: 12px; }
.site-tabs button small { margin-top: 3px; color: var(--muted); font-size: 9px; }
.site-tabs button.active { border-color: var(--blue); background: var(--blue-soft); box-shadow: inset 0 0 0 1px var(--blue); }
.site-tabs button.active strong { color: #0550ae; }

.site-list { margin-top: 12px; }
.site-card { border: 1px solid var(--line); border-radius: 8px; background: #fff; overflow: hidden; }
.site-context { min-height: 42px; padding: 10px 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px; border-bottom: 1px solid var(--line-soft); }
.site-context span { font-size: 13px; font-weight: 700; }
.site-context small { color: var(--muted); font-size: 10px; }

.queue-grid { padding: 8px; display: flex; gap: 8px; align-items: flex-start; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: thin; }
.queue { flex: 0 0 min(86vw, 390px); min-width: 300px; border: 1px solid var(--line); border-radius: 8px; background: #fff; overflow: hidden; scroll-snap-align: start; }
.queue > header { min-height: 56px; padding: 8px; display: flex; align-items: center; justify-content: space-between; gap: 5px; border-bottom: 1px solid var(--line); }
.queue > header span { min-width: 0; font-size: 12px; font-weight: 800; }
.queue > header small { display: block; margin-top: 2px; color: var(--muted); font-size: 8px; font-weight: 500; }
.queue > header strong { font-size: 24px; line-height: 1; }
.queue.plug > header { border-top: 4px solid var(--red); background: var(--red-soft); color: var(--red); }
.queue.charging > header { border-top: 4px solid var(--blue); background: var(--blue-soft); color: #0550ae; }
.queue.unplug > header { border-top: 4px solid var(--green); background: var(--green-soft); color: var(--green); }

.vehicle-list { padding: 6px; display: flex; flex-direction: column; gap: 6px; }
.vehicle-card {
  width: 100%;
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}
.vehicle-card > header { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.vehicle-card > header div { min-width: 0; }
.vehicle-card strong, .vehicle-card small { display: block; }
.vehicle-card strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.vehicle-card small { margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 8px; }
.vehicle-card b { color: var(--blue); font-size: 18px; line-height: 1; white-space: nowrap; }
.vehicle-card b.unknown { color: var(--muted); }
.vehicle-card p { min-height: 28px; margin: 7px 0; color: var(--muted); font-size: 8px; line-height: 1.45; }
.vehicle-card footer { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; }
.vehicle-tags { min-width: 0; display: flex; flex-wrap: wrap; gap: 4px; }
.priority-tag { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 2px 5px; border: 1px solid var(--tag-color); border-radius: 999px; background: #fff; color: var(--tag-color); font-size: 7px; font-weight: 800; }
.power-state { padding: 3px 5px; border-radius: 999px; font-size: 7px; font-weight: 700; }
.power-state.off { background: var(--bg); color: var(--muted); }
.power-state.on { background: var(--amber-soft); color: #7d4e00; }
.power-state.unknown { background: var(--bg); color: #8c959f; }
.horn-button {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid #d4a72c;
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: var(--amber-soft);
  color: #7d4e00;
}
.horn-button svg { width: 15px; height: 15px; fill: currentColor; }
.horn-button:disabled { opacity: .55; }
.card-actions { display: flex; gap: 5px; align-items: center; }
.power-button {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: #fff;
  color: var(--muted);
}
.power-button.power-on { border-color: #1a7f37; background: #dafbe1; color: #1a7f37; }
.power-button.power-off { border-color: #cf222e; background: #ffebe9; color: #cf222e; }
.power-button svg { width: 15px; height: 15px; fill: currentColor; }
.power-button:disabled { opacity: .55; }
.queue-header-right { display: flex; align-items: center; gap: 6px; }
.batch-power-btn {
  padding: 3px 8px;
  border: 1px solid #1a7f37;
  border-radius: 5px;
  background: #dafbe1;
  color: #1a7f37;
  font-size: 9px;
  font-weight: 700;
  white-space: nowrap;
}
.batch-power-btn:disabled { opacity: .55; }
.spinner { width: 13px; height: 13px; border: 2px solid #d4a72c; border-top-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
.queue-empty { margin: 0; padding: 26px 12px; color: var(--muted); text-align: center; font-size: 11px; }
.field-empty { padding: 48px 16px; text-align: center; color: var(--muted); font-size: 13px; }

.field-modal-backdrop { position: fixed; inset: 0; z-index: 60; padding: 16px; display: grid; place-items: center; background: #1f232899; }
.field-modal { width: min(620px, 100%); max-height: min(820px, calc(100vh - 32px)); overflow: auto; border-radius: 10px; background: #fff; box-shadow: 0 20px 60px #1f232866; }
.field-modal > header { position: sticky; top: 0; z-index: 2; padding: 13px 15px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); background: #fff; }
.field-modal > header strong, .field-modal > header small { display: block; }
.field-modal > header strong { font-size: 15px; }
.field-modal > header small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.field-modal > header button { width: 32px; height: 32px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--muted); font-size: 20px; }
.field-modal form { padding: 14px; }
.priority-form-section { margin-bottom: 14px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; }
.priority-form-section h2 { margin: 0; font-size: 13px; }
.priority-form-section p { margin: 4px 0 10px; color: var(--muted); font-size: 10px; }
.priority-form-section > label { display: block; margin-top: 9px; color: var(--muted); font-size: 10px; font-weight: 700; }
.priority-form-section input, .priority-form-section select, .priority-form-section textarea { width: 100%; margin-top: 4px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); font: inherit; font-size: 12px; }
.priority-form-section input, .priority-form-section select { min-height: 38px; padding: 0 9px; }
.priority-form-section textarea { padding: 8px 9px; resize: vertical; }
.priority-group-list { margin-top: 9px; display: flex; flex-direction: column; gap: 6px; }
.priority-group-row { min-height: 42px; padding: 6px 8px; display: grid; grid-template-columns: 18px 8px minmax(0, 1fr) 72px; align-items: center; gap: 8px; border: 1px solid var(--line-soft); border-radius: 6px; }
.priority-group-row > input[type=checkbox] { width: 16px; min-height: 16px; margin: 0; }
.priority-group-row i { width: 8px; height: 24px; border-radius: 4px; background: var(--group-color); }
.priority-group-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; font-weight: 700; }
.priority-group-row > input[type=number] { min-height: 32px; margin: 0; }
.priority-new-group { margin-top: 8px; display: grid; grid-template-columns: minmax(0, 1fr) 90px; gap: 8px; }
.priority-new-group input { margin: 0; }
.field-modal form > footer { display: flex; justify-content: flex-end; gap: 8px; }
.field-modal form > footer button { min-height: 38px; padding: 0 14px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); font-weight: 700; }
.field-modal form > footer button.primary { border-color: var(--blue); background: var(--blue); color: #fff; }

.toast-root { position: fixed; z-index: 50; left: 12px; right: 12px; top: calc(74px + env(safe-area-inset-top)); }
.toast { padding: 12px; border-radius: 7px; background: var(--nav); color: #fff; text-align: center; font-size: 12px; box-shadow: 0 8px 24px #1f232833; }

@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 520px) {
  .header-admin { padding: 0 7px; font-size: 9px; }
  main { padding: 8px 5px; }
  .site-switcher > header small { display: none; }
  .site-tabs button { min-width: 132px; }
  .site-context { align-items: flex-start; flex-direction: column; gap: 3px; }
  .queue-grid { padding: 5px; gap: 7px; }
  .queue { flex-basis: 88vw; min-width: 0; }
  .queue > header { min-height: 52px; padding: 6px; }
  .queue > header span { font-size: 10px; }
  .queue > header strong { font-size: 20px; }
  .vehicle-list { padding: 4px; gap: 4px; }
  .vehicle-card { padding: 6px; }
  .vehicle-card > header { display: block; }
  .vehicle-card b { display: block; margin-top: 5px; font-size: 20px; }
  .vehicle-card footer { align-items: flex-end; }
  .horn-button { width: 26px; height: 26px; }
}
