/* ==========================================================================
   DGM UI Styleguide — Wiederverwendbares Design-System
   Von DGM Kommunikation

   Enthält: Variables, Reset, Typografie, Buttons, Forms, Cards, Tables,
   Tabs, Badges, Alerts, Modals, Toggle-Switches, Tooltips, Upload

   Abhängigkeiten:
   - Google Font "Inter" (300-700)
   - Lucide Icons (optional, für Icon-Buttons)
   ========================================================================== */

/* ==========================================================================
   1. CSS CUSTOM PROPERTIES
   ========================================================================== */

:root {
  /* Primary Brand */
  --admin-primary: #840732;
  --admin-primary-hover: #6a0628;
  --admin-primary-rgb: 132, 7, 50;
  --admin-primary-faint: rgba(var(--admin-primary-rgb), 0.2);

  /* Semantic Colors */
  --admin-danger: #ef4444;
  --admin-danger-hover: #dc2626;
  --admin-success: #22c55e;

  /* Surfaces (Dark Theme — Default) */
  --admin-bg: #222222;
  --admin-bg-elevated: #313131;
  --admin-card: #313131;
  --admin-card-hover: #3a3a3a;

  /* Borders & Shadows */
  --admin-border: #444444;
  --admin-radius: 3px;
  --admin-shadow: 0 2px 8px rgba(0,0,0,0.3);
  --admin-shadow-heavy: 0 25px 50px rgba(0,0,0,0.5);

  /* Text */
  --admin-text: #ebebeb;
  --admin-text-muted: #6a6a6a;
  --admin-text-faint: #555555;

  /* Interactive */
  --admin-hover-bg: rgba(255,255,255,0.04);
  --admin-subtle-bg: rgba(255,255,255,0.08);
}

/* ==========================================================================
   2. LIGHT THEME
   ========================================================================== */

[data-theme="light"] {
  --admin-bg: #f5f5f7;
  --admin-bg-elevated: #ffffff;
  --admin-card: #ffffff;
  --admin-card-hover: #f0f0f2;
  --admin-border: #d1d1d6;
  --admin-text: #1d1d1f;
  --admin-text-muted: #86868b;
  --admin-text-faint: #aeaeb2;
  --admin-shadow: 0 2px 8px rgba(0,0,0,0.06);
  --admin-shadow-heavy: 0 25px 50px rgba(0,0,0,0.12);
  --admin-hover-bg: rgba(0,0,0,0.04);
  --admin-subtle-bg: rgba(0,0,0,0.05);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --admin-bg: #f5f5f7;
    --admin-bg-elevated: #ffffff;
    --admin-card: #ffffff;
    --admin-card-hover: #f0f0f2;
    --admin-border: #d1d1d6;
    --admin-text: #1d1d1f;
    --admin-text-muted: #86868b;
    --admin-text-faint: #aeaeb2;
    --admin-shadow: 0 2px 8px rgba(0,0,0,0.06);
    --admin-shadow-heavy: 0 25px 50px rgba(0,0,0,0.12);
    --admin-hover-bg: rgba(0,0,0,0.04);
    --admin-subtle-bg: rgba(0,0,0,0.05);
  }
}

/* ==========================================================================
   3. RESET & BASE
   ========================================================================== */

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

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--admin-bg);
  color: var(--admin-text);
  font-size: 0.9rem;
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--admin-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.text-muted { color: var(--admin-text-muted); font-size: 0.85rem; }

/* ==========================================================================
   4. BUTTONS
   ========================================================================== */

/* Primary Size: 38px — Main Content */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  height: 38px;
  padding: 0 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: var(--admin-radius);
  cursor: pointer;
  text-decoration: none !important;
  transition: all 0.15s;
  font-family: inherit;
  line-height: 1;
}
.btn svg { width: 18px; height: 18px; }

/* Small Size: 28px — Editor-Panels, Card-Actions, kompakte Bereiche */
.btn-small {
  height: 28px;
  padding: 0 0.6rem;
  font-size: 0.8rem;
}
.btn-small svg { width: 16px; height: 16px; }

/* Icon-only Buttons (quadratisch) */
.btn-icon { padding: 0; width: 38px; }
.btn-small.btn-icon { padding: 0; width: 28px; }

/* Varianten */
.btn-primary { background: var(--admin-primary); color: #fff; }
.btn-primary:hover { background: var(--admin-primary-hover); }

.btn-secondary {
  background: var(--admin-card);
  color: var(--admin-text);
  border-color: var(--admin-border);
}
.btn-secondary:hover { background: var(--admin-card-hover); }

.btn-danger { background: color-mix(in srgb, var(--admin-primary) 70%, #000); color: #fff; }
.btn-danger:hover { background: color-mix(in srgb, var(--admin-primary) 55%, #000); }

.btn-success { background: var(--admin-success); color: #fff; border-color: var(--admin-success); }
.btn-success:hover { opacity: 0.85; }

.btn-outline { background: transparent; border: 1px solid var(--admin-border); color: var(--admin-text); }
.btn-outline:hover { border-color: var(--admin-primary); color: var(--admin-primary); }

.btn-outline-danger { background: transparent; border: 1px solid var(--admin-danger); color: var(--admin-danger); }
.btn-outline-danger:hover { background: rgba(229,62,62,0.1); }

.btn-block { display: block; width: 100%; justify-content: center; }

/* ==========================================================================
   5. FORMS
   ========================================================================== */

/* Form Container */
.admin-form {
  background: var(--admin-card);
  border: 1px solid var(--admin-border);
  border-radius: var(--admin-radius);
  padding: 1.5rem;
}

.form-group { margin-bottom: 1rem; }

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--admin-text-muted);
  margin-bottom: 0.35rem;
}

/* Input Fields — Primary (38px) */
.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="url"],
.form-group input[type="tel"],
.form-group input[type="number"],
.form-group input[type="password"],
.form-group input[type="date"],
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0 0.75rem;
  height: 38px;
  font-size: 0.9rem;
  border: 1px solid var(--admin-border);
  border-radius: var(--admin-radius);
  font-family: inherit;
  background: var(--admin-bg);
  color: var(--admin-text);
  transition: border-color 0.15s;
}

/* Input Fields — Small (28px) */
.form-small input[type="text"],
.form-small input[type="email"],
.form-small input[type="url"],
.form-small input[type="tel"],
.form-small input[type="number"],
.form-small input[type="password"],
.form-small input[type="date"],
.form-small select {
  height: 28px;
  padding: 0 0.5rem;
  font-size: 0.8rem;
}

.form-group textarea {
  height: auto;
  padding-top: 0.75rem;
  padding-bottom: 0.75rem;
}

/* Focus State */
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--admin-primary);
  box-shadow: 0 0 0 3px rgba(var(--admin-primary-rgb), 0.15);
}

.form-group select option {
  background: var(--admin-card);
  color: var(--admin-text);
}

/* Form Layouts */
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.form-section {
  border: 1px solid var(--admin-border);
  border-radius: var(--admin-radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--admin-border);
}

.form-hint {
  font-size: 0.85rem;
  color: var(--admin-text-muted);
  margin-bottom: 1rem;
}

/* Checkbox */
.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-weight: 400 !important;
}

.checkbox-label input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  margin: 0;
  padding: 0;
  border: 1px solid var(--admin-border);
  border-radius: var(--admin-radius);
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  display: block;
  box-sizing: border-box;
}
.checkbox-label input[type="checkbox"]:checked {
  background: var(--admin-bg);
  border-color: var(--admin-border);
}
.checkbox-label input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 7px;
  top: 3px;
  width: 5px;
  height: 10px;
  border: solid var(--admin-text);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  width: 36px;
  height: 20px;
  display: inline-block;
  vertical-align: middle;
}
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--admin-border);
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  top: 2px;
  left: 2px;
  transition: transform 0.2s;
}
.toggle-switch input:checked + .toggle-slider {
  background: var(--admin-success);
}
.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(16px);
}

/* Color Input */
.color-input-hex {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.color-input-hex input[type="color"] {
  width: 48px;
  height: 48px;
  border: 1px solid var(--admin-border);
  border-radius: var(--admin-radius);
  cursor: pointer;
  padding: 5px;
  background: var(--admin-bg);
  flex-shrink: 0;
}
.color-input-hex input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-input-hex input[type="color"]::-webkit-color-swatch { border: none; border-radius: 2px; }
.color-input-hex input[type="color"]::-moz-color-swatch { border: none; border-radius: 2px; }
.color-input-hex input[type="text"] {
  flex: 1;
  font-family: monospace;
  letter-spacing: 0.05em;
}

/* ==========================================================================
   6. CARDS
   ========================================================================== */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}

.card-link {
  display: block;
  text-decoration: none;
  color: inherit;
  background: var(--admin-card);
  border: 1px solid var(--admin-border);
  border-radius: var(--admin-radius);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.card-link:hover { border-color: var(--admin-primary); box-shadow: var(--admin-shadow); text-decoration: none; }

.card-preview {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 160px;
  background: var(--admin-subtle-bg);
  border-radius: var(--admin-radius) var(--admin-radius) 0 0;
  overflow: hidden;
}
.card-preview img { width: 100%; height: 100%; object-fit: cover; }

.card-body { padding: 10px 0 0 0; }
.card-body h3 { font-size: 1rem; font-weight: 600; }

.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 10px;
}
.card-title { font-weight: 600; font-size: 14px; }
.card-size { font-size: 11px; color: var(--admin-text-muted); white-space: nowrap; }

.card-actions { display: flex; justify-content: space-between; margin-top: 10px; padding: 0 10px 10px; }
.card-actions-left, .card-actions-right { display: flex; gap: 6px; }

/* ==========================================================================
   7. TABLES
   ========================================================================== */

.table-wrap { overflow-x: auto; }

.admin-table {
  width: 100%;
  background: var(--admin-card);
  border: 1px solid var(--admin-border);
  border-radius: var(--admin-radius);
  overflow: hidden;
}

.admin-table th, .admin-table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--admin-border);
}

.admin-table th {
  background: var(--admin-bg-elevated);
  font-weight: 500;
  font-size: 0.85rem;
  color: var(--admin-text-muted);
}

.admin-table tr:last-child td { border-bottom: none; }
.admin-table th:last-child, .admin-table td:last-child { text-align: right; }

.actions-cell { display: flex; gap: 0.4rem; flex-wrap: nowrap; white-space: nowrap; }

/* ==========================================================================
   8. BADGES
   ========================================================================== */

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  background: var(--admin-subtle-bg);
  border-radius: var(--admin-radius);
  font-size: 0.75rem;
  color: var(--admin-text-muted);
}

/* Status Badges */
.status-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: var(--admin-radius);
  font-size: 0.75rem;
  font-weight: 500;
}
.status-active { background: rgba(34,197,94,0.15); color: #4ade80; }
.status-inactive { background: rgba(239,68,68,0.15); color: #f87171; }
.status-entwurf { background: rgba(160,160,160,0.15); color: #a0a0a0; }
.status-bearbeitung { background: rgba(251,191,36,0.15); color: #fbbf24; }
.status-freigegeben { background: rgba(34,197,94,0.15); color: #4ade80; }
.status-versendet { background: rgba(99,102,241,0.15); color: #818cf8; }

/* Role Badges */
.role-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: var(--admin-radius);
  font-size: 0.75rem;
  font-weight: 500;
}
.role-super-admin { background: rgba(234,179,8,0.15); color: #facc15; }
.role-tenant-user { background: rgba(59,130,246,0.15); color: #60a5fa; }

/* Light Mode Badge Overrides */
[data-theme="light"] .status-active { color: #16a34a; }
[data-theme="light"] .status-inactive { color: #dc2626; }
[data-theme="light"] .role-super-admin { color: #a16207; }
[data-theme="light"] .role-tenant-user { color: #2563eb; }

/* ==========================================================================
   9. TABS
   ========================================================================== */

.tabs-wrap {
  position: relative;
  margin: -1.5rem -1.5rem 0 -1.5rem;
}
.tabs-wrap::after {
  content: '';
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 32px;
  background: linear-gradient(to right, transparent, #181818);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}
.tabs-wrap.has-overflow::after { opacity: 1; }

.tabs {
  display: flex;
  gap: 0.35rem;
  padding: 1.5rem 1.5rem 0 1.5rem;
  background: #181818;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

[data-theme="light"] .tabs { background: #e0e0e2; }
[data-theme="light"] .tabs-wrap::after { background: linear-gradient(to right, transparent, #e0e0e2); }

.tab {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  font-weight: 500;
  border: none;
  background: rgba(255,255,255,0.06);
  border-radius: var(--admin-radius) var(--admin-radius) 0 0;
  cursor: pointer;
  color: var(--admin-text-muted);
  white-space: nowrap;
  font-family: inherit;
  transition: color 0.15s, background 0.15s;
}
.tab:hover { color: var(--admin-text); }
.tab.active { color: var(--admin-primary); background: var(--admin-card); }

.tab-content { display: none; padding-top: 1.5rem; }
.tab-content.active { display: block; }
.tab-content h4 {
  font-size: 0.85rem;
  font-weight: 500;
  text-transform: uppercase;
  opacity: 0.4;
  padding-bottom: 15px;
}

/* ==========================================================================
   10. ALERTS
   ========================================================================== */

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--admin-radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.alert-success {
  background: rgba(34,197,94,0.12);
  color: #4ade80;
  border: 1px solid rgba(34,197,94,0.25);
}

.alert-error {
  background: rgba(239,68,68,0.12);
  color: #f87171;
  border: 1px solid rgba(239,68,68,0.25);
}

.empty-state {
  text-align: center;
  padding: 0.2rem 0 1.5rem 0;
  color: var(--admin-text-muted);
}

/* ==========================================================================
   11. MODALS
   ========================================================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--admin-bg-elevated);
  border: 1px solid var(--admin-border);
  border-radius: 8px;
  width: 100%;
  max-width: 440px;
  padding: 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}
.modal-close {
  background: none;
  border: none;
  color: var(--admin-text-muted);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
  padding: 0;
}
.modal-close:hover { color: var(--admin-text); }

.modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* ==========================================================================
   12. UPLOAD AREA
   ========================================================================== */

.upload-area {
  border: 2px dashed var(--admin-border);
  border-radius: var(--admin-radius);
  padding: 1.5rem;
  text-align: center;
  transition: border-color 0.15s;
  margin-bottom: 1rem;
}
.upload-area.dragover {
  border-color: var(--admin-primary);
  background: rgba(var(--admin-primary-rgb), 0.05);
}

.upload-hint {
  font-size: 0.8rem;
  color: var(--admin-text-muted);
  margin-top: 0.5rem;
}

.file-input {
  display: block;
  margin: 0 auto;
  font-size: 0.85rem;
  color: var(--admin-text-muted);
}

/* ==========================================================================
   13. TOOLTIPS
   ========================================================================== */

.tooltip-wrap {
  display: inline-block;
  position: relative;
  cursor: help;
  font-size: 0.95em;
  color: var(--admin-text-muted);
  margin-left: 4px;
}
.tooltip-wrap svg { width: 16px; height: 16px; }
.tooltip-wrap:hover { color: var(--admin-primary); }

.tooltip-text {
  display: none;
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  transform: translateX(-50%);
  background: #000;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 400;
  line-height: 1.4;
  padding: 8px 12px;
  border-radius: 6px;
  width: 300px;
  white-space: normal;
  z-index: 10000;
  pointer-events: none;
}
.tooltip-wrap:hover .tooltip-text { display: block; }

/* ==========================================================================
   14. PAGE LAYOUT HELPERS
   ========================================================================== */

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.page-header h2, .page-header h3 { font-weight: 600; }
.page-header > div:first-child {
  font-size: 0.9rem;
  color: var(--admin-text-muted);
}

.header-actions { display: flex; gap: 0.5rem; align-items: center; }

.detail-card {
  background: var(--admin-card);
  border: 1px solid var(--admin-border);
  border-radius: var(--admin-radius);
  padding: 1.5rem;
}
