/* =======================================================================
   app.css  –  Kundenbestellung MVP
   Alle Design-Tokens in :root anpassen, um Layout & Aussehen zu steuern.
   ======================================================================= */

/* -----------------------------------------------------------------------
   1. CSS-Variablen (Design Tokens) – zentrale Steuerung
   ----------------------------------------------------------------------- */
:root {
  /* Seitenfarben */
  --color-bg:           #f6f7f9;
  --color-card:         #ffffff;
  --color-text:         #111111;
  --color-muted:        #666666;
  --color-border:       #e5e7eb;
  --color-shadow:       0 1px 4px rgba(0,0,0,.08);

  /* Markenfarben */
  --color-brand:        #111111;
  --color-brand2:       #444444;
  --color-danger:       #b00020;

  /* Badge */
  --color-badge-bg:     #eef2ff;
  --color-badge-border: #dbeafe;

  /* === Sidebar (linke Navigation) === */
  --sidebar-width:      220px;    /* Breite der Seitenleiste */
  --sidebar-bg:         #1a1d23;  /* Hintergrundfarbe */
  --sidebar-text:       #e8eaed;  /* Textfarbe */
  --sidebar-brand-size: 15px;     /* Logo-Schriftgröße */

  /* === Topbar (nur mobil sichtbar) === */
  --topbar-height:      52px;
  --topbar-bg:          var(--sidebar-bg);

  /* === Nav-Gruppen-Akzentfarben === */
  --nav-color-customer: #78b4ff;
  --nav-color-product:  #8ce6aa;
  --nav-color-supplier: #ffbe78;

  /* === Inhaltsbereich === */
  --content-max-width:  1100px;
  --content-padding:    16px;

  /* === Abstände === */
  --space-xs:  6px;
  --space-sm:  10px;
  --space-md:  14px;
  --space-lg:  20px;

  /* === Radien === */
  --radius-sm:   8px;
  --radius-md:  12px;
  --radius-lg:  16px;
  --radius-pill: 999px;

  /* Rückwärtskompatibilität (alte Variablennamen bleiben gültig) */
  --bg:          var(--color-bg);
  --card:        var(--color-card);
  --text:        var(--color-text);
  --muted:       var(--color-muted);
  --border:      var(--color-border);
  --shadow:      var(--color-shadow);
  --brand:       var(--color-brand);
  --brand2:      var(--color-brand2);
  --danger:      var(--color-danger);
  --badgeBg:     var(--color-badge-bg);
  --badgeBorder: var(--color-badge-border);
}

/* -----------------------------------------------------------------------
   2. Reset & Basis
   ----------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
}

/* -----------------------------------------------------------------------
   3. Haupt-Layout – Sidebar + Inhaltsbereich
   ----------------------------------------------------------------------- */
.layout {
  display: flex;
  min-height: 100vh;
}

/* -----------------------------------------------------------------------
   4. Sidebar (linke Navigation)
   ----------------------------------------------------------------------- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 100;
  flex-shrink: 0;
  transition: transform 0.25s ease;
}

.sidebar::-webkit-scrollbar        { width: 4px; }
.sidebar::-webkit-scrollbar-thumb  { background: rgba(255,255,255,.2); border-radius: 2px; }

/* Logo / Markenname */
.sidebar__brand {
  padding: 18px 16px;
  font-weight: 700;
  font-size: var(--sidebar-brand-size);
  letter-spacing: 0.01em;
  border-bottom: 1px solid rgba(255,255,255,.1);
  flex-shrink: 0;
}
.sidebar__brand a {
  color: var(--sidebar-text);
  text-decoration: none;
}

/* Navigationsbereich */
.sidebar__nav {
  flex: 1;
  padding: 10px 0;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Benutzer-Fußzeile */
.sidebar__footer {
  padding: 12px 14px;
  border-top: 1px solid rgba(255,255,255,.1);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sidebar__user-badge {
  font-size: 12px;
  color: rgba(255,255,255,.6);
  word-break: break-all;
}
.sidebar__user-role {
  display: inline-block;
  margin-top: 2px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: rgba(255,255,255,.4);
}

/* -----------------------------------------------------------------------
   5. Sidebar Navigation – Gruppen & Links
   ----------------------------------------------------------------------- */
.nav-group {
  padding: 6px 10px 10px;
  margin-bottom: 2px;
}
.nav-group + .nav-group {
  border-top: 1px solid rgba(255,255,255,.07);
}

.nav-title {
  display: block;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  padding: 6px 8px 5px;
  color: rgba(255,255,255,.45);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-group-customers .nav-title { color: var(--nav-color-customer); }
.nav-group-products  .nav-title { color: var(--nav-color-product);  }
.nav-group-suppliers .nav-title { color: var(--nav-color-supplier); }

.nav-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,.8);
  text-decoration: none;
  font-size: 13.5px;
  line-height: 1.35;
  transition: background 0.15s, color 0.15s;
  white-space: normal;
  margin-bottom: 1px;
}
.nav-link:hover {
  background: rgba(255,255,255,.1);
  color: #fff;
}
.nav-link.is-active {
  background: rgba(255,255,255,.15);
  color: #fff;
  font-weight: 600;
}
.nav-link.danger        { color: #ff9898; }
.nav-link.danger:hover  { color: #ffbaba; background: rgba(255,0,0,.12); }

/* Farbiger linker Balken beim aktiven Link je Gruppe */
.nav-group-customers .nav-link.is-active { box-shadow: -3px 0 0 var(--nav-color-customer) inset; }
.nav-group-products  .nav-link.is-active { box-shadow: -3px 0 0 var(--nav-color-product)  inset; }
.nav-group-suppliers .nav-link.is-active { box-shadow: -3px 0 0 var(--nav-color-supplier) inset; }

/* -----------------------------------------------------------------------
   6. Seiteninhalt-Wrapper (rechts neben Sidebar)
   ----------------------------------------------------------------------- */
.page-wrap {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* -----------------------------------------------------------------------
   7. Topbar (nur auf Mobilgeräten sichtbar)
   ----------------------------------------------------------------------- */
.topbar {
  display: none;
  height: var(--topbar-height);
  background: var(--topbar-bg);
  color: #fff;
  padding: 0 14px;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 90;
  flex-shrink: 0;
}
.topbar__brand {
  font-weight: 700;
  font-size: 15px;
}

/* Hamburger-Button */
.nav-toggle {
  display: none;
  background: transparent;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  cursor: pointer;
  min-height: 40px;
  min-width: 40px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 4px;
  touch-action: manipulation;
}
.nav-toggle__bar {
  display: block;
  width: 18px;
  height: 2px;
  background: #fff;
  border-radius: 2px;
}

/* -----------------------------------------------------------------------
   8. Hauptinhalt (.main)
   ----------------------------------------------------------------------- */
.main {
  padding: var(--content-padding);
  width: 100%;
  max-width: var(--content-max-width);
  margin: 0 auto;
  flex: 1;
}

/* Alias für Seiten die .container nutzen */
.container {
  padding: var(--content-padding);
  max-width: var(--content-max-width);
  margin: 0 auto;
}

/* -----------------------------------------------------------------------
   9. Karten (Cards)
   ----------------------------------------------------------------------- */
.card {
  background: var(--color-card);
  border-radius: var(--radius-md);
  padding: var(--content-padding);
  box-shadow: var(--color-shadow);
  margin-bottom: 12px;
  border: 1px solid rgba(0,0,0,.03);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.card-narrow { max-width: 520px; margin-left: auto; margin-right: auto; }

/* -----------------------------------------------------------------------
   10. Typografie & Abstände
   ----------------------------------------------------------------------- */
h1, h2, h3 { margin: 0 0 10px 0; }
.mt-1 { margin-top: var(--space-sm); }
.mt-2 { margin-top: var(--space-md); }
.mt-3 { margin-top: var(--space-lg); }
.muted { color: var(--color-muted); font-size: 13px; }

/* -----------------------------------------------------------------------
   11. Badges
   ----------------------------------------------------------------------- */
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  background: var(--color-badge-bg);
  border: 1px solid var(--color-badge-border);
  font-size: 12px;
  color: #111;
}

/* -----------------------------------------------------------------------
   12. Formulare
   ----------------------------------------------------------------------- */
label { display: block; font-weight: 600; margin-bottom: 6px; }
input[type=text],
input[type=password],
input[type=number],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 16px; /* verhindert iOS-Zoom */
  background: #fff;
  color: #111;
}
textarea { min-height: 90px; }

.row      { display: grid; grid-template-columns: 1fr 1fr;     gap: 12px; }
.row3     { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.grid2    { display: grid; grid-template-columns: 1fr 1fr;     gap: 12px; }
.form-grid{ display: grid; grid-template-columns: 1fr 1fr;     gap: 12px; }

.inline  { display: inline; }
.nowrap  { white-space: nowrap; }

.checkbox {
  display: flex;
  gap: 10px;
  align-items: center;
  font-weight: 600;
}
.checkbox input {
  width: auto;
  min-width: 18px;
  min-height: 18px;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.field {} /* Wrapper-Klasse, absichtlich leer */

/* -----------------------------------------------------------------------
   13. Buttons
   ----------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--color-brand);
  color: #fff;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  font-size: 15px;
  text-decoration: none;
  min-height: 42px;
  touch-action: manipulation;
  white-space: nowrap;
}
.btn.secondary { background: var(--color-brand2); }
.btn.danger    { background: var(--color-danger); }
.btn:active    { transform: translateY(1px); }
.btn[disabled] { opacity: .6; cursor: not-allowed; transform: none; }

.btn-small    { padding: 8px 12px; font-size: 14px; border-radius: var(--radius-sm); min-height: 34px; }
.inline-form  { display: inline; margin: 0; }

/* -----------------------------------------------------------------------
   14. Tabellen
   ----------------------------------------------------------------------- */
table { width: 100%; border-collapse: collapse; min-width: 820px; }
th, td { padding: 10px; border-bottom: 1px solid #eee; vertical-align: top; }
th {
  text-align: left;
  font-size: 14px;
  color: #333;
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.w-26 { width: 26%; }
.w-14 { width: 14%; }
.w-12 { width: 12%; }
.w-10 { width: 10%; }
.num  { text-align: right; white-space: nowrap; }

/* -----------------------------------------------------------------------
   15. Status & Hilfsmittel
   ----------------------------------------------------------------------- */
.ok   { color: #0a7; }
.warn { color: #c70; }
.err  { color: var(--color-danger); }

.flex      { display: flex; }
.align-end { align-items: flex-end; }
.gap-2     { gap: 8px; }

.row-warn  { background: rgba(255,200,0,.12); }

.cw-truncate {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

/* -----------------------------------------------------------------------
   16. Alerts
   ----------------------------------------------------------------------- */
.alert {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin: 10px 0;
}
.alert-error { background: #ffecec; border: 1px solid #ffb4b4; }
.alert-info  { background: #eef6ff; border: 1px solid #b8d9ff; }

/* -----------------------------------------------------------------------
   17. Mengen-Eingabe (Kundenbestellung)
   ----------------------------------------------------------------------- */
.qty-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(90px, 1fr));
  gap: .5rem;
}
.qty-grid--single { grid-template-columns: minmax(140px, 1fr); }

.qty-field span {
  display: block;
  font-size: .85rem;
  opacity: .85;
  margin-bottom: .25rem;
}
.qty-input {
  width: 100%;
  padding: .6rem .7rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 1.05rem;
}
.qty-hint {
  margin-top: .35rem;
  font-size: .85rem;
  opacity: .8;
}

/* -----------------------------------------------------------------------
   18. Lager-Anzeige (Stk / VE / kg)
   ----------------------------------------------------------------------- */
.stock-stack {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  align-items: flex-start;
}
.stock-metric {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 52px;
}
.stock-val,
.stock-lbl {
  font-weight: 700;
  font-size: 16px;
  line-height: 1.1;
}

/* -----------------------------------------------------------------------
   19. Aktions-Buttons Kundenliste
   ----------------------------------------------------------------------- */
.co-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* -----------------------------------------------------------------------
   20. Lieferschein – Mehrseitige Ansicht
   ----------------------------------------------------------------------- */
.cw-doc-header     { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.cw-doc-title      { margin: 0 0 6px 0; font-size: 1.25rem; }
.cw-doc-actions    { display: flex; gap: 8px; flex-wrap: wrap; }
.cw-upload-card    { padding: 12px; }
.cw-label          { display: block; font-weight: 600; margin: 8px 0 6px; }
.cw-input          { width: 100%; font-size: 16px; padding: 12px; border-radius: var(--radius-sm); border: 1px solid rgba(0,0,0,.15); background: #fff; }
.cw-inline-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.cw-sticky-notice  { position: sticky; top: 8px; z-index: 10; background: var(--color-card); border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: 10px; }
.cw-page-grid      { display: grid; grid-template-columns: 1fr; gap: 12px; margin-top: 10px; }
.cw-page-card      { border: 1px solid rgba(0,0,0,.12); border-radius: var(--radius-md); overflow: hidden; background: #fff; }
.cw-page-head      { padding: 10px 12px; border-bottom: 1px solid rgba(0,0,0,.08); display: flex; gap: 10px; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; }
.cw-page-img       { display: block; width: 100%; height: auto; }
.cw-page-foot      { padding: 10px 12px; border-top: 1px solid rgba(0,0,0,.08); display: flex; justify-content: flex-end; }

/* -----------------------------------------------------------------------
   21. Responsive Breakpoints
   ----------------------------------------------------------------------- */

/* Lieferschein-Grid ab Tablet/Desktop */
@media (min-width: 900px)  { .cw-page-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1200px) { .cw-page-grid { grid-template-columns: repeat(3, 1fr); } }

/* --- Tablet & Mobile (< 900px) ---------------------------------------- */
@media (max-width: 899px) {

  /* Sidebar verstecken; Topbar & Hamburger einblenden */
  .sidebar          { transform: translateX(-100%); }
  body.nav-open .sidebar { transform: translateX(0); }
  .topbar           { display: flex; }
  .nav-toggle       { display: inline-flex; }

  /* Inhaltsbereich ohne Sidebar-Offset */
  .page-wrap        { margin-left: 0; }

  /* Grids einspannen */
  .row, .row3, .grid2, .form-grid { grid-template-columns: 1fr; }

  /* Tabellen-Header-Fixierung entfernen */
  th { position: static; }

  /* Tabellen → Card-Ansicht */
  .card { overflow-x: visible; }
  table { min-width: 0; border-collapse: separate; border-spacing: 0 10px; }
  thead { display: none; }
  tbody, tr, td { display: block; width: 100%; }
  tr {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--color-shadow);
    padding: 10px;
    margin-bottom: 10px;
  }
  td {
    border-bottom: none;
    padding: 8px 4px;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    min-width: 0;
  }
  td::before {
    content: attr(data-label);
    font-weight: 700;
    color: var(--color-muted);
    flex: 0 0 42%;
    max-width: 42%;
  }
  td > * { max-width: 58%; overflow-wrap: anywhere; word-break: break-word; }

  /* Aktionszelle */
  .co-actions {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }
  .co-actions .btn { width: 100%; }
  .co-actions::before {
    content: "Aktion";
    font-weight: 700;
    color: var(--color-muted);
    margin-bottom: 4px;
    font-size: 13px;
  }
}

/* --- Kleine Phones (< 520px) ------------------------------------------ */
@media (max-width: 519px) {
  .main, .container { padding: var(--space-sm); }
  .btn              { width: 100%; }
  .qty-grid         { grid-template-columns: 1fr; }
  .nav-link         { white-space: normal; line-height: 1.2; }
}

/* Abdunkel-Overlay wenn Sidebar auf Mobilgerät geöffnet ist */
body.nav-open::before {
  content: '';
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 99;
  pointer-events: auto;
}
