/* ============================================================
   Serviceportal - Hauptstylesheet
   Design: EDV Technik Müller
   Farben werden per CSS-Variablen gesteuert (aus DB überschreibbar)
   ============================================================ */

/* ---- CSS Variablen (Default, werden per PHP/JS aus DB gesetzt) ---- */
:root {
  --color-primary:        #1a4a8a;
  --color-primary-dark:   #122f5c;
  --color-primary-light:  #2a6dd9;
  --color-accent:         #e8a020;
  --color-bg:             #f4f6f9;
  --color-sidebar:        #1e2a3a;
  --color-header-bg:      #1e2a3a;
  --color-sidebar-text:   #c8d3e0;
  --color-sidebar-active: #2a6dd9;
  --color-text:           #333333;
  --color-text-muted:     #6c757d;
  --color-border:         #dee2e6;
  --color-white:          #ffffff;
  --color-success:        #28a745;
  --color-warning:        #ffc107;
  --color-danger:         #dc3545;
  --color-info:           #17a2b8;
  --color-card-shadow:    rgba(0, 0, 0, 0.08);

  --font-main:   'Segoe UI', Arial, sans-serif;
  --font-size:   14px;
  --radius:      6px;
  --radius-lg:   10px;
  --sidebar-w:   250px;
  --header-h:    60px;
  --transition:  0.2s ease;
}

/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: var(--font-size); scroll-behavior: smooth; }

body {
  font-family: var(--font-main);
  background:  var(--color-bg);
  color:       var(--color-text);
  line-height: 1.6;
  min-height:  100vh;
}

a { color: var(--color-primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--color-primary-light); }

img { max-width: 100%; height: auto; }

/* ============================================================
   LAYOUT - Login-Seite
   ============================================================ */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--color-primary-dark) 0%, var(--color-primary) 60%, var(--color-primary-light) 100%);
}

.login-box {
  background: var(--color-white);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 40px rgba(0,0,0,0.25);
  padding: 40px;
  width: 100%;
  max-width: 420px;
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo img { max-height: 70px; }

.login-logo .portal-name {
  display: block;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--color-primary);
  margin-top: 10px;
}

.login-box h2 {
  font-size: 1.1rem;
  color: var(--color-text-muted);
  text-align: center;
  margin-bottom: 28px;
  font-weight: 400;
}

/* ============================================================
   LAYOUT - Portal (eingeloggt)
   ============================================================ */
.portal-wrapper {
  display: flex;
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--color-sidebar);
  color: var(--color-sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 1000;
  transition: width var(--transition);
}

.sidebar-header {
  padding: 0 20px;
  background: var(--color-header-bg);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--header-h);
  min-height: var(--header-h);
  flex-shrink: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}

.sidebar-logo img { height: 36px; }

.sidebar-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-white);
  line-height: 1.2;
}

.sidebar-subtitle {
  font-size: 0.72rem;
  color: var(--color-sidebar-text);
  opacity: 0.7;
}

/* Navigation */
.sidebar-nav { padding: 12px 0; flex: 1; }

.nav-group-label {
  padding: 16px 20px 6px;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--color-sidebar-text);
  opacity: 0.5;
  font-weight: 600;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 20px;
  color: var(--color-sidebar-text);
  font-size: 0.9rem;
  transition: background var(--transition), color var(--transition);
  border-left: 3px solid transparent;
  cursor: pointer;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255,255,255,0.07);
  color: var(--color-white);
  border-left-color: var(--color-sidebar-active);
}

.nav-item .nav-icon {
  width: 20px;
  text-align: center;
  opacity: 0.8;
  flex-shrink: 0;
}

.nav-item.active .nav-icon { opacity: 1; }

/* Sidebar Footer */
.sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 0.8rem;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.sidebar-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--color-primary);
  display: flex; align-items: center; justify-content: center;
  color: var(--color-white);
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-avatar img { width: 100%; height: 100%; object-fit: cover; }

.sidebar-user-name { font-weight: 600; color: var(--color-white); font-size: 0.85rem; }
.sidebar-user-role { font-size: 0.72rem; opacity: 0.6; }

/* ---- Hauptbereich ---- */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Topbar */
.topbar {
  height: var(--header-h);
  background: var(--color-white);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 900;
  box-shadow: 0 1px 4px var(--color-card-shadow);
}

.topbar-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-primary);
}

.topbar-actions { display: flex; align-items: center; gap: 12px; }

/* Seiteninhalt */
.page-content {
  padding: 28px;
  flex: 1;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--color-white);
  border-radius: var(--radius-lg);
  box-shadow: 0 2px 10px var(--color-card-shadow);
  margin-bottom: 20px;
  overflow: hidden;
}

.card-header {
  padding: 16px 22px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--color-white);
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-body { padding: 22px; }

/* ============================================================
   STAT-KARTEN (Dashboard)
   ============================================================ */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 18px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--color-white);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: 0 2px 10px var(--color-card-shadow);
  display: flex;
  align-items: center;
  gap: 16px;
  border-left: 4px solid var(--color-primary);
}

.stat-card.accent  { border-left-color: var(--color-accent); }
.stat-card.success { border-left-color: var(--color-success); }
.stat-card.warning { border-left-color: var(--color-warning); }
.stat-card.danger  { border-left-color: var(--color-danger); }

.stat-icon {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: rgba(26,74,138,0.1);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}

.stat-card.accent  .stat-icon { background: rgba(232,160,32,0.12); }
.stat-card.success .stat-icon { background: rgba(40,167,69,0.12); }
.stat-card.warning .stat-icon { background: rgba(255,193,7,0.12); }
.stat-card.danger  .stat-icon { background: rgba(220,53,69,0.12); }

.stat-value { font-size: 1.8rem; font-weight: 800; color: var(--color-primary); line-height: 1; }
.stat-card.accent  .stat-value { color: var(--color-accent); }
.stat-card.success .stat-value { color: var(--color-success); }
.stat-card.warning .stat-value { color: #c7960e; }
.stat-card.danger  .stat-value { color: var(--color-danger); }
.stat-label { font-size: 0.82rem; color: var(--color-text-muted); margin-top: 3px; }

/* ============================================================
   FORMS
   ============================================================ */
.form-group { margin-bottom: 18px; }

label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 0.88rem;
  color: var(--color-text);
}

.form-control {
  display: block;
  width: 100%;
  padding: 10px 14px;
  font-size: 0.9rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-white);
  color: var(--color-text);
  transition: border-color var(--transition), box-shadow var(--transition);
  font-family: var(--font-main);
}

.form-control:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(26,74,138,0.12);
}

textarea.form-control { min-height: 120px; resize: vertical; }

select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236c757d' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }

.form-hint { font-size: 0.78rem; color: var(--color-text-muted); margin-top: 4px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  font-family: var(--font-main);
  text-decoration: none;
  white-space: nowrap;
}

.btn:active { transform: translateY(1px); }

.btn-primary   { background: var(--color-primary); color: var(--color-white); }
.btn-primary:hover { background: var(--color-primary-dark); color: var(--color-white); box-shadow: 0 4px 12px rgba(26,74,138,0.3); }

.btn-secondary { background: #6c757d; color: var(--color-white); }
.btn-secondary:hover { background: #545b62; color: var(--color-white); }

.btn-success { background: var(--color-success); color: var(--color-white); }
.btn-success:hover { background: #1e7e34; color: var(--color-white); }

.btn-danger { background: var(--color-danger); color: var(--color-white); }
.btn-danger:hover { background: #b21f2d; color: var(--color-white); }

.btn-warning { background: var(--color-warning); color: #333; }
.btn-warning:hover { background: #d39e00; }

.btn-outline {
  background: transparent;
  border: 2px solid var(--color-primary);
  color: var(--color-primary);
}
.btn-outline:hover { background: var(--color-primary); color: var(--color-white); }

.btn-sm  { padding: 6px 14px; font-size: 0.8rem; }
.btn-lg  { padding: 13px 28px; font-size: 1rem; width: 100%; justify-content: center; }
.btn-icon { padding: 8px; border-radius: var(--radius); }

/* ============================================================
   TABELLEN
   ============================================================ */
.table-wrapper { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

thead th {
  background: var(--color-bg);
  padding: 12px 16px;
  text-align: left;
  font-weight: 700;
  color: var(--color-primary);
  border-bottom: 2px solid var(--color-border);
  white-space: nowrap;
}

tbody tr { border-bottom: 1px solid var(--color-border); transition: background var(--transition); }
tbody tr:hover { background: rgba(26,74,138,0.03); }
tbody td { padding: 12px 16px; vertical-align: middle; }
tbody tr:last-child { border-bottom: none; }

/* ============================================================
   BADGES
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-primary { background: rgba(26,74,138,0.12); color: var(--color-primary); }
.badge-success { background: rgba(40,167,69,0.12); color: var(--color-success); }
.badge-warning { background: rgba(255,193,7,0.2); color: #856404; }
.badge-danger  { background: rgba(220,53,69,0.12); color: var(--color-danger); }
.badge-info    { background: rgba(23,162,184,0.12); color: var(--color-info); }
.badge-secondary { background: #e9ecef; color: #495057; }

/* ============================================================
   ALERTS / FLASH MESSAGES
   ============================================================ */
.alert {
  padding: 12px 18px;
  border-radius: var(--radius);
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  border-left: 4px solid;
}

.alert-success { background: #d4edda; border-color: var(--color-success); color: #155724; }
.alert-danger  { background: #f8d7da; border-color: var(--color-danger);  color: #721c24; }
.alert-warning { background: #fff3cd; border-color: var(--color-warning); color: #856404; }
.alert-info    { background: #d1ecf1; border-color: var(--color-info);    color: #0c5460; }

/* ============================================================
   2FA PIN-Eingabe
   ============================================================ */
.tfa-inputs {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin: 20px 0;
}

.tfa-input {
  width: 50px; height: 58px;
  text-align: center;
  font-size: 1.5rem;
  font-weight: 700;
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.tfa-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(26,74,138,0.15);
  outline: none;
}

/* ============================================================
   SETTINGS PAGE
   ============================================================ */
.settings-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.settings-tab {
  padding: 8px 18px;
  border-radius: 6px;
  border: 1px solid #dee2e6;
  background: #fff;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  color: #495057;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.settings-tab:hover { background: #f0f4ff; border-color: #b8c7ff; color: #1a4a8a; }
.settings-tab.active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

.settings-section { display: none; }
.settings-section.active { display: block; }

/* Farb-Picker */
.color-picker-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.color-picker-group input[type="color"] {
  width: 44px; height: 38px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
  padding: 2px;
  background: none;
}

/* Avatar-Vorschau */
.avatar-preview {
  width: 80px; height: 80px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--color-border);
  margin-bottom: 10px;
}

/* Logo-Vorschau */
.logo-preview {
  max-height: 80px;
  max-width: 250px;
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
  padding: 8px;
  background: var(--color-bg);
  margin-bottom: 10px;
}

/* ============================================================
   LDAP-Server-Karten
   ============================================================ */
.ldap-server-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 14px;
  background: var(--color-white);
  transition: box-shadow var(--transition);
}

.ldap-server-card:hover { box-shadow: 0 4px 16px var(--color-card-shadow); }

.ldap-server-card .ldap-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.ldap-status {
  width: 10px; height: 10px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
}

.ldap-status.active   { background: var(--color-success); }
.ldap-status.inactive { background: var(--color-text-muted); }

/* ============================================================
   PAGINATION
   ============================================================ */
.pagination {
  display: flex;
  gap: 4px;
  align-items: center;
  justify-content: center;
  margin-top: 20px;
}

.page-btn {
  padding: 7px 13px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-white);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all var(--transition);
  color: var(--color-text);
}

.page-btn:hover { background: var(--color-primary); color: var(--color-white); border-color: var(--color-primary); }
.page-btn.active { background: var(--color-primary); color: var(--color-white); border-color: var(--color-primary); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 2000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--color-white);
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 40px rgba(0,0,0,0.25);
  width: 90%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title { font-weight: 700; font-size: 1rem; color: var(--color-primary); }
.modal-close { background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--color-text-muted); line-height: 1; }
.modal-body { padding: 22px; }
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--color-border); display: flex; gap: 10px; justify-content: flex-end; }

/* ============================================================
   TOPBAR DROPDOWN
   ============================================================ */
.topbar-dropdown {
  position: relative;
}

.topbar-dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(0,0,0,0.12);
  min-width: 180px;
  display: none;
  z-index: 1500;
}

.topbar-dropdown.open .topbar-dropdown-menu { display: block; }

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  font-size: 0.88rem;
  color: var(--color-text);
  transition: background var(--transition);
  cursor: pointer;
}

.dropdown-item:hover { background: var(--color-bg); }
.dropdown-item.danger { color: var(--color-danger); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 900px) {
  .sidebar { width: 60px; overflow: hidden; }
  .sidebar-title, .sidebar-subtitle, .nav-item span, .nav-group-label,
  .sidebar-user-name, .sidebar-user-role, .sidebar-footer .btn { display: none; }
  .main-content { margin-left: 60px; }
  .nav-item { justify-content: center; padding: 12px; }
  .sidebar-header { justify-content: center; padding: 14px; }
  .sidebar-logo img { height: 28px; }
  .sidebar-avatar { margin: 0 auto; }
  .form-row { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 600px) {
  .page-content { padding: 16px; }
  .stat-grid { grid-template-columns: 1fr; }
  .settings-tabs { flex-direction: column; }
  .tfa-inputs { gap: 6px; }
  .tfa-input { width: 42px; height: 50px; font-size: 1.2rem; }
}

/* ============================================================
   UTILITIES
   ============================================================ */
.d-flex  { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-10 { gap: 10px; }
.gap-16 { gap: 16px; }
.mt-10  { margin-top: 10px; }
.mt-20  { margin-top: 20px; }
.mb-10  { margin-bottom: 10px; }
.mb-20  { margin-bottom: 20px; }
.text-muted { color: var(--color-text-muted); }
.text-center { text-align: center; }
.text-right  { text-align: right; }
.fw-bold { font-weight: 700; }
.w-100  { width: 100%; }
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); border: 0;
}

/* Divider */
.divider {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 20px 0;
}

/* Spinner */
.spinner {
  width: 20px; height: 20px;
  border: 3px solid rgba(255,255,255,0.3);
  border-top-color: var(--color-white);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   PRINT
   ============================================================ */
@media print {
  .sidebar, .topbar, .btn { display: none !important; }
  .main-content { margin-left: 0; }
  .page-content { padding: 0; }
}