:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #1c2430;
  --muted: #6b7787;
  --line: #e3e7ec;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --error: #c0392b;
  --badge: #eef2f7;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 8px 24px rgba(0,0,0,.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.45;
}

h1 { font-size: 20px; margin: 0; }
h2 { font-size: 17px; margin: 0; }
.muted { color: var(--muted); font-size: 13px; margin: 4px 0 0; }
.center { text-align: center; }
.error { color: var(--error); padding: 10px 24px; margin: 0; }

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 14px;
  transition: background .12s, border-color .12s;
}
button:hover { border-color: #c7cdd6; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.primary:disabled { opacity: .6; cursor: default; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }

input, select {
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--card);
  color: var(--ink);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ── Topbar ── */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 18px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.actions { display: flex; gap: 8px; }

/* ── Toolbar ── */
.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 14px 24px;
}
.toolbar input[type="search"] { flex: 1; max-width: 420px; }

/* ── Status-Tabs (feste Filter über der Liste) ── */
.status-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 14px 24px 0;
}
.status-tabs button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 13px;
  font-weight: 600;
}
.status-tabs button:hover { border-color: #c7cdd6; color: var(--ink); }
.status-tabs button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.status-tabs-count {
  display: inline-block;
  min-width: 18px;
  text-align: center;
  background: var(--badge);
  color: var(--muted);
  border-radius: 999px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 700;
}
.status-tabs button.active .status-tabs-count {
  background: rgba(255, 255, 255, .25);
  color: var(--accent-ink);
}

/* ── Lade-Spinner ── */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: -2px;
  margin-right: 7px;
}
.spinner-lg { width: 26px; height: 26px; border-width: 3px; margin: 0 0 6px; color: var(--accent); }
.loading-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 30px 12px;
  color: var(--muted);
  font-size: 13px;
}

/* ── Tabelle ── */
table.tickets {
  width: calc(100% - 48px);
  margin: 0 24px 40px;
  border-collapse: collapse;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
table.tickets th, table.tickets td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
table.tickets th {
  background: #fafbfc;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
table.tickets tr.row:hover { background: #f0f5ff; cursor: pointer; }
table.tickets td:nth-child(4), table.tickets td:nth-child(5) {
  max-width: 280px; overflow: hidden; text-overflow: ellipsis;
}

.badge {
  display: inline-block;
  background: var(--badge);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 12px;
  white-space: nowrap;
}
.badge-error { background: #fdecea; color: var(--error); margin-left: 6px; }
.badge-odoo { background: #e7f0ff; color: var(--accent); margin-left: 6px; font-weight: 600; }

/* ── Odoo-Objekt-Match (Drawer) ── */
.odoo-box {
  display: flex; gap: 10px; align-items: flex-start;
  background: #f0f6ff; border: 1px solid #cfe0ff; border-radius: 8px;
  padding: 10px 12px; margin: 0 0 14px;
}
.odoo-box .odoo-badge {
  flex: none; background: var(--accent); color: var(--accent-ink);
  border-radius: 6px; padding: 3px 8px; font-size: 12px; font-weight: 600; white-space: nowrap;
}
.odoo-box .muted { margin-top: 2px; }

/* ── Odoo-Tab ── */
.odoo-tab h3 { font-size: 14px; margin: 0 0 8px; }
.odoo-tab h3.mt { margin-top: 18px; }
.odoo-tab code { background: #eef1f5; padding: 1px 5px; border-radius: 4px; font-size: 12px; }
table.odoo-orders { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 4px; }
table.odoo-orders th, table.odoo-orders td {
  text-align: left; padding: 7px 9px; border-bottom: 1px solid var(--line); vertical-align: top;
}
table.odoo-orders th { color: var(--muted); font-weight: 600; font-size: 12px; white-space: nowrap; }
table.odoo-orders td:nth-child(4) { white-space: nowrap; }
table.odoo-orders a { color: var(--accent); font-weight: 600; text-decoration: none; }
table.odoo-orders a:hover { text-decoration: underline; }

/* ── Login ── */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--bg);
}
.login-card {
  background: var(--card);
  padding: 32px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-card h1 { text-align: center; }
.login-card label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.login-card input { font-size: 15px; }
.login-card button { margin-top: 6px; }

/* ── Detail-Drawer ── */
.drawer-backdrop {
  position: fixed; inset: 0;
  background: rgba(20,30,45,.35);
  z-index: 10;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(560px, 92vw);
  background: var(--card);
  box-shadow: -8px 0 30px rgba(0,0,0,.15);
  z-index: 11;
  padding: 20px 22px;
  overflow-y: auto;
}
.drawer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.tabs button {
  border: none; border-radius: 0; background: transparent; color: var(--muted);
  padding: 8px 12px; border-bottom: 2px solid transparent;
}
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.fields { display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.field { display: grid; grid-template-columns: 180px 1fr; background: var(--card); }
.field .k { padding: 8px 12px; color: var(--muted); font-size: 12px; background: #fafbfc; word-break: break-word; }
.field .v { padding: 8px 12px; word-break: break-word; }

.comm { display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.comm-line { padding: 4px 8px; border-bottom: 1px solid var(--line); white-space: pre-wrap; word-break: break-word; }

/* ── Statuswechsel (gegated) ── */
.statuswrite {
  border: 1px solid #cfe0ff;
  background: #f6f9ff;
  border-radius: 8px;
  padding: 12px 14px;
  margin: 0 0 16px;
}
.sw-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sw-row strong { font-size: 15px; }
.sw-hint {
  margin: 10px 0 0; font-size: 12px; color: #7a5b00;
  background: #fff8e6; border: 1px solid #f0e0a8; border-radius: 6px; padding: 7px 10px;
}
.sw-hint code { background: #fff; padding: 1px 5px; border-radius: 4px; }
.sw-confirm {
  margin-top: 12px; padding: 12px; border-radius: 8px;
  background: #fff; border: 1px solid #f0c9c2;
}
.sw-confirm p { margin: 0 0 10px; }
.sw-actions { display: flex; gap: 8px; }
.sw-log { margin-top: 12px; font-size: 13px; }
.sw-log summary { cursor: pointer; color: var(--muted); user-select: none; }
.sw-log ul { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-direction: column; gap: 6px; }
.sw-log li { padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fafbfc; }
.sw-log li .badge { margin-left: 4px; }

/* Handoff-Box: gleiche Basis wie .statuswrite, leicht abgesetzter Akzent. */
.handoff { border-color: #cddccc; background: #f5faf6; }
.handoff-blocker { margin: 8px 0 0; padding-left: 18px; font-size: 12px; color: var(--muted); }
.handoff-blocker li { margin: 2px 0; }
.handoff-ok { margin-top: 4px; font-size: 14px; }
.handoff-ok .btn-link { margin-left: 8px; }

/* ── Medien-Tab ── */
.medien h3 { font-size: 14px; margin: 0 0 10px; }
.doclist { list-style: none; padding: 0; margin: 0 0 16px; display: flex; flex-direction: column; gap: 4px; }
.doclist li {
  display: flex; gap: 8px; align-items: center;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: #fafbfc; font-size: 13px; word-break: break-word;
}
.doc-icon { flex: none; }
.media-zip { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.btn-link {
  display: inline-block; text-decoration: none;
  background: var(--accent); color: var(--accent-ink);
  padding: 9px 14px; border-radius: 8px; font-weight: 600; font-size: 14px;
}
.btn-link:hover { filter: brightness(.95); }
.small { font-size: 12px; }

/* ── Ausgegraute (nicht mehr aktive) Tickets ── */
table.tickets tr.row.inactive { opacity: .5; }
table.tickets tr.row.inactive:hover { opacity: .72; background: #f4f6f9; }
.badge-muted { background: #eef1f5; color: var(--muted); margin-left: 6px; }
.chk { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: 13px; white-space: nowrap; }

/* ── Lauf-Verlauf (Logs) ── */
.drawer.drawer-wide { width: min(820px, 96vw); }
table.runs { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
table.runs th, table.runs td {
  text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line);
  vertical-align: top;
}
table.runs th { color: var(--muted); font-weight: 600; font-size: 12px; }
table.runs tr.run-error td { background: #fdf3f2; }
table.runs td .small { display: block; margin-top: 2px; max-width: 320px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge-ok { background: #e7f6ec; color: #1b7f3b; }

/* ── Anhang-Spalte ── */
.col-anh { width: 32px; text-align: center; padding-left: 6px; padding-right: 6px; }
.chk input { width: auto; }
.note-muted {
  background: #fff8e6; border: 1px solid #f0e0a8; color: #7a5b00;
  padding: 8px 11px; border-radius: 8px; font-size: 13px; margin: 0 0 14px;
}

/* ── Link, der wie ein Ghost-Button aussieht (Topbar-Navigation) ── */
.linkbtn {
  font: inherit; text-decoration: none; color: var(--muted);
  border: 1px solid transparent; border-radius: 8px; padding: 8px 14px;
  display: inline-flex; align-items: center;
}
.linkbtn:hover { border-color: #c7cdd6; color: var(--ink); }

/* ── Handwerker-Verwaltung ── */
.hw-tabs { display: flex; gap: 6px; padding: 0 24px 12px; }
.hw-tabs button.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.hw-layout {
  display: grid; grid-template-columns: 320px 1fr; gap: 18px;
  padding: 0 24px 24px; align-items: start;
}
.hw-list {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  max-height: 72vh; overflow: auto;
}
.hw-list button {
  display: block; width: 100%; text-align: left; border: 0;
  border-bottom: 1px solid var(--line); border-radius: 0; background: transparent; padding: 10px 12px;
}
.hw-list button:hover { background: #f3f6fb; }
.hw-list button.active { background: #eef4ff; }
.code { font-variant-numeric: tabular-nums; color: var(--muted); margin-right: 6px; }

.hw-detail {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px;
}
.hw-row {
  display: grid; grid-template-columns: 240px minmax(0, 1fr) auto; gap: 10px;
  align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line);
}
.hw-row .gw { font-weight: 600; }
.hw-row select, .hw-row .hw-assign { width: 100%; }
.hw-hist { margin: 2px 0 10px; padding: 8px 12px; background: var(--badge); border-radius: 8px; }
.hw-hist .item { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; }
.hw-empty { color: var(--muted); }
.small { font-size: 12px; }

.hw-form { display: flex; gap: 8px; flex-wrap: wrap; padding: 4px 24px 14px; align-items: center; }
.hw-table { width: 100%; border-collapse: collapse; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.hw-table th, .hw-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.hw-table th { background: #f7f9fc; font-weight: 600; }

.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; }
.pill.on { background: #e6f6ec; color: #1a7f43; }
.pill.off { background: #f0f0f0; color: #888; }

/* ── Ticket-Detail: Handwerker-Tab ── */
.handwerker-tab .gw-select { min-width: 220px; }
.hw-all { width: 100%; border-collapse: collapse; margin-top: 4px; }
.hw-all td { padding: 6px 8px; border-bottom: 1px solid var(--line); }
.hw-all td.gwname { color: var(--muted); width: 44%; }
.hw-all tr { cursor: pointer; }
.hw-all tr:hover td { background: #f3f6fb; }
.hw-all tr.row-active td { background: #eef4ff; font-weight: 600; }

/* ── Gewerk-Kategorien (Handwerkerliste) ── */
.gw-chips { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.gw-chip { background: #eef2f7; color: #445; border-radius: 999px; padding: 1px 7px; font-size: 11px; white-space: nowrap; }
.gw-edit { border: 0; background: transparent; color: var(--accent); padding: 1px 4px; font-size: 12px; }
.gw-editor { display: flex; flex-wrap: wrap; gap: 4px; max-width: 420px; }
.gw-toggle { border: 1px solid var(--line); background: var(--card); color: var(--muted);
  border-radius: 999px; padding: 2px 9px; font-size: 11px; }
.gw-toggle.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.gw-done { font-size: 11px; padding: 2px 9px; }

/* Gebäude-Liste je Handwerker (Spalte „Gebäude") */
.geb-cell { display: flex; flex-direction: column; gap: 3px; }
.geb-list { display: flex; flex-direction: column; gap: 2px; margin-top: 2px;
  max-height: 200px; overflow: auto; padding-right: 2px; }
.geb-item { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline;
  font-size: 12px; line-height: 1.3; }
.geb-name { color: var(--ink); }
.geb-gw { color: var(--muted); font-size: 10px; text-transform: none;
  background: #eef2f7; border-radius: 999px; padding: 0 6px; white-space: nowrap; }

@media (max-width: 800px) {
  .hw-layout { grid-template-columns: 1fr; }
  .hw-row { grid-template-columns: 1fr; }
}

/* ── Odoo-Suche / -Verknüpfung ── */
[x-cloak] { display: none !important; }
.odoo-search { padding: 0 24px 12px; }
.odoo-search-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  background: #f0f5ff; border: 1px solid #d6e2fb; border-radius: var(--radius); padding: 10px 12px; }
.odoo-search-bar input[type="search"] { flex: 1; min-width: 260px; }
.odoo-link { margin: 8px 0 4px; }
.odoo-link .linkbtn { padding-left: 0; color: var(--accent); }
.odoo-link button.ghost { color: var(--accent); }
