:root {
  --bg: var(--trv-white);
  --fg: var(--trv-gray-900);
  --muted: var(--trv-gray-700);
  --line: var(--trv-gray-300);
  --card: var(--trv-gray-100);
  --primary: var(--trv-red);
  --primary-hover: var(--trv-red-dark);
  --primary-fg: var(--trv-white);
  --ok: var(--sig-ok);
  --warn: var(--sig-partial);
  --bad: var(--sig-blocked);
  --bar-bg: var(--trv-white);
  --bar-fg: var(--trv-gray-900);
  --tabs-h: 64px;
  --status-h: 48px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161616; --fg: #ededed; --muted: #b4b4b4; --line: #3a3a3a; --card: #232323;
    --primary: var(--trv-red-screen); --primary-hover: #ff3a3a; --bar-bg: #1f1f1f; --bar-fg: #ededed;
  }
}
:root[data-theme="dark"] {
  --bg: #161616; --fg: #ededed; --muted: #b4b4b4; --line: #3a3a3a; --card: #232323;
  --primary: var(--trv-red-screen); --primary-hover: #ff3a3a; --bar-bg: #1f1f1f; --bar-fg: #ededed;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font: 16px/1.5 var(--trv-font);
  overflow: hidden; overscroll-behavior: none;
}
h2 { margin: 0 0 12px; font-size: 1.25rem; font-weight: 700; }
h3 { margin: 16px 0 8px; font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

#statusbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  height: calc(var(--status-h) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 8px 0 10px;
  display: flex; align-items: center; gap: 10px;
  background: var(--bar-bg); color: var(--bar-fg);
  border-top: 4px solid var(--trv-red); border-bottom: 1px solid var(--line);
}
.conn {
  display: flex; align-items: center; gap: 6px; font: inherit; font-weight: 600; white-space: nowrap;
  background: var(--card); color: inherit; border: 1px solid var(--line); border-radius: 16px; padding: 4px 10px; cursor: pointer;
}
.conn.simulated { background: var(--warn); border-color: var(--warn); color: #fff; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #999; }
.dot.online { background: var(--ok); }
.dot.offline { background: var(--warn); }
.freshness { flex: 1; font-size: .85rem; opacity: .95; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.freshness.stale { color: #9a5800; font-weight: 700; }
.freshness.very-stale { color: var(--primary); font-weight: 700; }
.icon-btn { background: none; border: 0; color: inherit; font-size: 1.5rem; width: 40px; height: 40px; cursor: pointer; }
.icon-btn.spinning { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#alert-banner {
  position: absolute; top: 0; left: 0; right: 0; z-index: 700;
  background: var(--trv-red); color: #fff; padding: 8px 12px; font-weight: 700; cursor: pointer;
}

#main { position: fixed; top: calc(var(--status-h) + env(safe-area-inset-top)); bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom)); left: 0; right: 0; }
#map { position: absolute; inset: 0; background: #dfe5ea; }
#main.has-alert #map-buttons { top: 52px; }
#map-buttons { position: absolute; right: 10px; top: 10px; transition: top .2s; z-index: 500; display: flex; flex-direction: column; gap: 8px; }
.fab {
  width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--bg); color: var(--fg); font-size: 1.3rem; box-shadow: 0 2px 6px rgba(0,0,0,.25); cursor: pointer;
}

#pick-overlay { position: absolute; inset: 0; z-index: 600; pointer-events: none; }
.crosshair { position: absolute; left: 50%; top: 50%; width: 44px; height: 44px; margin: -22px 0 0 -22px; }
.crosshair::before, .crosshair::after { content: ""; position: absolute; background: var(--bad); }
.crosshair::before { left: 21px; top: 0; width: 2px; height: 44px; }
.crosshair::after { top: 21px; left: 0; height: 2px; width: 44px; }
.pick-bar {
  position: absolute; left: 8px; right: 8px; bottom: 8px; pointer-events: auto;
  background: var(--bg); border-radius: 12px; padding: 12px; box-shadow: 0 2px 12px rgba(0,0,0,.3);
}

#tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 1000;
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: var(--bg); border-top: 1px solid var(--line);
}
#tabs button {
  flex: 1; border: 0; background: none; color: var(--muted); font-size: .75rem; position: relative; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
#tabs button span { font-size: 1.35rem; }
#tabs button.active { color: var(--primary); font-weight: 700; box-shadow: inset 0 3px 0 var(--primary); }
#tabs b {
  position: absolute; top: 6px; left: 55%; min-width: 18px; height: 18px; border-radius: 9px; padding: 0 5px;
  background: var(--bad); color: #fff; font-size: .7rem; line-height: 18px;
}

.sheet {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom)); z-index: 900;
  max-height: calc(100% - var(--tabs-h) - var(--status-h) - 40px); overflow-y: auto;
  background: var(--bg); border-radius: 16px 16px 0 0; padding: 16px; box-shadow: 0 -4px 16px rgba(0,0,0,.2);
}
@media (min-width: 700px) {
  .sheet { left: auto; width: 420px; right: 12px; bottom: calc(var(--tabs-h) + 12px); border-radius: 16px; }
}

.list { display: flex; flex-direction: column; gap: 8px; }
.card { background: var(--card); border-radius: 10px; padding: 10px 12px; }
.card h4 { margin: 0 0 4px; font-size: 1rem; }
.card .meta { color: var(--muted); font-size: .8rem; }
.card.prio-3 { border-left: 6px solid var(--bad); }
.card.prio-2 { border-left: 6px solid var(--warn); }
.card.prio-1 { border-left: 6px solid var(--primary); }
.card.unread h4::after { content: " • ny"; color: var(--bad); font-size: .8rem; }
.card p { margin: 6px 0 0; white-space: pre-wrap; }
.card .row { margin-top: 8px; }

.btn {
  border: 0; border-radius: 10px; padding: 10px 14px; font-size: 1rem; font-weight: 600; cursor: pointer; min-height: 44px;
}
.btn.primary { background: var(--primary); color: var(--primary-fg); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.secondary { background: var(--card); color: var(--fg); border: 1px solid var(--line); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > .btn { flex: 1; }
.pos-actions { display: grid; gap: 8px; margin: 12px 0; }

fieldset { border: 0; padding: 0; margin: 0 0 14px; }
legend { font-weight: 700; margin-bottom: 6px; }
label.block { display: block; margin-bottom: 12px; font-weight: 600; }
textarea, input[type="search"], input[type="text"] {
  width: 100%; margin-top: 4px; padding: 10px; font: inherit; color: var(--fg); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; font-weight: 400;
}
.type-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.type-grid label { display: block; }
.type-grid input, .seg input { position: absolute; opacity: 0; pointer-events: none; }
.type-grid span {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px; padding: 8px 2px;
  border: 2px solid var(--line); border-radius: 10px; font-size: .7rem; cursor: pointer; min-height: 70px;
}
.type-grid span i { font-style: normal; font-size: 1.6rem; }
.type-grid input:checked + span, .seg input:checked + span { border-color: var(--primary); background: var(--card); font-weight: 700; }
.seg { display: flex; gap: 6px; }
.seg label { flex: 1; }
.seg span { display: block; text-align: center; padding: 10px 4px; border: 2px solid var(--line); border-radius: 10px; cursor: pointer; font-size: .9rem; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + 20px); transform: translateX(-50%); z-index: 2000;
  background: #222; color: #fff; padding: 10px 16px; border-radius: 20px; max-width: 90%;
  opacity: 0; transition: opacity .2s; pointer-events: none; text-align: center;
}
#toast.show { opacity: .95; }

dialog { border: 0; border-radius: 12px; padding: 16px; max-width: 95vw; background: var(--bg); color: var(--fg); }
#qr-video { width: 100%; max-height: 60vh; background: #000; border-radius: 8px; margin-bottom: 8px; }
progress { width: 60%; }

/* Kartsymboler */
.inc {
  width: 34px; height: 34px; border-radius: 50%; background: #fff; border: 3px solid var(--warn);
  display: flex; align-items: center; justify-content: center; font-size: 18px; box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
.inc.b-full { border-color: var(--bad); }
.inc.b-partial { border-color: var(--warn); }
.inc.b-none, .inc.b-unknown { border-color: #7a8794; }
.inc.s-new { border-style: dashed; }
.inc.s-in_progress { box-shadow: 0 0 0 3px var(--sig-info); }
.inc.pending { opacity: .75; border-style: dotted; border-color: #555; }
.wifi-icon {
  width: 30px; height: 30px; border-radius: 8px; background: var(--sig-info); color: #fff; font-size: 16px;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
.me-icon { width: 18px; height: 18px; border-radius: 50%; background: var(--sig-info); border: 3px solid #fff; box-shadow: 0 0 0 2px var(--sig-info); }
.me-icon.stale { background: #90a4ae; box-shadow: 0 0 0 2px #90a4ae; }
.leaflet-popup-content { font-size: .9rem; }
.leaflet-popup-content h4 { margin: 0 0 4px; font-size: 1rem; }
.leaflet-popup-content .meta { color: #5b6876; font-size: .8rem; }
.legend-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.legend-row .inc { flex: none; }

#app-banner {
  position: fixed; left: 8px; right: 8px; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 8px); z-index: 950;
  display: flex; align-items: center; gap: 10px; padding: 10px 6px 10px 14px;
  background: var(--bg); border: 1px solid var(--line); border-left: 5px solid var(--primary); border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
#app-banner-text { flex: 1; font-size: .9rem; }
#statusbar .trv-logo { height: 30px; }
#app-banner .btn { min-height: 38px; padding: 6px 12px; }
@media (min-width: 700px) { #app-banner { left: auto; width: 420px; right: 12px; } }
