/* mfw - Technische Materialverwaltung */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f5;
  --text: #1f2933;
  --muted: #68747f;
  --line: #dde3e8;
  --accent: #0f5c8c;
  --accent-text: #ffffff;
  --ok-bg: #e4f4ea;      --ok-text: #1b6b3a;
  --open-bg: #fdeeda;    --open-text: #8a5200;
  --warn-bg: #fde6e6;    --warn-text: #962121;
  --info-bg: #e5eef6;    --info-text: #1c5a85;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15191e;
    --surface: #1c2127;
    --surface-2: #232931;
    --text: #e6eaef;
    --muted: #96a1ad;
    --line: #2f3741;
    --accent: #4aa3dd;
    --accent-text: #0d1317;
    --ok-bg: #1b3326;      --ok-text: #7ddba3;
    --open-bg: #3a2d16;    --open-text: #f0c070;
    --warn-bg: #3a1f22;    --warn-text: #f09b9b;
    --info-bg: #1d2c38;    --info-text: #8ec5ea;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body.centered {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 16px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Kopfzeile ----------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: center;
  padding: 8px 0;
  color: var(--text);
}
/* Logo als Maske, damit es im hellen wie im dunklen Design sichtbar bleibt */
/* Logo als Maske, damit es im hellen wie im dunklen Design sichtbar bleibt.
   Seitenverhältnis 1,447 : 1 — Breite und Höhe immer zusammen ändern. */
/* Logo. Seitenverhältnis 1,447 : 1 — Breite und Höhe immer zusammen ändern. */
.logo { display: block; height: auto; }
.brand .logo { width: 80px; }
.brand:hover { opacity: 0.75; }
.login .logo { width: 232px; margin: 0 auto 6px; }

/* Das Logo ist einfarbig dunkel; im dunklen Design wird es umgekehrt. */
@media (prefers-color-scheme: dark) {
  .logo { filter: invert(1); }
}
.mainnav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.mainnav a {
  padding: 14px 12px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
}
.mainnav a:hover { color: var(--text); text-decoration: none; }
.mainnav a.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
/* Schnellzugriff auf das zuletzt geöffnete Projekt */
.mainnav a.zuletzt {
  align-self: center;
  margin-left: 8px;
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  font-size: 13px;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mainnav a.zuletzt::before { content: "↩ "; color: var(--muted); }
.mainnav a.zuletzt:hover { border-color: var(--accent); color: var(--accent); }
.userbox { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.who { color: var(--muted); }
.tag {
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--info-bg);
  color: var(--info-text);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

main { max-width: 1400px; margin: 0 auto; padding: 24px 20px 60px; }

h1 { font-size: 24px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 24px 0 8px; }
h3 { font-size: 14px; margin: 0; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12px; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.nowrap a { margin-left: 10px; }
.right { text-align: right; }
.center { text-align: center; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.rot { font-size: 11px; }
.mt { margin-top: 12px; }
.plain { list-style: none; padding: 0; margin: 4px 0; color: var(--muted); font-size: 13px; }

/* --- Projektleiste ------------------------------------------------------- */
.projectbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  margin-bottom: 20px;
}
.projectbar h1 { margin: 2px 0; }
.projectbar p { margin: 0 0 10px; font-size: 13px; }
.back { font-size: 12px; color: var(--muted); }
.back::before { content: "← "; }
.tabs { display: flex; gap: 2px; }
.tabs a {
  padding: 8px 14px;
  color: var(--muted);
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.on {
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
  font-weight: 600;
  margin-bottom: -1px;
  padding-bottom: 9px;
}

/* --- Karten und Formulare ------------------------------------------------ */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.card > h2:first-child, .card > h1:first-child { margin-top: 0; }
details.card > summary { cursor: pointer; }
details.card[open] > summary { margin-bottom: 14px; }

.login { width: min(380px, 100%); text-align: center; }
.login label { text-align: left; }
.login label, .login button { margin-top: 12px; }
.login button { width: 100%; }

label { display: block; font-size: 12px; color: var(--muted); }
label.check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text);
  padding: 3px 0;
}
label.check input { width: auto; margin: 0; }

input, select, textarea {
  width: 100%;
  padding: 7px 9px;
  margin-top: 3px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input:disabled, select:disabled { background: var(--surface-2); color: var(--muted); }
input[type="search"] { padding-left: 12px; }

.grid3, .grid4 { display: grid; gap: 12px; align-items: end; }
.grid3 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.grid4 .wide, .grid3 .wide { grid-column: span 2; }
.radios { display: flex; flex-direction: column; gap: 2px; margin-bottom: 12px; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row input, .row select { margin-top: 0; width: auto; flex: 1; min-width: 120px; }
.row.tight { gap: 6px; }
.w80 { flex: 0 0 72px !important; min-width: 0 !important; }
.unit { font-size: 12px; color: var(--muted); }
.qty { width: 64px !important; text-align: right; margin-top: 0; padding: 4px 6px; }
.searchbar { margin: 16px 0; max-width: 560px; }

button {
  font: inherit;
  font-size: 14px;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.small { padding: 4px 10px; font-size: 13px; }
button.danger { background: var(--warn-bg); border-color: var(--warn-bg); color: var(--warn-text); }
button.link {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font-size: 13px;
  text-decoration: underline;
}
button.link.danger { color: var(--warn-text); background: none; }

.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; font-size: 14px; }
.flash.success { background: var(--ok-bg); color: var(--ok-text); }
.flash.error { background: var(--warn-bg); color: var(--warn-text); }
.flash.info { background: var(--info-bg); color: var(--info-text); }

/* --- Tabellen ------------------------------------------------------------ */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
}
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th {
  background: var(--surface-2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
table.compact th, table.compact td { padding: 5px 8px; font-size: 13px; }
tr.inaktiv td { opacity: 0.55; }
td form { margin: 0; }
.scroll { overflow-x: auto; }
table.dispo th.supplier { writing-mode: horizontal-tb; min-width: 86px; font-size: 11px; }

/* --- Kennzahlen --------------------------------------------------------- */
.kpis { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }
.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
  min-width: 104px;
  display: flex;
  flex-direction: column;
}
.kpi .num { font-size: 20px; font-weight: 600; text-align: left; }
.kpi span:last-child { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.kpi.alarm { border-color: var(--open-text); }
.kpi.alarm .num { color: var(--open-text); }

.cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.card.mod h3 { text-transform: none; font-size: 15px; color: var(--text); letter-spacing: 0; }
.card.mod p { margin: 4px 0 10px; font-size: 12px; }

/* --- Badges ------------------------------------------------------------- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge.ok { background: var(--ok-bg); color: var(--ok-text); }
.badge.open { background: var(--open-bg); color: var(--open-text); }
.badge.warn { background: var(--warn-bg); color: var(--warn-text); }
.badge.info { background: var(--info-bg); color: var(--info-text); }
.badge.muted { background: var(--surface-2); color: var(--muted); }

/* --- Projektstruktur ---------------------------------------------------- */
section.ort { margin-bottom: 28px; }
.orthead { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.orthead h2 { margin: 0; }
section.ort > h2 {
  padding-bottom: 6px;
  border-bottom: 2px solid var(--line);
}
.addgroup { margin: 10px 0 14px; }

article.gruppe {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
}
article.gruppe > header { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
article.gruppe table { border: none; margin-bottom: 8px; background: none; }
article.gruppe th { background: none; border-bottom: 1px solid var(--line); }
.addmaterial { border-top: 1px dashed var(--line); padding-top: 10px; }

/* --- Pop-up zum Einbuchen von Material ---------------------------------- */
dialog.materialwahl {
  width: min(760px, 94vw);
  max-height: 86vh;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
dialog.materialwahl::backdrop { background: rgba(16, 20, 26, 0.55); }
dialog.materialwahl form { display: flex; flex-direction: column; max-height: 86vh; }
dialog.materialwahl header { padding: 16px 18px 0; }
dialog.materialwahl header h3 {
  margin: 0;
  font-size: 17px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
}
dialog.materialwahl header p { margin: 2px 0 0; }
dialog.materialwahl > form > input[type="search"] { margin: 12px 18px; width: auto; }

.trefferliste { overflow-y: auto; padding: 0 18px; flex: 1; }
.trefferliste h4 {
  position: sticky;
  top: 0;
  margin: 0;
  padding: 6px 0 4px;
  background: var(--surface);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.trefferliste .treffer {
  display: grid;
  grid-template-columns: 56px 1fr auto 44px;
  gap: 10px;
  align-items: baseline;
  width: 100%;
  margin: 0;
  padding: 7px 8px;
  border: none;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}
/* muss nach .treffer stehen, sonst gewinnt display:grid gegen [hidden] */
.trefferliste .treffer[hidden],
.trefferliste .gewerk-block[hidden] { display: none; }
.trefferliste .treffer:hover { background: var(--surface-2); }
.trefferliste .treffer.aktiv { background: var(--info-bg); color: var(--info-text); }
.trefferliste .treffer .bez { font-weight: 500; }
.trefferliste .treffer .einheit { text-align: right; }

dialog.materialwahl footer {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}
dialog.materialwahl footer #material-gewaehlt { flex: 1; min-width: 140px; font-size: 13px; }
dialog.materialwahl footer input { margin-top: 0; width: auto; }
dialog.materialwahl footer input[name="bemerkung"] { flex: 1; min-width: 120px; }

/* Gleiche Spaltenbreiten in allen Gruppen eines Projekts */
table.positionen { table-layout: fixed; }
table.positionen th:nth-child(1) { width: 72px; }
table.positionen th:nth-child(3) { width: 90px; }
table.positionen th:nth-child(4) { width: 86px; }
table.positionen th:nth-child(5) { width: 48px; }
table.positionen th:nth-child(7) { width: 104px; }
table.positionen th:nth-child(8) { width: 88px; }
table.positionen td { overflow: hidden; text-overflow: ellipsis; }

/* --- Drag & Drop -------------------------------------------------------- */
.handle {
  cursor: grab;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  user-select: none;
  touch-action: none;
}
.handle:hover { background: var(--surface-2); color: var(--text); }
.handle:active { cursor: grabbing; }
.sortable-ghost { opacity: 0.35; }
.sortable-drag { opacity: 0.95; }
.gruppen-liste { min-height: 8px; }
.inline-edit { font-size: 12px; }
.inline-edit > summary { cursor: pointer; color: var(--accent); }
.inline-edit form { margin: 8px 0; }

section.gewerk { margin-bottom: 24px; }
section.gewerk h2 { padding-bottom: 6px; border-bottom: 2px solid var(--line); }

/* --- Export / Transport ------------------------------------------------- */
fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin: 0 0 10px;
}
legend { padding: 0 6px; font-size: 13px; }
.gruppenwahl { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); margin: 10px 0; }
.transporthead { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.transporthead h2 { margin: 0; }
.transporthead p { margin: 2px 0; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 20px; margin: 0 0 16px; }
.kv dt { color: var(--muted); font-size: 12px; }
.kv dd { margin: 0; }

.foot {
  text-align: center;
  padding: 20px;
  font-size: 11px;
  color: var(--muted);
  border-top: 1px solid var(--line);
}
