:root {
  --amber: #f5a800;
  --amber-dark: #c98a00;
  --teal: #0e7c74;
  --teal-dark: #0b4a47;
  --side-bg: #000;
  --side-fg: #b9c6c5;
  --side-active: #12201f;
  --bg: #f4f6f6;
  --card: #fff;
  --fg: #1b2526;
  --muted: #687576;
  --line: #dfe5e5;
  --danger: #c0392b;
  --ok: #1e8e5a;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 1px 8px rgba(0, 0, 0, .04);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 14px;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); }
a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, Consolas, monospace; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex-shrink: 0; background: var(--side-bg); color: var(--side-fg);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar .logo { display: block; padding: 14px 12px 6px; }
.sidebar .logo img { width: 100%; display: block; }
.sidebar nav { flex: 1; padding: 8px; overflow-y: auto; }
.sidebar nav a {
  display: flex; align-items: center; justify-content: space-between;
  color: var(--side-fg); padding: 9px 12px; border-radius: 6px; margin-bottom: 2px; font-weight: 500;
}
.sidebar nav a:hover { background: var(--side-active); text-decoration: none; color: #fff; }
.sidebar nav a.active { background: var(--side-active); color: var(--amber); box-shadow: inset 3px 0 0 var(--amber); }
.sidebar nav .sep { height: 1px; background: #1c2a29; margin: 10px 4px; }
.sidebar .badge { background: var(--amber); color: #000; }
.sidebar .badge.red { background: var(--danger); color: #fff; }
.sidebar .user { padding: 12px 16px; border-top: 1px solid #1c2a29; font-size: 12px; }
.sidebar .user a { color: var(--side-fg); }
.sidebar .user button { background: none; border: 0; color: var(--side-fg); padding: 0; cursor: pointer; font: inherit; text-decoration: underline; }

.main { flex: 1; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 12px 24px; background: var(--card);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.topbar form { flex: 1; max-width: 420px; }
.topbar input { width: 100%; }
.topbar .devmode { margin-left: auto; }
.content { padding: 24px; max-width: 1400px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }

/* ---------- Komponenten ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.card.flush { padding: 0; }
.card > .card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 8px; }
.card.flush > .card-head { padding: 14px 16px 0; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.layout-detail { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }

.stat { padding: 14px 16px; }
.stat .num { font-size: 26px; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; background: #fafbfb; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f9fbfb; }
tr.clickable { cursor: pointer; }
.table-wrap { overflow-x: auto; }
.empty { padding: 24px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; line-height: 18px; white-space: nowrap; background: #e8eded; color: #3c4a4b; }
.st-new { background: #fff3cf; color: #7a5600; }
.st-open { background: #dff1ef; color: #0b5a54; }
.st-in_progress { background: #dce9fb; color: #1d4f91; }
.st-waiting { background: #efe5fb; color: #5c3a8c; }
.st-closed { background: #e8eded; color: #5a6667; }
.pr-low { background: #eef1f1; color: #5a6667; }
.pr-normal { background: #e6f0ef; color: #2f5755; }
.pr-high { background: #ffe8cc; color: #8a4b00; }
.pr-urgent { background: #fbdcd9; color: #9b1c12; }
.badge.warn { background: #fbdcd9; color: #9b1c12; }

/* Formulare */
label { display: block; font-weight: 600; font-size: 12px; margin-bottom: 4px; color: #3c4a4b; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=date], input[type=datetime-local], input[type=number], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #cdd6d6; border-radius: 6px; font: inherit; background: #fff; color: var(--fg);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(14, 124, 116, .25); border-color: var(--teal); }
textarea { min-height: 110px; resize: vertical; }
.field { margin-bottom: 12px; }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.check { display: flex; align-items: center; gap: 6px; font-weight: 500; font-size: 13px; }
.check input { margin: 0; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.filters > * { min-width: 140px; }
.filters input[type=search] { min-width: 220px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 6px; border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; background: var(--teal); color: #fff; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--teal-dark); text-decoration: none; }
.btn.amber { background: var(--amber); color: #000; }
.btn.amber:hover { background: var(--amber-dark); }
.btn.ghost { background: #fff; color: var(--fg); border-color: #cdd6d6; }
.btn.ghost:hover { background: #f1f4f4; }
.btn.danger { background: #fff; color: var(--danger); border-color: #e7c1bc; }
.btn.danger:hover { background: #fbecea; }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
form.inline { display: inline; }

.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; border: 1px solid; }
.flash.success { background: #e5f5ec; border-color: #b9e2ca; color: #145c3a; }
.flash.error { background: #fbecea; border-color: #efc4be; color: #8a2116; }
.flash.info { background: #e6f0ef; border-color: #bfdcd9; color: #0b4a47; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a, .tabs button { padding: 8px 14px; border: 0; background: none; font: inherit; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 600; }
.tabs a.active, .tabs button.active { color: var(--fg); border-bottom-color: var(--amber); }
.tabs a:hover { text-decoration: none; color: var(--fg); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Ticket-Verlauf */
.timeline { display: flex; flex-direction: column; gap: 12px; }
.entry { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; overflow: hidden; }
.entry-head { display: flex; justify-content: space-between; gap: 12px; padding: 8px 12px; background: #fafbfb; border-bottom: 1px solid var(--line); font-size: 12px; flex-wrap: wrap; }
.entry-head .who { font-weight: 600; font-size: 13px; }
.entry-body { padding: 12px; overflow-x: auto; word-wrap: break-word; }
.entry-body img { max-width: 100%; height: auto; }
.entry-body pre { white-space: pre-wrap; font-family: inherit; margin: 0; }
.entry.email_in { border-left: 4px solid var(--teal); }
.entry.email_out { border-left: 4px solid var(--amber); }
.entry.note { border-left: 4px solid #8c7ae6; background: #fbfaff; }
.entry.note .entry-head { background: #f4f1ff; }
.entry.system { border: 0; background: none; }
.entry.system .entry-body { padding: 2px 12px; color: var(--muted); font-size: 12px; }
.entry .attachments { padding: 8px 12px; border-top: 1px dashed var(--line); display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; gap: 6px; align-items: center; padding: 3px 10px; background: #eef3f3; border-radius: 999px; font-size: 12px; color: var(--fg); }
.mail-body { max-height: 520px; overflow: auto; }

dl.props { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; margin: 0; }
dl.props dt { color: var(--muted); font-size: 12px; }
dl.props dd { margin: 0; word-break: break-word; }

.callback { border: 1px solid var(--line); border-radius: 6px; padding: 10px; margin-bottom: 8px; }
.callback.overdue { border-color: #efc4be; background: #fff7f6; }
.callback.done { opacity: .6; }
details summary { cursor: pointer; font-weight: 600; }
details[open] summary { margin-bottom: 10px; }

.login-wrap { min-height: 100vh; display: grid; place-items: center; background: #000; padding: 16px; }
.login-box { width: 100%; max-width: 380px; }
.login-box img { width: 100%; margin-bottom: 8px; }
.login-box .card { padding: 24px; }

.pagination { display: flex; gap: 6px; justify-content: flex-end; padding: 12px 16px; }

@media (max-width: 1100px) {
  .layout-detail { grid-template-columns: 1fr; }
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 800px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .sidebar .logo img { width: 160px; }
  .sidebar nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .sidebar nav .sep { display: none; }
  .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; }
  .content { padding: 16px; }
  .topbar { padding: 10px 16px; }
}
