/* Materialplaner – Oberfläche
   Ruhige Werkstatt-Optik: kühles Grau als Grundton, ein einziger Signalton
   für Konflikte. Die Aufmerksamkeit gehört dem Raster, nicht der Dekoration. */

:root {
  --ink:     #16202b;
  --paper:   #eceef1;
  --panel:   #ffffff;
  --line:    #d3d9df;
  --line-2:  #e6eaee;
  --muted:   #66737f;
  --accent:  #0f5c58;
  --danger:  #a32a2a;

  --c-full:  #e8f0ea;
  --c-part:  #f8e7c4;
  --c-none:  #f1d6d6;
  --c-over:  #a32a2a;

  --radius:  3px;
  --day-w:   34px;
  --label-w: 210px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

a { color: var(--accent); }
a:hover { color: var(--ink); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ------------------------------------------------------------- Kopfzeile */

.topbar {
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 0 20px;
  background: var(--ink);
  color: #e7ecf0;
}

.topbar .brand {
  font-weight: 600;
  letter-spacing: -0.01em;
  color: #fff;
  text-decoration: none;
  padding: 14px 0;
}

.topbar nav { display: flex; gap: 4px; margin-right: auto; }

.topbar nav a {
  color: #b9c4cd;
  text-decoration: none;
  padding: 15px 12px 13px;
  border-bottom: 2px solid transparent;
}
.topbar nav a:hover { color: #fff; }
.topbar nav a.on { color: #fff; border-bottom-color: #6fbfb6; }

.topbar .me {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 13px;
  color: #9fadb8;
}
.topbar .me a { color: #cfd8df; }

main { padding: 24px 20px 64px; }
main.narrow { max-width: 880px; margin: 0 auto; }
main.wide   { max-width: 1600px; margin: 0 auto; }

/* --------------------------------------------------------------- Typografie */

h1 { font-size: 25px; line-height: 1.2; letter-spacing: -0.015em; margin: 0 0 4px; }
h2 { font-size: 18px; letter-spacing: -0.01em; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 0 0 10px; }

.section-title {
  margin: 32px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}
.section-title .count {
  font-weight: 400;
  color: var(--muted);
  font-size: 14px;
}

.muted { color: var(--muted); }
.strong { font-weight: 600; color: var(--ink); text-decoration: none; }
.sub { display: block; color: var(--muted); font-size: 13px; }
.nowrap { white-space: nowrap; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0; }
.byline { color: var(--muted); font-size: 13px; margin: 4px 0 0; }
.empty {
  color: var(--muted);
  background: var(--panel);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 18px;
}

.pagehead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.pagehead p { margin: 0; }
.pagehead .actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ------------------------------------------------------------- Bausteine */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}
.card.info { white-space: normal; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { border-color: #9aa6b1; color: var(--ink); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn.primary:hover { background: #0b4a47; color: #fff; }
.btn.danger { color: var(--danger); border-color: #e0c2c2; }
.btn.danger:hover { background: #fbf2f2; border-color: var(--danger); }

.linkbtn {
  background: none;
  border: 0;
  padding: 0 4px;
  font: inherit;
  font-size: 13px;
  color: var(--accent);
  cursor: pointer;
}
.linkbtn.danger { color: var(--danger); }
.linkbtn:hover { text-decoration: underline; }

form.inline { display: inline; }

.flash {
  margin: 0 0 10px;
  padding: 10px 14px;
  border-radius: var(--radius);
  border-left: 3px solid;
  font-size: 14px;
}
.flash-ok  { background: #e8f0ea; border-color: #3d7c57; }
.flash-bad { background: #f7eaea; border-color: var(--danger); }

.tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  border-radius: 20px;
  font-size: 12px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.tag.live { background: #e8f0ea; border-color: #a9c9b5; color: #2f6144; }
.tag.done { background: var(--line-2); }
.tag.open { background: #fdf3e2; border-color: #e2c690; color: #7d5a16; }

/* --------------------------------------------------------------- Formulare */

label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 7px; color: var(--ink); font-size: 14px; }

input[type=text], input[type=password], input[type=search], input[type=number],
input[type=date], input[type=email], select, textarea {
  display: block;
  width: 100%;
  min-height: 34px;
  margin-top: 4px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.35;
  /* Safari rendert Suchfelder und Auswahllisten sonst nativ und ignoriert
     dabei padding und height – die Felder fallen auf wenige Pixel zusammen. */
  -webkit-appearance: none;
  appearance: none;
}

/* Eigene Regel: fällt ein Browser über :not([type]), bleibt der Block oben heil. */
input:not([type]) {
  display: block;
  width: 100%;
  min-height: 34px;
  margin-top: 4px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.35;
  -webkit-appearance: none;
  appearance: none;
}

/* Pfeil für die Auswahllisten, da das native Element abgeschaltet ist. */
select {
  padding-right: 30px;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' fill='none' stroke='%2366737f' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

input[type=search]::-webkit-search-decoration,
input[type=search]::-webkit-search-cancel-button { -webkit-appearance: none; }

textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; }

.form .cols {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0 16px;
}
.form .actions { display: flex; gap: 10px; margin-top: 6px; }

fieldset { border: 0; padding: 0; margin: 0 0 14px; }
legend { font-size: 13px; color: var(--muted); padding: 0 0 6px; }

.swatches { display: flex; gap: 8px; align-items: center; }
.swatch input { position: absolute; opacity: 0; }
.swatch span {
  display: block;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--bar);
  cursor: pointer;
  box-shadow: 0 0 0 2px var(--panel), 0 0 0 2px var(--line);
}
.swatch input:checked + span { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--ink); }
.swatch input:focus-visible + span { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--accent); }

.auth { width: min(380px, 100%); }
.auth h1 { margin-bottom: 16px; }
.auth .btn { width: 100%; text-align: center; }

/* --------------------------------------------------------------- Tabellen */

table.list {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 14px;
}
table.list th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
}
table.list td { padding: 9px 12px; border-top: 1px solid var(--line-2); vertical-align: top; }
table.list tbody tr:hover td { background: #f7f9fa; }
table.list .num { text-align: right; font-variant-numeric: tabular-nums; }
table.list tr.grouprow td {
  background: var(--line-2);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding: 5px 12px;
}
table.list tr.grouprow:hover td { background: var(--line-2); }

.filters { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.filters label { margin-bottom: 0; }
.filters.bar {
  align-items: center;
  min-height: 60px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 14px;
}
.filters input, .filters select {
  flex: 0 0 auto;
  width: auto;
  min-width: 180px;
}
.filters.bar > input, .filters.bar > select { margin-top: 0; }
.filters .btn { flex: 0 0 auto; }

/* Zeilen-Formulare (Einzelstücke, Benutzer) */
.unitrows { padding: 0; }
.unitrow {
  display: grid;
  grid-template-columns: 1fr 1fr 160px auto;
  gap: 10px;
  align-items: center;
  padding: 9px 14px;
  border-top: 1px solid var(--line-2);
}
.unitrow.userrow { grid-template-columns: 160px 1fr 130px 1fr auto; }
.unitrow.catedit { grid-template-columns: 1fr 130px 90px auto; }
.unitrow.priceedit { grid-template-columns: 130px 130px 130px auto; }
.unitrow:first-child { border-top: 0; }
.unitrow.head {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: var(--line-2);
}
.unitrow input, .unitrow select { margin-top: 0; }
.unitrow .nowrap { display: flex; gap: 8px; align-items: center; }

.chiplist { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; padding: 0; margin: 0 0 14px; }
.chiplist li {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px 3px 10px;
  border: 1px solid var(--line);
  border-radius: 20px;
  font-size: 13px;
}

.linelist { list-style: none; padding: 0; margin: 0; }
.linelist li {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  padding: 9px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-bottom: 0;
  font-size: 14px;
}
.linelist li:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.linelist li:last-child { border-bottom: 1px solid var(--line); border-radius: 0 0 var(--radius) var(--radius); }
.linelist a { display: flex; align-items: center; gap: 9px; text-decoration: none; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--bar); flex: none; }

/* ------------------------------------------------------- Benachrichtigungen */

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 18px; margin: 0 0 14px; font-size: 14px; }
.facts dt { color: var(--muted); font-size: 13px; }
.facts dd { margin: 0; }

.pricebox { padding-bottom: 12px; }
.total { margin: 0; font-size: 15px; }
.total strong { font-size: 19px; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.hint.warn { color: var(--danger); }

table.list tfoot td {
  border-top: 2px solid var(--line);
  padding: 10px 12px;
  color: var(--muted);
}
table.list tfoot .strong { color: var(--ink); font-size: 15px; }

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  background: var(--line-2);
  border-radius: var(--radius);
  padding: 8px 10px;
  margin: 6px 0;
}
.mono.break { word-break: break-all; }

.logline {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  margin: 0;
  padding: 3px 10px;
  background: var(--panel);
  border-left: 3px solid var(--line);
}
.logline.bad { border-left-color: var(--danger); color: var(--danger); }
.logline:first-of-type { padding-top: 8px; }
.logline:last-of-type { padding-bottom: 8px; margin-bottom: 18px; }

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 8px;
}
.tile {
  display: block;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-decoration: none;
  color: var(--ink);
}
.tile:hover { border-color: #9aa6b1; }
.tile b { display: block; font-size: 30px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile span { font-size: 13px; color: var(--muted); }
.tile.alert b { color: var(--danger); }

/* ------------------------------------------------- Zeitstrahl & Quick-Check */

.toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.stepper { display: flex; gap: 4px; }
.toolbar .filters { flex: 1; }

.legend { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin: 0; }
.legend .key {
  width: 13px; height: 13px;
  border: 1px solid var(--line);
  border-radius: 2px;
  margin-left: 10px;
}
.legend .key.full { background: var(--c-full); }
.legend .key.part { background: var(--c-part); }
.legend .key.none { background: var(--c-none); }
.legend .key.over { background: var(--c-over); border-color: var(--c-over); }

.board {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: auto;
  max-height: 72vh;
}

.board-inner { min-width: max-content; }

/* Die Spaltenliste kommt als --cols aus dem PHP-Template: repeat() braucht
   eine echte Zahl, keine Variable. */
.row {
  display: grid;
  grid-template-columns: var(--cols);
}

.cell { min-height: 26px; }

.cell.label {
  grid-column: 1;
  grid-row: 1;
  position: sticky;
  left: 0;
  z-index: 3;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 4px 10px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.row.months, .row.dayhead { position: sticky; z-index: 5; background: var(--panel); }
.row.months { top: 0; }
.row.dayhead { top: 24px; }
.row.months .cell.label, .row.dayhead .cell.label { z-index: 6; }

.cell.month {
  grid-row: 1;
  height: 24px;
  display: flex;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
  border-left: 1px solid var(--line);
  padding-left: 7px;
  overflow: hidden;
  white-space: nowrap;
}

.cell.day {
  grid-row: 1;
  height: 34px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.1;
  border-left: 1px solid var(--line-2);
  border-bottom: 1px solid var(--line);
}
.cell.day em { font-style: normal; font-size: 9px; color: var(--muted); }
.cell.day b { font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }

.weekend { background: #f2f4f6; }
.cell.day.weekend em, .cell.day.weekend b { color: #8b98a3; }
.today { box-shadow: inset 2px 0 0 var(--accent); }
.cell.day.today b { color: var(--accent); }

.row.lane { min-height: 30px; align-items: center; }
.row.lane .cell.grid {
  grid-row: 1;
  height: 30px;
  border-left: 1px solid var(--line-2);
}

.bar {
  grid-row: 1;
  z-index: 2;
  align-self: center;
  height: 22px;
  margin: 0 2px;
  padding: 0 8px;
  border-radius: 2px;
  background: var(--bar);
  color: #fff;
  font-size: 12px;
  line-height: 22px;
  text-decoration: none;
  overflow: hidden;
  white-space: nowrap;
  position: relative;
}
.bar span { display: block; overflow: hidden; text-overflow: ellipsis; }
.bar:hover { color: #fff; filter: brightness(1.12); }
.bar.billed { opacity: 0.55; }
.bar.cut-left  { margin-left: 0;  border-radius: 0 2px 2px 0; }
.bar.cut-right { margin-right: 0; border-radius: 2px 0 0 2px; }

.empty-lane {
  grid-row: 1;
  padding: 10px;
  font-size: 13px;
  color: var(--muted);
}

.row.section { background: var(--ink); }
.row.section .cell.label {
  background: var(--ink);
  color: #fff;
  font-weight: 600;
  border-right-color: #2d3a47;
}
.section-note {
  grid-row: 1;
  color: #9fadb8;
  font-size: 12px;
  display: flex;
  align-items: center;
  padding-left: 10px;
}

.row.catrow .cell.label.cat {
  background: var(--line-2);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  min-height: 22px;
}
.cat-fill { grid-row: 1; background: var(--line-2); }

.mat-label { justify-content: space-between; }
/* Material mit hinterlegter Beschreibung: Hinweis auf den Tooltip */
.mat-label.has-note { cursor: help; }
.mat-label.has-note .mat-name { border-bottom: 1px dotted #aab4bd; }
.mat-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mat-stock {
  flex: none;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.cell.avail {
  grid-row: 1;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  border-left: 1px solid rgba(255, 255, 255, 0.75);
  border-bottom: 1px solid var(--panel);
}
.cell.avail.full { background: var(--c-full); color: #7f8d85; }
.cell.avail.part { background: var(--c-part); color: #6d5417; font-weight: 600; }
.cell.avail.none { background: var(--c-none); color: #8a3a3a; font-weight: 600; }
.cell.avail.over { background: var(--c-over); color: #fff; font-weight: 700; }
.cell.avail.weekend { filter: brightness(0.965); }

/* ------------------------------------------------------- Buchungsformular */

.bookform h2 { margin-bottom: 14px; }
.unitlist {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 6px 14px;
  max-height: 260px;
  overflow-y: auto;
}
.unitopt { display: flex; align-items: baseline; gap: 8px; font-size: 14px; color: var(--ink); margin: 0; }
.unitopt input { margin: 0; flex: none; }
.unitopt .why { color: var(--danger); font-size: 12px; }
.unitopt.blocked { color: var(--muted); }

#free-hint.warn { color: var(--danger); font-weight: 600; }

/* ------------------------------------------------------------- Kleine Screens */

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 0 16px; padding: 0 12px; }
  .topbar .me { width: 100%; padding-bottom: 10px; }
  main { padding: 16px 12px 48px; }
  :root { --label-w: 150px; --day-w: 30px; }
  .unitrow, .unitrow.userrow, .unitrow.catedit, .unitrow.priceedit { grid-template-columns: 1fr; }
  .unitrow.head { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
