:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #1d3445;
  --muted: #64707d;
  --line: #e2e7ec;
  /* GSM-Firmenfarben (www.gsm-gmbh.com) */
  --primary: #1f9bd7;
  --primary-dark: #157db0;
  --primary-soft: #e6f4fb;
  --navy: #1d3445;
  --success: #1f9d55;
  --success-soft: #e5f6ec;
  --warn: #c77700;
  --warn-soft: #fff4e0;
  --danger: #c53030;
  --danger-soft: #fdecec;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: .1rem 0 .2rem; line-height: 1.25; }
h2 { font-size: 1.05rem; margin: 0 0 .8rem; }
h3 { font-size: .95rem; }
p { margin: .3rem 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ---------- Kopfzeile ---------- */
.topbar {
  display: flex; align-items: center; gap: 1.5rem;
  padding: .6rem 1.5rem; background: var(--surface);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: .6rem; color: var(--text); font-weight: 700; }
.brand:hover { text-decoration: none; }
.brand small { display: block; font-weight: 400; font-size: .75rem; color: var(--muted); }
.logo {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px;
  background: var(--primary); color: #fff; font-size: 1.1rem;
}
.logo-img { height: 38px; width: auto; }
.logo-login { display: block; width: 170px; height: auto; margin: 0 auto 1rem; }
.topbar nav { display: flex; gap: .25rem; flex: 1; }
.topbar nav a { padding: .45rem .8rem; border-radius: 8px; color: var(--muted); font-weight: 500; }
.topbar nav a:hover { background: var(--bg); text-decoration: none; color: var(--text); }
.topbar nav a.active { background: var(--primary-soft); color: var(--primary-dark); }
.user { display: flex; align-items: center; gap: .9rem; font-size: .9rem; }
.user a { color: var(--text); font-weight: 500; }
.user form { margin: 0; }

/* ---------- Layout ---------- */
.container { max-width: 1120px; margin: 0 auto; padding: 1.5rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.back { font-size: .85rem; color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: 1.3fr 1fr; gap: 1.25rem; align-items: start; }
.grid-detail { display: grid; grid-template-columns: 1fr 320px; gap: 1.25rem; align-items: start; }
.stack { display: grid; gap: 1.25rem; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.25rem; box-shadow: var(--shadow); margin-bottom: 1.25rem;
}
.stack > .card, .grid-2 > .card, .grid-detail > .card { margin-bottom: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card.accent { border-color: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.card.narrow { max-width: 460px; }
.card.center { margin: 3rem auto; text-align: center; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: .6rem; }
.card-head h2 { margin: 0; }
.card-head a { font-size: .85rem; }
.link-card { display: block; color: var(--text); }
.link-card:hover { text-decoration: none; border-color: var(--primary); }
.empty { color: var(--muted); padding: 1rem; text-align: center; }

/* ---------- Kennzahlen ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1.25rem; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.25rem; color: var(--text); box-shadow: var(--shadow);
}
.stat:hover { text-decoration: none; border-color: var(--primary); }
.stat b { display: block; font-size: 1.9rem; line-height: 1.1; }
.stat span { color: var(--muted); font-size: .9rem; }
.stat.done b { color: var(--success); }

/* ---------- Badges ---------- */
.badge {
  display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 600;
  background: var(--bg); color: var(--muted); white-space: nowrap;
}
.status-offen { background: var(--warn-soft); color: var(--warn); }
.status-in_bearbeitung { background: #e8efff; color: #2f5bd3; }
.status-erledigt { background: var(--success-soft); color: var(--success); }
.prio-hoch { background: var(--danger-soft); color: var(--danger); }
.prio-niedrig { background: var(--bg); color: var(--muted); }
.tag { font-size: .7rem; background: var(--primary-soft); color: var(--primary-dark); padding: .05rem .4rem; border-radius: 4px; font-weight: 600; }

/* ---------- Ticketliste ---------- */
.ticket-row, .list-row {
  display: flex; align-items: center; gap: .9rem; padding: .8rem 1rem;
  border-bottom: 1px solid var(--line); color: var(--text);
}
.card:not(.flush) .ticket-row, .card:not(.flush) .list-row { margin: 0 -1.25rem; padding-left: 1.25rem; padding-right: 1.25rem; }
.ticket-row:last-child, .list-row:last-child { border-bottom: 0; }
.ticket-row:hover, .list-row:hover { background: #fafbfc; text-decoration: none; }
.tid { color: var(--muted); font-variant-numeric: tabular-nums; font-size: .85rem; min-width: 2.5rem; }
.ticket-main, .list-row > span:first-child { flex: 1; min-width: 0; }
.ticket-main strong, .list-row strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ticket-main small, .list-row small { display: block; color: var(--muted); }
.ticket-badges { display: flex; gap: .35rem; }

.filters { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.tabs { display: flex; gap: .25rem; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .25rem; flex-wrap: wrap; }
.tabs a { padding: .35rem .75rem; border-radius: 7px; color: var(--muted); font-size: .9rem; }
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs a.active { background: var(--primary); color: #fff; }
.filter-inputs { display: flex; gap: .5rem; }
.filter-inputs input, .filter-inputs select, .filters > select { width: auto; }

/* ---------- Formulare ---------- */
label { display: block; font-weight: 500; font-size: .9rem; margin-bottom: .9rem; }
input, select, textarea {
  display: block; width: 100%; margin-top: .3rem; padding: .6rem .7rem;
  font: inherit; color: inherit; background: #fff;
  border: 1px solid #cfd6dd; border-radius: 8px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea { resize: vertical; }
.form textarea, .comment-form textarea { margin: 0 0 .8rem; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; margin-top: .8rem; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid .btn:only-child, .form-grid > button { justify-self: start; }
.inline-form { display: flex; gap: .5rem; align-items: center; margin: .6rem 0; }
.inline-form input { margin: 0; }
.inline-form label { margin: 0; flex: 1; }
.actions { display: flex; justify-content: flex-end; gap: .5rem; }
.actions.full { justify-content: flex-start; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
  padding: .55rem 1rem; font: inherit; font-weight: 600; font-size: .9rem;
  border-radius: 8px; border: 1px solid #cfd6dd; background: #fff; color: var(--text); cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; }
.btn.success:hover { filter: brightness(.95); }
.btn.danger { color: var(--danger); border-color: #f0c4c4; }
.btn.wide { width: 100%; margin-top: .4rem; }
.btn-group { display: flex; gap: .5rem; flex-wrap: wrap; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--primary); cursor: pointer; }
.link.danger { color: var(--danger); }
.stack form + form { margin-top: .3rem; }

.file {
  display: flex; flex-direction: column; align-items: center; padding: .9rem;
  border: 2px dashed #cfd6dd; border-radius: 10px; cursor: pointer; text-align: center; margin-bottom: .6rem;
}
.file:hover { border-color: var(--primary); background: var(--primary-soft); }
.file input { display: none; }
.file small { color: var(--muted); font-weight: 400; }
.preview { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .6rem; }
.preview img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; }

details.add { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: .8rem; }
details summary { cursor: pointer; font-weight: 600; color: var(--primary); list-style: none; }
details summary::-webkit-details-marker { display: none; }

/* ---------- Meldungen ---------- */
.flash { padding: .75rem 1rem; border-radius: 10px; margin-bottom: 1rem; font-weight: 500; }
.flash.success { background: var(--success-soft); color: #156b3a; }
.flash.error { background: var(--danger-soft); color: var(--danger); }

/* ---------- Ticketdetails ---------- */
.meta { display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; color: var(--muted); font-size: .88rem; margin-top: .3rem; }
.service-ref { font-size: .88rem; margin-top: .5rem; background: var(--primary-soft); display: inline-block; padding: .3rem .7rem; border-radius: 8px; }
.done-banner {
  display: flex; gap: 1rem; align-items: center; padding: 1rem 1.25rem; margin-bottom: 1.25rem;
  background: var(--success-soft); border: 1px solid #b7e4c7; border-radius: var(--radius); color: #156b3a;
}
.done-banner .check {
  display: grid; place-items: center; width: 40px; height: 40px; flex: none;
  background: var(--success); color: #fff; border-radius: 50%; font-size: 1.3rem; font-weight: 700;
}
.timeline { list-style: none; padding: 0; margin: 0 0 1rem; position: relative; }
.timeline::before { content: ""; position: absolute; left: 7px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.ev { position: relative; padding: 0 0 1.25rem 1.8rem; }
.ev::before {
  content: ""; position: absolute; left: 0; top: 4px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; border: 3px solid #cfd6dd;
}
.ev.from-team::before { border-color: var(--primary); }
.ev.ev-done::before { background: var(--success); border-color: var(--success); }
.ev-head { display: flex; flex-wrap: wrap; gap: .35rem; align-items: baseline; font-size: .9rem; }
.ev-head time { margin-left: auto; color: var(--muted); font-size: .8rem; }
.ev-text { white-space: pre-wrap; background: var(--bg); padding: .6rem .8rem; border-radius: 8px; margin-top: .4rem; }
.ev.from-team .ev-text { background: var(--primary-soft); }
.ev.ev-done .ev-text { background: var(--success-soft); }
.gallery { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .5rem; }
.gallery img { width: 120px; height: 120px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.comment-form { border-top: 1px solid var(--line); padding-top: 1rem; }

.steps { list-style: none; padding: 0; margin: 0 0 .8rem; }
.steps li { padding: .35rem 0 .35rem 1.8rem; position: relative; color: var(--muted); }
.steps li::before { content: ""; position: absolute; left: 0; top: .55rem; width: 14px; height: 14px; border-radius: 50%; border: 2px solid #cfd6dd; }
.steps li.done { color: var(--text); font-weight: 600; }
.steps li.done::before { background: var(--primary); border-color: var(--primary); }

/* ---------- Notizen ---------- */
.notes { display: grid; gap: .8rem; }
.note { margin: 0; }
.note p { white-space: pre-wrap; margin: 0 0 .6rem; }
.note.from-team { border-left: 4px solid var(--primary); }
.note footer { display: flex; justify-content: space-between; align-items: center; font-size: .82rem; color: var(--muted); }
.note footer form { margin: 0; }
.note-mini { padding: .6rem 0; border-bottom: 1px solid var(--line); }
.note-mini:last-child { border-bottom: 0; }
.note-mini small { color: var(--muted); }

/* ---------- Leistungsverzeichnis ---------- */
.lv-area { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--primary-dark); margin: 1rem 0 .3rem; }
.lv .lv-area { margin: 0; padding: .8rem 1.25rem; background: #fafbfc; border-bottom: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
td:nth-child(2), th:nth-child(2) { width: 20%; }
th, td { text-align: left; padding: .65rem 1.25rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td:first-child { width: 55%; }
.freq { display: inline-block; font-size: .8rem; font-weight: 600; background: var(--primary-soft); color: var(--primary-dark); padding: .1rem .5rem; border-radius: 6px; white-space: nowrap; }
.lv-item { border-bottom: 1px solid var(--line); padding: .55rem 0; }
.lv-item summary { display: flex; justify-content: space-between; align-items: center; gap: .5rem; color: var(--text); font-weight: 400; }
.lv-item summary:hover { color: var(--primary); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login { width: 100%; max-width: 400px; text-align: center; padding: 2rem; }
.login form { text-align: left; margin-top: 1.5rem; }

/* ---------- Verträge ---------- */
.contract-row { align-items: center; }
.contract-row form { margin: 0; }
.file-icon {
  display: grid; place-items: center; flex: none; width: 44px; height: 52px; border-radius: 6px;
  background: var(--primary-soft); color: var(--primary-dark); font-size: .7rem; font-weight: 700;
  border: 1px solid #cfe6f3;
}
.list-row > span.file-icon { flex: none; }
.contract-row > span:nth-child(2) { flex: 1; min-width: 0; }
.contract-row strong { white-space: normal; }
.contract-note { font-style: italic; }
.contract-row .btn { padding: .4rem .8rem; }

/* ---------- Fußzeile & Rechtstexte ---------- */
.site-footer { display: flex; justify-content: center; gap: 1.2rem; padding: 1.5rem 1rem 2rem; font-size: .82rem; color: var(--muted); }
.site-footer a { color: var(--muted); }
.login-wrap + .site-footer { margin-top: -5rem; }
.legal { max-width: 760px; }
.legal h2 { margin-top: 1.6rem; }
.legal .todo { background: var(--warn-soft); color: var(--warn); padding: .1rem .35rem; border-radius: 4px; font-weight: 600; }

/* ---------- Mobil ---------- */
@media (max-width: 860px) {
  .grid-2, .grid-detail { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; gap: .5rem 1rem; padding: .6rem 1rem; }
  .topbar nav { order: 3; flex-basis: 100%; overflow-x: auto; scrollbar-width: none; }
  .topbar nav::-webkit-scrollbar { display: none; }
  .user { margin-left: auto; }
  .container { padding: 1rem; }
}
@media (max-width: 560px) {
  .stats { gap: .5rem; }
  .stat { padding: .7rem; }
  .stat b { font-size: 1.5rem; }
  .row, .form-grid { grid-template-columns: 1fr; }
  .ticket-row { flex-wrap: wrap; }
  .ticket-badges { width: 100%; padding-left: 3.4rem; }
  td, th { padding: .55rem .8rem; }
  .gallery img { width: 96px; height: 96px; }
  h1 { font-size: 1.35rem; }
}

@media print {
  .topbar, .btn, .flash, .muted.small { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
}
