:root {
  --bg: #f6f5fb;
  --bg-grad-1: #efeafd;
  --bg-grad-2: #fdeef4;
  --surface: #ffffff;
  --surface-2: #f4f4f7;
  --border: #e7e5ee;
  --text: #1f1b2e;
  --text-muted: #6b6880;
  --primary: #8b5cf6;
  --primary-dark: #7c3aed;
  --danger: #e11d48;
  --danger-dark: #be123c;
  --shadow-sm: 0 1px 2px rgba(24, 20, 45, 0.06);
  --shadow-md: 0 8px 24px rgba(24, 20, 45, 0.10);
  --shadow-lg: 0 20px 48px rgba(24, 20, 45, 0.18);
  --radius: 18px;
  --radius-sm: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.06s ease, background 0.15s ease, box-shadow 0.15s ease;
  text-decoration: none;
  line-height: 1;
}
.btn:active { transform: translateY(1px); }
.btn i { width: 18px; height: 18px; }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { box-shadow: var(--shadow-md); }

.btn-ghost {
  background: var(--surface-2);
  color: var(--text);
}
.btn-ghost:hover { background: #ecebf1; }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover { background: var(--danger-dark); }

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

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: inline-flex;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.link-btn {
  background: none;
  border: none;
  color: var(--primary-dark);
  cursor: pointer;
  font-weight: 600;
  font-size: inherit;
  padding: 0;
}
.link-btn:hover { text-decoration: underline; }

/* ---------- Login ---------- */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 10% -10%, var(--bg-grad-1), transparent),
    radial-gradient(1000px 500px at 110% 110%, var(--bg-grad-2), transparent),
    var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  padding: 40px 34px;
  width: 100%;
  max-width: 400px;
  text-align: center;
}
.login-emblem { font-size: 2.6rem; }
.login-card h1 {
  margin: 10px 0 4px;
  font-size: 1.5rem;
}
.login-sub {
  color: var(--text-muted);
  margin: 0 0 26px;
}

/* ---------- Form fields ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  margin-bottom: 16px;
}
.field > span {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}
.field > span em { font-weight: 400; font-style: normal; opacity: 0.75; }

input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input[type="text"]:focus,
input[type="password"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15);
}

.form-error {
  background: #fdecef;
  color: var(--danger-dark);
  border: 1px solid #f8c9d3;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.9rem;
  margin: 4px 0 0;
}

/* ---------- Topbar ---------- */
.topbar {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-emblem { font-size: 1.8rem; }
.brand h1 { margin: 0; font-size: 1.25rem; }
.brand-sub { margin: 0; font-size: 0.82rem; color: var(--text-muted); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

/* ---------- Content ---------- */
.dashboard-page {
  background:
    radial-gradient(1200px 500px at 0% -5%, var(--bg-grad-1), transparent),
    radial-gradient(1000px 500px at 100% 0%, var(--bg-grad-2), transparent),
    var(--bg);
  min-height: 100vh;
}
.content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 20px 64px;
}

/* ---------- Tiles grid ---------- */
.tiles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 18px;
}

.tile {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  color: var(--text);
  overflow: hidden;
  transition: transform 0.12s ease, box-shadow 0.15s ease;
  min-height: 92px;
}
.tile::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--tile-color, var(--primary));
  opacity: 0.10;
  pointer-events: none;
}
.tile:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}
.tile-icon {
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--tile-color, var(--primary));
  box-shadow: 0 6px 14px color-mix(in srgb, var(--tile-color, var(--primary)) 40%, transparent);
  z-index: 1;
}
.tile-icon i { width: 26px; height: 26px; }
.tile-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  z-index: 1;
  min-width: 0;
}
.tile-title {
  font-weight: 700;
  font-size: 1.02rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tile-subtitle {
  font-size: 0.83rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile-edit {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--border);
  border-radius: 9px;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--text-muted);
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.15s ease, transform 0.15s ease, background 0.15s ease;
}
.tile:hover .tile-edit { opacity: 1; transform: translateY(0); }
.tile-edit:hover { color: var(--primary-dark); background: #fff; }
.tile-edit i { width: 16px; height: 16px; }

/* Reorder-Modus */
.tiles-grid.is-reordering .tile { cursor: grab; }
.tiles-grid.is-reordering .tile-edit { display: none; }
.tile.dragging { opacity: 0.55; transform: scale(0.98); }
.tile.drag-over { outline: 2px dashed var(--primary); outline-offset: 3px; }

.reorder-hint {
  background: #efeafd;
  border: 1px solid #ded3fb;
  color: var(--primary-dark);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 18px;
  font-size: 0.9rem;
}

/* ---------- States ---------- */
.empty-state, .loading-state {
  text-align: center;
  color: var(--text-muted);
  padding: 60px 20px;
}
.empty-state i { width: 48px; height: 48px; opacity: 0.5; }
.empty-state p { margin: 12px 0 20px; }
.loading-state { font-size: 0.95rem; }

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal[hidden] { display: none !important; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(24, 20, 45, 0.45);
  backdrop-filter: blur(2px);
}
.modal-card {
  position: relative;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 720px;
  max-height: 92vh;
  overflow-y: auto;
  animation: modal-in 0.15s ease;
}
.modal-card-narrow { max-width: 460px; }
.modal-hint {
  margin: 0 0 16px;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.45;
}
.form-success {
  background: #ecfdf5;
  color: #047857;
  border: 1px solid #a7f3d0;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.9rem;
  margin: 4px 0 0;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
.modal-head h2 { margin: 0; font-size: 1.2rem; }
.modal-body { padding: 20px 22px 22px; }

.modal-columns {
  display: grid;
  grid-template-columns: 1fr 240px;
  gap: 22px;
}
.modal-fields { min-width: 0; }

/* Preview */
.modal-preview {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.preview-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}
.tile-preview {
  cursor: default;
  position: sticky;
  top: 76px;
}
.tile-preview:hover { transform: none; box-shadow: var(--shadow-sm); }

/* Colors */
.color-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.color-presets { display: flex; gap: 8px; flex-wrap: wrap; }
.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.1s ease;
}
.color-swatch:hover { transform: scale(1.12); }
.color-swatch.selected {
  border-color: var(--text);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.06);
}
.color-custom {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
}
.color-custom input[type="color"] {
  width: 34px;
  height: 34px;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
}

/* Icons */
.icon-search { margin-bottom: 10px; }
.icon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.icon-option {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--surface);
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.1s ease;
}
.icon-option:hover { color: var(--text); border-color: var(--border); }
.icon-option.selected {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.icon-option i { width: 20px; height: 20px; }

.modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.modal-foot-right { display: flex; gap: 10px; margin-left: auto; }

/* ---------- Feature-Sektionen ---------- */
.feature-section {
  margin-top: 32px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.feature-section-title {
  margin: 0 0 12px;
  font-size: 1.1rem;
  font-weight: 600;
}
.feature-section-body:empty { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .modal-columns { grid-template-columns: 1fr; }
  .modal-preview { order: -1; }
  .tile-preview { position: static; }
  .brand-sub { display: none; }
  .topbar-actions .btn span { display: none; }
  .topbar-actions .btn { padding: 10px; }
  .tiles-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}
