:root {
  /* ===== High-Contrast Dark Theme ===== */
  --bg: #05080f;
  --bg-soft: #0a1120;
  --card: #0d1627;

  /* Seiten- & Überschriftentext (Darkmode hell) */
  --text: #e6edf8;         /* Normaler Text auf dunklem Hintergrund */
  --text-strong: #000000;  /* Überschriften / Labels */

  --muted: #a9b9da;
  --brand: #6366f1;       /* Bright indigo */
  --brand-2: #22c55e;     /* Green accent */
  --danger: #ef4444;
  --ring: rgba(99, 102, 241, .55);
  --border: #253451;

  /* Eingabefelder: bewusst unabhängig vom Seitentext */
  --input-bg: #ffffff;     /* Weißer Input-Background im Darkmode */
  --input-fg: #0b1220;     /* Dunkler Text IM Eingabefeld */
  --input-border: #33415f; /* Rahmen im Darkmode */
  --input-bg-focus: #ffffff;
  --input-placeholder: #91a0c2;

  /* Layout tokens */
  --radius: 16px;
  --radius-sm: 10px;
  --sp-1: 6px;
  --sp-2: 10px;
  --sp-3: 14px;
  --sp-4: 18px;
  --sp-5: 22px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: 'Montserrat', system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, var(--bg) 0%, #0b1220 100%);
  -webkit-text-size-adjust: 100%; /* prevent iOS font scaling quirks */
}

/* ==== Helpers ==== */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.hide-xs { display: none; }
.show-xs { display: block; }

/* ==== Layout ==== */
.app { min-height: 100vh; }

.app-header {
  position: sticky;
  top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-4);
  background: rgba(11, 17, 32, 0.85);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.brand-logo { width: 34px; height: 34px; border-radius: 10px; flex: 0 0 auto; }
h1 { font-size: clamp(1rem, 3.6vw, 1.35rem); margin: 0; color: var(--text-strong); }
.sub { margin: 2px 0 0; font-size: clamp(.78rem, 3vw, .9rem); color: var(--muted); }

.header-actions { display: none; gap: var(--sp-2); }

.content {
  max-width: 1100px;
  margin: 20px auto;
  padding: 0 var(--sp-3) calc(90px + env(safe-area-inset-bottom)); /* make room for bottom bar on phones */
}

.grid { display: grid; grid-template-columns: 1fr; gap: var(--sp-3); }
.card-spanning { grid-column: 1 / -1; }

/* ==== Card ==== */
.card {
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.02));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-4) var(--sp-4);
  box-shadow: 0 12px 32px rgba(0,0,0,.35);
}
.card:hover { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(99,102,241,.2); }
.card-title { margin: 0 0 var(--sp-3); font-size: 1.05rem; color: var(--text-strong); }
.card-title-row { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); margin-bottom: var(--sp-2); }

/* ==== Form Fields ==== */
.field { margin-bottom: var(--sp-3); }
.field.inline { display: flex; align-items: center; gap: var(--sp-2); }
.two-col, .three-col { display: grid; grid-template-columns: 1fr; gap: var(--sp-2); }

label { display: block; font-weight: 600; margin-bottom: 6px; color: var(--text-strong); }
.req { color: #ff7070; margin-left: 4px; }

input[type="text"],
input[type="date"],
input[type="number"],
select,
textarea {
  width: 100%;
  background: var(--input-bg);
  color: var(--input-fg);
  border: 1px solid var(--input-border);
  outline: none;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  transition: box-shadow .2s, border-color .2s, background .2s;
  font-size: 16px; /* avoid iOS zoom-on-focus */
}
textarea { min-height: 110px; resize: vertical; }

input::placeholder, textarea::placeholder { color: var(--input-placeholder); opacity: 1; }

input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
  background: var(--input-bg-focus);
  box-shadow: 0 0 0 3px var(--ring);
}

input:hover, select:hover, textarea:hover { border-color: #55699a; }

/* ==== Checkbox & Radio ==== */
.checkbox { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.checkbox input { width: 20px; height: 20px; accent-color: var(--brand); }

.radio-group { display: flex; flex-wrap: wrap; gap: 8px; }
.radio-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 999px;
  cursor: pointer; color: var(--muted); user-select: none; transition: all .15s ease;
}
.radio-pill input { accent-color: var(--brand); }
.radio-pill:has(input:checked) { border-color: var(--brand); background: #ffffff2e; color: var(--text-strong); }

/* ==== Buttons ==== */
.btn { appearance: none; border: none; cursor: pointer; font-weight: 600; border-radius: var(--radius-sm); padding: 12px 16px; transition: transform .05s, opacity .2s; color: white; width: 100%; }
.btn:hover { opacity: .95; }
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--brand); }
.btn-secondary { background: #334155; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger); }
.btn-xs { padding: 8px 10px; font-size: .85rem; border-radius: 8px; width: auto; }

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

/* ==== Items Table ==== */
.table-wrap { margin-top: var(--sp-3); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; }
.table thead th { background: #0b1527; position: sticky; top: 0; text-align: left; font-weight: 700; font-size: .9rem; color: var(--muted); padding: 12px 14px; border-bottom: 1px solid var(--border); }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: top; color: var(--text); }
.table tr:last-child td { border-bottom: none; }
.table .num { text-align: right; white-space: nowrap; }
.table .actions { white-space: nowrap; display: flex; gap: 6px; justify-content: flex-end; }

.price-stack { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.price-stack s { color: #8092bf; font-size: .85rem; }
.price-stack span { color: var(--text-strong); }

/* ==== Mobile-first table: stack rows; auto labels via nth-child ==== */
@media (max-width: 600px) {
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border-bottom: 1px solid var(--border); }
  .table td { display: grid; grid-template-columns: 120px 1fr; align-items: start; gap: 8px; }
  .table td::before { content: attr(data-label); font-weight: 700; color: var(--muted); text-transform: uppercase; font-size: .8rem; }
  .table .num { text-align: left; }
}

/* We provide data-labels from HTML/JS; if not present, fall back to nth-child titles */
@media (max-width: 600px) {
  .table td:nth-child(1):not([data-label])::before { content: "POS"; }
  .table td:nth-child(2):not([data-label])::before { content: "Description"; }
  .table td:nth-child(3):not([data-label])::before { content: "Qty"; }
  .table td:nth-child(4):not([data-label])::before { content: "Condition"; }
  .table td:nth-child(5):not([data-label])::before { content: "Lead Time"; }
  .table td:nth-child(6):not([data-label])::before { content: "Unit Price"; }
  .table td:nth-child(7):not([data-label])::before { content: "Line Total"; }
  .table td:nth-child(8):not([data-label])::before { content: "Actions"; }
}

/* ==== Bottom mobile actions bar ==== */
.mobile-actions { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-2); padding: var(--sp-3) var(--sp-3) calc(var(--sp-3) + env(safe-area-inset-bottom)); background: rgba(11, 17, 32, 0.92); backdrop-filter: saturate(160%) blur(12px); border-top: 1px solid var(--border); }
.mobile-actions .btn { width: 100%; }

/* Show header actions on wider screens, hide bottom bar */
@media (min-width: 721px) {
  .header-actions { display: flex; }
  .mobile-actions { display: none; }
  .content { padding-bottom: 60px; }
  .two-col { grid-template-columns: 1fr 1fr; }
  .three-col { grid-template-columns: 1fr 1fr 1fr; }
}

/* ==== Light Mode (auto) ==== */
@media (prefers-color-scheme: light) {
  :root {
    --bg: rgb(242, 245, 251);
    --bg-soft: rgb(255, 255, 255);
    --card: rgb(255, 255, 255);
    --muted: rgb(75, 85, 99);
    --text: rgb(0, 0, 0);
    --text-strong: rgb(0, 0, 0);
    --brand: rgb(1, 248, 184);
    --brand-2: rgb(0, 195, 239);
    --border: rgb(209, 213, 219);
    --ring: rgba(79,70,229,.25);
    --input-bg: #fff; --input-fg: #000; --input-border: #cbd5e1; --input-bg-focus: #fff; --input-placeholder: #64748b;
  }
  html, body { background: #f5f7fb; color: var(--text); }
  .app-header { background: #ffffffaa; }
  .table thead th { background: #f4f6fb; }
}
