:root {
  --bg: #12141b;
  --bg-elevated: #1a1d27;
  --bg-elevated-2: #232734;
  --border: #2c303e;
  --text: #eef0f5;
  --text-dim: #9aa0b4;
  --text-faint: #666c82;
  --accent: #f2a93b;
  --accent-dim: #a8781f;
  --accent-text: #1a1206;
  --danger: #e35d5d;
  --warn: #c77dff;
  --ok: #4fb87a;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

/* Immobilien: only the page background gets a subtle green tint; cards,
   inputs, and the top/bottom chrome bars stay the same neutral gray as
   Pendeln (native date-input chrome can't be tinted anyway, so tinting
   every surface just looked inconsistent against it). --accent etc. still
   switch, so buttons and active states are green. */
body[data-context="immobilien"] {
  --accent: #4caf6e;
  --accent-dim: #2f7a48;
  --accent-text: #06180d;
  --bg: #10160f;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .3s ease;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + var(--safe-top)) 20px 14px;
  background: rgba(18, 20, 27, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  font-size: 20px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.02em;
}

.version {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-faint);
  letter-spacing: 0;
  vertical-align: middle;
}

.offline-badge {
  font-size: 12px;
  font-weight: 600;
  color: var(--danger);
  background: rgba(227, 93, 93, 0.14);
  border: 1px solid rgba(227, 93, 93, 0.35);
  padding: 4px 10px;
  border-radius: 999px;
}

.context-switch {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  transition: background-color .3s ease, border-color .3s ease;
}

.context-btn {
  flex: 1;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 9px;
  border-radius: 999px;
  transition: background-color .15s ease, color .15s ease, border-color .15s ease;
}

.context-btn.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

main {
  flex: 1;
  padding: 16px 16px calc(96px + var(--safe-bottom));
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}

#view-root.context-transition {
  animation: context-enter 280ms ease-out;
}

@keyframes context-enter {
  0% { opacity: 0; transform: translateY(10px); }
  100% { opacity: 1; transform: translateY(0); }
}

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: rgba(26, 29, 39, 0.94);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding: 8px 12px calc(8px + var(--safe-bottom));
  z-index: 20;
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 11px;
  font-family: inherit;
  padding: 6px 0;
  border-radius: var(--radius-sm);
  transition: color .15s ease;
}

.tab-btn.active { color: var(--accent); }
.tab-btn:active { background: var(--bg-elevated); }

/* ---- Sections / cards ---- */

.section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin: 22px 4px 10px;
}

.section-title:first-child { margin-top: 4px; }

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
}

.field {
  margin-bottom: 16px;
}

.field:last-child { margin-bottom: 0; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 7px;
}

input[type="text"],
input[type="datetime-local"],
input[type="password"],
textarea,
select {
  width: 100%;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color .15s ease;
  -webkit-appearance: none;
  appearance: none;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%23666c82' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

textarea {
  resize: vertical;
  min-height: 84px;
  line-height: 1.4;
}

.char-count {
  text-align: right;
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 5px;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

button {
  font-family: inherit;
  cursor: pointer;
}

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  font-size: 16px;
  font-weight: 700;
  padding: 15px;
  border-radius: var(--radius-md);
  margin-top: 20px;
}

.btn-primary:active { opacity: 0.85; }
.btn-primary:disabled { opacity: 0.45; cursor: default; }

.btn-secondary {
  background: var(--bg-elevated-2);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 14px;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: var(--radius-md);
}

.btn-text {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  padding: 6px 2px;
}

.btn-danger {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 14px;
  font-weight: 600;
}

/* ---- Picker (location / vehicle) ---- */

.trigger-row {
  display: flex;
  gap: 8px;
}

.trigger-row .picker-trigger {
  flex: 1;
  min-width: 0;
}

.icon-btn {
  flex-shrink: 0;
  width: 46px;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:active { background: var(--bg-elevated); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 8px 7px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.chip button {
  background: var(--bg-elevated);
  border: none;
  color: var(--text-faint);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 15px;
  line-height: 1;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.chip-suggestion {
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 999px;
}

.chip-suggestion:active { background: var(--bg-elevated); }

.mode-switch {
  display: flex;
  gap: 8px;
}

.mode-switch button {
  flex: 1;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 10px;
  border-radius: var(--radius-md);
  transition: background-color .15s ease, color .15s ease, border-color .15s ease;
}

.mode-switch button.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.picker-trigger {
  width: 100%;
  text-align: left;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 16px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.picker-trigger .placeholder { color: var(--text-faint); }
.picker-trigger .chev { color: var(--text-faint); flex-shrink: 0; }

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 30;
  display: flex;
  align-items: flex-end;
}

.sheet {
  background: var(--bg-elevated);
  border-radius: 20px 20px 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
  width: 100%;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding-bottom: var(--safe-bottom);
}

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 10px auto 4px;
}

.sheet-header {
  padding: 8px 18px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sheet-header h2 {
  font-size: 16px;
  margin: 0;
}

.sheet-search {
  padding: 0 18px 10px;
}

.sheet-list {
  overflow-y: auto;
  padding: 0 10px 18px;
}

.sheet-item {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  font-size: 16px;
  padding: 13px 10px;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sheet-item:active { background: var(--bg-elevated-2); }
.sheet-item .sub { font-size: 13px; color: var(--text-faint); }

.sheet-item.new-item { color: var(--accent); font-weight: 600; }

.sheet-empty {
  color: var(--text-faint);
  font-size: 14px;
  padding: 20px 10px;
  text-align: center;
}

/* ---- Distance status ---- */

.distance-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 15px;
}

.distance-value { font-weight: 700; }
.distance-value.pending { color: var(--text-faint); font-weight: 500; font-style: italic; }
.distance-value.error { color: var(--danger); font-weight: 500; }

.retry-btn {
  background: none;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
}

/* ---- Trip list ---- */

.trip-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 10px;
}

.trip-row-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.trip-route {
  font-weight: 600;
  font-size: 15px;
}

.trip-km {
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

.trip-meta {
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-dim);
}

.trip-note {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-dim);
  white-space: pre-wrap;
}

.trip-actions {
  margin-top: 10px;
  display: flex;
  gap: 14px;
}

.empty-state {
  text-align: center;
  color: var(--text-faint);
  padding: 60px 20px;
  font-size: 15px;
}

.manage-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}

.manage-row:last-child { border-bottom: none; }
.manage-row .sub { font-size: 12px; color: var(--text-faint); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + var(--safe-bottom));
  transform: translateX(-50%);
  background: #2a2e3a;
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 14px;
  padding: 11px 18px;
  border-radius: 999px;
  z-index: 50;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

#flash-overlay {
  position: fixed;
  inset: 0;
  background: var(--accent);
  opacity: 0;
  pointer-events: none;
  z-index: 999;
}

#flash-overlay.flash {
  animation: flash-pulse 460ms ease-out;
}

@keyframes flash-pulse {
  0% { opacity: 0; }
  18% { opacity: 0.55; }
  36% { opacity: 0; }
  54% { opacity: 0.55; }
  72% { opacity: 0; }
  100% { opacity: 0; }
}

.autocomplete-list {
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-elevated-2);
}

.autocomplete-list .sheet-item {
  padding: 11px 12px;
}

.input-suffix {
  position: relative;
}

.input-suffix input {
  padding-right: 48px;
}

.input-suffix.has-clear input {
  padding-right: 78px;
}

.input-suffix .suffix {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  font-size: 14px;
  pointer-events: none;
}

.input-suffix .input-clear {
  right: 44px;
}

/* ---- Clearable text fields ---- */

.text-input-wrap {
  position: relative;
}

.text-input-wrap input {
  padding-right: 38px;
}

.textarea-wrap textarea {
  padding-right: 38px;
}

.textarea-wrap .input-clear {
  top: 12px;
  transform: none;
}

.input-clear {
  display: none;
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 26px;
  height: 26px;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: var(--bg-elevated);
  border: none;
  border-radius: 50%;
  color: var(--text-faint);
  font-size: 16px;
  line-height: 1;
}

.input-clear:active { background: var(--bg-elevated-2); }

input:not(:placeholder-shown) ~ .input-clear,
textarea:not(:placeholder-shown) ~ .input-clear {
  display: flex;
}

.hint {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 6px;
  line-height: 1.4;
}

.warn-text {
  color: var(--warn);
  font-weight: 600;
}
