/* ==========================================================================
   JK CNC Technik – CRM  |  Design-System (angelehnt an das ESS-Portal)
   ========================================================================== */

:root {
  /* Farbpsychologie:
     Navy = Vertrauen/Kompetenz/Ruhe · Grün = Fortschritt/Erfolg
     Amber = Energie/Optimismus · Rot bewusst entschärft (weniger Stress) */

  --sidebar-bg:  #17296f;   /* wärmeres, einladenderes Navy */
  --sidebar-bg2: #12266a;   /* leichter Verlauf für Tiefe */
  --navy-900:    #0f1c54;
  --brand:       #1b2a86;   /* Überschriften: kräftiges, positives Blau */
  --brand-2:     #2a44c8;

  --accent:      #12b886;   /* Teal/Grün – Aktion & Fortschritt */
  --accent-dark: #0ca678;
  --accent-soft: #e3f7ef;
  --success:     #20c997;   /* frischer Erfolgs-Grünton */

  /* Warmer Motivations-Akzent */
  --warm:      #ff9f1c;
  --warm-dark: #e6870b;
  --warm-soft: #fff2df;
  --amber:     #ff9f1c;     /* Alias für bestehende Klassen */
  --amber-soft:#fff2df;

  --sky:       #3b82f6;     /* freundliches Info-Blau */
  --sky-soft:  #e8f0fe;

  --danger:      #e5556a;   /* weicheres Rot */
  --danger-soft: #fdecef;

  --ink:   #232838;
  --muted: #6b7280;
  --line:  #e7e9f0;

  --bg:      #f4f8f6;       /* frischer, heller, leicht grün getönter Grund */
  --card:    #ffffff;
  --radius:  14px;
  --shadow:  0 1px 3px rgba(16,24,64,.07), 0 8px 22px rgba(16,24,64,.12);
  --font:    -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); font-size: 14px; line-height: 1.5; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; color: var(--brand); }
.muted { color: var(--muted); }
.right { margin-left: auto; }
.nowrap { white-space: nowrap; }

/* ------- Layout ------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 256px; flex: 0 0 256px;
  background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg2) 100%); color: #fff;
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; padding: 18px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 4px; }
.brand .logo {
  width: 40px; height: 40px; border-radius: 50%;
  background: #fff; color: var(--sidebar-bg);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 15px; letter-spacing: -.5px; flex: 0 0 40px;
}
.brand .logo-img { width: 40px; height: 40px; object-fit: contain; flex: 0 0 40px; }
.brand .name { font-weight: 800; font-size: 16px; line-height: 1.1; }
.brand .sub { font-size: 11px; color: #9fb0f0; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
/* Volles Wort-Bild-Logo im Menueband (weiss auf dunkel/rot) */
.brand.with-logo { flex-direction: column; align-items: flex-start; gap: 6px; }
.brand .brand-logo-img { width: 100%; max-width: 190px; height: auto; display: block; }

.nav { margin-top: 22px; display: flex; flex-direction: column; gap: 4px; }
.nav-label { font-size: 11px; color: #7f8fd6; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; padding: 14px 14px 6px; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: 10px;
  color: #c9d2f5; font-weight: 600; font-size: 14px;
}
.nav a svg { width: 18px; height: 18px; flex: 0 0 18px; }
.nav a:hover { background: rgba(255,255,255,.09); color: #fff; }
.nav a.active { background: #fff; color: var(--brand); }
.nav .spacer { flex: 1; }
.sidebar-foot { margin-top: auto; padding: 12px 8px 4px; border-top: 1px solid rgba(255,255,255,.12); }
.sidebar-foot a { color: #c9d2f5; font-size: 13px; font-weight: 600; display: flex; gap: 8px; align-items: center; padding: 8px; border-radius: 8px; }
.sidebar-foot a:hover { background: rgba(255,255,255,.09); color: #fff; }
.sidebar-foot svg { width: 18px; height: 18px; flex: 0 0 18px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column;
  background: linear-gradient(180deg, #f7fbf9 0%, #edf6f1 100%); }

/* ------- Topbar ------- */
.topbar { display: flex; align-items: center; gap: 20px; padding: 20px 32px 4px; }
.topbar .greet h1 { font-size: 24px; font-weight: 800; }
.topbar .greet .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.search { flex: 1; max-width: 720px; margin-left: auto; position: relative; }
.search input {
  width: 100%; padding: 10px 14px 10px 38px; border: 1px solid var(--line);
  border-radius: 10px; font-size: 14px; font-family: inherit; background: #fff;
}
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--muted); }
.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--brand-2); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; }

/* ------- Content ------- */
.content { padding: 22px 32px 40px; width: 100%; max-width: 1240px; }

/* ------- Cards ------- */
.card { background: var(--card); border: 1px solid #eef1f6; border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px 24px; margin-bottom: 22px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; }
.card-title { font-size: 17px; font-weight: 700; }
.card.pad0 { padding: 0; overflow: hidden; }
.card.pad0 .card-head { padding: 20px 24px 4px; margin-bottom: 8px; }

.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 22px; align-items: start; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }

/* ------- Stat tiles ------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-bottom: 22px; }
.stat { background: #fff; border: 1px solid #eef1f6; border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; display: flex; align-items: center; gap: 14px; }
.stat .ico { width: 44px; height: 44px; border-radius: 11px; display: flex; align-items: center; justify-content: center; background: var(--accent-soft); color: var(--accent-dark); flex: 0 0 44px; }
.stat .ico svg { width: 22px; height: 22px; }
.stat .num { font-size: 26px; font-weight: 800; color: var(--brand); line-height: 1; }
.stat .lbl { color: var(--muted); font-size: 13px; font-weight: 600; margin-top: 4px; }
.stat.amber .ico { background: var(--amber-soft); color: var(--amber); }
.stat.red .ico { background: var(--danger-soft); color: var(--danger); }
.stat.blue .ico { background: #e8ecff; color: var(--brand-2); }

/* ------- Buttons ------- */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; border-radius: 9px; font-weight: 600; font-size: 14px; font-family: inherit; border: 1px solid transparent; cursor: pointer; transition: .15s; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: linear-gradient(180deg, #17c496 0%, var(--accent) 55%, var(--accent-dark) 100%); color: #fff; box-shadow: 0 2px 6px rgba(18,184,134,.28); }
.btn-primary:hover { filter: brightness(1.04); box-shadow: 0 3px 10px rgba(18,184,134,.34); }
.btn-secondary { background: #fff; color: var(--brand); border-color: var(--line); }
.btn-secondary:hover { background: #f7f9fc; }
.btn-danger { background: #fff; color: var(--danger); border-color: #f3c9cb; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ------- Badges ------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 700; }
.badge-green { background: var(--accent-soft); color: var(--accent-dark); }
.badge-red   { background: var(--danger-soft); color: var(--danger); }
.badge-amber { background: var(--amber-soft); color: #b5730a; }
.badge-blue  { background: #e8ecff; color: var(--brand-2); }
.badge-muted { background: #eef1f6; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ------- Tags ------- */
.tag { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; background: #eef1f6; color: var(--ink); }

/* ------- List rows (grüner Akzentbalken links) ------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.list-row { display: flex; align-items: center; gap: 14px; background: #fbfdff; border: 1px solid #eef1f6; border-left: 3px solid var(--accent); border-radius: 10px; padding: 12px 16px; }
.list-row:hover { background: #f3faf7; }
.list-row .rl-title { font-weight: 600; }
.list-row .rl-sub { color: var(--muted); font-size: 13px; }
.list-empty { color: var(--muted); padding: 18px; text-align: center; background: #fbfdff; border: 1px dashed var(--line); border-radius: 10px; }

/* ------- Tables ------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 700; }
.table td { padding: 13px 16px; border-bottom: 1px solid #f0f2f7; }
.table tbody tr:hover td, .table tr:hover td { background: #f8fafc; }
.table a.rowlink { color: var(--brand); font-weight: 600; }

/* ------- Timeline (Protokoll) ------- */
.timeline { position: relative; padding-left: 26px; margin-top: 4px; }
.timeline::before { content: ""; position: absolute; left: 9px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.tl-item { position: relative; padding: 0 0 20px 4px; }
.tl-item:last-child { padding-bottom: 0; }
.tl-item::before { content: ""; position: absolute; left: -21px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); border: 2px solid #fff; box-shadow: 0 0 0 3px var(--accent-soft); }
.tl-item.t-anruf::before { background: var(--brand-2); box-shadow: 0 0 0 3px #e8ecff; }
.tl-item.t-email::before { background: var(--amber); box-shadow: 0 0 0 3px var(--amber-soft); }
.tl-item.t-system::before { background: var(--muted); box-shadow: 0 0 0 3px #eef1f6; }
.tl-meta { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.tl-subject { font-weight: 600; }
.tl-body { color: #3a4152; white-space: pre-wrap; margin-top: 2px; }

/* ------- Forms ------- */
.form-row { margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.form-label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.form-control, select.form-control, textarea.form-control {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px;
  font-size: 14px; font-family: inherit; background: #fff; color: var(--ink);
}
textarea.form-control { min-height: 90px; resize: vertical; }
.form-control:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-help { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* Neue/zusätzliche Werte bei Doublette hervorheben (blaues Glimmen) */
@keyframes fieldGlow {
  0%, 100% { box-shadow: 0 0 0 3px rgba(59,130,246,.15); border-color: var(--sky); }
  50%      { box-shadow: 0 0 0 4px rgba(59,130,246,.45); border-color: var(--sky); }
}
.field-new { border-color: var(--sky) !important; background: #f1f7ff !important; animation: fieldGlow 1.6s ease-in-out infinite; }

/* Aufklappbare Ansprechpartner (wie CentralStation) */
.contact-list { display: flex; flex-direction: column; gap: 8px; }
.contact-item { border: 1px solid #eef1f6; border-left: 3px solid var(--accent); border-radius: 10px; background: #fbfdff; }
.contact-item > summary { list-style: none; cursor: pointer; padding: 11px 34px 11px 14px; position: relative; }
.contact-item > summary::-webkit-details-marker { display: none; }
.contact-item > summary::after { content: "▾"; position: absolute; right: 14px; top: 11px; color: var(--muted); transition: transform .15s; }
.contact-item[open] > summary::after { transform: rotate(180deg); }
.contact-item .ci-name { font-weight: 600; display: block; }
.contact-item .ci-role { font-size: 13px; color: var(--muted); }
.contact-item .ci-body { padding: 0 14px 12px; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.contact-item .ci-body a { color: var(--brand-2); font-weight: 600; }
.form-errors { color: var(--danger); font-size: 13px; margin-top: 4px; }
.form-actions { display: flex; gap: 10px; margin-top: 8px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: 16px; height: 16px; }

/* ------- Toolbar / search on list pages ------- */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar form { display: flex; gap: 10px; flex: 1; }
.input { padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px; font-size: 14px; font-family: inherit; background: #fff; }

/* ------- Definition list (Detailinfos) ------- */
.dl { display: grid; grid-template-columns: 130px 1fr; gap: 10px 14px; }
.dl dt { color: var(--muted); font-size: 13px; font-weight: 600; }
.dl dd { margin: 0; }

/* ------- Messages ------- */
.messages { margin-bottom: 18px; }
.msg { padding: 12px 16px; border-radius: 10px; margin-bottom: 10px; font-weight: 600; }
.msg-success { background: var(--accent-soft); color: var(--accent-dark); }
.msg-error, .msg-danger { background: var(--danger-soft); color: var(--danger); }
.msg-info { background: #e8ecff; color: var(--brand-2); }
.msg-warning { background: var(--amber-soft); color: #b5730a; }

/* ------- Login ------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--sidebar-bg), var(--navy-900)); padding: 20px; }
.login-card { background: #fff; border-radius: 16px; padding: 34px 34px 30px; width: 370px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-card .brand { justify-content: center; margin-bottom: 6px; }
.login-card h1 { font-size: 20px; text-align: center; margin-bottom: 20px; }
.login-card .btn-primary { width: 100%; justify-content: center; margin-top: 6px; }

/* ------- Utilities ------- */
.flex { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.mt0 { margin-top: 0; } .mb0 { margin-bottom: 0; }
.section-sub { color: var(--muted); font-size: 13px; margin: -8px 0 14px; }
.pill-row { display: flex; gap: 6px; flex-wrap: wrap; }

@media (max-width: 900px) {
  .sidebar { width: 72px; flex-basis: 72px; }
  .brand .name, .brand .sub, .nav a span, .nav-label, .sidebar-foot a span { display: none; }
  .nav a { justify-content: center; }
  .grid-2 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .content, .topbar { padding-left: 18px; padding-right: 18px; }
}

/* Umgebungs-Hinweis (STAGING) – nur sichtbar, wenn APP_ENV != production */
.env-banner {
  background: #b0201d;
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: .02em;
  text-align: center;
  padding: 9px 14px;
}

/* Staging: komplett rotes Menueband statt Navy – unverwechselbar */
body.env-staging {
  --sidebar-bg:  #b0201d;
  --sidebar-bg2: #8c1714;
}
.env-badge {
  display: inline-block;
  background: #f59e0b;
  color: #1a1a1a;
  font-weight: 800;
  font-size: 10px;
  letter-spacing: .06em;
  padding: 1px 6px;
  border-radius: 6px;
  margin-left: 4px;
  vertical-align: middle;
}
