/* ============================================================
   Personalverwaltung – Modern Sidebar Layout
   ============================================================ */

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

:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --success: #16a34a;
  --warning: #ea580c;
  --danger: #dc2626;
  --danger-hover: #b91c1c;

  --bg: #f6f7fb;
  --card: #ffffff;
  --border: #e4e7ed;
  --border-light: #f0f1f5;
  --text: #1f2937;
  --text-muted: #6b7280;
  --text-light: #6b7280; /* Alias für Backwards-Compat */

  --sidebar-bg: #1e2536;
  --sidebar-text: #c5c8d4;
  --sidebar-text-muted: #7a8499;
  --sidebar-active: #2a3349;
  --sidebar-hover: #252c40;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.04);
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 25px rgba(0,0,0,.08), 0 4px 10px rgba(0,0,0,.05);
}

/* Dark mode */
[data-theme="dark"] {
  --primary: #818cf8;
  --primary-hover: #6366f1;
  --primary-light: rgba(99, 102, 241, .15);
  --success: #4ade80;
  --warning: #fb923c;
  --danger: #f87171;
  --danger-hover: #ef4444;

  --bg: #0f1117;
  --card: #1a1d2e;
  --border: #2a2d3e;
  --border-light: #232638;
  --text: #e2e4eb;
  --text-muted: #8b8fa5;
  --text-light: #8b8fa5;

  --sidebar-bg: #111320;
  --sidebar-text: #b0b4c8;
  --sidebar-text-muted: #5e6380;
  --sidebar-active: #1e2140;
  --sidebar-hover: #181b2c;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.2);
  --shadow: 0 1px 3px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.2);
  --shadow-lg: 0 10px 25px rgba(0,0,0,.4), 0 4px 10px rgba(0,0,0,.25);
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   App Layout: Sidebar + Main
   ============================================================ */

.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  overflow-y: auto;
  z-index: 50;
}

.sidebar-brand {
  padding: 20px 22px 16px;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -.01em;
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-brand-icon {
  width: 30px; height: 30px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 800;
}

.sidebar-nav {
  flex: 1;
  padding: 8px 12px 20px;
}
.sidebar-group {
  margin-top: 14px;
}
.sidebar-group-title {
  padding: 0 10px 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--sidebar-text-muted);
}
.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--sidebar-text);
  background: none;
  border: 0;
  width: 100%;
  text-align: left;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 1px;
  transition: background .12s, color .12s;
}
.sidebar-item:hover {
  background: var(--sidebar-hover);
  color: #fff;
}
.sidebar-item.active {
  background: var(--sidebar-active);
  color: #fff;
}
.sidebar-item.active::before {
  content: '';
  position: absolute;
  margin-left: -12px;
  width: 3px; height: 18px;
  background: var(--primary);
  border-radius: 2px;
}
.sidebar-icon {
  width: 18px; height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
  opacity: .85;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,.06);
  font-size: 12px;
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.sidebar-user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name {
  color: #fff;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-role {
  font-size: 11px;
  color: var(--sidebar-text-muted);
}
.sidebar-logout {
  display: block;
  width: 100%;
  padding: 6px 10px;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.08);
  color: var(--sidebar-text);
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  text-align: center;
  transition: background .12s;
}
.sidebar-logout:hover { background: rgba(255,255,255,.1); color: #fff; }

/* Main */
.main {
  flex: 1;
  margin-left: 240px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}
.topbar-status {
  font-size: 13px;
  color: var(--text-muted);
}

.content {
  padding: 24px 28px 40px;
  max-width: 1280px;
  width: 100%;
}
/* Breite Tabellen (Mitarbeiter, Lohn) nutzen die volle verfügbare Breite */
.content.content-wide { max-width: none; }

/* Mobile menu button */
.menu-toggle {
  display: none;
  background: none;
  border: 0;
  font-size: 22px;
  cursor: pointer;
  color: var(--text);
  padding: 4px 8px;
}

/* ============================================================
   Page header (innerhalb des content)
   ============================================================ */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  gap: 12px;
  flex-wrap: wrap;
}
.page-header h2 {
  font-size: 18px;
  font-weight: 600;
}
.page-header .page-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

/* ============================================================
   Cards
   ============================================================ */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}
.card-pad-0 { padding: 0; }
.card h2, .card h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
}
.card h3 { font-size: 14px; }

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
}
.card-header h2 { margin: 0; }

/* Stat cards */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: var(--shadow-sm);
}
.stat-value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -.02em;
  line-height: 1.1;
}
.stat-label {
  font-size: 12.5px;
  color: var(--text-muted);
}
.stat-color-primary { color: var(--primary); }
.stat-color-success { color: var(--success); }
.stat-color-warning { color: var(--warning); }
.stat-color-danger { color: var(--danger); }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s, box-shadow .12s;
  white-space: nowrap;
  font-family: inherit;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Spalten-Auswahl (Mitarbeiterübersicht) */
.column-picker {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 50;
  width: 250px;
  max-height: 70vh;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 6px 20px rgba(0,0,0,.15);
  padding: 10px;
}
.column-picker input[type=search] { width: 100%; margin-bottom: 8px; box-sizing: border-box; }
.column-picker > .btn { width: 100%; margin-bottom: 8px; }
.column-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 4px;
  font-size: 14px;
  cursor: pointer;
  border-radius: 4px;
}
.column-item:hover { background: var(--primary-light); }
.column-item input { cursor: pointer; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #15803d; }
.btn-outline {
  background: var(--card);
  border-color: var(--border);
  color: var(--text);
}
.btn-outline:hover:not(:disabled) { border-color: #cbd1da; background: var(--bg); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--bg); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px 8px; }

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ============================================================
   Tabellen
   ============================================================ */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--card);
}
.table-wrap table { border: 0; }
th, td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border-light);
}
th {
  font-weight: 600;
  font-size: 11.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  background: var(--bg);
}
tbody tr:last-child td { border-bottom: 0; }
tr.selected { background: var(--primary-light); }
tr.birthday-row { background: #fef9c3; }
[data-theme="dark"] tr.birthday-row { background: #422006; }
tr.birthday-row td:first-child::before { content: '🎂 '; }
tbody tr:hover { background: var(--border-light); }
td.center, th.center { text-align: center; }
td.right, th.right { text-align: right; }

.row-check { width: 16px; height: 16px; cursor: pointer; }

.payroll-remark-input {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 0.85rem;
  background: var(--card);
  color: var(--text);
  width: 100%;
  min-width: 120px;
}
.payroll-remark-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-light); }
.payroll-remark-input.input-error { border-color: var(--danger); }
.payroll-auto-remark { color: var(--text-muted); font-size: 0.8rem; white-space: nowrap; }

input.input-warning { border-color: #faad14 !important; }
input.input-warning:focus { box-shadow: 0 0 0 2px rgba(250,173,20,.2); }
input.input-error { border-color: var(--danger) !important; }
input.input-error:focus { box-shadow: 0 0 0 2px rgba(220,38,38,.15); }
.phone-hint { font-size: 12px; margin-top: 3px; min-height: 16px; }
.phone-hint-error { color: var(--danger); }
.phone-hint-warning { color: #b45309; }
[data-theme="dark"] .phone-hint-warning { color: #faad14; }

/* Badge / Pill */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
}
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #ffedd5; color: #9a3412; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-muted { background: var(--bg); color: var(--text-muted); }
.badge-info { background: var(--primary-light); color: var(--primary); }

[data-theme="dark"] .badge-success { background: rgba(74, 222, 128, .15); color: #4ade80; }
[data-theme="dark"] .badge-warning { background: rgba(251, 146, 60, .15); color: #fb923c; }
[data-theme="dark"] .badge-danger { background: rgba(248, 113, 113, .15); color: #f87171; }

/* ============================================================
   Forms
   ============================================================ */
.form-group { margin-bottom: 14px; }
label {
  display: block;
  font-size: 12.5px;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--text);
}
input[type="text"], input[type="number"], input[type="date"],
input[type="password"], input[type="tel"], input[type="email"],
select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  outline: 0;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .12);
}
input[readonly] { background: var(--bg); color: var(--text-muted); }

textarea { resize: vertical; }

/* Inline-Form (Filter-Bar) */
.inline-form {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.inline-form label { margin: 0; }
.inline-form input, .inline-form select {
  width: auto;
  padding: 6px 10px;
  font-size: 13px;
}
.inline-form input[type="number"] { width: 90px; }

.form-row {
  display: flex;
  gap: 12px;
}
.form-row > .form-group { flex: 1; }
@media (max-width: 600px) {
  .form-row { flex-direction: column; gap: 0; }
}

/* IBAN-Status */
.iban-status {
  font-size: 12px;
  margin-top: 2px;
  min-height: 16px;
}
.iban-status.valid { color: var(--success); }
.iban-status.invalid { color: var(--danger); }

/* Suffix */
.input-suffix { position: relative; }
.input-suffix input { padding-right: 40px; }
.input-suffix .suffix {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 13px;
  color: var(--text-muted);
  pointer-events: none;
}

/* ============================================================
   Modal
   ============================================================ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  backdrop-filter: blur(2px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.active { display: flex; }
#login-overlay {
  background: linear-gradient(135deg, #1e2536 0%, #2a3349 100%);
  backdrop-filter: none;
}
.modal {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  width: 420px;
  max-width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal h3 {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 18px;
}
.modal .btn-group {
  margin-top: 22px;
  justify-content: flex-end;
}
.modal-lg { width: 960px; max-width: calc(100vw - 40px); }

/* Form-Tabs (im Modal) */
.form-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
  overflow-x: auto;
}
.form-tab {
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--text-muted);
  background: none;
  white-space: nowrap;
  font-family: inherit;
}
.form-tab:hover { color: var(--text); }
.form-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.form-tab-content { display: none; }
.form-tab-content.active { display: block; }

/* ============================================================
   Tab-Content (Sidebar-Navigation)
   ============================================================ */
.tab-content { display: none; }
.tab-content.active { display: block; }

/* Adress-Autocomplete-Dropdown (Nominatim) */
.addr-suggest {
  position: absolute;
  z-index: 100;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  width: 360px;
  max-height: 240px;
  overflow-y: auto;
  margin-top: 2px;
}
.addr-suggest-item {
  padding: 8px 10px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--border-light);
}
.addr-suggest-item:last-child { border-bottom: 0; }
.addr-suggest-item:hover { background: var(--primary-light); }
.addr-suggest-empty {
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text-muted);
}

/* Login-Modal */
#login-overlay .modal {
  width: 380px;
  background: var(--card);
}

/* ============================================================
   Urlaubskalender
   ============================================================ */
.vacation-cal {
  font-size: 11px;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--card);
}
.vacation-cal th, .vacation-cal td {
  padding: 4px 2px;
  text-align: center;
  min-width: 24px;
  white-space: nowrap;
  border: 1px solid var(--border);
}
.vacation-cal th:first-child, .vacation-cal td:first-child {
  text-align: left;
  min-width: 130px;
  padding-left: 10px;
  border-right: 2px solid var(--text-light);
  font-weight: 500;
}
.vacation-cal .cal-we { background: #e5e7eb; color: #9ca3af; }
.vacation-cal .cal-holiday { background: var(--danger); color: #fff; }
.vacation-cal .cal-vacation { background: var(--success); color: #fff; font-weight: 600; }
.vacation-cal .cal-sick { background: var(--warning); color: #fff; font-weight: 600; }
.vacation-cal thead th { font-size: 10px; background: var(--bg); }
.vacation-cal .cal-we.cal-hdr { background: #d1d5db; color: #fff; }
.vacation-cal .cal-holiday.cal-hdr { background: #b91c1c; color: #fff; }

[data-theme="dark"] .vacation-cal .cal-we { background: #2a2d3e; color: #5e6380; }
[data-theme="dark"] .vacation-cal .cal-we.cal-hdr { background: #353850; color: #8b8fa5; }

/* Dark mode toggle */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  color: var(--text-muted);
  transition: background .12s, border-color .12s;
}
.theme-toggle:hover {
  background: var(--bg);
  border-color: var(--text-muted);
}

/* Login dark mode */
[data-theme="dark"] #login-overlay {
  background: linear-gradient(135deg, #0f1117 0%, #1a1d2e 100%);
}
[data-theme="dark"] .modal-overlay {
  background: rgba(0, 0, 0, .65);
}

/* Vertragsvorlagen-Liste */
.ct-item:hover { background: var(--bg); }
.ct-item.ct-active:hover { background: var(--primary) !important; }

/* ============================================================
   Login Screen
   ============================================================ */
#login-overlay .modal-brand {
  text-align: center;
  margin-bottom: 22px;
}
#login-overlay .modal-brand-icon {
  width: 48px; height: 48px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 10px;
}
#login-overlay .modal-brand-name {
  font-size: 16px;
  font-weight: 600;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform .2s;
  }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .menu-toggle { display: inline-flex; }
  .content { padding: 16px; }
  .topbar { padding: 12px 16px; }
}
@media (max-width: 600px) {
  .modal { padding: 18px; }
  .modal-lg { width: 100%; }
  .stat-value { font-size: 22px; }
  th, td { padding: 8px 10px; }
}

/* ============================================================
   Skeleton Loading
   ============================================================ */
.skeleton {
  background: var(--border-light);
  border-radius: 4px;
  display: inline-block;
  position: relative;
  overflow: hidden;
}
.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, var(--bg) 50%, transparent 100%);
  animation: skeleton-shimmer 1.5s infinite;
}
@keyframes skeleton-shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}
.skeleton-line {
  height: 14px;
  width: 70%;
  margin: 3px 0;
}
.skeleton-line-short { width: 40%; }
.skeleton-line-wide { width: 90%; }
.skeleton-badge {
  height: 20px;
  width: 60px;
  border-radius: 999px;
}
.skeleton-stat {
  height: 32px;
  width: 48px;
  border-radius: 4px;
}
.skeleton-text-sm {
  height: 12px;
  width: 80%;
  margin: 3px 0;
}
[data-theme="dark"] .skeleton { background: var(--border); }
[data-theme="dark"] .skeleton::after {
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,.04) 50%, transparent 100%);
}

/* Helpers */
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }
.text-sm { font-size: 12px; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.flex-spacer { flex: 1; }
