/* MiniERP — vollständiges Stylesheet (Phase 2)
   - Desktop: linke Sidebar (klassischer ERP-Look)
   - Mobile: Bottom-Navigation + Drawer für die Sidebar
   - Datentabellen mit Sortier-Indikatoren
   - SVG-basierte Charts (inline)
   - Command-Palette + Help-Overlay
*/

:root {
  --brand:        #2563eb;
  --brand-dark:   #1d4ed8;
  --brand-soft:   #eff6ff;
  --bg:           #f8fafc;
  --surface:      #ffffff;
  --border:       #e2e8f0;
  --text:         #0f172a;
  --text-soft:    #475569;
  --text-mute:    #94a3b8;
  --green:        #16a34a;
  --green-soft:   #dcfce7;
  --red:          #dc2626;
  --red-soft:     #fee2e2;
  --yellow:       #ca8a04;
  --yellow-soft:  #fef9c3;
  --blue:         #1e40af;
  --blue-soft:    #dbeafe;
  --grey-soft:    #e2e8f0;
  --shadow-sm:    0 1px 2px rgba(15,23,42,.04);
  --shadow:       0 1px 3px rgba(15,23,42,.06), 0 1px 2px rgba(15,23,42,.04);
  --shadow-lg:    0 10px 30px rgba(15,23,42,.15);
  --radius:       10px;
  --radius-lg:    14px;
  --sidebar-w:    240px;
  --topbar-h:     56px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.45;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

/* Skip-Link */
.skip-link {
  position: absolute; top: -40px; left: 8px; background: var(--text); color: #fff;
  padding: 6px 10px; border-radius: var(--radius); z-index: 200;
}
.skip-link:focus { top: 8px; }

/* ============================================================
   Sidebar (Desktop)
   ============================================================ */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: none;
  flex-direction: column;
  z-index: 60;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  display: grid; place-items: center; color: #fff; font-size: 20px;
}
.brand-name { font-weight: 700; font-size: 15px; }
.brand-sub  { font-size: 11px; color: var(--text-mute); }

.side-nav {
  padding: 12px 8px;
  display: flex; flex-direction: column; gap: 2px;
  flex: 1; overflow-y: auto;
}
.side-section {
  font-size: 11px; color: var(--text-mute); font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em;
  padding: 14px 12px 6px;
}
.side-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-soft);
  font-weight: 500;
}
.side-link:hover { background: var(--bg); color: var(--text); }
.side-link.active {
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 600;
}
.side-link .icn {
  width: 18px; text-align: center; font-size: 16px;
}

.side-foot {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  font-size: 11px; color: var(--text-mute);
  line-height: 1.7;
}
.kbd-hint kbd + kbd { margin-left: 2px; }

/* ============================================================
   Topbar
   ============================================================ */
.topbar {
  position: fixed; top: 0; right: 0; left: 0;
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  z-index: 50;
}
.menu-btn { display: none; }
.topbar-title {
  font-weight: 600; font-size: 16px; flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-actions { display: flex; gap: 4px; }
.icon-btn {
  background: transparent; border: none;
  width: 36px; height: 36px; border-radius: 8px;
  cursor: pointer; font-size: 16px;
  color: var(--text-soft);
}
.icon-btn:hover { background: var(--bg); color: var(--text); }

/* ============================================================
   Content
   ============================================================ */
.content {
  padding: calc(var(--topbar-h) + 16px) 16px 96px;
  max-width: 1400px; margin: 0 auto;
}

/* ============================================================
   Bottom-Nav (Mobile)
   ============================================================ */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  z-index: 40;
}
.nav-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 4px 12px;
  font-size: 11px; color: var(--text-mute);
  background: none; border: none; cursor: pointer;
}
.nav-btn .nav-ico { font-size: 18px; }
.nav-btn.active { color: var(--brand); font-weight: 600; }

/* FAB */
.fab {
  position: fixed; bottom: 76px; right: 16px;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--brand); color: #fff;
  font-size: 28px; line-height: 1;
  border: none;
  box-shadow: 0 6px 16px rgba(37,99,235,.45);
  z-index: 45; cursor: pointer;
  transition: transform .12s ease;
}
.fab:hover { transform: translateY(-2px); }
.fab.hidden { display: none; }

/* ============================================================
   Drawer-Overlay (für mobile Sidebar)
   ============================================================ */
.drawer-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  z-index: 55;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
.drawer-overlay.open { opacity: 1; pointer-events: auto; }

/* ============================================================
   Karten / Panels
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}
.card-row { display: flex; gap: 12px; align-items: center; }
.card-row.clickable { cursor: pointer; }
.card-row.clickable:hover { background: var(--bg); }
.card-row .grow { flex: 1; min-width: 0; }
.card-row .title { font-weight: 600; font-size: 14px; }
.card-row .sub   { color: var(--text-soft); font-size: 12px; margin-top: 2px; }

/* KPI-Kacheln (Dashboard) */
.kpi-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  position: relative; overflow: hidden;
}
.kpi-label { font-size: 11px; color: var(--text-mute); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.kpi-value { font-size: 22px; font-weight: 700; color: var(--text); margin-top: 4px; }
.kpi-sub   { font-size: 12px; color: var(--text-soft); margin-top: 2px; }
.kpi.warn .kpi-value { color: var(--yellow); }
.kpi.danger .kpi-value { color: var(--red); }
.kpi.good .kpi-value { color: var(--green); }
.kpi-stripe {
  position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--brand);
}
.kpi.warn .kpi-stripe { background: var(--yellow); }
.kpi.danger .kpi-stripe { background: var(--red); }
.kpi.good .kpi-stripe { background: var(--green); }

/* Badges */
.badge {
  font-size: 11px; padding: 3px 8px; border-radius: 999px;
  font-weight: 600; display: inline-block;
}
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.red   { background: var(--red-soft);   color: var(--red); }
.badge.yellow{ background: var(--yellow-soft);color: var(--yellow); }
.badge.blue  { background: var(--blue-soft);  color: var(--blue); }
.badge.grey  { background: var(--grey-soft);  color: var(--text-soft); }

/* Datentabelle */
.table-wrap { overflow-x: auto; }
.table {
  width: 100%; border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.table th, .table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: middle;
}
.table th {
  background: var(--bg);
  font-weight: 600;
  font-size: 12px;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: .03em;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.table th .sort-ind { color: var(--text-mute); font-size: 10px; margin-left: 4px; }
.table th.sorted .sort-ind { color: var(--brand); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--bg); }
.table tbody tr.clickable { cursor: pointer; }
.table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; }
.table .empty { text-align: center; padding: 28px; color: var(--text-mute); }

/* Toolbar (Suche, Filter) */
.toolbar {
  display: flex; gap: 8px; align-items: center; margin-bottom: 12px;
  flex-wrap: wrap;
}
.toolbar .grow { flex: 1; min-width: 200px; }
.toolbar input[type=text], .toolbar input[type=search], .toolbar select {
  height: 38px; padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
}
.toolbar input:focus, .toolbar select:focus {
  outline: none; border-color: var(--brand);
}

/* Form-Felder */
.field { margin-bottom: 12px; }
.field label {
  display: block; font-size: 12px; color: var(--text-soft);
  margin-bottom: 4px; font-weight: 600;
}
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
.field-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: 8px;
  font-weight: 600; font-size: 13px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .12s;
  text-decoration: none;
}
.btn:hover { filter: brightness(.95); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-success { background: var(--green); color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-soft); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

/* Modal */
.modal {
  position: fixed; inset: 0; z-index: 70;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal.hidden { display: none; }
.modal-backdrop {
  position: absolute; inset: 0; background: rgba(15,23,42,.55);
}
.modal-card {
  position: relative; width: 100%;
  max-width: 720px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 0;
  max-height: 92vh; overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modalIn .18s ease-out;
}
@keyframes modalIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 16px; font-weight: 700; }
.modal-close {
  background: none; border: none; font-size: 28px;
  cursor: pointer; color: var(--text-mute);
  width: 32px; height: 32px;
  border-radius: 8px;
}
.modal-close:hover { background: var(--bg); color: var(--text); }
#modal-body {
  padding: 20px; overflow-y: auto;
}
@media (max-width: 540px) {
  .modal { padding: 0; align-items: flex-end; }
  .modal-card { border-radius: var(--radius-lg) var(--radius-lg) 0 0; max-height: 95vh; }
}

/* Toast */
.toast {
  position: fixed; bottom: 90px; left: 50%;
  transform: translateX(-50%);
  background: var(--text); color: #fff;
  padding: 10px 18px; border-radius: 10px;
  font-size: 13px; z-index: 80;
  box-shadow: var(--shadow-lg);
  animation: toastIn .2s ease-out;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* Positionen in Beleg-Form */
.pos-row {
  display: grid; gap: 6px;
  grid-template-columns: 1fr 60px 90px 70px 32px;
  margin-bottom: 6px;
  align-items: center;
}
.pos-row input, .pos-row select {
  padding: 8px 10px; font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}
.pos-row .pos-x {
  background: transparent; border: none; color: var(--text-mute);
  cursor: pointer; font-size: 18px; padding: 0;
}

/* Charts */
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 12px;
}
.chart-title { font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.chart-svg { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; font-size: 12px; color: var(--text-soft); }
.legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }

/* Dashboard-Grids */
.grid-2 {
  display: grid; gap: 12px;
  grid-template-columns: 1fr;
}
@media (min-width: 768px) {
  .grid-2 { grid-template-columns: 2fr 1fr; }
}
.grid-3 {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

/* Status-Badge Helper */
.dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  margin-right: 6px;
}
.dot.green  { background: var(--green); }
.dot.red    { background: var(--red); }
.dot.yellow { background: var(--yellow); }
.dot.grey   { background: var(--text-mute); }

/* ============================================================
   Command-Palette
   ============================================================ */
.palette {
  position: fixed; inset: 0; z-index: 90;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 80px 16px 16px;
}
.palette.hidden { display: none; }
.palette-backdrop {
  position: absolute; inset: 0; background: rgba(15,23,42,.55);
}
.palette-card {
  position: relative; width: 100%; max-width: 560px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modalIn .15s ease-out;
}
#palette-input {
  width: 100%; padding: 16px 20px;
  font-size: 16px;
  border: 0; border-bottom: 1px solid var(--border);
  outline: none;
  background: transparent;
}
#palette-results {
  max-height: 360px; overflow-y: auto;
  padding: 8px 0;
}
.palette-item {
  display: flex; gap: 10px; align-items: center;
  padding: 10px 20px; cursor: pointer;
  font-size: 14px;
}
.palette-item:hover, .palette-item.sel {
  background: var(--brand-soft);
  color: var(--brand);
}
.palette-item .icn { width: 20px; text-align: center; }
.palette-item .meta { color: var(--text-mute); font-size: 12px; margin-left: auto; }
.palette-empty { padding: 24px; text-align: center; color: var(--text-mute); font-size: 13px; }
.palette-foot {
  padding: 10px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  font-size: 11px; color: var(--text-mute);
}

/* Help-Overlay */
.help-overlay {
  position: fixed; inset: 0; z-index: 95;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.help-overlay.hidden { display: none; }
.help-backdrop {
  position: absolute; inset: 0; background: rgba(15,23,42,.6);
}
.help-card {
  position: relative; width: 100%; max-width: 480px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-lg);
}
.help-card h2 { margin: 0 0 12px; font-size: 18px; }
.help-table { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.help-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); font-size: 13px; }
.help-table td:first-child { white-space: nowrap; }

/* kbd-Elemente */
kbd {
  display: inline-block;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  padding: 2px 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: var(--text);
}

/* Such-Input */
.search-input {
  position: relative;
}
.search-input input {
  width: 100%; height: 38px; padding: 0 12px 0 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--surface);
}
.search-input::before {
  content: "🔍";
  position: absolute; left: 10px; top: 50%;
  transform: translateY(-50%);
  font-size: 13px; opacity: .6;
  pointer-events: none;
}

/* ============================================================
   Desktop-Layout (Sidebar sichtbar)
   ============================================================ */
@media (min-width: 900px) {
  .sidebar { display: flex; }
  .topbar {
    left: var(--sidebar-w);
    padding-left: 24px;
  }
  .menu-btn { display: none; }
  .content {
    margin-left: var(--sidebar-w);
    padding: calc(var(--topbar-h) + 20px) 28px 60px;
  }
  .bottom-nav { display: none; }
  .fab { right: 32px; bottom: 32px; }
}

/* Tablet: Sidebar klein + einklappbar */
@media (max-width: 899px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform .2s;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: none; display: flex; }
}

/* Empty-State */
.empty-state {
  padding: 40px 16px; text-align: center;
  color: var(--text-mute);
}
.empty-state .icn { font-size: 36px; margin-bottom: 8px; }

/* Section-Header in Content */
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px; gap: 12px;
}
.section-head h2 { font-size: 14px; font-weight: 600; margin: 0; color: var(--text-soft); }

/* Inline status change buttons */
.status-actions { display: flex; gap: 6px; flex-wrap: wrap; }
