:root {
  --bg: #f4f1f7;
  --surface: #ffffff;
  --border: #e6e1ec;
  --text: #1f1530;
  --muted: #6b6577;
  /* Teliatis-Markenfarbe (Violett) */
  --accent: #7c2d91;
  --accent-hover: #642477;
  --accent-soft: #f6ecfa;
  --danger: #dc2626;
  --success: #16a34a;
  --warn: #d97706;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 3px rgba(31,21,48,0.07), 0 1px 2px rgba(31,21,48,0.04);
  --shadow-md: 0 6px 18px rgba(124,45,145,0.12);
  --sidebar-w: 240px;
  /* Akzentfarben für KPIs / Icons */
  --c-blue:#3b82f6; --c-green:#10b981; --c-amber:#f59e0b; --c-purple:#8b5cf6;
  --c-pink:#ec4899; --c-teal:#14b8a6; --c-red:#ef4444; --c-violet:#7c2d91;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

/* ============ LAYOUT ============ */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: linear-gradient(180deg, #5b1d6e 0%, #3a1248 100%);
  color: #e4d4ec;
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0;
  z-index: 50;
  overflow-y: auto;
}
.sidebar .brand {
  padding: 16px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.10);
  background: #fff;
}
.sidebar .brand img { display: block; max-width: 170px; height: auto; }
.sidebar .brand-fallback {
  font-size: 17px; font-weight: 700; color: #fff;
  display: flex; align-items: center; gap: 9px;
}
.sidebar .brand-fallback .logo-dot {
  width: 26px; height: 26px; border-radius: 7px;
  background: linear-gradient(135deg,#b06fc4,#7c2d91);
  display: inline-flex; align-items: center; justify-content: center; font-size: 14px;
}
.sidebar .navgroup { padding: 12px 0 4px; }
.sidebar .navgroup-title {
  padding: 6px 20px; font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: #c98fde; opacity: 0.95;
}
.sidebar nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 8px 20px; color: #e4d4ec; font-weight: 500; font-size: 13.5px;
  border-left: 3px solid transparent;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.07); color: #fff; text-decoration: none; }
.sidebar nav a.active {
  background: rgba(176,111,196,0.26);
  color: #fff; border-left-color: #c98fde;
}
.sidebar nav a .ico { width: 18px; text-align: center; font-size: 15px; flex-shrink: 0; }

.sidebar .side-user {
  margin-top: auto;
  padding: 14px 18px;
  border-top: 1px solid rgba(255,255,255,0.10);
  display: flex; align-items: center; gap: 10px;
}
.sidebar .side-user .avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg,#b06fc4,#7c2d91); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 12px; flex-shrink: 0; text-decoration: none;
}
.sidebar .side-user .uname { font-size: 12.5px; color: #f3e8f8; font-weight: 600; line-height: 1.2; }
.sidebar .side-user .urole { font-size: 11px; color: #c98fde; }
.sidebar .side-user .admin-links { display: flex; gap: 8px; margin-left: auto; }
.sidebar .side-user .admin-links a { color: #d8b8e6; font-size: 14px; padding: 2px; }
.sidebar .side-user .admin-links a:hover { color: #fff; text-decoration: none; }

.main-area {
  flex: 1; min-width: 0;
  margin-left: var(--sidebar-w);
  display: flex; flex-direction: column;
}

/* Mobile-Topbar (nur sichtbar < 900px) */
.mobile-topbar {
  display: none;
  align-items: center; gap: 12px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 16px; height: 54px;
  position: sticky; top: 0; z-index: 40;
}
.mobile-topbar .brand img { height: 30px; width: auto; display: block; }
.hamburger {
  background: none; border: none; cursor: pointer;
  width: 38px; height: 38px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; color: var(--text);
}
.hamburger:hover { background: var(--bg); }
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0; background: rgba(31,21,48,0.5); z-index: 49;
}

.container { max-width: 1240px; margin: 0 auto; padding: 28px; width: 100%; }

.bottombar {
  margin-top: auto; padding: 18px 28px; text-align: center;
  color: var(--muted); border-top: 1px solid var(--border); font-size: 12px;
}

h1 { margin: 0 0 20px; font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }
h2 { margin: 28px 0 14px; font-size: 16px; font-weight: 600; }

.flash {
  background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46;
  padding: 11px 16px; border-radius: var(--radius); margin-bottom: 18px;
  display: flex; align-items: center; gap: 8px;
}
.flash::before { content: "✓"; font-weight: 700; }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--border);
  padding: 8px 15px; border-radius: var(--radius-sm); cursor: pointer;
  color: var(--text); font: inherit; font-weight: 500; text-decoration: none;
  transition: all 0.14s ease; min-height: 38px;
}
.btn:hover { background: #faf7fc; border-color: #d6c7e0; text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; box-shadow: var(--shadow-md); }
.btn-danger { color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: 5px 10px; font-size: 12px; min-height: 30px; }

/* ============ CARDS ============ */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; margin-bottom: 18px;
}

/* ============ TABLES ============ */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); border: 1px solid var(--border); margin-bottom: 18px; }
.table-wrap table { border: 0; border-radius: 0; margin-bottom: 0; }
table {
  width: 100%; border-collapse: collapse; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
th { background: #faf7fc; font-weight: 600; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: 0; }
tbody tr { transition: background 0.1s; }
tbody tr:hover td { background: #faf7fc; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
th a { color: inherit; }
th a.sort-active { color: var(--accent); }

form.inline { display: inline; }

/* ============ FORMS ============ */
.form-row { margin-bottom: 16px; }
.form-row label { display: block; font-weight: 600; margin-bottom: 5px; font-size: 13px; }
.form-row input[type=text], .form-row input[type=email], .form-row input[type=number],
.form-row input[type=password], .form-row select, .form-row textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); font: inherit; background: #fff;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.form-row textarea { min-height: 200px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.form-row .help { color: var(--muted); font-size: 12px; margin-top: 5px; }

.error { background: #fef2f2; border: 1px solid #fecaca; color: var(--danger); padding: 11px 16px; border-radius: var(--radius); margin-bottom: 18px; }

.filterbar {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 18px; margin-bottom: 18px;
  display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end;
}
.filterbar .group { display: flex; flex-direction: column; gap: 6px; }
.filterbar label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.filterbar select[multiple] { min-width: 180px; min-height: 70px; }
.filterbar .group select, .filterbar .group input { padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; }

/* ============ STATUS BADGES ============ */
.status { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; }
.status-draft { background: #f1f5f9; color: #475569; }
.status-sending { background: #fef9c3; color: #854d0e; }
.status-sent { background: #dcfce7; color: #15803d; }
.status-sample-sent { background: #ede9fe; color: #6d28d9; }
.status-failed { background: #fee2e2; color: #b91c1c; }
.status-scheduled { background: #f3e8ff; color: #7c2d91; }
.status-skipped { background: #f1f5f9; color: #475569; }
.status-subscribed, .status-active { background: #dcfce7; color: #15803d; }
.status-unsubscribed { background: #f1f5f9; color: #475569; }
.status-bounced { background: #fee2e2; color: #b91c1c; }

/* ============ KPIs ============ */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 26px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); position: relative; overflow: hidden;
  display: flex; align-items: center; gap: 14px;
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}
a.kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); text-decoration: none; border-color: #d6c7e0; }
.kpi .kpi-icon {
  width: 42px; height: 42px; border-radius: 11px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 20px;
}
.kpi .kpi-body { min-width: 0; }
.kpi .label { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.kpi .value { font-size: 23px; font-weight: 700; margin-top: 2px; letter-spacing: -0.02em; color: var(--text); }

.preview-frame { border: 1px solid var(--border); border-radius: var(--radius); background: #fff; padding: 16px; max-width: 640px; }

.muted { color: var(--muted); }
.right { text-align: right; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

/* ============ RESPONSIVE ============ */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.22s ease; box-shadow: var(--shadow-md); }
  .sidebar.open { transform: translateX(0); }
  .main-area { margin-left: 0; }
  .mobile-topbar { display: flex; }
  body.nav-open .sidebar-backdrop { display: block; }
  .container { padding: 18px 16px; }
  .split { grid-template-columns: 1fr; }
  h1 { font-size: 21px; }
}

@media (max-width: 560px) {
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 13px; gap: 10px; }
  .kpi .kpi-icon { width: 36px; height: 36px; font-size: 17px; }
  .kpi .value { font-size: 19px; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar .btn { width: 100%; justify-content: center; }
}

/* Fallback: nackte Tabellen (ohne .table-wrap) auf Mobile horizontal scrollbar machen */
@media (max-width: 760px) {
  .container > table,
  .card > table {
    display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap;
  }
}
