:root {
  color-scheme: dark light;
  --bg: #161412;
  --surface: #1f1c19;
  --surface-2: #2a2622;
  --text: #ece7e1;
  --muted: #a89f95;
  --line: #38332e;
  --accent: #d9772b;
  --accent-text: #170d05;
  --link: #e8a06a;
  --danger: #c9372c;
  --danger-text: #ffffff;
  --danger-link: #ee9d94;
  --ok-text: #8fd19e;
  --ok-bg: #1b2b1f;
  --warn-text: #e6c477;
  --warn-bg: #2e2612;
  --err-text: #ee9d94;
  --err-bg: #331a18;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f5f2;
    --surface: #ffffff;
    --surface-2: #efebe6;
    --text: #231c16;
    --muted: #665b51;
    --line: #dcd5cd;
    --accent: #ad4f0e;
    --accent-text: #ffffff;
    --link: #9c4509;
    --danger: #b3261e;
    --danger-text: #ffffff;
    --danger-link: #8f2318;
    --ok-text: #1d5c2c;
    --ok-bg: #e4f2e7;
    --warn-text: #694c05;
    --warn-bg: #f9efd5;
    --err-text: #8f2318;
    --err-bg: #fae5e2;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.35rem; line-height: 1.3; font-weight: 650; margin: 0 0 .35rem; overflow-wrap: anywhere; }
h2 {
  font-size: .8rem;
  font-weight: 650;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 1.75rem 0 .5rem;
}
p { margin: 0 0 .5rem; }

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .25rem 1.5rem;
  padding: .6rem 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { color: var(--text); font-weight: 650; }
.brand:hover { text-decoration: none; }
.mainnav { display: flex; flex-wrap: wrap; align-items: center; gap: .15rem 1.1rem; }
.mainnav form { margin: 0; }
.mainnav a, .mainnav .linklike { color: var(--muted); }
.mainnav a:hover, .mainnav .linklike:hover { color: var(--text); text-decoration: none; }
.mainnav a[aria-current=page] { color: var(--text); font-weight: 600; }
.count {
  display: inline-block;
  min-width: 1.15rem;
  padding: 0 .3rem;
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 3px;
  font-size: .75rem;
  font-weight: 650;
  line-height: 1.15rem;
  text-align: center;
}

main { margin: 0 auto; padding: 1.5rem 16px 3rem; }
main.tiny { max-width: 26rem; }
main.narrow { max-width: 42rem; }
main.wide { max-width: 72rem; }

.muted { color: var(--muted); font-weight: 400; }
.prewrap { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.after-form { margin-top: 1rem; }

.stack { display: grid; gap: 1rem; margin-top: 1rem; }
.stack > button { justify-self: start; }
.field { display: grid; gap: .3rem; min-width: 0; align-content: start; }
.field-hint { margin: 0; font-size: .85rem; }
.field-error { color: var(--err-text); margin: 0; font-size: .875rem; }
.button-row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }

label, legend { font-weight: 600; font-size: .9rem; }

input:not([type=radio], [type=checkbox]), select, textarea {
  width: 100%;
  padding: .5rem .65rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 4px;
  font: inherit;
}
textarea { resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--muted); }
input:focus-visible, select:focus-visible, textarea:focus-visible,
button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

fieldset { border: 0; padding: 0; margin: 0; }
legend { padding: 0; margin-bottom: .3rem; }
.choices-list { display: grid; gap: .2rem; }
.choice { display: flex; align-items: baseline; gap: .45rem; font-weight: 400; cursor: pointer; }
.choice input { margin: 0; accent-color: var(--accent); }
.choice strong { font-weight: 600; }

button, .button-link {
  display: inline-block;
  padding: .5rem 1rem;
  background: var(--accent);
  color: var(--accent-text);
  border: 1px solid transparent;
  border-radius: 4px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
button:hover { filter: brightness(1.08); }
button.secondary, .button-link { background: transparent; color: var(--text); border-color: var(--line); }
button.secondary:hover, .button-link:hover { background: var(--surface-2); filter: none; text-decoration: none; }
button.danger { background: var(--danger); color: var(--danger-text); }
button.small { padding: .2rem .55rem; font-size: .85rem; font-weight: 500; }
button.linklike { padding: 0; background: none; border: 0; font-weight: 400; }
.delete-link { color: var(--danger-link); font-size: .85rem; }

.notice { padding: .6rem .8rem; border-radius: 4px; margin: 0 0 1rem; overflow-wrap: anywhere; }
.notice.ok { background: var(--ok-bg); color: var(--ok-text); }
.notice.warn { background: var(--warn-bg); color: var(--warn-text); }
.notice.error { background: var(--err-bg); color: var(--err-text); }
.notice .copy { margin: .4rem 0; }
.notice p:last-child { margin-bottom: 0; }

.heading-row { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: .35rem 1rem; }
.badges { display: flex; flex-wrap: wrap; gap: .3rem; }

.details {
  display: grid;
  grid-template-columns: repeat(4, auto);
  justify-content: space-between;
  gap: .6rem 1.5rem;
  margin: .75rem 0 0;
  padding: .7rem .85rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
}
.details dt { font-size: .78rem; color: var(--muted); }
.details dd { margin: 0; overflow-wrap: anywhere; }
.details-wide { grid-column: 1 / -1; }

.badge {
  display: inline-block;
  padding: .05rem .45rem;
  border: 1px solid currentColor;
  border-radius: 3px;
  font-size: .78rem;
  font-weight: 600;
  white-space: nowrap;
}
.status-offen { color: var(--text); }
.status-arbeit { color: var(--warn-text); }
.status-erledigt { color: var(--ok-text); }
.urgent { background: var(--danger); border-color: var(--danger); color: var(--danger-text); }
.new { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.confidential { color: var(--muted); }
.only-phone { display: none; }

.filters { display: flex; flex-wrap: wrap; gap: .1rem 1.1rem; margin: .75rem 0 0; border-bottom: 1px solid var(--line); }
.filters a { padding: .35rem 0; margin-bottom: -1px; color: var(--muted); border-bottom: 2px solid transparent; font-size: .92rem; }
.filters a:hover { color: var(--text); text-decoration: none; }
.filters a[aria-current=page] { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }

.tickets, .accounts { width: 100%; border-collapse: collapse; }
.tickets th, .accounts th {
  padding: .6rem .6rem .35rem;
  text-align: left;
  font-size: .78rem;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.tickets th a { color: var(--muted); }
.tickets th a:hover { color: var(--text); text-decoration: none; }
.tickets th a.active { color: var(--text); font-weight: 650; }
.tickets td, .accounts td { padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: baseline; }
.tickets tbody tr { position: relative; }
.tickets tbody tr:hover { background: var(--surface); }
.tickets th:first-child, .tickets td:first-child, .accounts th:first-child, .accounts td:first-child { padding-left: 0; }
.tickets th:last-child, .tickets td:last-child, .accounts th:last-child, .accounts td:last-child { padding-right: 0; }
.cell-subject { overflow-wrap: anywhere; font-weight: 600; }
.cell-subject a { color: var(--text); }
/* Der Link deckt die ganze Zeile ab: Hervorhebung und Klickfläche stimmen überein. */
.cell-subject a::after { content: ""; position: absolute; inset: 0; }
.tickets tbody tr:hover .cell-subject a { color: var(--link); text-decoration: none; }
.cell-meta { color: var(--muted); font-size: .9rem; }
.cell-date, .cell-status, .cell-num { white-space: nowrap; }

.account-name { font-weight: 600; overflow-wrap: anywhere; }
.inline-actions { display: flex; flex-wrap: wrap; gap: .35rem; margin: 0; }

.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.timeline li { padding: .5rem .75rem; background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--line); border-radius: 4px; }
.timeline li.from-admin { border-left-color: var(--accent); }
.timeline li.internal { background: var(--surface-2); border-style: dashed; border-left-style: solid; border-left-color: var(--muted); }
.timeline li.status { background: none; border: 0; padding: 0 .75rem; color: var(--muted); }
.timeline-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0 1rem; font-size: .8rem; margin: 0 0 .1rem; }

.attachments { display: grid; grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); gap: .5rem; margin-top: .6rem; }
.attachments a { display: block; }
.attachments img { display: block; width: 100%; height: 7rem; object-fit: cover; background: var(--surface-2); border: 1px solid var(--line); border-radius: 4px; }

.status-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .6rem; }
.status-form .field { flex: 1 1 12rem; }

.copy { font-size: .875rem; }

/* Unterhalb dieser Breite passen die acht Spalten nicht mehr nebeneinander. */
@media (max-width: 56rem) {
  .tickets, .tickets thead, .tickets tbody { display: block; }
  .tickets tr { display: flex; flex-wrap: wrap; align-items: baseline; gap: .1rem .4rem; padding: .6rem 0; border-bottom: 1px solid var(--line); }
  /* Die Spaltenköpfe bleiben als knappe Sortierleiste erhalten. */
  .tickets thead tr { gap: .1rem .8rem; padding: .45rem 0; font-size: .85rem; color: var(--muted); }
  .tickets thead tr::before { content: "Sortieren:"; }
  .tickets th, .tickets th:first-child, .tickets th:last-child { display: block; padding: 0; border: 0; font-size: inherit; }
  .tickets th.sort-secondary { display: none; }
  .tickets td, .tickets td:first-child, .tickets td:last-child { display: block; padding: 0; border: 0; }
  /* Nummer und Betreff füllen die erste Zeile exakt, die Metadaten beginnen immer darunter. */
  .cell-num { flex: 0 0 2.2rem; font-size: .85rem; }
  .cell-subject { flex: 0 0 calc(100% - 2.6rem); }
  .cell-meta { font-size: .85rem; }
  .cell-meta + .cell-meta::before { content: "· "; }
  .cell-status { flex: 0 0 100%; margin-top: .2rem; }
  .tickets td.cell-urgent, .tickets td.cell-updated { display: none; }
  .only-phone { display: inline-block; }
}

@media (max-width: 42rem) {
  .details { grid-template-columns: 1fr 1fr; justify-content: stretch; }

  .accounts, .accounts tbody, .accounts tr, .accounts td { display: block; }
  .accounts thead { display: none; }
  .accounts tr { padding: .6rem 0; border-bottom: 1px solid var(--line); }
  .accounts td, .accounts td:first-child, .accounts td:last-child { padding: .05rem 0; border: 0; }
  .accounts .inline-actions { margin-top: .35rem; }
}
