:root {
  --primary: #1565c0;
  --primary-dark: #0d47a1;
  --accent: #ff6f00;
  --bg: #f5f6fa;
  --card: #fff;
  --text: #222;
  --text-muted: #666;
  --border: #e0e0e0;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,.08);
  --gruen: #2e7d32;
  --gelb: #f9a825;
  --rot: #c62828;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* Nav */
.nav {
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 20px;
  height: 54px;
  box-shadow: 0 2px 4px rgba(0,0,0,.15);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav h1 { font-size: 18px; margin-right: 30px; font-weight: 700; }

.nav-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,.7);
  font-size: 14px;
  padding: 8px 16px;
  cursor: pointer;
  border-radius: var(--radius) var(--radius) 0 0;
  transition: all .2s;
}
.nav-btn:hover { background: rgba(255,255,255,.1); color: #fff; }
.nav-btn.active { background: rgba(255,255,255,.15); color: #fff; font-weight: 600; }

/* Nav User */
.nav-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
.nav-user span { font-weight: 600; }

/* Login */
.login-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: var(--bg);
  display: none; justify-content: center; align-items: center;
  z-index: 500;
}
.login-overlay.active { display: flex; }
.login-box {
  background: var(--card);
  padding: 40px;
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,.15);
  width: 320px;
  text-align: center;
}

/* Content */
.content { max-width: 1400px; margin: 0 auto; padding: 20px; }
.page { display: none; }
.page.active { display: block; }

/* Cards */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.card-header {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
}

/* Dashboard Grid */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.typ-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  border-left: 5px solid var(--border);
  cursor: pointer;
  transition: transform .15s, box-shadow .15s;
}
.typ-card:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0,0,0,.12); }

.typ-card.ampel-gruen { border-left-color: var(--gruen); }
.typ-card.ampel-gelb { border-left-color: var(--gelb); }
.typ-card.ampel-rot { border-left-color: var(--rot); }

.typ-code {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
}

.typ-basis {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.typ-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; font-size: 13px; }
.typ-stat-label { color: var(--text-muted); }
.typ-stat-value { font-weight: 600; text-align: right; }
.typ-stat-value.negativ { color: var(--rot); }

.ampel-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 4px;
}
.ampel-dot.gruen { background: var(--gruen); }
.ampel-dot.gelb { background: var(--gelb); }
.ampel-dot.rot { background: var(--rot); }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { background: var(--primary); color: #fff; padding: 8px 10px; text-align: left; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
tr:hover { background: #f0f4f8; }
tr:nth-child(even) { background: #fafbfd; }
td.negativ { color: var(--rot); font-weight: 600; }

/* Lager-Stufen */
.lager-flow {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 13px;
  flex-wrap: wrap;
}

.lager-stufe {
  background: #e3f2fd;
  border-radius: 6px;
  padding: 4px 10px;
  text-align: center;
  min-width: 60px;
}
.lager-stufe .label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; }
.lager-stufe .val { font-weight: 700; font-size: 16px; }
.lager-arrow { color: var(--text-muted); font-size: 18px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: #e65100; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* Forms */
select, input[type=number], input[type=text], input[type=file] {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  background: #fff;
}
select:focus, input:focus { outline: none; border-color: var(--primary); }

label { font-size: 13px; font-weight: 600; display: block; margin-bottom: 4px; }

.form-row { display: flex; gap: 12px; align-items: flex-end; margin-bottom: 12px; flex-wrap: wrap; }
.form-group { display: flex; flex-direction: column; }

/* Modal */
.modal-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,.5);
  display: none; justify-content: center; align-items: center;
  z-index: 200;
}
.modal-overlay.active { display: flex; }

.modal {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 900px;
  width: 95%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
}
.modal h3 { margin-bottom: 16px; }

/* Feedback */
.feedback {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--primary);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 300;
  display: none;
  animation: slideIn .3s;
}
@keyframes slideIn { from { transform: translateY(20px); opacity: 0; } }

/* Filter-Leiste */
.filter-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  align-items: center;
  flex-wrap: wrap;
}

/* Statistik-Kacheln */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-value { font-size: 28px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* Schweißplan Matrix */
.sp-matrix { border-collapse: collapse; font-size: 12px; }
.sp-matrix th, .sp-matrix td { padding: 4px 6px; text-align: center; white-space: nowrap; min-width: 42px; }
.sp-matrix th { position: sticky; top: 0; z-index: 2; }
.sp-matrix th.sp-typ-header { text-align: left; min-width: 80px; }
.sp-matrix td.sp-typ-cell { text-align: left; font-weight: 600; font-size: 11px; position: sticky; left: 0; background: #fff; z-index: 1; }
.sp-matrix td.sp-bedarf { font-weight: 600; background: #f5f5f5; }

.sp-group-row td { background: var(--primary) !important; color: #fff; font-weight: 700; font-size: 12px; text-align: left; padding: 4px 8px; position: sticky; left: 0; z-index: 3; }

/* Schweißen-Tabelle: Raster + Monats-Trennlinien + Sticky-Spalten */
#sw-table td, #sw-table th { border: 1px solid #e0e0e0; }
#sw-table .sw-month-start { border-left: 2.5px solid #999; }
#sw-table .sw-col-typ { position:sticky; left:0; z-index:3; background:#fff; }
#sw-table .sw-col-roh { position:sticky; left:80px; z-index:3; background:#fff; }
#sw-table .sw-col-bedarf { position:sticky; left:118px; z-index:3; background:#f5f5f5; }
#sw-table th.sw-col-typ, #sw-table th.sw-col-roh, #sw-table th.sw-col-bedarf { z-index:4; }
#sw-table .sp-summe .sw-col-typ { background:#e8eaf6; }
#sw-table .sp-group-row td { position:static; }
#sw-table .sp-group-row .sw-col-typ { position:sticky; left:0; z-index:3; }
#sw-table .sp-summe .sw-col-roh, #sw-table .sp-summe .sw-col-bedarf { background:#e8eaf6; }

.sp-cell { cursor: pointer; min-height: 24px; border-radius: 3px; transition: background .15s; }
.sp-cell:hover { background: #e3f2fd !important; }
.sp-cell.has-value { background: #c8e6c9; font-weight: 600; }
.sp-cell.manuell { outline: 2px solid var(--accent); outline-offset: -2px; }

.sp-summe td { font-weight: 700; background: #e8eaf6 !important; border-top: 2px solid var(--primary); }
.sp-summe .sp-over { color: var(--rot); }

.sp-cell.sp-past { background: #f5f5f5; color: #bbb; }
.sp-kw-current { background: var(--primary-dark) !important; }

.sp-cell-input {
  width: 36px; padding: 2px; text-align: center; font-size: 12px; font-weight: 600;
  border: 2px solid var(--primary); border-radius: 3px; background: #fff;
}

/* Lieferplan Ampel */
.sp-cell.lp-gruen { background: #c8e6c9 !important; }
.sp-cell.lp-gelb { background: #fff9c4 !important; }
.sp-cell.lp-rot { background: #ffcdd2 !important; color: var(--rot); font-weight: 700; }

.lp-verzinkt { font-weight: 600; color: var(--gruen); }

/* Schweißen [+] Button */
.sw-plus {
  display: inline-block;
  cursor: pointer;
  background: var(--primary);
  color: #fff;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 700;
  width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  margin-left: 4px;
  vertical-align: middle;
}
.sw-plus:hover { background: var(--accent); }
.lp-pipeline { cursor: help; }

/* Identisch-Badge */
.identisch-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  background: #e3f2fd;
  color: var(--primary);
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 4px;
  white-space: nowrap;
}

/* KW-Zusammenstellung */
.kw-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.kw-tab {
  padding: 6px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all .2s;
}
.kw-tab:hover { border-color: var(--primary); color: var(--primary); }
.kw-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.kw-tab .kw-tab-count { font-size: 11px; font-weight: 400; opacity: .8; margin-left: 4px; }

.kw-detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
.kw-detail-group {
  background: #f5f6fa;
  border-radius: var(--radius);
  padding: 12px;
  border-left: 4px solid var(--primary);
}
.kw-detail-group-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 8px;
}
.kw-detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.kw-detail-row:last-child { border-bottom: none; }
.kw-detail-code { font-weight: 600; }
.kw-detail-menge { font-weight: 700; font-size: 15px; color: var(--primary); }
.kw-detail-ampel { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.kw-detail-ampel.gruen { background: var(--gruen); }
.kw-detail-ampel.gelb { background: var(--gelb); }
.kw-detail-ampel.rot { background: var(--rot); }

.kw-detail-summe {
  margin-top: 16px;
  padding: 12px 16px;
  background: #e8eaf6;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 15px;
  display: flex;
  justify-content: space-between;
}

@media print {
  .nav, .filter-bar, #lp-table, .kw-tabs, #kw-print-btn, .card-header button { display: none !important; }
  #kw-zusammenstellung { box-shadow: none; border: 1px solid #ccc; }
  .kw-detail-grid { grid-template-columns: repeat(2, 1fr); }
  body { background: #fff; }
  .page { display: none !important; }
  #page-lieferplan { display: block !important; }
  #page-lieferplan > .card:first-child { display: none; }
}

/* Responsive */
@media (max-width: 768px) {
  .nav {
    padding: 0 10px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-wrap: nowrap;
    gap: 2px;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav h1 { font-size: 15px; margin-right: 10px; flex-shrink: 0; }
  .nav-btn { padding: 6px 10px; font-size: 12px; white-space: nowrap; flex-shrink: 0; }
  .content { padding: 10px; }
  .dash-grid { grid-template-columns: 1fr; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .card { padding: 12px; }
  .card-header { font-size: 14px; flex-wrap: wrap; gap: 8px; }
  .form-row { flex-direction: column; }
  .form-group { width: 100%; }
  .modal { padding: 16px; width: 98%; }

  /* Tabellen horizontal scrollbar */
  .sp-matrix { font-size: 11px; }
  .sp-matrix th, .sp-matrix td { padding: 3px 4px; min-width: 36px; }

  /* KW-Zusammenstellung */
  .kw-detail-grid { grid-template-columns: 1fr; }
  .kw-detail-summe { font-size: 14px; }

  /* Lager-Flow */
  .lager-flow { font-size: 11px; }
  .lager-stufe .val { font-size: 14px; }
}

/* Identische Typen */
.identisch-hint { font-size: 0.75em; color: #888; font-weight: normal; }
.kw-month { font-size: 9px; color: inherit; font-weight: normal; opacity: 0.75; }
.we-nas-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; margin-bottom: 4px; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; transition: background .15s;
}
.we-nas-item:hover { background: #e3f2fd; border-color: var(--primary); }
.follower-row { opacity: 0.45; }
tr.follower-row:hover { opacity: 0.7; }
