:root {
  color-scheme: dark;
  --bg: #050505;
  --panel: #111;
  --panel-2: #191919;
  --text: #fff;
  --muted: #a7a7a7;
  --line: #2b2b2b;
  --accent: #ffffff;
  --ok: #62d083;
  --warn: #f4bf54;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.admin {
  height: 100vh;
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button,
.ghost-link {
  border: 1px solid var(--text);
  border-radius: 8px;
  background: var(--text);
  color: #000;
  padding: 10px 14px;
  text-decoration: none;
  cursor: pointer;
}

button.secondary,
.ghost-link {
  background: transparent;
  color: var(--text);
}

button.small {
  padding: 7px 10px;
  font-size: 13px;
}

button:disabled {
  opacity: .45;
  cursor: not-allowed;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0b0b0b;
  color: var(--text);
  padding: 10px 12px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

h1,
h2,
p {
  margin: 0;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.muted {
  color: var(--muted);
}

.screen {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  padding: 10px;
  display: grid;
  grid-template-rows: 68px 1fr;
  gap: 10px;
}

.screen-header {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
}

.area-title {
  text-align: center;
  min-width: 0;
}

.screen h1 {
  font-size: clamp(30px, 3.1vw, 58px);
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.screen-header .muted {
  display: none;
}

.status-cluster {
  position: absolute;
  right: 0;
  top: 0;
  display: flex;
  align-items: center;
}

.countdown-ring {
  width: 64px;
  height: 64px;
  position: relative;
  display: grid;
  place-items: center;
}

.countdown-ring svg,
.countdown-ring > div {
  grid-area: 1 / 1;
}

.countdown-ring > div {
  text-align: center;
}

.countdown-ring strong {
  display: block;
  font-size: 13px;
}

.countdown-ring span {
  color: var(--muted);
  font-size: 10px;
}

.ring-bg,
.ring-progress {
  fill: none;
  stroke-width: 7;
}

.ring-bg {
  stroke: #202020;
}

.ring-progress {
  stroke: var(--text);
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
  stroke-dasharray: 326.73;
  stroke-dashoffset: 326.73;
}

.camera-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.camera-tile {
  min-height: 0;
  position: relative;
  overflow: hidden;
  border: 1px solid #181818;
  background: #080808;
}

.camera-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.camera-label {
  position: absolute;
  left: 10px;
  top: 10px;
  max-width: calc(100% - 20px);
  padding: 6px 9px;
  border-radius: 6px;
  background: rgba(0, 0, 0, .58);
  backdrop-filter: blur(4px);
}

.camera-label strong {
  display: block;
  max-width: 100%;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.camera-label span {
  color: #d8d8d8;
  font-size: 14px;
}

.camera-tile.image-error::after {
  content: "Bild kunde inte laddas";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: #080808;
}

.admin-shell {
  max-width: none;
  height: 100vh;
  margin: 0 auto;
  padding: 12px 16px;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 10px;
  overflow: hidden;
}

.admin-header,
.control-bar,
.editor-layout,
.form-row,
.list-heading,
.map-toolbar {
  display: flex;
  gap: 14px;
}

.admin-header {
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0;
}

.admin-header h1 {
  font-size: 30px;
  line-height: 1;
}

.control-bar {
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  margin-bottom: 0;
  flex-wrap: wrap;
}

.control-bar label {
  min-width: 150px;
}

.control-eyebrow {
  flex: 0 0 100%;
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.panel-heading .step-heading.compact,
.list-heading .step-heading.compact {
  margin: 0;
}

.editor-layout {
  align-items: stretch;
  min-height: 0;
}

.area-list {
  width: 220px;
  flex: 0 0 220px;
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 12px;
  min-height: 0;
  overflow: auto;
}

.list-heading {
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.area-button {
  width: 100%;
  text-align: left;
  margin-bottom: 8px;
  background: transparent;
  color: var(--text);
  border-color: var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.area-button.active {
  background: var(--text);
  color: #000;
}

.area-button.shown {
  border-color: #62d083;
}

.area-button b {
  font-size: 11px;
  font-weight: 700;
  color: #62d083;
}

.area-button.active b {
  color: #11642b;
}

.editor {
  min-width: 0;
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
}

.form-row label {
  flex: 1;
}

.camera-picker {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px 320px;
  gap: 10px;
  min-height: 0;
}

.picker-map,
.result-panel,
.selected-panel {
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 10px;
  min-height: 0;
  overflow: hidden;
}

.result-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.picker-map {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
}

.map-toolbar {
  margin-bottom: 8px;
}

.map-toolbar button {
  flex: 0 0 auto;
}

.camera-status {
  min-width: 0;
  min-height: 18px;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.map-toolbar input {
  flex: 1;
}

.admin-info-footer {
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 7px 10px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 420px);
  gap: 12px;
  align-items: center;
}

.sse-status {
  min-width: 0;
  font-size: 12px;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.panel-heading h2 {
  font-size: 18px;
}

.camera-map {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 1px solid #333;
  background: #151515;
}

.map-legend {
  height: 28px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.map-legend i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.map-legend .traffic {
  background: #f4bf54;
}

.map-legend .road {
  background: #5db7ff;
}

.map-legend .used {
  background: #b48cff;
}

.map-legend .selected {
  background: #62d083;
}

.leaflet-container {
  background: #151515;
  color: #111;
  font: inherit;
}

.leaflet-control-attribution {
  font-size: 10px;
}

.map-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
  padding: 20px;
}

.step-heading {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 8px;
}

.step-heading.compact {
  margin: 10px 0 8px;
}

.step-heading span {
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #fff;
  color: #000;
  font-weight: 800;
}

.step-heading h2 {
  font-size: 18px;
}

.step-heading p {
  margin-top: 3px;
  line-height: 1.35;
  font-size: 13px;
}

.camera-search-list {
  min-height: 0;
  height: auto;
  overflow: auto;
  margin-top: 8px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  align-content: start;
}

.camera-list-item {
  min-width: 0;
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  align-items: center;
  gap: 3px;
  text-align: left;
  background: #151515;
  color: var(--text);
  border-color: var(--line);
  padding: 8px;
}

.camera-list-item.selected {
  background: var(--ok);
  color: #000;
  border-color: var(--ok);
}

.camera-list-item:hover {
  border-color: #fff;
}

.camera-list-item strong,
.camera-list-item span {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.camera-list-item img {
  width: 72px;
  height: 54px;
  object-fit: cover;
  background: #060606;
  border: 1px solid #252525;
}

.camera-list-item img.is-missing {
  opacity: .2;
}

.camera-list-item span {
  color: inherit;
  opacity: .72;
  font-size: 12px;
}

.selected-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
  align-content: start;
  gap: 10px;
}

.selected-list {
  display: grid;
  align-content: start;
  gap: 8px;
  min-height: 0;
  overflow: auto;
}

.camera-card {
  border: 1px solid var(--line);
  background: var(--panel-2);
  padding: 10px;
  display: grid;
  grid-template-columns: 86px 1fr auto;
  gap: 10px;
  align-items: center;
}

.camera-card img {
  width: 86px;
  height: 52px;
  object-fit: cover;
  background: #000;
}

.thumb-error {
  width: 86px;
  height: 52px;
  display: grid;
  place-items: center;
  background: #0b0b0b;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.camera-card button {
  padding: 7px 10px;
}

.save {
  margin-top: 8px;
}

.camera-hover-tooltip {
  border: 0;
  background: transparent;
  box-shadow: none;
  padding: 0;
}

.camera-hover-tooltip::before {
  display: none;
}

.camera-hover {
  width: 290px;
  background: #050505;
  color: #fff;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 8px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, .4);
}

.camera-hover img {
  display: block;
  width: 100%;
  height: 164px;
  object-fit: cover;
  background: #111;
  margin-bottom: 7px;
}

.camera-hover strong,
.camera-hover span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.camera-hover span {
  color: var(--muted);
  font-size: 12px;
}

.replace-new {
  margin: 14px 0;
  border: 1px solid var(--ok);
  background: rgba(98, 208, 131, .08);
  padding: 10px;
}

.replace-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.replace-card,
.replace-new {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 12px;
  align-items: center;
  text-align: left;
}

.replace-card {
  background: #151515;
  color: var(--text);
  border-color: var(--line);
}

.replace-card:hover {
  border-color: #fff;
}

.replace-card img,
.replace-new img,
.thumb-error.large {
  width: 130px;
  height: 76px;
  object-fit: cover;
}

.replace-card span,
.replace-new span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.replace-card strong,
.replace-new strong {
  display: block;
  margin: 3px 0;
}

dialog {
  width: min(900px, calc(100vw - 30px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #080808;
  color: var(--text);
  padding: 18px;
}

dialog::backdrop {
  background: rgba(0, 0, 0, .76);
}

dialog img {
  width: 100%;
  max-height: 62vh;
  object-fit: contain;
  background: #000;
  margin: 14px 0;
}

.dialog-close {
  float: right;
  width: 36px;
  height: 36px;
  padding: 0;
  background: transparent;
  color: var(--text);
}

@media (max-width: 900px) {
  .camera-grid,
  .camera-picker {
    grid-template-columns: 1fr;
  }

  .editor-layout,
  .form-row,
  .screen-header {
    flex-direction: column;
  }

  .area-list {
    width: 100%;
    flex-basis: auto;
  }
}
