:root {
  --primary: #2b5fa6;
  --primary-dark: #1a4a8a;
  --danger: #c62828;
  --danger-dark: #8e1a1a;
  --success: #2e7d32;
  --warning: #f57c00;
  --bg: #f0f2f5;
  --surface: #ffffff;
  --border: #dde3ee;
  --text: #2c3547;
  --text-muted: #6b7694;
  --shadow: 0 2px 8px rgba(0,0,0,.08);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ===== HEADER ===== */
header {
  background: var(--primary);
  color: white;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
  position: sticky;
  top: 0;
  z-index: 100;
}
header h1 { font-size: 1.1rem; font-weight: 600; }
.header-right { display: flex; align-items: center; gap: 16px; font-size: .9rem; }
.user-info { opacity: .85; }
.btn-logout {
  background: rgba(255,255,255,.15);
  color: white;
  border: 1px solid rgba(255,255,255,.3);
  padding: 6px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-size: .85rem;
  text-decoration: none;
  transition: background .2s;
}
.btn-logout:hover { background: rgba(255,255,255,.25); }

/* ===== LAYOUT ===== */
.container { max-width: 1100px; margin: 0 auto; padding: 20px; }

/* ===== CARD ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: #f7f9fc;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-header h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-body { padding: 20px; }

/* ===== FORM ===== */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
label {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .03em;
}
label .req { color: var(--danger); margin-left: 2px; }

input[type=text], input[type=date], input[type=email], input[type=number],
textarea, select {
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: .9rem;
  color: var(--text);
  background: #fff;
  transition: border-color .2s, box-shadow .2s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(43,95,166,.1);
}
input[readonly] { background: #f8f9fc; color: var(--text-muted); }
textarea { resize: vertical; min-height: 70px; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: .9rem;
  font-weight: 600;
  transition: all .2s;
  text-decoration: none;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(43,95,166,.3); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: var(--danger-dark); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #1b5e20; }
.btn-secondary { background: white; border: 1.5px solid var(--border); color: var(--text-muted); }
.btn-secondary:hover { background: var(--bg); border-color: #b0b8cc; }
.btn-sm { padding: 5px 10px; font-size: .8rem; }
.btn-icon { padding: 5px 8px; font-size: .85rem; border-radius: 4px; }

/* ===== ACTIONS BAR ===== */
.actions-bar {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 0 0;
  border-top: 1px solid var(--border);
  margin-top: 16px;
}

/* ===== ITEM LIST (Multi-Item Tabelle) ===== */
.item-list-container {
  border: 2px dashed var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.item-list-header {
  display: grid;
  gap: 6px;
  padding: 10px 12px;
  background: #f0f4fb;
  border-bottom: 1px solid var(--border);
  font-size: .75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.item-list-header.zugang-cols {
  grid-template-columns: 36px 130px 120px 1fr 120px 90px 90px 50px;
}
.item-list-header.abgang-cols {
  grid-template-columns: 36px 130px 120px 1fr 120px 110px 90px 50px;
}

.item-row-wrap {
  border-bottom: 1px solid #edf0f7;
}
.item-row-wrap:last-child { border-bottom: none; }

.item-row {
  display: grid;
  gap: 6px;
  padding: 8px 12px;
  align-items: center;
}
.item-row.zugang-cols {
  grid-template-columns: 36px 130px 120px 1fr 120px 90px 90px 50px;
}
.item-row.abgang-cols {
  grid-template-columns: 36px 130px 120px 1fr 120px 110px 90px 50px;
}
.item-row input, .item-row select {
  padding: 7px 9px;
  font-size: .85rem;
  border-radius: 5px;
}
.item-num {
  background: var(--primary);
  color: white;
  text-align: center;
  padding: 6px 4px;
  border-radius: 4px;
  font-size: .8rem;
  font-weight: 700;
  min-width: 32px;
}
.item-num.abgang { background: var(--danger); }

.item-detail {
  padding: 10px 12px 14px 62px;
  background: #fafbff;
  border-top: 1px dashed #dde3f5;
  display: none;
}
.item-detail.open { display: block; }
.item-detail .form-row { gap: 10px; }
.item-detail label { font-size: .75rem; }
.item-detail input, .item-detail select { font-size: .85rem; padding: 6px 10px; }

.btn-toggle-detail {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: .8rem;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 3px;
}
.btn-toggle-detail:hover { color: var(--primary); }

/* Conditional fields */
.conditional-field { display: none; }
.conditional-field.visible { display: block; }

/* ===== ADD ITEM BUTTON ===== */
.add-item-bar {
  padding: 12px;
  background: #fafbff;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ===== BADGES ===== */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: .78rem;
  font-weight: 600;
}
.badge-zugang { background: #e8f5e9; color: #2e7d32; }
.badge-abgang { background: #ffebee; color: #c62828; }
.badge-neu { background: #e3f2fd; color: #1565c0; }
.badge-bearbeitung { background: #fff3e0; color: #e65100; }
.badge-abgeschlossen { background: #e8f5e9; color: #2e7d32; }

/* ===== INFO BOX ===== */
.info-box {
  padding: 12px 16px;
  border-radius: 6px;
  font-size: .85rem;
  margin: 12px 0;
}
.info-box.blue { background: #e3f2fd; border-left: 4px solid #1976d2; color: #0d47a1; }
.info-box.green { background: #e8f5e9; border-left: 4px solid #4caf50; color: #1b5e20; }
.info-box.yellow { background: #fff8e1; border-left: 4px solid #ffc107; color: #6d4c00; }
.info-box.red { background: #ffebee; border-left: 4px solid #f44336; color: #8b0000; }

/* ===== MODAL ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: white;
  border-radius: 10px;
  max-width: 800px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-body { padding: 24px; }
.modal-footer { padding: 14px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.btn-close-modal { background: none; border: none; cursor: pointer; font-size: 1.4rem; color: var(--text-muted); line-height: 1; }

/* ===== DASHBOARD TABLE ===== */
.data-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.data-table th { padding: 12px; text-align: left; background: #f0f4fb; border-bottom: 2px solid var(--border); font-size: .8rem; text-transform: uppercase; color: var(--text-muted); }
.data-table td { padding: 12px; border-bottom: 1px solid #edf0f7; }
.data-table tr:hover td { background: #f7f9ff; }
.data-table tr:last-child td { border-bottom: none; }
.clickable-row { cursor: pointer; }

/* ===== STATS ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card { background: white; border: 1px solid var(--border); border-radius: 8px; padding: 16px; text-align: center; }
.stat-value { font-size: 2rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: .8rem; color: var(--text-muted); margin-top: 4px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .item-list-header, .item-row { display: flex; flex-wrap: wrap; }
  .item-list-header { display: none; }
  header h1 { font-size: .95rem; }
}

/* ===== SPINNER ===== */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== TOAST ===== */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 14px 20px;
  border-radius: 8px;
  font-weight: 600;
  font-size: .9rem;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
  z-index: 9999;
  transition: opacity .3s;
  opacity: 0;
  pointer-events: none;
}
#toast.show { opacity: 1; }
#toast.success { background: #2e7d32; color: white; }
#toast.error { background: #c62828; color: white; }
