:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1c2530;
  --muted: #6b7785;
  --border: #e2e7ec;
  --primary: #1f6feb;
  --primary-dark: #1a5fd0;
  --green: #1a9e5f;
  --amber: #d98a00;
  --red: #d64545;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.04);
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  min-height: 56px;
}
.topbar .brand { font-weight: 700; font-size: 1.05rem; margin-right: auto; display: flex; align-items: center; gap: 8px; }
.topbar .brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); display: inline-block; }
.nav-links { display: flex; align-items: center; gap: 4px; }
.nav-links a, .nav-links button {
  padding: 10px 14px; border-radius: 8px; color: var(--text);
  font-size: .95rem; background: none; border: none; cursor: pointer; min-height: 44px;
  display: inline-flex; align-items: center;
}
.nav-links a:hover, .nav-links button:hover { background: var(--bg); text-decoration: none; }
.nav-links a.active { color: var(--primary); font-weight: 600; }
.hamburger { display: none; background: none; border: none; font-size: 1.5rem; cursor: pointer;
  min-width: 44px; min-height: 44px; color: var(--text); }
.user-chip { font-size: .85rem; color: var(--muted); padding: 0 6px; white-space: nowrap; }

/* ---------- Layout ---------- */
.container { max-width: 1100px; margin: 0 auto; padding: 20px 16px 96px; }
h1 { font-size: 1.5rem; margin: 0 0 4px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.subtle { color: var(--muted); font-size: .9rem; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 18px; border-radius: 10px;
  font-size: 1rem; font-weight: 600; cursor: pointer; border: 1px solid transparent;
  background: var(--primary); color: #fff; transition: background .15s;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn.secondary { background: var(--card); color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: var(--bg); }
.btn.danger { background: var(--red); }
.btn.small { min-height: 38px; padding: 6px 12px; font-size: .9rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Cards / Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 22px; }
.stat {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.stat .num { font-size: 1.9rem; font-weight: 700; line-height: 1; }
.stat .label { color: var(--muted); font-size: .85rem; margin-top: 6px; }
.stat.warn .num { color: var(--red); }
.stat.arbeit .num { color: var(--amber); }
.stat.done .num { color: var(--green); }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }

/* ---------- Filter ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.filters select { flex: 1 1 140px; }

/* ---------- Forms ---------- */
label { display: block; font-weight: 600; font-size: .9rem; margin: 14px 0 6px; }
input, select, textarea {
  width: 100%; padding: 12px 14px; font-size: 1rem; font-family: inherit;
  border: 1px solid var(--border); border-radius: 10px; background: #fff; color: var(--text);
  min-height: 48px;
}
textarea { min-height: 120px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-actions { display: flex; gap: 10px; margin-top: 22px; flex-wrap: wrap; }

/* ---------- Table (Desktop) ---------- */
.ticket-table { width: 100%; border-collapse: collapse; background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.ticket-table th, .ticket-table td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: .92rem; }
.ticket-table th { background: #fafbfc; color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .02em; }
.ticket-table tr:last-child td { border-bottom: none; }
.ticket-table tbody tr { cursor: pointer; }
.ticket-table tbody tr:hover { background: #f7f9fb; }

/* ---------- Ticket cards (Mobile) ---------- */
.ticket-cards { display: none; flex-direction: column; gap: 12px; }
.tcard { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; cursor: pointer; }
.tcard .tc-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.tcard .tc-title { font-weight: 600; font-size: 1rem; }
.tcard .tc-meta { color: var(--muted); font-size: .85rem; margin-top: 8px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px;
  font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge.prio-hoch { background: #fdeaea; color: var(--red); }
.badge.prio-mittel { background: #fdf3e0; color: var(--amber); }
.badge.prio-niedrig { background: #eef1f4; color: var(--muted); }
.badge.st-offen { background: #e7f0fe; color: var(--primary); }
.badge.st-in_arbeit { background: #fdf3e0; color: var(--amber); }
.badge.st-erledigt { background: #e6f5ee; color: var(--green); }
.badge.st-delegiert { background: #efe9fb; color: #6d4bd0; }
.badge.firma { background: #eef1f4; color: var(--muted); }
.overdue { color: var(--red); font-weight: 600; }

/* ---------- Timeline ---------- */
.timeline { list-style: none; padding: 0; margin: 8px 0 0; }
.timeline li { position: relative; padding: 0 0 18px 26px; border-left: 2px solid var(--border); }
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before { content: ''; position: absolute; left: -7px; top: 2px; width: 12px; height: 12px;
  border-radius: 50%; background: var(--primary); border: 2px solid var(--card); }
.timeline li.typ-status_geaendert::before { background: var(--amber); }
.timeline li.typ-delegiert::before { background: #6d4bd0; }
.timeline li.typ-erledigt::before { background: var(--green); }
.timeline .tl-head { font-size: .85rem; color: var(--muted); }
.timeline .tl-body { margin-top: 3px; white-space: pre-wrap; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow); padding: 28px 24px; width: 100%; max-width: 380px; }
.login-card h1 { text-align: center; margin-bottom: 4px; }
.login-card .subtle { text-align: center; margin-bottom: 8px; }

/* ---------- Alerts ---------- */
.alert { padding: 12px 14px; border-radius: 10px; margin: 10px 0; font-size: .92rem; }
.alert.error { background: #fdeaea; color: var(--red); }
.alert.ok { background: #e6f5ee; color: var(--green); }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }

.dl { display: grid; grid-template-columns: 150px 1fr; gap: 8px 16px; margin: 0; }
.dl dt { color: var(--muted); font-size: .9rem; }
.dl dd { margin: 0; }

.detail-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 6px; }
.detail-actions select { flex: 1 1 160px; max-width: 220px; }

/* ---------- Bottom nav (Mobile) ---------- */
.bottom-nav { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .stats { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .container { padding: 16px 12px 90px; }
  .stats { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .ticket-table { display: none; }
  .ticket-cards { display: flex; }
  .nav-links { display: none; }
  .nav-links.open {
    display: flex; flex-direction: column; align-items: stretch;
    position: absolute; top: 56px; left: 0; right: 0; background: var(--card);
    border-bottom: 1px solid var(--border); padding: 8px; gap: 2px; box-shadow: var(--shadow);
  }
  .nav-links.open a, .nav-links.open button { justify-content: flex-start; }
  .hamburger { display: inline-flex; align-items: center; justify-content: center; }
  .user-chip { display: none; }

  /* Bottom navigation */
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
    background: var(--card); border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottom-nav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    color: var(--muted); font-size: .7rem; padding: 6px 0; min-height: 52px; justify-content: center;
  }
  .bottom-nav a.active { color: var(--primary); }
  .bottom-nav a .ic { font-size: 1.35rem; line-height: 1; }
  .bottom-nav a:hover { text-decoration: none; }
}
