/* MS Energie & Haustechnik – PV-Betrieb */
:root {
  --navy: #0b1c2c;
  --navy-2: #12283c;
  --navy-3: #1a3a54;
  --ink: #152033;
  --muted: #5c6b7c;
  --line: #e2e8f0;
  --bg: #eef2f6;
  --card: #ffffff;
  --accent: #0f9d8a;
  --accent-dark: #0b7d6e;
  --accent-soft: #e6f7f4;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --warn: #b54708;
  --header-h: 58px;
  --sidebar-w: 248px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 8px 24px rgba(15, 23, 42, 0.04);
  --radius: 12px;
  --font: "Segoe UI", "Helvetica Neue", system-ui, -apple-system, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

/* ---------- App shell ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--navy) 0%, #08141f 100%);
  color: #e8eef5;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.15rem 1.1rem 1.2rem;
  color: #fff;
  text-decoration: none;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-brand:hover { text-decoration: none; color: #fff; }
.logo-mark { flex-shrink: 0; display: block; width: 36px; height: 36px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 0.98rem; font-weight: 700; letter-spacing: 0.01em; }
.brand-text span { font-size: 0.75rem; color: #9db0c3; font-weight: 500; }
.sidebar-nav { display: flex; flex-direction: column; gap: 0.2rem; padding: 1rem 0.7rem; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  color: #c5d3e0;
  text-decoration: none;
  padding: 0.58rem 0.75rem;
  border-radius: 9px;
  font-weight: 600;
  font-size: 0.94rem;
  border-left: 3px solid transparent;
  padding-left: calc(0.75rem - 3px);
}
.nav-item svg { flex-shrink: 0; opacity: 0.9; }
.nav-item:hover { background: rgba(255,255,255,0.07); color: #fff; text-decoration: none; }
.nav-item.active {
  background: rgba(15, 157, 138, 0.18);
  color: #fff;
  border-left-color: var(--accent);
}
.pill {
  margin-left: auto;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: rgba(255,255,255,0.1);
  color: #9db0c3;
  padding: 0.12rem 0.4rem;
  border-radius: 999px;
}
.sidebar-footer {
  padding: 0.9rem 1.1rem 1.2rem;
  font-size: 0.75rem;
  color: #7d8fa0;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--header-h);
  background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1.25rem;
  position: sticky;
  top: 0;
  z-index: 20;
}
.menu-btn {
  display: none;
  background: none;
  border: 0;
  padding: 0.35rem;
  cursor: pointer;
  color: var(--ink);
}
.topbar-title { font-weight: 700; font-size: 1.05rem; margin-right: auto; }
.topbar-user { display: flex; align-items: center; gap: 0.7rem; }
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.22rem 0.7rem 0.22rem 0.3rem;
  font-weight: 600;
  font-size: 0.88rem;
}
.user-chip::before {
  content: "";
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--navy) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='1.8'%3E%3Ccircle cx='12' cy='8' r='3'/%3E%3Cpath d='M5 19c1.5-3 4-4.5 7-4.5S17.5 16 19 19'/%3E%3C/svg%3E") center/16px no-repeat;
}
.btn-logout {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.38rem 0.75rem;
  cursor: pointer;
  font-weight: 650;
  font-size: 0.88rem;
}
.btn-logout:hover { background: #f8fafc; border-color: #cbd5e1; }

main.page { padding: 1.35rem 1.5rem 2.4rem; max-width: 1280px; width: 100%; margin: 0 auto; }
.page-header { margin-bottom: 1.15rem; }
.page-header h1 { font-size: 1.55rem; margin: 0 0 0.25rem; letter-spacing: -0.02em; }
.lede { color: var(--muted); margin: 0; }
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.toolbar .spacer { flex: 1; }

/* ---------- Buttons & forms ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 0.48rem 0.9rem;
  font-weight: 650;
  cursor: pointer;
  background: #fff;
  text-decoration: none;
  color: var(--ink);
  min-height: 38px;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-secondary { background: #fff; border-color: var(--line); }
.btn-secondary:hover { background: #f8fafc; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.95); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: #f1f5f9; color: var(--ink); }
.btn-sm { min-height: 32px; padding: 0.28rem 0.65rem; font-size: 0.86rem; }

.field { display: flex; flex-direction: column; gap: 0.28rem; margin-bottom: 0.85rem; }
.field label, .field-label { font-weight: 650; font-size: 0.88rem; }
.field .hint { color: var(--muted); font-size: 0.8rem; font-weight: 400; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; }
input[type="text"], input[type="password"], input[type="email"], input[type="tel"],
input[type="search"], input[type="number"], input[type="datetime-local"], input[type="date"],
select, textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid #c9d4e0;
  border-radius: 9px;
  padding: 0.45rem 0.7rem;
  background: #fff;
}
textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(15, 157, 138, 0.35);
  border-color: var(--accent);
}
.search-input { min-width: 240px; max-width: 360px; }

/* ---------- Cards, tables, badges ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.15rem;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 1rem; }
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}
.card-head h2 { font-size: 1.02rem; margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }

.table-wrap { overflow-x: auto; }
table.app-table { width: 100%; border-collapse: collapse; }
.app-table th, .app-table td {
  text-align: left;
  padding: 0.72rem 0.65rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.app-table th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}
.app-table th.sortable { cursor: pointer; user-select: none; }
.app-table th.sortable:hover { color: var(--ink); }
.app-table th .sort { opacity: 0.35; margin-left: 0.15rem; }
.app-table th.is-sorted .sort { opacity: 1; color: var(--accent-dark); }
.app-table tbody tr:last-child td { border-bottom: 0; }
.app-table tbody tr.is-link { cursor: pointer; }
.app-table tbody tr.is-link:hover { background: #f5faf9; }
.app-table .mono { font-variant-numeric: tabular-nums; font-weight: 650; color: var(--navy); }
.app-table a.cell-link { font-weight: 650; color: var(--navy); }
.app-table a.cell-link:hover { color: var(--accent-dark); }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 2.6rem 1.2rem;
}
.empty strong { display: block; color: var(--ink); font-size: 1.08rem; margin: 0.35rem 0 0.25rem; }
.empty-icon { font-size: 1.8rem; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.16rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  background: #e8eef5;
  color: #334155;
  white-space: nowrap;
}
.phase-anfrage { background: #e8edf3; color: #334155; }
.phase-einwilligung { background: #ece7fb; color: #5b21b6; }
.phase-planung { background: #e4eefe; color: #1d4ed8; }
.phase-mastr { background: #f3e8ff; color: #7e22ce; }
.phase-netzportal { background: #e0f4fb; color: #0e7490; }
.phase-zaehlertermin { background: #fef4d7; color: #9a6700; }
.phase-installation { background: #ffedd5; color: #c2410c; }
.phase-abgeschlossen { background: #e4f7ea; color: #157a3a; }
.typ-besichtigung { background: #e0edff; color: #1e40af; }
.typ-montage { background: #ffedd5; color: #c2410c; }
.typ-zaehlertermin { background: #fef4d7; color: #9a6700; }
.typ-sonstiges { background: #e8eef5; color: #334155; }

.meta { display: grid; grid-template-columns: 140px 1fr; gap: 0.35rem 0.75rem; margin: 0; }
.meta dt { color: var(--muted); font-size: 0.84rem; }
.meta dd { margin: 0; font-weight: 600; }
.muted { color: var(--muted); }
.error, .form-error { color: var(--danger); margin: 0.4rem 0 0; }
.form-error[hidden] { display: none; }
.banner-error {
  background: var(--danger-soft);
  border: 1px solid #f5c2c0;
  color: var(--danger);
  padding: 0.65rem 0.8rem;
  border-radius: 9px;
  margin-bottom: 0.8rem;
}

/* ---------- Login ---------- */
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(15,157,138,0.28), transparent 50%),
    linear-gradient(180deg, var(--navy) 0 46%, var(--bg) 46%);
}
.login-card { width: min(100%, 420px); padding: 1.6rem 1.5rem 1.5rem; }
.login-brand { display: flex; align-items: center; gap: 0.8rem; margin-bottom: 1.15rem; }
.login-brand .brand-text strong { font-size: 1.05rem; color: var(--ink); }
.login-brand .brand-text span { color: var(--muted); }
.login-card h1 { font-size: 1.35rem; margin: 0 0 0.2rem; }
.login-card .sub { color: var(--muted); margin: 0 0 1.15rem; }
.login-card button.btn-primary { width: 100%; min-height: 46px; margin-top: 0.4rem; }
.login-error {
  color: var(--danger);
  min-height: 1.25em;
  margin: 0.75rem 0 0;
  font-weight: 600;
}

/* ---------- Case detail ---------- */
.case-hero { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 0.7rem 1rem; }
.case-hero .back { color: var(--muted); font-size: 0.88rem; font-weight: 600; }
.case-nr { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 700; letter-spacing: 0.02em; }
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.7rem;
}
.gallery figure {
  margin: 0;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
}
.gallery img { display: block; width: 100%; height: 140px; object-fit: cover; background: #dbe3ec; }
.gallery figcaption { padding: 0.4rem 0.55rem 0.55rem; font-size: 0.78rem; color: var(--muted); }
.lightbox {
  position: fixed; inset: 0; background: rgba(8, 16, 28, 0.82);
  display: flex; align-items: center; justify-content: center;
  z-index: 80; padding: 1.5rem; cursor: zoom-out;
}
.lightbox[hidden] { display: none; }
.lightbox img { max-width: min(960px, 100%); max-height: 90vh; border-radius: 8px; box-shadow: 0 12px 40px rgba(0,0,0,0.4); }

.timeline { list-style: none; margin: 0; padding: 0 0 0 0.4rem; }
.timeline li {
  position: relative;
  padding: 0 0 1.1rem 1.3rem;
  border-left: 2px solid #d9e2ea;
}
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 0.35rem;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px #fff;
}
.timeline .when { color: var(--muted); font-size: 0.8rem; }
.timeline .what { font-weight: 650; }
.timeline .who { color: var(--muted); font-size: 0.85rem; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(11, 28, 44, 0.45);
  z-index: 70;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 6vh 1rem 2rem;
  overflow: auto;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: #fff;
  border-radius: 14px;
  width: min(560px, 100%);
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.22);
  padding: 1.25rem 1.25rem 1.15rem;
}
.modal h2 { margin: 0 0 1rem; font-size: 1.15rem; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: flex-end; margin-top: 0.5rem; }
.modal-actions .push { margin-right: auto; }

/* ---------- Calendar ---------- */
.cal-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-bottom: 0.9rem; }
.cal-views { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: #fff; }
.cal-views button {
  border: 0;
  background: transparent;
  padding: 0.4rem 0.8rem;
  cursor: pointer;
  font-weight: 650;
  color: var(--muted);
}
.cal-views button.is-active { background: var(--navy); color: #fff; }
.cal-label { font-weight: 750; font-size: 1.05rem; margin-left: 0.3rem; }

.cal-week, .cal-day {
  display: grid;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.cal-week { grid-template-columns: 56px repeat(7, 1fr); }
.cal-day-grid { grid-template-columns: 56px 1fr; }
.cal-head, .cal-gutter, .cal-slot-col {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.cal-week > *:nth-child(8n), .cal-day-grid > *:nth-child(2n) { border-right: 0; }
.cal-head {
  background: #f7f9fb;
  padding: 0.55rem 0.4rem;
  text-align: center;
  font-size: 0.82rem;
  font-weight: 700;
  position: sticky;
  top: var(--header-h);
  z-index: 2;
}
.cal-head .num { display: block; font-size: 1.05rem; }
.cal-head.is-today { background: var(--accent-soft); color: var(--accent-dark); }
.cal-gutter {
  color: var(--muted);
  font-size: 0.72rem;
  text-align: right;
  padding: 0 0.35rem 0 0;
  height: 48px;
  position: relative;
}
.cal-gutter span { position: relative; top: -0.55em; background: #fff; padding-left: 2px; }
.cal-slot-col { position: relative; height: calc(14 * 48px); cursor: pointer; background-image: linear-gradient(to bottom, transparent 47px, #edf1f5 47px, #edf1f5 48px); background-size: 100% 48px; }
.cal-event {
  position: absolute;
  left: 3px;
  right: 3px;
  border-radius: 6px;
  padding: 0.15rem 0.35rem;
  font-size: 0.75rem;
  font-weight: 650;
  color: #0f172a;
  overflow: hidden;
  cursor: pointer;
  border-left: 3px solid currentColor;
  z-index: 1;
}
.cal-event.typ-besichtigung { background: #dbeafe; color: #1e3a8a; }
.cal-event.typ-montage { background: #ffedd5; color: #9a3412; }
.cal-event.typ-zaehlertermin { background: #fef3c7; color: #92400e; }
.cal-event.typ-sonstiges { background: #e2e8f0; color: #1e293b; }
.cal-event .ev-time { display: block; font-weight: 600; font-size: 0.7rem; opacity: 0.85; }

.cal-month {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.cal-month .dow {
  background: #f7f9fb;
  padding: 0.5rem;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--line);
}
.cal-month .cell {
  min-height: 110px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 0.35rem;
  cursor: pointer;
  vertical-align: top;
}
.cal-month .cell:nth-child(7n) { border-right: 0; }
.cal-month .cell.muted { background: #f8fafc; color: #94a3b8; }
.cal-month .cell.is-today { background: var(--accent-soft); }
.cal-month .daynum { font-weight: 700; font-size: 0.85rem; margin-bottom: 0.2rem; }
.cal-month .pill-ev {
  display: block;
  font-size: 0.72rem;
  font-weight: 650;
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  margin-bottom: 0.15rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Customer ---------- */
.kv-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.4rem 0 1rem; }

#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(8, 16, 28, 0.45);
  z-index: 30;
}

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: none;
  }
  .sidebar.is-open { transform: translateX(0); box-shadow: 8px 0 30px rgba(0,0,0,0.25); }
  .menu-btn { display: inline-flex; }
  #sidebar-overlay.is-open { display: block; }
  .grid-2, .grid-3, .form-row { grid-template-columns: 1fr; }
  .cal-week { min-width: 720px; }
  .cal-scroll { overflow-x: auto; }
}

@media (max-width: 640px) {
  main.page { padding: 1rem; }
  .search-input { max-width: none; width: 100%; }
  .user-chip { max-width: 110px; overflow: hidden; text-overflow: ellipsis; }
}
