:root {
  /* Lihovar palette: graphite ink, cool paper, verdigris (patina of the distillery's copper stills) */
  --bg: #F4F6F8; --panel: #fff; --text: #1B2230; --muted: #5F6878; --line: #E1E5EB;
  --accent: #0E7A6E; --accent-strong: #0A5F56; --accent-soft: #E3F2EF;
  --ok: #1F7A45; --ok-soft: #E3F3E9; --warn: #B86E00; --warn-soft: #FDF0DA;
  --bad: #C2362F; --bad-soft: #FBE6E4; --pause: #5A52B5; --pause-soft: #ECEAFA;
  --radius: 8px; font-size: 14px;
  --font: system-ui, -apple-system, "Segoe UI Variable", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 1rem 0 .5rem; }
small, .muted { color: var(--muted); }

header { background: var(--text); color: #fff; display: flex; align-items: center; gap: 1.5rem; padding: 0 1.5rem; height: 52px; }
header .brand { font-weight: 700; letter-spacing: .02em; }
header nav { display: flex; gap: .25rem; flex: 1; }
header nav a { color: #c9cfdc; padding: .4rem .7rem; border-radius: 6px; }
header nav a.active, header nav a:hover { color: #fff; background: rgba(255,255,255,.1); text-decoration: none; }
header .who { color: #c9cfdc; font-size: .9rem; display: flex; gap: .75rem; align-items: center; }
header .who button { background: transparent; border: 1px solid #4a5266; color: #c9cfdc; }
.clock { font-variant-numeric: tabular-nums; }

main { max-width: 1280px; margin: 0 auto; padding: 1.5rem; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-bottom: 1rem; }
.grid { display: grid; gap: 1rem; }
.cols-2 { grid-template-columns: 2fr 1fr; }
.cols-half { grid-template-columns: 1fr 1fr; }
@media (max-width: 960px) { .cols-2, .cols-half { grid-template-columns: 1fr; } }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; }
.kpi .v { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: .85rem; }
.kpi.bad .v { color: var(--bad); } .kpi.warn .v { color: var(--warn); } .kpi.ok .v { color: var(--ok); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .82rem; color: var(--muted); font-weight: 600; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #fafbfd; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; background: var(--line); color: var(--text); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.pause { background: var(--pause-soft); color: var(--pause); }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.badge.crit { background: var(--bad); color: #fff; }

.timer { display: grid; grid-template-columns: 1fr auto; gap: .2rem .75rem; padding: .7rem 0; border-bottom: 1px solid var(--line); }
.timer:last-child { border-bottom: 0; }
.timer .lbl { font-weight: 600; }
.timer .meta { color: var(--muted); font-size: .85rem; grid-column: 1 / -1; }

form .row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .75rem; }
label { display: block; font-weight: 600; font-size: .85rem; margin: .6rem 0 .25rem; }
label.inline { display: flex; align-items: center; gap: .45rem; font-weight: 500; }
input, select, textarea { width: 100%; font: inherit; padding: .5rem .6rem; border: 1px solid #cfd4de; border-radius: 6px; background: #fff; }
input[type=checkbox], input[type=radio] { width: auto; }
textarea { min-height: 90px; resize: vertical; }
.hint { color: var(--muted); font-size: .82rem; margin-top: .2rem; }
button, .btn { font: inherit; padding: .48rem .9rem; border-radius: 6px; border: 1px solid #cfd4de; background: #fff; cursor: pointer; display: inline-block; color: var(--text); }
button:hover, .btn:hover { background: #f1f3f7; text-decoration: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-strong); }
button.danger { color: var(--bad); border-color: #ecc; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.toolbar input[type=search] { max-width: 280px; }
.tabs { display: flex; gap: .25rem; }
.tabs a { padding: .35rem .75rem; border-radius: 6px; color: var(--muted); }
.tabs a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.alert { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid; }
.alert.bad { background: var(--bad-soft); border-color: #f2c4c4; color: #8d1f1f; }
.alert.warn { background: var(--warn-soft); border-color: #f0d9a8; color: #7a4a00; }
.alert.info { background: var(--accent-soft); border-color: #c9d6f6; color: #1f3f99; }

.toast { position: fixed; bottom: 1.25rem; right: 1.25rem; background: #1d2330; color: #fff; padding: .7rem 1rem; border-radius: var(--radius); box-shadow: 0 6px 20px rgba(0,0,0,.2); z-index: 10; max-width: 420px; }
.toast.err { background: var(--bad); }

.comment { border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem .8rem; margin-bottom: .6rem; }
.comment.internal { background: #fffbea; border-color: #f0e2a8; }
.comment .h { font-size: .82rem; color: var(--muted); margin-bottom: .25rem; }
.pre { white-space: pre-wrap; }
.events { list-style: none; padding: 0; margin: 0; font-size: .88rem; }
.events li { padding: .35rem 0; border-bottom: 1px dashed var(--line); }
.events time { color: var(--muted); margin-right: .5rem; font-variant-numeric: tabular-nums; }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }
details summary { cursor: pointer; font-weight: 600; margin: .5rem 0; }

.login { max-width: 380px; margin: 12vh auto; }
.login .panel { padding: 1.75rem; }

@media print {
  header, .toolbar, .no-print { display: none !important; }
  body { background: #fff; }
  .panel { border: 0; padding: 0; }
}
header .who a.me { color: inherit; }
.spacer { flex: 1; }
.mt { margin-top: .5rem; }
.m0 { margin: 0; }
input.auto { width: auto; }
.narrow { max-width: 420px; }

/* ---------- v2: workflow, dialogs, attachments, profylaxe, mobile ---------- */
.alert.ok { background: var(--ok-soft); border-color: #bfe3cc; color: #145c33; }
.alert.pausebox { background: var(--pause-soft); border-color: #d7d0f5; color: #3d2f99; }
.alert.pausebox button { margin-left: .5rem; }
.badge.live { background: #fff4e0; color: #9a5800; animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .65; } }
button.danger-solid { background: var(--bad); border-color: var(--bad); color: #fff; }
button.link { border: 0; background: none; padding: 0; color: var(--accent); cursor: pointer; }
button.link.danger { color: var(--bad); }
button:disabled { opacity: .5; cursor: not-allowed; }
a.btn.primary-link { background: var(--accent); border-color: var(--accent); color: #fff; }
.nowrap { white-space: nowrap; }
.mb { margin-bottom: 1rem; }
input.invalid, textarea.invalid, select.invalid { border-color: var(--bad); background: #fff8f8; }
fieldset.consent { border: 1px solid var(--line); border-radius: 6px; margin: .8rem 0; padding: .4rem .8rem .6rem; }
fieldset.consent legend { font-weight: 600; font-size: .85rem; padding: 0 .3rem; }
.print-only { display: none; }

.tw { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tw table { min-width: 560px; }
tr.inactive td { opacity: .5; }

dialog { border: 0; border-radius: 10px; padding: 0; width: min(560px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(20, 24, 33, .45); }
.modal { padding: 1.25rem 1.4rem; }
.modal-actions { margin-top: 1rem; justify-content: flex-end; }

.control { border-left: 4px solid var(--accent); }
.control .work { display: grid; gap: .6rem; margin-bottom: .9rem; }
.session { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; background: #fffaf0; border: 1px solid #f3dfb4; border-radius: 8px; padding: .55rem .75rem; }
.status-row { grid-template-columns: minmax(180px, 1fr) 2fr auto; align-items: end; margin-bottom: .8rem; }
.status-row .end { display: flex; align-items: end; }
.files { list-style: none; padding: 0; margin: .3rem 0 .6rem; }
.files li { padding: .25rem 0; display: flex; flex-wrap: wrap; gap: .5rem; align-items: baseline; }
.comment.from-customer { border-left: 3px solid var(--accent); }
.history-cycle { padding: .4rem 0; border-top: 1px dashed var(--line); font-size: .88rem; }
.events li.ev-correction { color: var(--bad); }

.steps { display: grid; gap: .5rem; }
.step { border: 1px solid var(--line); border-radius: 8px; padding: .55rem .75rem; }
.step.done-ok { background: #f6fbf8; border-color: #cfe9d9; }
.step.done-issue { background: #fff6f6; border-color: #f2c4c4; }
.step.done-na { background: #f7f7f9; }
.step-head { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: .4rem; }
.step-ctl { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.step-ctl .step-note { flex: 1 1 220px; }
.checklist { list-style: none; padding-left: .2rem; margin: .4rem 0; }
.checklist li { padding: .15rem 0; }
.prof-summary { padding: .4rem 0; border-bottom: 1px solid var(--line); }

header .menu-toggle { display: none; background: transparent; border: 1px solid #4a5266; color: #fff; font-size: 1.1rem; padding: .2rem .6rem; }

@media (max-width: 860px) {
  header { flex-wrap: wrap; height: auto; padding: .5rem 1rem; gap: .5rem; }
  header .brand { flex: 1; }
  header .menu-toggle { display: block; }
  header nav, header .who { display: none; width: 100%; }
  header.open nav { display: flex; flex-direction: column; }
  header.open .who { display: flex; flex-wrap: wrap; padding: .5rem 0; border-top: 1px solid #39404f; }
  main { padding: .8rem; }
  h1 { font-size: 1.2rem; }
  .panel { padding: .9rem; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpi .v { font-size: 1.25rem; }
  .status-row { grid-template-columns: 1fr; }
  .toolbar input[type=search] { max-width: none; flex: 1 1 100%; }
  .actions button, .actions .btn { flex: 1 1 auto; }
  dl.facts { grid-template-columns: 1fr; }
  dl.facts dd { margin-bottom: .3rem; }
}

@media print {
  .print-only { display: block; }
  .control, .actions, dialog, .toast, input[type=file] { display: none !important; }
  .tw { overflow: visible; }
  .kpis { grid-template-columns: repeat(4, 1fr); }
}
.grid > *, .row > * { min-width: 0; }
form .row, .row { grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); }
.tabs { flex-wrap: wrap; }
@media (max-width: 860px) { .status-row { grid-template-columns: 1fr; } }

/* ---------- v3: ticket control & SLA process line ---------- */
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (prefers-reduced-motion: reduce) { .badge.live, .node.is-active .dot { animation: none !important; } }
.toast.ok { background: var(--accent-strong); }

.ticket-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: .4rem 1rem; margin-bottom: .9rem; }
.ticket-head h1 { margin: 0; font-size: 1.5rem; letter-spacing: -.01em; }
.ticket-no { color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; margin-right: .2rem; }
.ticket-tags { display: flex; flex-wrap: wrap; gap: .35rem; }

/* the process line – the one bold element of the page */
.rail { list-style: none; margin: 0 0 1rem; padding: 1rem 1.1rem .9rem; display: flex; gap: 0; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
.node { position: relative; flex: 1 1 0; min-width: 118px; padding: 1.35rem .6rem 0 0; display: flex; flex-direction: column; gap: .1rem; }
.node::before { content: ""; position: absolute; top: 7px; left: 0; right: 0; height: 4px; background: var(--line); }
.node:first-child::before { left: 7px; }
.node:last-child::before { right: auto; width: 7px; }
.node .dot { position: absolute; top: 0; left: 0; width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 3px solid #C9CFD8; box-sizing: border-box; }
.node-label { font-weight: 650; font-size: .92rem; }
.node-detail { font-size: .82rem; font-variant-numeric: tabular-nums; color: var(--muted); }
.node-sub { font-size: .76rem; color: var(--muted); }
.node.is-done::before, .node.is-late::before { background: var(--accent); }
.node.is-done .dot { background: var(--accent); border-color: var(--accent); }
.node.is-late .dot { background: var(--warn); border-color: var(--warn); }
.node.is-late .node-detail { color: var(--warn); }
.node.is-active .dot { border-color: var(--warn); animation: pulse 2s infinite; }
.node.is-active .node-detail { color: var(--warn); font-weight: 600; }
.node.is-overdue .dot { background: var(--bad); border-color: var(--bad); }
.node.is-overdue .node-detail { color: var(--bad); font-weight: 650; }
.node.is-paused .dot { border-color: var(--pause); border-style: dashed; }
.node.is-paused .node-detail { color: var(--pause); }
.node.is-todo .node-label { color: var(--muted); font-weight: 550; }

/* control panel */
.control { border-left: 0; border-top: 3px solid var(--accent); }
.control-row { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1rem; }
.next-step { display: flex; flex-wrap: wrap; gap: .5rem; flex: 1 1 auto; }
.next-step button { padding: .6rem 1.05rem; font-weight: 600; }
.status-pick { display: flex; align-items: center; gap: .5rem; margin: 0; font-size: .85rem; color: var(--muted); }
.status-pick select { width: auto; min-width: 210px; font-weight: 600; color: var(--text); }
.session { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem 1rem;
  background: var(--warn-soft); border: 1px solid #F0D49C; border-radius: var(--radius); padding: .7rem .9rem; margin-bottom: .8rem; }
.session.mine { border-width: 2px; }
.session-info { display: flex; flex-wrap: wrap; align-items: baseline; gap: .2rem .8rem; }
.session-kind { font-weight: 650; }
.session-time { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--warn); }
.session button { padding: .6rem 1.2rem; font-weight: 650; }

details.menu { position: relative; }
details.menu > summary { list-style: none; cursor: pointer; padding: .48rem .9rem; border: 1px solid #cfd4de; border-radius: 6px; background: #fff; font-weight: 500; margin: 0; }
details.menu > summary::-webkit-details-marker { display: none; }
details.menu > summary::after { content: " ▾"; color: var(--muted); }
details.menu[open] > summary { background: #f1f3f7; }
.menu-list { position: absolute; right: 0; top: calc(100% + 4px); z-index: 5; min-width: 260px; background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: 0 10px 30px rgba(27, 34, 48, .16); padding: .3rem; display: grid; }
.menu-list button { border: 0; background: none; text-align: left; padding: .55rem .7rem; border-radius: 5px; }
.menu-list button:hover, .menu-list button:focus-visible { background: var(--accent-soft); }
.backdate { margin-top: .8rem; padding: .6rem .8rem; background: var(--pause-soft); border-radius: 6px; display: grid; gap: .3rem; }
.backdate label { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.backdate input { width: auto; }

@media (max-width: 860px) {
  .ticket-head h1 { font-size: 1.2rem; }
  .rail { padding: .8rem; }
  .node { min-width: 104px; }
  .control-row { flex-direction: column; align-items: stretch; }
  .next-step button { flex: 1 1 40%; }
  .status-pick select { flex: 1; min-width: 0; }
  .menu-list { left: 0; right: auto; width: 100%; }
}
@media print { .rail { overflow: visible; flex-wrap: wrap; } }
@media (max-width: 860px) {
  /* on phones the process line runs top-down */
  .rail { flex-direction: column; overflow: visible; padding: .9rem .9rem .3rem; }
  .node { min-width: 0; padding: 0 0 .75rem 1.9rem; }
  .node::before { top: 0; bottom: 0; left: 7px; right: auto; width: 4px; height: auto; }
  .node:first-child::before { top: 7px; left: 7px; }
  .node:last-child::before { width: 4px; height: 7px; bottom: auto; }
  .node .dot { top: 0; }
}

/* ---------- v4: Web Interface Guidelines + frontend-design pass ---------- */
html { -webkit-text-size-adjust: 100%; }
a, button, input, select, textarea, label, summary { touch-action: manipulation; }
a, button, summary { -webkit-tap-highlight-color: rgba(14, 122, 110, .15); }
h1, h2, h3 { text-wrap: balance; }
p, .pre, .hint { text-wrap: pretty; }
.pre, td, dd, .node-detail, .files a, .comment { overflow-wrap: anywhere; }
input, select, textarea { color: var(--text); background-color: #fff; }
input[aria-invalid="true"], textarea[aria-invalid="true"], select[aria-invalid="true"], fieldset[aria-invalid="true"] { border-color: var(--bad); background: #fff8f7; }
.field-error { color: var(--bad); font-size: .84rem; margin-top: .25rem; font-weight: 550; }
dialog { overscroll-behavior: contain; }
dialog .modal { max-height: 85vh; overflow-y: auto; overscroll-behavior: contain; }
button:active:not(:disabled) { transform: translateY(1px); }
button.primary:hover, a.btn.primary-link:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
h2.h-sub { font-size: .95rem; margin: 1.1rem 0 .45rem; }
h2.h-sub:first-child { margin-top: 0; }

/* skip link */
.skip { position: absolute; left: .75rem; top: -3rem; z-index: 20; background: var(--accent); color: #fff; padding: .5rem .9rem; border-radius: 6px; font-weight: 600; }
.skip:focus { top: .5rem; text-decoration: none; }
main:focus { outline: none; }

/* loading state – a thin verdigris bar under the header, only when the server is slow */
main[aria-busy="true"] { position: relative; }
main[aria-busy="true"]::before { content: ""; position: fixed; top: 0; left: 0; height: 3px; width: 40%; background: var(--accent); animation: loadbar 1.1s ease-in-out infinite; z-index: 30; }
@keyframes loadbar { from { transform: translateX(-100%); } to { transform: translateX(260%); } }
@media (prefers-reduced-motion: reduce) { main[aria-busy="true"]::before { animation: none; width: 100%; opacity: .6; } }

/* header & brand: safe areas on notched phones */
header { padding-left: max(1.5rem, env(safe-area-inset-left)); padding-right: max(1.5rem, env(safe-area-inset-right)); }
header .brand { font-weight: 750; letter-spacing: -.01em; font-size: 1.05rem; }
header .brand span { font-weight: 400; color: #9FB8B3; }
header nav a[aria-current="page"] { color: #fff; background: rgba(14, 122, 110, .45); }
main { padding-left: max(1.5rem, env(safe-area-inset-left)); padding-right: max(1.5rem, env(safe-area-inset-right)); padding-bottom: max(1.5rem, env(safe-area-inset-bottom)); }

/* situation strip instead of a wall of identical number cards */
.kpis { display: flex; flex-wrap: wrap; gap: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .2rem 0; }
.kpi { border: 0; border-radius: 0; background: none; padding: .55rem 1.1rem; display: flex; align-items: baseline; gap: .5rem; border-right: 1px solid var(--line); }
.kpi:last-child { border-right: 0; }
.kpi .v { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: .86rem; }
.kpi.ok .v { color: var(--text); }
.kpi.warn .v { color: var(--warn); }
.kpi.bad .v, .kpi.bad .l { color: var(--bad); }

/* login: the brand as a quiet wordmark */
.login { max-width: 400px; }
.login .panel { border-top: 4px solid var(--accent); }
.login h1 { font-size: 1.9rem; letter-spacing: -.02em; margin-bottom: .3rem; }
.login h1 span { display: block; font-size: 1rem; font-weight: 500; color: var(--muted); letter-spacing: 0; margin-top: .2rem; }

@media (max-width: 860px) {
  main { padding: .8rem max(.8rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(.8rem, env(safe-area-inset-left)); }
  .kpi { flex: 1 1 45%; border-right: 0; border-bottom: 1px solid var(--line); padding: .5rem .8rem; }
  .kpi .v { font-size: 1.1rem; }
}
pre.log { background: #12161f; color: #d6dde8; padding: .8rem; border-radius: 6px; font-size: .78rem; max-height: 320px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
