/* ============================================
   E&V OPERATIONS — DESIGN SYSTEM
   Light Mode, DM Sans, E&V Rot
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:opsz,wght@9..40,300;9..40,400;9..40,500;9..40,600;9..40,700&display=swap');

/* ============================================
   1. CSS VARIABLES (Design Tokens)
   ============================================ */
:root {
  /* Surfaces */
  --bg:             #fafaf8;
  --surface:        #ffffff;
  --surface-hover:  rgba(0,0,0,.012);
  --border:         #e8e5e0;
  --border-light:   #f0eee9;

  /* Text */
  --text:           #1a1a1a;
  --text-secondary: #8a857d;
  --text-tertiary:  #b5b0a8;
  --text-faded:     #c5c0b8;

  /* Brand colors */
  --red:            #c8102e;
  --red-bg:         #fef5f5;
  --red-hover:      #a80d24;

  /* Semantic colors */
  --green:          #3d8b5e;
  --green-bg:       #f0f7f2;
  --amber:          #c49a20;
  --amber-bg:       #fdf8ec;
  --blue:           #4a6fa5;
  --blue-bg:        #f0f4fa;
  --purple:         #7b5ea7;
  --purple-bg:      #f5f0fa;

  /* Layout */
  --radius:         10px;
  --radius-sm:      6px;
  --header-height:  56px;
  --header-height-mobile: 48px;

  /* Shadows */
  --shadow-sm:      0 1px 3px rgba(0,0,0,.04), 0 1px 2px rgba(0,0,0,.03);
  --shadow:         0 2px 8px rgba(0,0,0,.05), 0 1px 3px rgba(0,0,0,.04);
  --shadow-lg:      0 8px 24px rgba(0,0,0,.08), 0 2px 8px rgba(0,0,0,.04);

  /* Typography */
  --font:           'DM Sans', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;

  /* Transitions */
  --transition:     all .15s ease;
}


/* ============================================
   2. RESET & BASE
   ============================================ */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  overscroll-behavior-y: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}


/* ============================================
   3. SCREENS (Loading / Login / App)
   ============================================ */
.screen {
  display: none;
  width: 100%;
}

.screen--active {
  display: block;
}

#loading-screen.screen--active,
#login-screen.screen--active {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
}


/* ============================================
   4. LOADING SCREEN
   ============================================ */
.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-light);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 14px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  font-size: 10px;
  color: var(--text-faded);
  letter-spacing: 2px;
  text-transform: uppercase;
}


/* ============================================
   5. LOGIN SCREEN
   ============================================ */
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 48px 40px;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  max-width: 420px;
  width: calc(100% - 40px);
}

.login-title {
  font-size: 22px;
  font-weight: 500;
  letter-spacing: 1.2px;
  color: var(--text);
  margin-bottom: 8px;
}

.login-title b {
  color: var(--red);
  font-weight: 500;
}

.login-subtitle {
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 32px;
}

.login-error {
  color: var(--red);
  font-size: 12px;
  margin-top: 16px;
  min-height: 1.2em;
  text-align: center;
}


/* ============================================
   6. APP SHELL — Header
   ============================================ */
.app-header {
  position: sticky;
  top: 0;
  z-index: 500;
  background: rgba(250,250,248,.92);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid var(--border);
  height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 24px;
}

.app-header__inner {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-header__brand {
  font-size: 15px;
  font-weight: 500;
  letter-spacing: .8px;
  color: var(--text);
}

.app-header__brand b {
  color: var(--red);
  font-weight: 500;
}

.app-header__user {
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 12px;
}


/* ============================================
   7. APP LAYOUT (Sidebar + Main)
   ============================================ */
#app-screen.screen--active {
  display: block;
  min-height: 100vh;
}

.app-layout {
  display: flex;
  min-height: calc(100vh - var(--header-height));
}

.app-sidebar {
  display: none;
  width: 200px;
  flex-shrink: 0;
  background: var(--bg);
  border-right: 1px solid var(--border-light);
  padding: 24px 0;
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height));
  overflow-y: auto;
}

.app-sidebar a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  border-left: 3px solid transparent;
}

.app-sidebar a:hover {
  color: var(--text);
  background: var(--surface);
}

.app-sidebar a.active {
  color: var(--red);
  font-weight: 500;
  border-left-color: var(--red);
  background: var(--red-bg);
}

.app-sidebar a svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.app-main {
  flex: 1;
  min-width: 0;
}

.app-welcome {
  padding: 28px 32px 24px;
  border-bottom: 1px solid var(--border-light);
  max-width: 1260px;
  margin: 0 auto;
}

.app-welcome h1 {
  font-size: 28px;
  font-weight: 300;
  line-height: 1.3;
  margin-bottom: 4px;
  letter-spacing: -.3px;
}

.app-welcome h1 em {
  color: var(--red);
  font-style: normal;
  font-weight: 400;
}

.app-welcome p {
  font-size: 13px;
  color: var(--text-secondary);
}

.app-content {
  padding: 0 32px 40px;
  max-width: 1260px;
  margin: 0 auto;
}


/* ============================================
   8. BOTTOM NAVIGATION (Mobile)
   ============================================ */
.app-bnav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(250,250,248,.92);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 500;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.app-bnav button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 4px 8px;
  font-size: 10px;
  font-weight: 500;
  color: var(--text-tertiary);
  min-height: 50px;
  font-family: var(--font);
  transition: color .2s;
  -webkit-tap-highlight-color: transparent;
}

.app-bnav button.active {
  color: var(--red);
}

.app-bnav__ico {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.app-bnav__ico svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}


/* ============================================
   9. BUTTONS
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 18px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font);
  color: var(--text-secondary);
  transition: var(--transition);
  white-space: nowrap;
}

.btn:hover {
  border-color: var(--text-tertiary);
  color: var(--text);
}

.btn--primary {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}

.btn--primary:hover {
  background: var(--red-hover);
  color: #fff;
  border-color: var(--red-hover);
}

.btn--ghost {
  border-color: var(--border);
}

.btn--large {
  padding: 12px 24px;
  font-size: 14px;
  width: 100%;
}


/* ============================================
   10. UTILITY CLASSES
   ============================================ */
.section {
  padding: 20px 0 0;
}

.sec-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.8px;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 14px;
}

.divider {
  height: 1px;
  background: var(--border-light);
  margin: 24px 0;
}

.text-muted {
  color: var(--text-secondary);
}

.text-faded {
  color: var(--text-faded);
}

.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 10px;
  font-weight: 600;
}

.pill-red    { background: var(--red-bg);   color: var(--red); }
.pill-green  { background: var(--green-bg); color: var(--green); }
.pill-amber  { background: var(--amber-bg); color: var(--amber); }
.pill-blue   { background: var(--blue-bg);  color: var(--blue); }


/* ============================================
   11. ERROR STATES
   ============================================ */
.page-error {
  max-width: 600px;
  margin: 64px auto;
  padding: 40px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.page-error h2 {
  color: var(--red);
  font-weight: 400;
  margin-bottom: 8px;
}


/* ============================================
   12. RESPONSIVE
   ============================================ */
@media (min-width: 860px) {
  .app-sidebar {
    display: block;
  }
  .app-bnav {
    display: none !important;
  }
  .app-welcome h1 {
    font-size: 32px;
  }
}

@media (max-width: 859px) {
  .app-header {
    padding: 0 16px;
    height: var(--header-height-mobile);
  }
  .app-welcome {
    padding: 20px 16px 16px;
  }
  .app-welcome h1 {
    font-size: 22px;
  }
  .app-content {
    padding: 0 16px 40px;
  }
  body {
    padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  }
}


/* ============================================
   13. iOS SAFE AREA
   ============================================ */
@supports (-webkit-touch-callout: none) {
  body.standalone .app-header {
    padding-top: env(safe-area-inset-top, 0px);
    height: calc(var(--header-height) + env(safe-area-inset-top, 0px));
  }
}

/* ============================================
   14. LOGO
   ============================================ */
.login-logo {
  height: 28px;
  width: auto;
  margin-bottom: 24px;
  display: block;
  margin-left: auto;
  margin-right: auto;
}

.app-header__logo {
  height: 18px;
  width: auto;
  display: block;
}

/* ============================================
   15. PAGE: ModWorld
   ============================================ */
.w-wrap {
  max-width: 1200px;
  margin: 0 auto;
}

/* Quick Links Card */
.ql-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: 20px;
}

.ql-main {
  padding: 14px 16px;
}

.ql-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 6px;
}

.ql-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 4px;
  background: var(--bg);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 10px;
  font-weight: 500;
  text-align: center;
  transition: all .12s;
}

.ql-tile:hover {
  border-color: var(--red);
  background: var(--surface);
  transform: translateY(-1px);
}

.ql-ico {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
}

.ql-ico svg {
  width: 15px;
  height: 15px;
}

.ql-ico--red    { background: var(--red-bg);    color: var(--red); }
.ql-ico--blue   { background: var(--blue-bg);   color: var(--blue); }
.ql-ico--green  { background: var(--green-bg);  color: var(--green); }
.ql-ico--amber  { background: var(--amber-bg);  color: var(--amber); }
.ql-ico--purple { background: var(--purple-bg); color: var(--purple); }
.ql-ico--teal   { background: #f0fdfa;          color: #0d9488; }

.ql-hint {
  font-size: 8px;
  color: var(--text-faded);
}

.ql-expand-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border-top: 1px solid var(--border-light);
  cursor: pointer;
  font-size: 10px;
  font-weight: 500;
  color: var(--text-tertiary);
  gap: 5px;
  user-select: none;
  transition: color .12s;
}

.ql-expand-bar:hover {
  color: var(--red);
}

.ql-expand-bar svg {
  width: 12px;
  height: 12px;
  transition: transform .2s;
}

.ql-expand-bar.open svg {
  transform: rotate(180deg);
}

.ql-extra {
  display: none;
  padding: 0 16px 14px;
}

.ql-extra.open {
  display: block;
}

.ql-sub {
  font-size: 9px;
  font-weight: 600;
  color: var(--text-faded);
  letter-spacing: .8px;
  text-transform: uppercase;
  margin: 10px 0 5px;
}


/* Meine Zahlen — Loading State */
.mz-loading {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-faded);
  font-size: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}


/* Vertriebskennzahlen Trigger */
.vk-trigger {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  margin-top: 6px;
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  gap: 8px;
  background: var(--red);
  border: none;
  border-radius: var(--radius);
  transition: all .15s;
  user-select: none;
  box-shadow: var(--shadow-sm);
  width: 100%;
  font-family: var(--font);
}

.vk-trigger:hover {
  background: var(--red-hover);
  box-shadow: var(--shadow);
}

.vk-trigger svg {
  width: 16px;
  height: 16px;
  transition: transform .2s;
}

.vk-trigger.open svg {
  transform: rotate(180deg);
}

.vk-section {
  display: none;
  margin-bottom: 20px;
}

.vk-section.open {
  display: block;
}

/* ============================================
   16. IMPERSONATION (Super-Admin only)
   ============================================ */
.app-header__impersonate {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  justify-content: center;
  max-width: 460px;
  margin: 0 16px;
}

.app-header__impersonate-input {
  flex: 1;
  min-width: 0;
  padding: 6px 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 12px;
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}

.app-header__impersonate-input:focus {
  border-color: var(--red);
}

.app-header__impersonate-input::placeholder {
  color: var(--text-faded);
}

.btn--small {
  padding: 6px 12px;
  font-size: 11px;
}


/* Impersonate Banner (im Welcome-Bereich) */
.impersonate-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  margin-bottom: 16px;
  background: var(--amber-bg);
  border: 1px solid #e8d896;
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text);
}

.impersonate-banner strong {
  color: var(--red);
}


@media (max-width: 859px) {
  .app-header__impersonate {
    display: none;
  }
}

/* ═══════════════════════════════════════
   BeraterCharts — Mobile Overrides
   ═══════════════════════════════════════ */
@media (max-width: 600px) {
  .bc-hent-grid { grid-template-columns: 1fr !important; }
  .bc-kpi-grid {
    display: flex !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    gap: 10px !important;
    flex-wrap: wrap;
    scroll-snap-type: x mandatory;
  }
  .bc-kpi-grid > div {
    flex: 0 0 calc(50% - 5px);
    min-width: calc(50% - 5px);
    scroll-snap-align: start;
  }
  .bc-funnel-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .bc-funnel-inner { min-width: 540px; }
  .bc-conv-grid { grid-template-columns: 1fr !important; }
}

/* ═══════════════════════════════════════
   Meine Zahlen — KPI Cards
   ═══════════════════════════════════════ */
.mz-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.mz-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}

.mz-label {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: .6px;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 6px;
}

.mz-val {
  font-size: 32px;
  font-weight: 300;
  letter-spacing: -.5px;
  line-height: 1.1;
}

.mz-sub {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 6px;
  line-height: 1.4;
}

.mz-sub b { font-weight: 600; color: var(--text); }

.mz-score-inner {
  display: flex;
  align-items: center;
  gap: 14px;
}

.mz-ring {
  position: relative;
  width: 64px;
  height: 64px;
  flex-shrink: 0;
}

.mz-ring svg { transform: rotate(-90deg); }
.mz-ring-bg { fill: none; stroke: var(--border-light, #ebe9e3); stroke-width: 6; }
.mz-ring-fill { fill: none; stroke-width: 6; stroke-linecap: round; transition: stroke-dashoffset .8s ease; }

.mz-ring-val {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mz-ring-num {
  font-size: 26px;
  font-weight: 600;
  line-height: 1;
}

.mz-detail {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.mz-detail b {
  color: var(--red);
  font-weight: 700;
  font-size: 14px;
}

/* Pills */
.pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 100px;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.5;
}
.pill-green { background: rgba(34, 139, 34, .12); color: #228B22; }
.pill-amber { background: rgba(245, 158, 11, .14); color: #d97706; }
.pill-red   { background: rgba(200, 16, 46, .12); color: var(--red); }

/* Section Label */
.sec-label {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 12px;
}

/* Mobile */
@media (max-width: 600px) {
  .mz-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .mz-card { padding: 14px 16px; }
  .mz-val { font-size: 24px; }
  .mz-label { font-size: 8px; letter-spacing: .4px; }
  .mz-sub { font-size: 10px; }
  .mz-score-inner { gap: 10px; }
  .mz-ring { width: 52px; height: 52px; }
  .mz-ring svg { width: 52px; height: 52px; }
  .mz-ring-num { font-size: 20px; }
  .mz-detail { font-size: 11px; }
  .mz-detail b { font-size: 12px; }
}

/* ═══════════════════════════════════════
   Banner-Hidden-Override
   Damit hidden-Attribut über display:flex gewinnt
   ═══════════════════════════════════════ */
.impersonate-banner[hidden],
#impersonate-bar[hidden],
#impersonate-reset[hidden] {
  display: none !important;
}