*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Colors */
  --bg-primary:    #ffffff;
  --bg-secondary:  #f8f9fa;
  --bg-tertiary:   #f1f3f5;
  --bg-hover:      #f0f4f8;
  --text-primary:  #111827;
  --text-secondary:#4b5563;
  --text-tertiary: #9ca3af;
  --border:        rgba(0,0,0,0.08);
  --border-md:     rgba(0,0,0,0.16);
  --accent:        #2563EB;
  --accent-dark:   #1d4ed8;
  --accent-light:  #eff6ff;
  --green:         #16a34a;
  --green-light:   #f0fdf4;
  --red:           #dc2626;
  --red-light:     #fef2f2;
  --orange:        #ea580c;
  --orange-light:  #fff7ed;
  --shadow-sm:     0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:     0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --radius-sm:     6px;
  --radius-md:     8px;
  --radius-lg:     12px;
  --radius-xl:     16px;
}

html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
#login-screen { min-height: 100vh; }
#app-wrapper  { display: none; }

/* ══ Layout ══════════════════════════════════════════════ */
.layout { display: flex; height: 100vh; width: 100%; overflow: hidden; }

/* ══ Sidebar ═════════════════════════════════════════════ */
.sidebar {
  width: 232px; min-width: 232px; flex-shrink: 0;
  background: #1e2433;
  display: flex; flex-direction: column;
  height: 100vh; overflow-y: auto;
  padding: 0;
}
.logo {
  padding: 1.25rem 1.25rem 1rem;
  font-size: 17px; font-weight: 700; letter-spacing: -0.3px;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: .5rem;
}
.logo span { color: #60a5fa; }
.nav-group {
  padding: .75rem 1.25rem .2rem;
  font-size: 10px; font-weight: 600;
  color: rgba(255,255,255,0.35);
  letter-spacing: .08em; text-transform: uppercase;
  margin-top: .25rem;
}
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: .45rem 1.25rem;
  font-size: 13px; cursor: pointer;
  color: rgba(255,255,255,0.6);
  transition: background .12s, color .12s;
  border-radius: 0;
}
.nav-item:hover { background: rgba(255,255,255,0.07); color: rgba(255,255,255,0.9); }
.nav-item.active {
  background: rgba(96,165,250,0.18);
  color: #93c5fd; font-weight: 500;
  border-left: 2px solid #60a5fa;
}
.nav-item.active .ni { opacity: 1; }
.ni { width: 15px; height: 15px; flex-shrink: 0; opacity: .65; }
.nav-item.active .ni, .nav-item:hover .ni { opacity: 1; }

/* Sub-nav (always visible) */
.nav-sub { padding: 0; }
.nav-sub-item {
  padding-left: 2.75rem !important;
  font-size: 12.5px !important;
}

/* ══ Main content ════════════════════════════════════════ */
.main {
  flex: 1; min-width: 0;
  overflow-y: auto;
  padding: 2rem 2rem 3rem;
  background: var(--bg-tertiary);
  height: 100vh;
}

/* ══ Sections ════════════════════════════════════════════ */
.section { display: none; }
.section.active { display: block; }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1.5rem;
}
.topbar h1 {
  font-size: 22px; font-weight: 700;
  color: var(--text-primary); letter-spacing: -.4px;
}

/* ══ Buttons ═════════════════════════════════════════════ */
button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 16px; font-size: 13px; font-weight: 500;
  border: 1px solid var(--border-md); border-radius: var(--radius-md);
  cursor: pointer; background: var(--bg-primary);
  color: var(--text-primary); font-family: inherit;
  transition: background .12s, box-shadow .12s, border-color .12s;
  white-space: nowrap;
}
button:hover { background: var(--bg-hover); border-color: rgba(0,0,0,0.22); }
.btn-primary {
  background: var(--accent) !important; color: #fff !important;
  border-color: var(--accent) !important;
  box-shadow: 0 1px 3px rgba(37,99,235,.25) !important;
}
.btn-primary:hover {
  background: var(--accent-dark) !important;
  box-shadow: 0 2px 6px rgba(37,99,235,.35) !important;
}
.btn-danger { background: var(--red) !important; color: #fff !important; border-color: var(--red) !important; }

/* ══ Cards ═══════════════════════════════════════════════ */
.card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-sm);
}
.card-hd {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1rem;
}
.card-title { font-size: 14px; font-weight: 600; color: var(--text-primary); }

/* ══ Tables ══════════════════════════════════════════════ */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; font-weight: 600;
  color: var(--text-secondary);
  padding: 10px 14px; font-size: 11.5px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  letter-spacing: .02em; text-transform: uppercase;
  white-space: nowrap;
}
th:first-child { border-radius: var(--radius-sm) 0 0 0; }
th:last-child  { border-radius: 0 var(--radius-sm) 0 0; }
td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-hover); }

/* ══ Badges ══════════════════════════════════════════════ */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 99px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
  letter-spacing: .02em;
}
.b-green  { background: #dcfce7; color: #15803d; }
.b-amber  { background: #fef9c3; color: #854d0e; }
.b-blue   { background: #dbeafe; color: #1d4ed8; }
.b-red    { background: #fee2e2; color: #b91c1c; }
.b-purple { background: #ede9fe; color: #6d28d9; }
.b-teal   { background: #ccfbf1; color: #0f766e; }
.b-gray   { background: #f3f4f6; color: #374151; }

/* ══ Forms ═══════════════════════════════════════════════ */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .875rem; margin-bottom: 1rem; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label {
  font-size: 12px; font-weight: 500;
  color: var(--text-secondary); letter-spacing: .01em;
}
.form-group input,
.form-group select,
.form-group textarea {
  padding: 8px 11px;
  border: 1px solid var(--border-md);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 13px; font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.form-group input::placeholder,
.form-group textarea::placeholder { color: var(--text-tertiary); }

/* ══ Position rows ═══════════════════════════════════════ */
/* 8 columns: # | desc | menge | preis | ust | rabatt | betrag | del */
.line-hd,
.doc-line {
  display: grid;
  grid-template-columns: 22px minmax(0,1fr) 120px 120px 80px 100px 90px 32px;
  gap: 8px;
  align-items: center;
}
/* KU mode: hide USt column (column 5) */
.line-hd.ku-mode,
.doc-line-wrap.ku-mode .doc-line {
  grid-template-columns: 22px minmax(0,1fr) 120px 120px 0 100px 90px 32px;
}
.line-hd.ku-mode .line-ust-hd,
.doc-line-wrap.ku-mode .line-ust-cell { display: none; }

.line-hd {
  font-size: 11px; font-weight: 600;
  color: var(--text-secondary);
  padding: 0 10px 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
  letter-spacing: .04em; text-transform: uppercase;
}
.doc-line-wrap {
  margin-bottom: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  background: var(--bg-primary);
  transition: border-color .12s, box-shadow .12s;
}
.doc-line-wrap:hover {
  border-color: rgba(37,99,235,.3);
  box-shadow: 0 0 0 3px rgba(37,99,235,.06);
}
.line-num { font-size:11px; color:var(--text-tertiary); text-align:center; }
.line-menge { display:flex; gap:4px; }
.line-menge input { width:52px; flex-shrink:0; }
.line-menge select { flex:1; min-width:44px; }
.line-ust-cell { display:flex; }
.line-ust-cell select { width:100%; }
.line-rabatt-cell { display:flex; align-items:center; gap:3px; }
.line-rabatt-cell input { flex:1; }
.pct-sign { font-size:11px; color:var(--text-tertiary); flex-shrink:0; }
.line-total { background:var(--bg-secondary) !important; text-align:right; font-weight:500; }

.doc-line input, .doc-line select {
  padding: 5px 8px;
  border: 1px solid var(--border-md);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 12px; width: 100%; font-family: inherit;
  transition: border-color .12s;
}
.doc-line input:focus, .doc-line select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37,99,235,.12);
}
.doc-line-detail { margin-top: 6px; }
.doc-line-detail textarea {
  width: 100%; padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px; font-family: inherit;
  resize: vertical; color: var(--text-secondary);
  background: var(--bg-secondary); min-height: 32px;
  transition: border-color .12s;
}
.doc-line-detail textarea:focus {
  outline: none; border-color: var(--accent);
  background: var(--bg-primary);
}
.ls-line-hd { display: grid; grid-template-columns: 3fr 80px 100px 30px; gap: 8px; font-size: 11px; font-weight: 600; color: var(--text-secondary); padding: 0 0 8px; border-bottom: 1px solid var(--border); margin-bottom: 8px; text-transform: uppercase; letter-spacing: .03em; }
.ls-line { display: grid; grid-template-columns: 3fr 80px 100px 30px; gap: 8px; align-items: center; margin-bottom: 6px; }
.ls-line input, .ls-line select { padding: 6px 9px; border: 1px solid var(--border-md); border-radius: var(--radius-sm); background: var(--bg-primary); color: var(--text-primary); font-size: 13px; width: 100%; font-family: inherit; }
.del-btn {
  background: none !important; border: none !important;
  cursor: pointer; color: var(--text-tertiary);
  font-size: 16px; padding: 0; line-height: 1;
  transition: color .12s;
}
.del-btn:hover { color: var(--red); background: none !important; }

/* ══ Totals ══════════════════════════════════════════════ */
.totals {
  border-top: 1px solid var(--border);
  padding-top: 1rem; margin-top: 1rem;
  display: flex; flex-direction: column; align-items: flex-end; gap: 4px;
}
.total-row {
  display: flex; gap: 3rem; font-size: 13px;
  color: var(--text-secondary);
}
.total-row span:last-child { min-width: 100px; text-align: right; }
.total-row.big {
  font-weight: 700; font-size: 16px;
  color: var(--text-primary);
  border-top: 1px solid var(--border);
  padding-top: 8px; margin-top: 4px;
}
.doc-footer {
  display: flex; gap: 8px; justify-content: flex-end;
  margin-top: 1.25rem; padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

/* ══ Metrics / KPI cards ══════════════════════════════════ */
.metrics {
  display: grid; grid-template-columns: repeat(4, minmax(0,1fr));
  gap: 1rem; margin-bottom: 1.5rem;
}
.metric {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.125rem 1.25rem;
  box-shadow: var(--shadow-sm);
}
.metric-label { font-size: 12px; font-weight: 500; color: var(--text-secondary); margin-bottom: 6px; }
.metric-value { font-size: 24px; font-weight: 700; letter-spacing: -.5px; }
.metric-sub { font-size: 12px; margin-top: 5px; color: var(--text-tertiary); }
.pos { color: var(--green); } .neg { color: var(--red); }

/* ══ Tabs ════════════════════════════════════════════════ */
.tabs {
  display: flex; gap: 0; margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}
.tab {
  padding: 8px 16px; font-size: 13px; font-weight: 500;
  cursor: pointer; color: var(--text-secondary);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color .12s, border-color .12s;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab:hover:not(.active) { color: var(--text-primary); }

/* ══ Action buttons ══════════════════════════════════════ */
.action-btns { display: flex; gap: 4px; }
.action-btns button { font-size: 12px; padding: 4px 10px; border-radius: var(--radius-sm); }
.action-btns .btn-edit { border-color: var(--border-md); color: var(--text-secondary); }
.action-btns .btn-edit:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-light); }
.action-btns .btn-del  { color: var(--red); border-color: rgba(220,38,38,.3); }
.action-btns .btn-del:hover { background: var(--red-light); border-color: var(--red); }

/* ══ Toggle switch ═══════════════════════════════════════ */
.toggle-wrap {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.125rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md); margin-bottom: 1rem;
}
.toggle-label-main { font-size: 13px; font-weight: 600; }
.toggle-label-sub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.toggle { position: relative; display: inline-block; width: 44px; height: 24px; cursor: pointer; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-track { position: absolute; inset: 0; background: #d1d5db; border-radius: 99px; transition: background .2s; display: block; }
.toggle-thumb { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; background: #fff; border-radius: 50%; transition: left .2s; display: block; box-shadow: 0 1px 3px rgba(0,0,0,.2); }

/* ══ New-doc dropdown ════════════════════════════════════ */
.new-doc-item {
  display: flex; align-items: center; gap: 9px;
  padding: .55rem 1rem; font-size: 13px; cursor: pointer;
  color: var(--text-primary);
  transition: background .1s;
}
.new-doc-item:hover { background: var(--bg-secondary); }
.new-doc-item .ni { flex-shrink: 0; opacity: .5; }

/* ══ Sidebar sub-nav (always open) ══════════════════════ */
.nav-sub { padding: 0; }
.nav-sub-item { padding-left: 2.75rem !important; font-size: 12.5px !important; }
.nav-expandable { cursor: default; }

@media print {
  .sidebar, .topbar button, .doc-footer { display: none !important; }
}

/* ── Sidebar user area ── */
#current-user-role { background: rgba(96,165,250,0.2) !important; color: #93c5fd !important; border: none; }
.nav-konfig .nav-group { color: rgba(255,255,255,0.35) !important; }
