:root {
  --bg: #f3f4f6; --card: #fff; --text: #1c2430; --muted: #6b7280; --line: #e2e5ea;
  --primary: #1f3a5f; --primary-2: #2c5282; --ok: #2f7d4f; --danger: #b42318; --warn: #b45309;
  --radius: 10px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary-2); }
h1 { font-size: 1.5rem; margin: .2em 0 .6em; }
h2 { font-size: 1.1rem; margin: 0 0 .7em; }
h3 { font-size: 1rem; margin: 0 0 .5em; }
.muted { color: var(--muted); }
small { font-size: .85em; }
code { background: #eef1f5; padding: 1px 5px; border-radius: 4px; font-size: 1.05em; }

/* Kopfzeile */
.topbar { background: var(--primary); color: #fff; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; padding: 10px 16px; position: sticky; top: 0; z-index: 10; }
.topbar a, .topbar .linkbtn { color: #dbe4f0; text-decoration: none; }
.topbar a:hover, .topbar a.active { color: #fff; }
.topbar a.active { text-decoration: underline; text-underline-offset: 4px; }
.brand { font-weight: 700; color: #fff !important; font-size: 1.05rem; }
.topbar nav { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; flex: 1; font-size: .95rem; }
.topbar nav small { opacity: .7; }
.btn-neu { margin-left: auto; background: #f5b301 !important; color: #1c2430 !important; border-color: #f5b301 !important; font-weight: 700; }
.linkbtn { background: none; border: 0; font: inherit; cursor: pointer; padding: 0; }
form.inline { display: inline; }

main { max-width: 1250px; margin: 0 auto; padding: 18px 16px 60px; }
.narrow { max-width: 640px; margin: 0 auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.login-box { max-width: 380px; margin: 12vh auto 0; }

/* Formulare */
label { display: block; margin-bottom: 14px; font-weight: 600; font-size: .95rem; }
label small { font-weight: 400; }
input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px; font: inherit; font-weight: 400;
  border: 1px solid #c9ced6; border-radius: 8px; background: #fff; color: var(--text); min-height: 44px; }
input[type=file] { display: block; margin-top: 6px; font: inherit; font-weight: 400; max-width: 100%; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #93b4e0; border-color: var(--primary-2); }
fieldset { border: 0; padding: 0; margin: 0 0 14px; }
legend { font-weight: 600; font-size: .95rem; margin-bottom: 6px; padding: 0; }
.row { display: flex; flex-wrap: wrap; gap: 0 12px; align-items: flex-end; }
.row > label { flex: 0 1 auto; }
.row > .grow { flex: 1 1 200px; }
.row.tight { gap: 6px; flex-wrap: nowrap; align-items: center; }
.row.tight input, .row.tight select { margin: 0; min-height: 36px; padding: 6px 8px; }
.row.tight .short { width: 110px; flex: none; }
.check { display: flex; align-items: center; gap: 6px; font-weight: 400; margin: 0; white-space: nowrap; }

.btn { display: inline-block; padding: 10px 16px; border-radius: 8px; border: 1px solid #c9ced6; background: #fff; color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; min-height: 44px; line-height: 1.5; white-space: nowrap; }
.btn:hover { background: #f1f3f6; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-2); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-ok:hover { background: #276a42; }
.btn-danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: #fdecea; }
.btn-warn { background: #fff4db; border-color: #f3c766; color: #7a4a00; }
.btn-small { padding: 5px 10px; min-height: 34px; font-size: .88rem; }
.btn-block { display: block; width: 100%; }
.btn-big { padding: 14px; font-size: 1.1rem; }
.btnrow { display: flex; gap: 10px; flex-wrap: wrap; }
.grow-btn { flex: 1; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: .7em; }
.card-head h2 { margin: 0; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; }
.flash-ok { background: #e8f5ec; border-color: #a9d8b8; color: #1e5233; }
.flash-error { background: #fdecea; border-color: #f2b8b5; color: #8a1c13; }
.flash-warn { background: #fff4db; border-color: #f3d48a; color: #7a4a00; }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; gap: 6px; align-items: center; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: #fff; text-decoration: none; color: var(--text); font-size: .9rem; }
.chip b { font-weight: 700; color: var(--muted); }
.chip.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.chip.on b { color: #cfe0f5; }
.status-chips { margin-bottom: 12px; }
.chip-radio { margin: 0; font-weight: 600; }
.chip-radio input { position: absolute; opacity: 0; }
.chip-radio span { display: inline-block; padding: 9px 16px; border: 1px solid #c9ced6; border-radius: 999px; background: #fff; cursor: pointer; }
.chip-radio input:checked + span { background: var(--primary); color: #fff; border-color: var(--primary); }
.chip-radio.urg-eilig input:checked + span { background: var(--warn); border-color: var(--warn); }
.chip-radio.urg-sofort input:checked + span { background: var(--danger); border-color: var(--danger); }
.chip-radio input:focus-visible + span { outline: 2px solid #93b4e0; }

/* Status-Farben */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .8rem; font-weight: 700; white-space: nowrap; background: #eef1f5; color: #374151; }
.badge.big { font-size: .95rem; padding: 4px 12px; }
.st-eingereicht { background: #e6effa; color: #1e4e8c; }
.st-freigegeben { background: #e3f4f4; color: #0f6363; }
.st-abgelehnt { background: #fdecea; color: #a1281d; }
.st-bestellt { background: #efe9fb; color: #5b3aa6; }
.st-teilgeliefert { background: #fff1d6; color: #8a5600; }
.st-geliefert { background: #e5f4ea; color: #22663c; }
.st-abgeschlossen { background: #eceef1; color: #4b5563; }
.chip.on.st-eingereicht, .chip.on.st-freigegeben, .chip.on.st-abgelehnt, .chip.on.st-bestellt,
.chip.on.st-teilgeliefert, .chip.on.st-geliefert, .chip.on.st-abgeschlossen { background: var(--primary); color: #fff; }
.badge.urg-eilig { background: #fff1d6; color: #8a5600; }
.badge.urg-sofort { background: var(--danger); color: #fff; }

/* Liste */
.list-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
button.chip { font: inherit; cursor: pointer; }
.chip-filter { margin-left: auto; font-weight: 600; }
.chip-filter.on { background: #fff; color: var(--primary); border-color: var(--primary); }
.filter-panel { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; max-width: 760px; margin-bottom: 12px; }
.filter-panel[hidden] { display: none; }
.filter-panel .check, .filter-panel .btnrow { grid-column: 1 / -1; }
.filter-panel .check { margin-bottom: 12px; }
.active-filters { margin-bottom: 12px; }
.chip-active { background: #e6effa; border-color: #b9cff0; color: #1e4e8c; }
.chip-active span { font-size: .8em; opacity: .7; }
.hint { font-size: .85rem; margin: -6px 0 14px; }
table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #f8f9fb; font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
table.reqs tbody tr { cursor: pointer; }
table.reqs tbody tr:hover { background: #f7f9fc; }
table.reqs td.c-was a { color: var(--text); font-weight: 600; text-decoration: none; }
table.reqs td.c-status .badge { margin: 1px 0; }
table.reqs td a { text-decoration: none; }
tr.urg-row-sofort td:first-child { box-shadow: inset 4px 0 0 var(--danger); }
tr.urg-row-eilig td:first-child { box-shadow: inset 4px 0 0 #e8a33d; }
td.num { text-align: right; white-space: nowrap; }
.overdue { color: var(--danger); font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 40px; }
tr.inactive { opacity: .55; }

/* Detail */
.detail-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 10px; }
.detail-head h1 { margin-bottom: .3em; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + .card { margin-top: 16px; }
.facts { display: grid; grid-template-columns: 150px 1fr; gap: 8px 12px; margin: 0; }
.facts dt { color: var(--muted); font-size: .9rem; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.extlink { word-break: break-all; }
.actions { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }
.action-box { margin-bottom: 14px; }
.action-box textarea { margin-bottom: 10px; }

.progress { list-style: none; display: flex; padding: 0; margin: 4px 0 18px; counter-reset: s; }
.progress li { flex: 1; text-align: center; font-size: .82rem; color: var(--muted); position: relative; padding-top: 28px; }
.progress li::before { counter-increment: s; content: counter(s); position: absolute; top: 0; left: 50%; transform: translateX(-50%); width: 24px; height: 24px; border-radius: 50%; background: #d9dde3; color: #fff; font-weight: 700; line-height: 24px; z-index: 1; }
.progress li::after { content: ""; position: absolute; top: 11px; left: -50%; width: 100%; height: 3px; background: #d9dde3; }
.progress li:first-child::after { display: none; }
.progress li.done { color: var(--text); }
.progress li.done::before, .progress li.done::after { background: var(--ok); }
.progress li.done::before { content: "✓"; }
.progress li.current { font-weight: 700; }
.progress.rejected li.current { color: var(--danger); }
.progress.rejected li.current::before { background: var(--danger); content: "✕"; }

.files { list-style: none; padding: 0; margin: 0 0 12px; }
.files li { padding: 6px 0; border-bottom: 1px dashed var(--line); display: flex; flex-wrap: wrap; gap: 4px 12px; }
.files li span { font-size: .85rem; }
/* Positionen im Formular */
.wide-form { max-width: 860px; }
.positions { margin-bottom: 18px; }
.pos-row { display: grid; grid-template-columns: minmax(0, 1fr) 90px 110px 150px 92px; gap: 8px; align-items: end; margin-bottom: 8px; }
.pos-row label { margin: 0; font-size: .85rem; }
.pos-row label small { font-weight: 400; }
.pos-row:not(:first-child) label > span { display: none; }  /* Beschriftung nur über der ersten Zeile */
.pos-werte { display: contents; }   /* am PC: Felder direkt im Raster der Zeile */
.pos-btns { display: flex; gap: 4px; }
.pos-btn { width: 44px; height: 44px; border-radius: 8px; border: 1px solid #c9ced6; background: #fff; font: inherit; font-size: 1.3rem; font-weight: 700; cursor: pointer; line-height: 1; }
.pos-add { background: var(--primary); border-color: var(--primary); color: #fff; }
.pos-add:hover { background: var(--primary-2); }
.pos-del { color: var(--danger); font-size: 1rem; }
.pos-row:not(:last-child) .pos-add { display: none; }       /* "+" nur in der letzten Zeile */
.pos-row:only-child .pos-del { display: none; }             /* einzige Zeile nicht löschbar */
.pos-footer { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: end; gap: 10px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.pos-moneda { margin: 0; display: flex; align-items: center; gap: 8px; }
.pos-moneda select { width: auto; margin: 0; }
.pos-total { font-size: 1rem; padding-bottom: 10px; }

/* Positionen in der Detailansicht */
.pos-table { border: 0; }
.pos-table th, .pos-table td { padding: 8px 10px; }
.pos-table tfoot td { font-weight: 700; border-bottom: 0; border-top: 2px solid var(--line); }
.mehr { display: inline-block; font-size: .78rem; font-weight: 700; color: var(--muted); background: #eef1f5; border-radius: 999px; padding: 0 7px; margin-left: 4px; vertical-align: 1px; }

/* Datei-Upload mit Drag & Drop */
.field { margin-bottom: 14px; }
.field-label { display: block; font-weight: 600; font-size: .95rem; margin-bottom: 6px; }
.dropzone { position: relative; border: 2px dashed #b8c1cc; border-radius: var(--radius); background: #f8fafc; padding: 22px 14px; text-align: center; transition: background .15s, border-color .15s; }
.dropzone input[type=file] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; margin: 0; }
.dropzone:hover, .dropzone:focus-within { border-color: var(--primary-2); }
.dropzone.drag { background: #e6effa; border-color: var(--primary-2); }
.dz-text { display: flex; flex-direction: column; align-items: center; gap: 2px; pointer-events: none; font-weight: 400; }
.dz-icon { font-size: 1.4rem; color: var(--primary-2); line-height: 1; }
.dz-list { list-style: none; padding: 0; margin: 8px 0 0; }
.dz-list:empty { display: none; }
.dz-list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 6px 10px; background: #fff; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; font-size: .92rem; overflow-wrap: anywhere; }
.dz-remove { border: 0; background: none; color: var(--danger); font-size: 1rem; cursor: pointer; padding: 4px 8px; min-width: 32px; min-height: 32px; }
.upload-form .btn { margin-top: 10px; }

.timeline { list-style: none; padding: 0; margin: 0 0 14px; }
.timeline li { border-left: 3px solid var(--line); padding: 2px 0 12px 14px; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 6px; width: 11px; height: 11px; border-radius: 50%; background: #fff; border: 2px solid #9aa3af; }
.timeline .when { font-size: .85rem; color: var(--muted); }
.timeline .comment { margin-top: 4px; background: #f8f9fb; padding: 8px 10px; border-radius: 8px; }
.comment-form textarea { margin-bottom: 8px; }

/* Handy */
@media (max-width: 760px) {
  .topbar { padding: 8px 12px; }
  .topbar nav { order: 3; flex-basis: 100%; font-size: .9rem; }
  .btn-neu { padding: 8px 12px; min-height: 38px; }
  main { padding: 12px 12px 60px; }
  .grid2 { grid-template-columns: 1fr; }
  .facts { grid-template-columns: 1fr; gap: 0; }
  .facts dt { margin-top: 8px; }
  /* Verwaltungstabellen: eine Karte pro Zeile */
  table.admin, table.admin thead, table.admin tbody, table.admin tr, table.admin td { display: block; }
  table.admin thead { display: none; }
  table.admin { border: 0; background: none; }
  table.admin tr { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; padding: 8px 12px; }
  table.admin td { border: 0; padding: 3px 0; display: flex; gap: 10px; }
  table.admin td[data-l]::before { content: attr(data-l); color: var(--muted); font-size: .85rem; min-width: 96px; flex: none; }
  .row.tight { flex-wrap: wrap; }

  /* Anforderungsliste: kompakt, zwei Zeilen pro Eintrag
     Zeile 1:  #12  Was wird benötigt …          $1,850.00 MXN
     Zeile 2:  [Status]  Projekt …                              */
  table.reqs, table.reqs tbody { display: block; }
  table.reqs thead { display: none; }
  table.reqs tr {
    display: grid; grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "nr was betrag" "status proj proj";
    gap: 2px 10px; align-items: center; padding: 9px 12px; border-bottom: 1px solid var(--line);
  }
  table.reqs td { display: block; border: 0; padding: 0; min-width: 0; }
  table.reqs tr { grid-template-columns: 5.6rem minmax(0, 1fr) auto; }
  table.reqs .c-nr { grid-area: nr; font-size: .9rem; }
  table.reqs .c-was { grid-area: was; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  table.reqs .c-betrag { grid-area: betrag; font-size: .9rem; font-weight: 600; }
  table.reqs .c-status { grid-area: status; }
  table.reqs .c-status .badge.urg-eilig, table.reqs .c-status .badge.urg-sofort { display: none; }
  table.reqs .c-proj { grid-area: proj; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: .88rem; }
  table.reqs .c-menge, table.reqs .c-von, table.reqs .c-fecha { display: none; }
  table.reqs tr.urg-row-sofort, table.reqs tr.urg-row-eilig { box-shadow: inset 4px 0 0 var(--danger); }
  table.reqs tr.urg-row-eilig { box-shadow: inset 4px 0 0 #e8a33d; }
  table.reqs tr td:first-child { box-shadow: none; }

  table.reqs .c-was { display: flex; align-items: center; gap: 4px; }
  table.reqs .c-was a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
  table.reqs .c-was .mehr { flex: none; }

  /* Positionen: oben Bezeichnung + Knöpfe, darunter Menge | Einheit | Preis */
  .pos-row { grid-template-columns: minmax(0, 1fr) 92px; grid-template-areas: "text btns" "werte werte";
             padding-bottom: 10px; border-bottom: 1px dashed var(--line); }
  .pos-row .pos-text { grid-area: text; }
  .pos-row .pos-btns { grid-area: btns; justify-content: flex-end; }
  .pos-row .pos-werte { grid-area: werte; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .pos-row:not(:first-child) label > span { display: block; }
  .pos-row:not(:first-child) .pos-text > span { display: none; }
  .pos-row .pos-preis small { display: none; }
  .pos-table .c-preis { display: none; }
  .pos-table { font-size: .88rem; }
  .pos-table th, .pos-table td { padding: 7px 6px; }
  .pos-table td.num { white-space: nowrap; }
  .filter-panel { grid-template-columns: 1fr; }
  .chip-filter { margin-left: 0; }
  .progress li { font-size: .72rem; }
}

/* Stornieren / Löschen / Bestellung bearbeiten */
.st-storniert { background: #fdecea; color: #a1281d; }
.st-geloescht { background: #3f3f46; color: #fff; }
.chip.on.st-storniert { background: var(--primary); color: #fff; }
.banner { padding: 12px 16px; border-radius: var(--radius); margin: 4px 0 16px; border: 1px solid; }
.banner-danger { background: #fdecea; border-color: #f2b8b5; color: #7a1a12; }
.danger-box { background: #fff7f6; border: 1px solid #f2b8b5; border-radius: 8px; padding: 12px; }
.danger-box[hidden], .pedido-form[hidden] { display: none; }
.card-head .btnrow { gap: 6px; }
.pedido-pos { display: grid; grid-template-columns: minmax(0, 1fr) 130px 170px; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.pedido-pos label { margin: 0; }
.pedido-pos input { margin-top: 0 !important; }
.pedido-kopf { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; border-bottom-width: 2px; }
.pp-label { display: none; }
.mt { margin-top: 14px; }
@media (max-width: 760px) {
  .pedido-kopf { display: none; }
  .pedido-pos { grid-template-columns: 1fr 1fr; }
  .pedido-pos .pp-text { grid-column: 1 / -1; font-weight: 600; }
  .pp-label { display: block; font-size: .8rem; color: var(--muted); font-weight: 600; }
  .card-head { flex-wrap: wrap; }
}

/* Filter: Betrags- und Datumsbereich */
.filter-panel label small { display: block; font-weight: 400; margin-top: 4px; }
.filter-range { margin-bottom: 14px; }
.filter-range legend { font-size: .95rem; }
.range-row { display: flex; gap: 8px; align-items: center; }
.range-row input, .range-row select { margin: 0 !important; min-width: 0; flex: 1; }
.range-row select { flex: 1.2; }
@media (max-width: 760px) {
  .range-row { flex-wrap: wrap; }
  .range-row input { flex: 1 1 40%; }
  .range-row select { flex: 1 1 100%; }
}
