:root {
  color-scheme: light;
  --font-sans: 'IBM Plex Sans', Arial, sans-serif;
  --font-condensed: 'IBM Plex Sans Condensed', Arial, sans-serif;
  --font-mono: 'IBM Plex Mono', 'Courier New', monospace;

  --color-page-bg: #1D1D1D;
  --color-app-bg: #F4F4F3;
  --color-black: #000000;
  --color-white: #FFFFFF;
  --color-border-strong: #C4C4C4;
  --color-border-light: #DCDCDC;
  --color-text: #000000;
  --color-text-muted: #5A5A5A;
  --color-text-mono: #3D3D3D;
  --color-star-off: #B9B9B9;

  --color-warn-bg: #FFF6E0;
  --color-warn-border: #E8B33D;
  --color-warn-text: #7A5A00;
  --color-stop-bg: #FDEAEA;
  --color-stop-border: #D64545;
  --color-stop-text: #8A1F1F;
  --color-ok-bg: #E8F6EC;
  --color-ok-border: #3FA35A;
  --color-ok-text: #1F6B34;

  --radius: 4px;
  --radius-lg: 12px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--color-page-bg);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

#app { height: 100%; }

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.screen {
  width: 100%;
  max-width: 430px;
  margin: 0 auto;
  height: 100dvh;
  background: var(--color-app-bg);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

/* ---------- Header ---------- */

.app-header {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 50px;
  padding: 0 8px;
  padding-top: env(safe-area-inset-top);
  background: var(--color-black);
  color: var(--color-white);
  flex: none;
}

.app-header__logo {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  flex: none;
  display: block;
}

.app-header__title-wrap {
  flex: 1;
  min-width: 0;
  padding: 0 8px;
}

.app-header__title {
  font-family: var(--font-condensed);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: .02em;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-header__title--sm { font-size: 17px; }

.app-header__subtitle {
  font-size: 13px;
  opacity: .7;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Main content ---------- */

.app-main {
  flex: 1;
  min-height: 0;
  padding: 14px;
  padding-bottom: calc(26px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* A flex column that is also a scroll container shrinks its children to fit
   (their automatic min-height becomes 0) instead of letting content overflow
   and scroll. Keep every section at its natural size so nothing gets squashed. */
.app-main > * {
  flex-shrink: 0;
}

.app-main--tight { gap: 14px; }

.eyebrow {
  font-weight: 600;
  font-size: 13px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.hint {
  font-size: 13px;
  line-height: 1.4;
  color: var(--color-text-muted);
}

.diagram-image {
  display: block;
  width: 100%;
  height: auto;
  background: var(--color-white);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius);
  padding: 8px;
  box-sizing: border-box;
}

.stack { display: flex; flex-direction: column; gap: 9px; }
.stack-16 { display: flex; flex-direction: column; gap: 14px; }
.stack-12 { display: flex; flex-direction: column; gap: 11px; }

/* ---------- Card ---------- */

.card {
  background: var(--color-white);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius);
  padding: 14px;
}

/* ---------- Form controls ---------- */

.field { display: flex; flex-direction: column; gap: 5px; }

.field__label {
  font-weight: 600;
  font-size: 12px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.field__label .required { color: var(--color-stop-border); margin-left: 2px; }

.control {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  background: var(--color-white);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius);
  font-size: 15px;
  color: var(--color-text);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}

.control:focus {
  border-color: var(--color-black);
}

.control--readonly {
  display: flex;
  align-items: center;
  background: var(--color-app-bg);
  color: var(--color-text-mono);
  font-weight: 500;
  border-color: var(--color-border-light);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 26px;
  padding: 0 10px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius);
  background: var(--color-white);
  color: var(--color-text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  flex: none;
}
.chip-btn:active { background: #F0F0F0; }
.chip-btn .icon { width: 14px; height: 14px; }

.qr-scanner-viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #000;
  overflow: hidden;
}

.qr-scanner-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.qr-scanner-frame {
  position: absolute;
  inset: 12%;
  border: 3px solid rgba(255, 255, 255, .85);
  border-radius: var(--radius-lg);
  pointer-events: none;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, .25);
}

.control.mono { font-family: var(--font-mono); font-weight: 500; }

textarea.control {
  height: auto;
  min-height: 72px;
  padding: 8px 12px;
  resize: vertical;
  line-height: 1.35;
}

.select-wrap { position: relative; }

select.control {
  padding-right: 36px;
  cursor: pointer;
}

.select-wrap::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 50%;
  width: 9px;
  height: 9px;
  border-right: 2px solid var(--color-text-muted);
  border-bottom: 2px solid var(--color-text-muted);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}

.field-row { display: flex; align-items: flex-end; gap: 8px; }
.field-row > .field { flex: 1; min-width: 0; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 20px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 15px;
  border: 1px solid transparent;
  cursor: pointer;
  background: none;
}

.btn--block { width: 100%; }
.btn--lg { height: 50px; font-size: 16px; }

.btn--primary {
  background: var(--color-black);
  color: var(--color-white);
}
.btn--primary:active { background: #2b2b2b; }
.btn--primary:disabled { background: #B9B9B9; cursor: not-allowed; }

.btn--secondary {
  background: var(--color-white);
  color: var(--color-black);
  border-color: var(--color-black);
}
.btn--secondary:active { background: #F0F0F0; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  flex: none;
  border: none;
  background: transparent;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--color-white);
}
.icon-btn:active { background: rgba(255,255,255,.12); }

.icon-btn--outline {
  background: var(--color-white);
  border: 1px solid var(--color-border-strong);
  color: var(--color-text);
}
.icon-btn--outline:active { background: #F0F0F0; }

.star-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  cursor: pointer;
  flex: none;
}

.tile .star-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
}

/* ---------- Favorite tiles ---------- */

.tile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.tile {
  display: flex;
  flex-direction: column;
  gap: 7px;
  background: var(--color-white);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius);
  padding: 11px;
  position: relative;
  text-align: left;
  cursor: pointer;
  min-height: 76px;
  font: inherit;
}

.tile:active { border-color: #7A7A7A; }

.tile__title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
  color: var(--color-text);
}

/* ---------- List (module list / history list) ---------- */

.list {
  display: flex;
  flex-direction: column;
  background: var(--color-white);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius);
  overflow: hidden;
}

.list-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px 0 12px;
  border-bottom: 1px solid var(--color-border-light);
  min-height: 50px;
}

.list-row:last-child { border-bottom: none; }

.list-row__btn {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  padding: 8px 0;
  text-align: left;
  cursor: pointer;
  font: inherit;
}

.list-row__text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.list-row__title {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-row__sub {
  font-size: 13px;
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kv-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--color-border-light);
  min-height: 40px;
}
.kv-row:last-child { border-bottom: none; }
.kv-row__label { font-size: 15px; color: var(--color-text); }
.kv-row__value { font-family: var(--font-mono); font-weight: 500; font-size: 15px; color: var(--color-text-mono); }

/* ---------- Project summary button ---------- */

.project-summary {
  text-align: left;
  background: var(--color-white);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius);
  padding: 11px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
  font: inherit;
  width: 100%;
}

.project-summary__row1 {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 14px;
  color: var(--color-text-mono);
}

.project-summary__kunde {
  font-size: 15px;
  color: var(--color-text);
  font-weight: 600;
}

.project-summary__meta {
  font-size: 14px;
  color: var(--color-text-muted);
}

/* ---------- Alerts ---------- */

.alert {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid;
  font-size: 14px;
  line-height: 1.4;
}

.alert--warn { background: var(--color-warn-bg); border-color: var(--color-warn-border); color: var(--color-warn-text); }
.alert--stop { background: var(--color-stop-bg); border-color: var(--color-stop-border); color: var(--color-stop-text); }
.alert--ok { background: var(--color-ok-bg); border-color: var(--color-ok-border); color: var(--color-ok-text); }

.alert .icon { flex: none; margin-top: 1px; }

/* ---------- Empty state ---------- */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  padding: 26px 16px;
  color: var(--color-text-muted);
}

.empty-state .icon { color: var(--color-border-strong); }

.empty-state__title {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text);
}

.empty-state__text {
  font-size: 14px;
  color: var(--color-text-muted);
  max-width: 260px;
}

/* ---------- Reference table ---------- */

.ref-table-wrap {
  flex: 1;
  flex-shrink: 1;
  min-height: 0;
  margin: 0 -14px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.hx-viewer-wrap {
  position: relative;
  flex: 1;
  flex-shrink: 1;
  min-height: 220px;
  margin: 0 -14px;
  display: flex;
}

.hx-viewer {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  touch-action: none;
}

.hx-expand-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius);
  background: rgba(0, 0, 0, .55);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.hx-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: #000;
}

.hx-fullscreen .hx-viewer { width: 100%; height: 100%; }

.hx-fullscreen__close {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  z-index: 2;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.hx-zoom-layer {
  position: relative;
  width: 100%;
  height: 100%;
  transform-origin: center center;
  will-change: transform;
}

.hx-zoom-layer img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.hx-markers {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.hx-marker line { stroke: currentColor; stroke-width: 2.5px; }
.hx-marker-dot { fill: currentColor; stroke: #fff; stroke-width: 2px; }
.hx-marker-label {
  font: 700 30px var(--font-sans);
  fill: #fff;
  paint-order: stroke;
  stroke: currentColor;
  stroke-width: 6px;
  stroke-linejoin: round;
}
.hx-marker--1 { color: #D64545; }
.hx-marker--2 { color: #1E6FD9; }

.ref-table {
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 13px;
  width: 100%;
}

.ref-table th, .ref-table td {
  box-sizing: border-box;
  border: 1px solid var(--color-border-light);
}

.ref-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--color-black);
  color: var(--color-white);
  padding: 0 10px;
  height: 33px;
  text-align: right;
  border-color: #3D3D3D;
}

.ref-table thead tr:first-child th:first-child {
  left: 0;
  z-index: 3;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  min-width: 110px;
}

.ref-table thead tr:nth-child(2) th {
  top: 33px;
  background: var(--color-border-light);
  color: var(--color-text-mono);
  font-weight: 500;
}

.ref-table thead tr:nth-child(2) th:first-child {
  left: 0;
  z-index: 3;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  min-width: 110px;
  border-color: var(--color-border-strong);
}

.ref-table tbody th {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--color-app-bg);
  color: var(--color-text);
  padding: 8px 10px;
  text-align: right;
  border-color: var(--color-border-strong);
}

.ref-table tbody td {
  padding: 6px 10px;
  text-align: right;
  background: var(--color-white);
  color: var(--color-text-mono);
}

/* ---------- Dialog ---------- */

.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}

.dialog {
  width: 100%;
  max-width: 430px;
  max-height: 90dvh;
  background: var(--color-white);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.dialog__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px;
  border-bottom: 1px solid var(--color-border-light);
  flex: none;
}

.dialog__title {
  font-family: var(--font-condensed);
  font-weight: 600;
  font-size: 17px;
}

.dialog__close {
  width: 30px;
  height: 30px;
  border: none;
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
}

.dialog__body {
  padding: 14px;
  overflow-y: auto;
}

/* ---------- Icons ---------- */

.icon svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* ---------- Misc ---------- */

.grow { flex: 1; min-width: 0; }
.row { display: flex; gap: 9px; }
.row > * { flex: 1; }

@media (max-width: 400px) {
  .tile-grid { gap: 7px; }
  .app-main { padding: 10px; }
}
