/* Farben aus dem kalucare-Logo: Navy (#000050) als Hauptfarbe, Hellblau (#C1DBEB) als Akzent.
   Hell/Dunkel folgt dem System; theme.js setzt data-theme, wenn jemand im Header umschaltet. */
:root {
  color-scheme: light;
  --navy: #0a0a5a; --pale: #c1dbeb;
  --bg: #f3f5fa; --card: #fff; --raised: #f7f9fc; --text: #14183d; --muted: #5d6483; --line: #dde3ee; --line-strong: #c5cddd;
  --primary: #0a0a5a; --primary-hover: #20207e; --primary-text: #fff;
  --link: #24249a; --soft: #e6f0f8; --soft-text: #0a0a5a; --focus: rgba(70, 120, 200, 0.35);
  --input: #fff; --header: #fff; --shadow: 0 1px 2px rgba(10, 10, 90, 0.05), 0 2px 8px rgba(10, 10, 90, 0.04);
  --ok: #1d7a4c; --ok-bg: #e3f4ea; --warn: #94570b; --warn-bg: #fdf0d9; --err: #b3261e; --err-bg: #fce8e6;
  --violet: #4b3fb0; --violet-bg: #ebe9fb; --grey: #5d6483; --grey-bg: #eceff5;
  --radius: 10px; --radius-sm: 7px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif; font-size: 15px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b0d1e; --card: #14172c; --raised: #191d35; --text: #e6e9f6; --muted: #9ba2c2; --line: #262b48; --line-strong: #353b5e;
    --primary: #c1dbeb; --primary-hover: #d8e8f3; --primary-text: #0a0a5a;
    --link: #a8cbec; --soft: #1d2647; --soft-text: #c9e0f2; --focus: rgba(168, 203, 236, 0.35);
    --input: #0f1225; --header: #10132a; --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    --ok: #6fd3a0; --ok-bg: #12301f; --warn: #f0b860; --warn-bg: #33250d; --err: #ff8a80; --err-bg: #3a1513;
    --violet: #b3abff; --violet-bg: #251f4d; --grey: #9ba2c2; --grey-bg: #1f2340;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0d1e; --card: #14172c; --raised: #191d35; --text: #e6e9f6; --muted: #9ba2c2; --line: #262b48; --line-strong: #353b5e;
  --primary: #c1dbeb; --primary-hover: #d8e8f3; --primary-text: #0a0a5a;
  --link: #a8cbec; --soft: #1d2647; --soft-text: #c9e0f2; --focus: rgba(168, 203, 236, 0.35);
  --input: #0f1225; --header: #10132a; --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  --ok: #6fd3a0; --ok-bg: #12301f; --warn: #f0b860; --warn-bg: #33250d; --err: #ff8a80; --err-bg: #3a1513;
  --violet: #b3abff; --violet-bg: #251f4d; --grey: #9ba2c2; --grey-bg: #1f2340;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
main { max-width: 1200px; margin: 0 auto; padding: 24px 20px 48px; }
h1 { font-size: 1.55rem; line-height: 1.25; letter-spacing: -0.01em; margin: 0.3em 0 0.4em; }
h2 { font-size: 1.05rem; margin: 1.2em 0 0.6em; }
.card > h2:first-child, form.card > input[type=hidden] + h2 { margin-top: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* Kopfzeile */
.top { position: sticky; top: 0; z-index: 10; background: var(--header); border-bottom: 1px solid var(--line); }
.top-inner { max-width: 1200px; margin: 0 auto; padding: 10px 20px; display: flex; flex-wrap: wrap; gap: 8px 20px;
  align-items: center; justify-content: space-between; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand img { width: 38px; height: 38px; object-fit: contain; background: #fff; border-radius: 50%; box-shadow: 0 0 0 1px var(--line); }
.brand-name { font-weight: 800; font-size: 1.15rem; letter-spacing: -0.02em; color: var(--text); }
.brand-sub { font-weight: 300; font-size: 1.05rem; color: var(--muted); }
.top nav { display: flex; flex-wrap: wrap; gap: 2px; align-items: center; }
.top nav a, .top nav button.link { padding: 6px 10px; border-radius: var(--radius-sm); color: var(--text); font-weight: 500; }
.top nav a:hover, .top nav button.link:hover { background: var(--soft); color: var(--soft-text); text-decoration: none; }
.top nav a.active { background: var(--soft); color: var(--soft-text); font-weight: 600; }
.top nav .sep { width: 1px; height: 22px; margin: 0 8px; background: var(--line); }
.top nav .user { color: var(--muted); }
.theme-toggle { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; padding: 0;
  margin-left: 4px; color: var(--text); background: transparent; border: 1px solid var(--line); border-radius: 50%; }
.theme-toggle:hover { background: var(--soft); color: var(--soft-text); }
.lang-switch { display: inline-flex; align-items: center; justify-content: center; min-width: 34px; height: 34px;
  padding: 0 6px; border-radius: 8px; font-size: 13px; font-weight: 600; letter-spacing: .03em; text-decoration: none; }
.lang-switch:hover { background: var(--soft); color: var(--soft-text); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .i-sun, .theme-toggle .i-moon, .theme-toggle .i-auto { display: none; }
.theme-toggle[data-mode="light"] .i-sun, .theme-toggle[data-mode="dark"] .i-moon, .theme-toggle[data-mode="auto"] .i-auto { display: block; }

/* Bausteine */
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin: 14px 0;
  box-shadow: var(--shadow); }
.narrow { max-width: 400px; margin: 40px auto; }
.login-logo { display: block; width: auto; max-width: 190px; max-height: 220px; height: auto; margin: 0 auto 8px; padding: 10px; background: #fff; border-radius: 14px; }
.login h1 { text-align: center; font-size: 1.25rem; margin-bottom: 1em; }
.login button { width: 100%; padding: 10px 14px; }

label { display: block; margin: 0 0 14px; font-weight: 600; font-size: 0.9rem; }
label.choice { display: inline-flex; gap: 8px; align-items: center; margin: 0; font-weight: 400; font-size: 1rem; }
label .hint { display: block; margin-top: 4px; font-weight: 400; }
input, select, textarea { width: 100%; margin-top: 5px; padding: 9px 11px; font: inherit; font-size: 1rem; font-weight: 400; color: var(--text);
  background: var(--input); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  transition: border-color 0.15s, box-shadow 0.15s; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.8; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--link); box-shadow: 0 0 0 3px var(--focus); }
input[type=checkbox], input[type=radio] { width: 17px; height: 17px; margin: 0; accent-color: var(--primary); box-shadow: none; }
input[type=file] { padding: 7px; background: var(--raised); border-style: dashed; }
input[type=file]::file-selector-button { margin-right: 10px; padding: 5px 12px; font: inherit; font-weight: 600; color: var(--soft-text);
  background: var(--soft); border: 0; border-radius: 6px; cursor: pointer; }
textarea { resize: vertical; }
input:not([type=checkbox]):not([type=radio]):not([type=file]), select { height: 40px; }

button, .button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; font: inherit;
  font-weight: 600; line-height: 1.2; cursor: pointer; color: var(--primary-text); background: var(--primary); border: 1px solid transparent;
  border-radius: var(--radius-sm); transition: background 0.15s, border-color 0.15s; }
button:hover, .button:hover { background: var(--primary-hover); text-decoration: none; }
button.secondary, .button.secondary { color: var(--text); background: var(--card); border-color: var(--line-strong); }
button.secondary:hover, .button.secondary:hover { background: var(--soft); border-color: var(--soft); color: var(--soft-text); }
button.link { padding: 0; color: var(--link); background: none; border: 0; font-weight: 500; }
button.link:hover { background: none; text-decoration: underline; }
button.danger, .button.danger { color: var(--err); background: var(--card); border-color: var(--err); }
button.danger:hover, .button.danger:hover { color: var(--card); background: var(--err); }
.danger-zone { margin-top: 16px; text-align: right; }
form.inline { display: inline; }
.choices { display: flex; flex-wrap: wrap; gap: 18px; }

.flash { padding: 11px 14px; border-radius: var(--radius-sm); border: 1px solid var(--line); border-left-width: 4px; background: var(--card); }
.flash.ok { border-color: var(--ok); background: var(--ok-bg); }
.flash.error { border-color: var(--err); background: var(--err-bg); color: var(--err); }

/* Liste und Tabellen */
.filters { display: grid; grid-template-columns: 2fr repeat(4, 1fr); gap: 10px; margin: 16px 0; }
.filters.with-brand { grid-template-columns: 1.6fr repeat(5, 1fr); }
.filters input, .filters select { margin: 0; }
.filters input[type=search] { padding-left: 34px; background: var(--input) no-repeat 11px center / 16px
  url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a91ad' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E"); }
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 700; background: var(--raised); }
td input, td select { margin: 0; }
/* Auswahlfelder in Tabellen so breit wie ihr längster Eintrag, Textfelder nicht zusammengedrückt */
td select { width: auto; }
td input:not([type=checkbox]):not([type=radio]) { min-width: 9em; }
td input[name=name]:not([type=checkbox]) { min-width: 11em; }
td input[type=email]:not([type=checkbox]), td input[name=emails]:not([type=checkbox]) { min-width: 13em; }
td input[type=checkbox] { vertical-align: middle; }
td.nowrap { white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
.tickets tbody tr { transition: background 0.1s; }
.tickets tbody tr:hover { background: var(--raised); }
.tickets td:first-child { white-space: nowrap; font-variant-numeric: tabular-nums; }
.tickets td:first-child a { color: var(--muted); font-weight: 600; }
.tickets td:nth-child(2) a { color: var(--text); font-weight: 600; }
.tickets td:last-child { color: var(--muted); white-space: nowrap; font-size: 0.9rem; }

/* Status und Priorität */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 600;
  line-height: 1.4; white-space: nowrap; color: var(--grey); background: var(--grey-bg); border: 1px solid transparent; }
.badge[class*=" s-"]::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.s-neu { color: var(--soft-text); background: var(--soft); }
.s-in_bearbeitung { color: var(--violet); background: var(--violet-bg); }
.s-wartet_auf_kunde { color: var(--warn); background: var(--warn-bg); }
.s-erledigt { color: var(--ok); background: var(--ok-bg); }
.s-geschlossen { color: var(--grey); background: var(--grey-bg); }
.p-niedrig { color: var(--grey); background: transparent; border-color: var(--line-strong); }
.p-normal { color: var(--text); background: transparent; border-color: var(--line-strong); }
.p-hoch { color: var(--warn); background: var(--warn-bg); }
.p-dringend { color: var(--err); background: var(--err-bg); }

/* Ticketdetail */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 14px; align-items: end; }
.grid3 > div { margin-bottom: 14px; }
.grid3 > .wide { grid-column: 1 / -1; }
td.access .access-state { margin-top: 4px; font-size: 0.85rem; }
td.access .access-state .small { margin: 2px 0; }
td.access .access-state .badge { font-size: 0.72rem; padding: 1px 8px; }
.grid3.top { align-items: start; }
label input[type=color] { display: block; }
/* Eine Zeile aus Feld, Häkchen und Knopf */
.form-row { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; }
.form-row label { margin: 0; }
.form-row label input:not([type=checkbox]) { display: inline-block; width: 6em; margin: 0 6px; }
.detail { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 24px; align-items: start; }
.detail aside .card:first-child { margin-top: 14px; }
.detail .grid3 { grid-template-columns: 1fr; }
.title-row h1 { margin-bottom: 0.2em; }
.card > .title-row:first-child { margin-bottom: 12px; }
.card > .title-row:first-child h2 { margin: 0; }
.title-row .actions { display: flex; gap: 10px; align-items: center; }
.title-row .actions select { width: auto; margin: 0; }
.title-row .badge { font-size: 0.85rem; padding: 5px 12px; }
.description, .comment .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.history { list-style: none; padding: 0 0 0 18px; margin: 0; border-left: 2px solid var(--line); margin-left: 6px; }
.history li { position: relative; margin: 10px 0; }
.history li::before { content: ""; position: absolute; left: -25px; top: 12px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--bg); border: 2px solid var(--line-strong); }
.history li.comment::before { top: 16px; border-color: var(--muted); background: var(--card); }
.history li.comment.external::before { border-color: var(--primary); background: var(--pale); }
.comment { background: var(--card); border: 1px solid var(--line); border-left-width: 4px; border-left-color: var(--line-strong);
  border-radius: var(--radius-sm); padding: 12px 14px; box-shadow: var(--shadow); }
.comment.external { border-left-color: var(--primary); }
/* Kommentar vom Kunden (per Mail oder Kundenportal) */
.comment.from-customer { border-left-color: var(--ok); background: color-mix(in srgb, var(--ok-bg) 45%, var(--card)); }
.history li.comment.from-customer::before { border-color: var(--ok); background: var(--ok-bg); }
.comment .meta { font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; }
.comment .meta strong { color: var(--text); }
.audit { font-size: 0.85rem; padding: 3px 0; }
.files, .mails { list-style: none; padding: 14px 20px; }
.files li, .mails li { margin: 6px 0; }
.files li + li, .mails li + li { padding-top: 6px; border-top: 1px solid var(--line); }
.grid-time { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.time-form { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
#zeiten h2 { display: flex; justify-content: space-between; align-items: baseline; }
#zeiten h2 .muted { font-variant-numeric: tabular-nums; font-weight: 600; }
#zeiten table { margin-top: 16px; }
#zeiten table td { padding: 8px 4px; }
#zeiten form button + button { margin-left: 6px; }
aside label.choice { margin-bottom: 14px; }
.button.danger, button.danger { color: var(--err); background: var(--card); border-color: var(--err); }
.button.danger:hover, button.danger:hover { color: var(--card); background: var(--err); }

@media (max-width: 800px) {
  main { padding: 16px 16px 40px; }
  .top-inner { padding: 10px 16px; }
  .brand-sub { display: none; }
  .top nav .sep { display: none; }
  .filters, .filters.with-brand { grid-template-columns: 1fr 1fr; }
  .filters input[type=search] { grid-column: 1 / -1; }
  .detail, .grid2 { grid-template-columns: 1fr; }
  .card { padding: 16px; }
}
.theme-corner { position: absolute; top: 14px; right: 16px; display: flex; align-items: center; gap: 4px; }
/* Ticketliste auf dem Handy als Karten statt breiter Tabelle */
@media (max-width: 640px) {
  .tickets thead { display: none; }
  .tickets, .tickets tbody { display: block; }
  .tickets tr { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .tickets tbody tr:last-child { border-bottom: 0; }
  .tickets td { display: block; padding: 0; border: 0; }
  .tickets td:empty { display: none; }
  .tickets td:nth-child(2) { order: -1; flex-basis: 100%; }
  .tickets td:first-child { font-size: 0.85rem; }
  .tickets td:last-child { flex-basis: 100%; font-size: 0.8rem; }
}
@media (max-width: 800px) {
  .top nav a, .top nav button.link { padding: 5px 8px; }
}

/* Öffentliches Kundenformular */
.public { max-width: 640px; margin: 32px auto; }
.public-head { display: flex; gap: 14px; align-items: center; margin-bottom: 18px; }
.public-head img { flex: none; object-fit: contain; border-radius: 50%; background: #fff; }
.public-head h1 { margin: 0; }
.public-head p { margin: 2px 0 0; }
fieldset.prio { display: flex; flex-wrap: wrap; gap: 10px 22px; margin: 0 0 14px; padding: 0; border: 0; }
fieldset.prio legend { width: 100%; padding: 0; margin-bottom: 8px; font-weight: 600; font-size: 0.9rem; }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.ticket-number { font-size: 1.6rem; font-weight: 700; letter-spacing: 0.02em; }
.link-url { display: flex; gap: 8px; align-items: center; }
.link-url input { min-width: 22em; margin: 0; font-family: ui-monospace, monospace; font-size: 0.85rem; }

/* Marken */
.projects table { table-layout: fixed; }
.projects th:first-child { width: 40%; }

.brand-preview { display: inline-flex; gap: 6px; vertical-align: middle; }
.brand-preview span { width: 18px; height: 18px; border-radius: 50%; box-shadow: 0 0 0 1px var(--line); }
.brand-thumb.wide { width: auto; max-width: 180px; padding: 4px; }
.brand-thumb { width: 48px; height: 48px; object-fit: contain; background: #fff; border-radius: var(--radius-sm); box-shadow: 0 0 0 1px var(--line); }
input[type=color] { width: 64px; height: 40px; padding: 3px; }
td.actions { white-space: nowrap; }
td.actions > * + * { margin-left: 6px; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--grey-bg); color: var(--grey); font-size: 0.8rem; font-weight: 600; }
.req { color: var(--err); font-weight: 700; }
.contact-email { margin: 0 0 14px; font-size: 0.9rem; }
.contact-email .label { display: block; font-weight: 600; }
.contact-email .value { display: flex; align-items: center; height: 40px; margin-top: 5px; color: var(--muted); }
.public [hidden] { display: none; }
.brand img.brand-wide { display: block; height: 46px; width: auto; max-width: 300px; object-fit: contain; padding: 2px 6px; background: #fff; border-radius: var(--radius-sm); }
.brand img.brand-logo { display: block; height: 64px; width: auto; object-fit: contain; padding: 3px 5px; background: #fff; border-radius: var(--radius-sm); box-shadow: 0 0 0 1px var(--line); }
.public-head img.public-logo { display: block; height: 96px; width: auto; object-fit: contain; padding: 4px 6px; background: #fff; border-radius: var(--radius-sm); }
.public-head img.public-wide { display: block; height: 52px; width: auto; max-width: 220px; object-fit: contain; padding: 4px 8px; background: #fff; border-radius: var(--radius-sm); }

/* Zwei-Faktor-Anmeldung */
.qr { margin: 12px 0; }
.qr svg { display: block; background: #fff; border-radius: var(--radius-sm); }
.recovery-codes { columns: 2; list-style: none; padding: 0; font-size: 1.05rem; }
.recovery-codes li { margin: 4px 0; }

/* Kundenportal */
.public.portal { max-width: 860px; }
.portal-nav { display: flex; gap: 16px; align-items: center; margin: -6px 0 16px; flex-wrap: wrap; }
.portal .history { margin-top: 8px; }
.portal-nav button.link { font-size: inherit; font-weight: inherit; }
.portal td:first-child, .portal td:last-child { white-space: nowrap; }

/* Auswertungen */
.report td.num, .report th { text-align: right; white-space: nowrap; }
.report td:first-child, .report th:first-child { text-align: left; white-space: normal; }
.report tr.sum td { border-top: 2px solid var(--line-strong); font-weight: 600; }
.report tr.mite td { border-top: none; padding-top: 0; color: var(--muted); }
.report td.diff { color: var(--warn); font-weight: 600; }
#update pre { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 24em; overflow: auto; padding: 10px; border-radius: var(--radius-sm); background: var(--soft); color: var(--soft-text); }
