/* Flaches Design: Schwarz, Grautöne und Gelb (#FFE000) als Akzent – passend zum Logo */
:root {
  --black: #1d1d1b;
  --yellow: #ffe000;
  --yellow-hover: #f2d400;
  --yellow-soft: #fff8c2;
  --gray-50: #f5f5f4;
  --gray-100: #ebebea;
  --gray-200: #d6d6d4;
  --gray-500: #6e6e6b;
  --white: #ffffff;
  --red: #c62828;
  --red-soft: #fdecea;
  --green: #0AA648;
  --orange: #FF9F22;
  --mint: #3CE5F4;
  --purple: #7C01B9;
  --radius: 2px;
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--gray-50);
  color: var(--black);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* --- Kopfleiste mit Logo --- */

.topbar {
  background: var(--white);
  border-bottom: 4px solid var(--yellow);
}
.topbar-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 16px;
}
.logo { display: block; height: 80px; width: 196px; }
/* Hauptmenü in der Kopfleiste */
.main-menu { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.main-menu a {
  color: var(--black);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  padding: 8px 14px;
  background: var(--gray-100);
  border-radius: var(--radius);
}
.main-menu a:hover { background: var(--gray-200); }
.main-menu a.active { background: var(--yellow); }

/* Startseite: Kacheln */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.tile {
  display: grid; align-content: start; gap: 8px; min-height: 160px; padding: 24px;
  background: var(--white); color: var(--black); text-decoration: none;
  border-top: 6px solid var(--yellow); border-radius: var(--radius);
}
.tile:hover { background: var(--yellow-soft); }
.tile-title { display: flex; align-items: center; gap: 10px; font-size: 1.35rem; font-weight: 800; }
.tile-text { color: var(--gray-500); }
.tile-count { padding: 2px 10px; background: var(--black); color: var(--yellow); font-size: 0.9rem; border-radius: 999px; }

/* LS-Listen (Fertige LS, Freigegebene LS, Offene LS) */
.list-head { display: flex; gap: 8px; align-items: center; }
.list-head input[type="search"] { flex: 1; margin: 0; }
.table-scroll { overflow-x: auto; }
.orders-table td { vertical-align: middle; padding-top: 22px; padding-bottom: 22px; }
.order-header { margin-top: 2px; font-size: 0.875rem; }
.order-header.has-suffix { color: var(--red); }
.storno-note { margin-top: 4px; color: var(--red); font-size: 0.85rem; font-weight: 600; }
.row-actions button { padding: 6px 12px; font-size: 0.85rem; }
.toggle { display: inline-flex; align-items: center; gap: 6px; margin-top: 10px; font-size: 0.9rem; cursor: pointer; }
.toggle input { accent-color: var(--black); }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; white-space: nowrap; }
.row-actions-stack { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.row-actions .button { padding: 6px 12px; font-size: 0.85rem; }

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 16px 64px;
}

h1 {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin: 0 0 24px;
}
h2 {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0 0 16px;
}

a { color: var(--black); text-decoration-color: var(--yellow); text-decoration-thickness: 2px; text-underline-offset: 3px; }
code { font-family: ui-monospace, Menlo, monospace; font-size: 0.875em; }

.muted { color: var(--gray-500); }

section {
  background: var(--white);
  padding: 24px;
  margin-bottom: 16px;
  border-radius: var(--radius);
}

/* --- Schrittanzeige --- */

.steps {
  display: flex;
  gap: 4px;
  list-style: none;
  padding: 0;
  margin: 0 0 16px;
  counter-reset: step;
  font-size: 0.875rem;
}
.steps li {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--gray-100);
  color: var(--gray-500);
  counter-increment: step;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.steps li::before {
  content: counter(step);
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--gray-200);
  color: var(--black);
  font-weight: 700;
  font-size: 0.75rem;
}
.steps li.done { background: var(--black); color: var(--white); }
.steps li.done::before { background: var(--yellow); }
.steps li.active { background: var(--yellow); color: var(--black); font-weight: 700; }
.steps li.active::before { background: var(--black); color: var(--yellow); }

/* --- Formularelemente --- */

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row label { font-weight: 600; margin-right: 4px; }
.stack { display: grid; gap: 8px; justify-items: start; max-width: 360px; }
.stack label { font-weight: 600; }
.stack input { width: 100%; }
.stack button { margin-top: 8px; }

input, select, textarea, button, .button {
  font: inherit;
  border-radius: var(--radius);
}
input:not([type="radio"]):not([type="file"]), select, textarea {
  padding: 10px 12px;
  border: 0;
  border-bottom: 2px solid var(--gray-200);
  background: var(--gray-50);
  color: var(--black);
}
input:not([type="radio"]):not([type="file"]):focus, select:focus, textarea:focus {
  outline: none;
  border-bottom-color: var(--black);
  background: var(--white);
}
textarea { width: 100%; font-family: ui-monospace, Menlo, monospace; font-size: 0.875rem; }
input[type="search"] { width: 100%; margin-bottom: 8px; }
input[type="radio"] { accent-color: var(--black); }
select { max-width: 100%; }

input[type="file"] { font-size: 0.875rem; }
input[type="file"]::file-selector-button {
  font: inherit;
  font-weight: 600;
  margin-right: 12px;
  padding: 8px 14px;
  border: 0;
  border-radius: var(--radius);
  background: var(--black);
  color: var(--white);
  cursor: pointer;
}
input[type="file"]::file-selector-button:hover { background: #3a3a37; }

button, .button {
  display: inline-block;
  padding: 10px 20px;
  border: 0;
  background: var(--yellow);
  color: var(--black);
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
}
button:hover:not(:disabled), .button:hover { background: var(--yellow-hover); }
button.secondary, .button.secondary { background: var(--gray-100); font-weight: 600; }
button.secondary:hover:not(:disabled), .button.secondary:hover { background: var(--gray-200); }
button:disabled { opacity: 0.4; cursor: default; }
:focus-visible { outline: 2px solid var(--black); outline-offset: 2px; }

button.link {
  justify-self: start;
  padding: 0;
  background: none;
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: underline;
  text-decoration-color: var(--yellow);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}
button.link:hover:not(:disabled) { background: none; text-decoration-color: var(--black); }

.actions { display: flex; gap: 8px; margin-top: 24px; flex-wrap: wrap; }

/* --- Kunde, Adressen --- */

.card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 16px;
  padding: 16px;
  background: var(--gray-50);
  border-left: 4px solid var(--yellow);
}

.choices { display: grid; gap: 6px; }
.choice {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px 14px;
  background: var(--gray-50);
  border-left: 4px solid transparent;
  cursor: pointer;
}
.choice:hover { background: var(--gray-100); }
.choice:has(input:checked) { background: var(--yellow-soft); border-left-color: var(--yellow); }
.choice input { margin-top: 5px; }
.address { white-space: pre-line; }
.tag { display: inline-block; margin-bottom: 4px; padding: 1px 8px; background: var(--black); color: var(--yellow); font-size: 0.75rem; font-weight: 700; border-radius: var(--radius); }
.choice .tag + .address { display: block; }

/* Kundenvorschläge (ohne Kundennummer im PDF) */
.suggestions { margin: 8px 0 16px; }
.suggestions h3 { margin: 0 0 4px; font-size: 1rem; }
.suggestion .address { margin-top: 2px; }
.reasons { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.reason { padding: 1px 8px; background: var(--yellow-soft); font-size: 0.75rem; font-weight: 600; border-radius: var(--radius); }
.reason-knr { background: var(--black); color: var(--yellow); }
.suggestions { margin-top: 16px; }

/* Formular „Neuen Kunden anlegen“ */
.new-customer { margin-top: 24px; padding: 20px; background: var(--gray-50); border-left: 4px solid var(--yellow); }
.new-customer h3 { margin: 0 0 4px; font-size: 1rem; }
.form-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px 16px; margin-top: 16px; }
.form-grid label { display: grid; gap: 4px; font-size: 0.8rem; font-weight: 600; color: var(--gray-500); }
.form-grid input:not([type="radio"]):not([type="file"]) { width: 100%; background: var(--white); color: var(--black); font-weight: 400; }
.form-grid .span-2 { grid-column: span 2; }

/* Schritt „Bemerkungen“: Original oben, bearbeitbare Überarbeitung darunter */
.remarks { display: grid; gap: 20px; }
.remarks label { display: grid; gap: 6px; }
.remarks-label { font-size: 0.8rem; font-weight: 700; color: var(--gray-500); text-transform: uppercase; letter-spacing: 0.04em; }
.remarks-label .muted { text-transform: none; letter-spacing: 0; font-weight: 400; }
.remarks-original { margin-top: 6px; padding: 12px 14px; background: var(--gray-50); border-left: 4px solid var(--gray-200); white-space: pre-line; color: var(--gray-500); }
.remarks textarea { font-family: inherit; font-size: 1rem; line-height: 1.5; resize: vertical; border-left: 4px solid var(--yellow); }

/* Schritt 1: PDF aus Google Drive oder hochladen */
.drive-panel { margin-bottom: 20px; }
.drive-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.drive-head h3 { margin: 0 8px 0 0; font-size: 1rem; }
.drive-head input[type="search"] { flex: 1; min-width: 200px; width: auto; margin: 0; }
.drive-list { display: grid; gap: 4px; }
.drive-file {
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center;
  width: 100%; padding: 10px 12px; text-align: left; font-weight: 400;
  background: var(--gray-50); border-left: 4px solid transparent;
}
.drive-file:hover:not(:disabled) { background: var(--gray-100); }
.drive-file.selected { background: var(--yellow-soft); border-left-color: var(--yellow); }
.drive-file .tag { margin: 0; }
.drive-row { display: flex; gap: 4px; }
.drive-row .drive-file { flex: 1; min-width: 0; }
.drive-view { display: flex; align-items: center; padding: 0 16px; font-size: 0.875rem; }
.drive-name { overflow-wrap: anywhere; }
.pdf-source { margin: 12px 0 0; font-weight: 600; }

/* --- Meldungen --- */

.error, .warnings {
  padding: 12px 16px;
  border-left: 4px solid;
}
.error { background: var(--red-soft); color: var(--red); border-color: var(--red); }
.warnings {
  background: var(--yellow-soft);
  border-color: var(--yellow);
  margin: 16px 0;
  padding-left: 36px;
}

/* --- Tabellen --- */

table { width: 100%; border-collapse: collapse; margin-top: 16px; font-size: 0.925rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--gray-100); vertical-align: top; }
th {
  color: var(--gray-500);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 2px solid var(--black);
}
tbody tr:hover { background: var(--gray-50); }
.num { text-align: right; }

.summary { display: grid; grid-template-columns: max-content 1fr; gap: 10px 24px; margin: 0; }
.summary dt { color: var(--gray-500); font-size: 0.875rem; }
.summary dd { margin: 0; font-weight: 600; }
.summary .summary-positions { margin-top: 8px; font-weight: 400; width: auto; }
.summary .summary-positions td { padding: 4px 10px 4px 0; }
.summary .summary-positions td:first-child { color: var(--gray-500); }
#done-details { margin: 16px 0 24px; }

/* --- Mapping-Hilfe --- */

.scroll { max-height: 70vh; overflow: auto; }
.scroll th { position: sticky; top: 0; background: var(--white); }
.parts-table th:nth-child(-n+2), .parts-table td:nth-child(-n+2) { width: 1%; white-space: nowrap; padding-right: 32px; }

/* Feste Spaltenbreiten, damit lange Produktnamen die Auswahlbox nicht verbreitern */
.fields-table { table-layout: fixed; }
.fields-table th:nth-child(1) { width: 25%; }
.fields-table th:nth-child(2) { width: 18%; }
.fields-table td { overflow-wrap: anywhere; }
/* Gelber Balken links an Feldern, die bereits eine Zuordnung haben */
.fields-table tr.mapped td:first-child { box-shadow: inset 4px 0 0 var(--yellow); }
.fields-table select { width: 100%; text-overflow: ellipsis; padding: 6px 8px; }
.part-selects { display: grid; gap: 4px; }
.part-selects label { font-size: 0.8rem; margin-top: 4px; }
/* Bedingte Zuordnung (z. B. „Wenn F2-2-CB1 angekreuzt ist“) */
.condition { margin-top: 8px; padding: 10px 12px; background: var(--gray-50); border-left: 4px solid var(--black); }
.condition-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; font-size: 0.85rem; }
.condition-add { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.condition-add select { flex: 1; }
.condition-add button { padding: 6px 12px; font-size: 0.85rem; }

/* Speichern-Leiste bleibt beim Scrollen am unteren Rand sichtbar */
.savebar {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  background: var(--black);
  color: var(--white);
}
.savebar .muted { color: var(--gray-200); }
.savebar .dirty { color: var(--yellow); font-weight: 700; }
.savebar button:disabled { background: #4a4a47; color: var(--gray-200); opacity: 1; }

/* Aufklappbare Bereiche (Produktliste, JSON-Ansicht) */
.collapsible { margin-bottom: 16px; background: var(--white); padding: 16px 24px; border-radius: var(--radius); }
.collapsible summary { cursor: pointer; font-weight: 700; }
.collapsible summary .muted { font-weight: 400; }
.collapsible[open] summary { margin-bottom: 16px; }

[hidden] { display: none !important; }

@media (max-width: 800px) {
  .tiles { grid-template-columns: 1fr; }
  .tile { min-height: 0; }
  .topbar-inner { flex-wrap: wrap; }
  .main-menu { justify-content: flex-start; }
  .main-menu a { padding: 6px 10px; font-size: 0.85rem; }
  .drive-file { grid-template-columns: 1fr; gap: 4px; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .steps li { font-size: 0; gap: 0; justify-content: center; padding: 10px 4px; }
  .steps li.active { font-size: 0.875rem; gap: 8px; flex: 3; }
  .logo { height: 60px; width: 147px; }
  section { padding: 16px; }
}

/* Betreffzusatz in Schritt 5 */
.subject-suffix { margin-top: 24px; max-width: 560px; }
.subject-suffix label { display: block; font-weight: 700; margin-bottom: 6px; }
.subject-suffix label .muted { font-weight: 400; }
.subject-suffix input { width: 100%; }

/* Kundennummer hinter dem Kundennamen in den LS-Listen */
.customer-number { color: #86867f; }
.customer-name { font-size: 1.05rem; }
/* Adresse in den LS-Listen: Link zu Google Maps, Unterstrich erst beim Darüberfahren */
.map-link { text-decoration: none; }
.map-link:hover { text-decoration: underline; text-decoration-color: var(--yellow); }

/* Tags im Schritt „Anlegen“ */
.order-tags { margin: 20px 0 0; padding: 0; border: 0; }
.order-tags legend { font-weight: 700; margin-bottom: 8px; padding: 0; }
.order-tags legend .muted { font-weight: 400; }
.order-tags-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px 24px; }
.order-tags-grid .check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.order-tags-grid input { accent-color: var(--black); width: 18px; height: 18px; margin: 0; }

/* Offene LS: Tag-Kacheln – Zahl immer oben rechts, auch bei zweizeiligem Namen */
.tag-tiles .tile { position: relative; }
.tag-tiles .tile-title { display: block; padding-right: 40px; font-size: 1.1rem; overflow-wrap: break-word; }
.tag-tiles .tile-count { position: absolute; top: 26px; right: 24px; }
.tag-tiles .tile-count.has-items { background: var(--red); color: var(--white); }

/* ToDo-Tags in den LS-Listen */
.todo-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.todo-tag { padding: 2px 8px; background: var(--red); color: #fff; font-size: 0.8rem; font-weight: 600; border-radius: 999px; }

/* Fenster „Tags“ */
.tag-dialog { width: min(640px, calc(100vw - 32px)); padding: 24px; border: 0; border-radius: var(--radius); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25); }
.tag-dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
.tag-dialog h3 { margin: 0 0 4px; }
.tag-dialog .muted { margin: 0 0 16px; }
.tag-dialog .order-tags-grid { margin-bottom: 8px; }

/* Startseite: Kacheln zweispaltig (auf schmalen Bildschirmen untereinander) */
.tiles.tiles-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 800px) {
  .tiles.tiles-2 { grid-template-columns: 1fr; }
}


/* Tag-Farben (config.php → order_tags: 'Bezeichnung' => 'Farbe') */
.todo-tag.tag-red { background: var(--red); color: var(--white); }
.todo-tag.tag-green { background: var(--green); color: var(--white); }
.todo-tag.tag-orange { background: var(--orange); color: var(--black); }
.todo-tag.tag-mint { background: var(--mint); color: var(--black); }
.todo-tag.tag-yellow { background: var(--yellow); color: var(--black); }
.todo-tag.tag-black { background: var(--black); color: var(--white); }

/* Kacheln auf „Offene LS“ / „Archiv ToDo“: oberer Rand in der Farbe des Tags */
.tag-tiles .tile-red { border-top-color: var(--red); }
.tag-tiles .tile-green { border-top-color: var(--green); }
.tag-tiles .tile-orange { border-top-color: var(--orange); }
.tag-tiles .tile-mint { border-top-color: var(--mint); }
.tag-tiles .tile-yellow { border-top-color: var(--yellow); }
.tag-tiles .tile-black { border-top-color: var(--black); }

/* „Alle offenen LS“: breite, flache Kachel über den Tag-Kacheln */
.tag-tiles .tile-all { grid-column: 1 / -1; min-height: 0; padding-top: 18px; padding-bottom: 18px; }
.tag-tiles .tile-all .tile-count { top: 18px; }

/* Nummer vor dem Tag-Namen auf „Offene LS“ */
.tag-tiles .tile-number { color: inherit; }
