:root {
  --bg: #f4f5f7; --panel: #fff; --text: #172b4d; --muted: #6b778c; --border: #dfe1e6;
  --accent: #0052cc; --accent-text: #fff; --ok: #e3fcef; --ok-b: #36b37e; --err: #ffebe6; --err-b: #de350b;
  --warn: #fffae6; --warn-b: #ffab00; --col: #ebecf0;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1d2125; --panel: #22272b; --text: #dee4ea; --muted: #8c9bab; --border: #38414a;
    --accent: #579dff; --accent-text: #1d2125; --ok: #1c3329; --err: #42221f; --warn: #3a2f10; --col: #161a1d; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 8px; } h2 { font-size: 16px; margin: 0 0 10px; } h3 { font-size: 14px; margin: 0 0 8px; }
main { padding: 16px 20px 40px; max-width: 1600px; margin: 0 auto; }
.muted { color: var(--muted); } .small { font-size: 12px; } .nowrap { white-space: nowrap; }
.inline { display: inline; }

.topbar { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; font-size: 16px; color: var(--text); }
.topbar nav { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; flex: 1; }
.topbar nav a.active { font-weight: 700; text-decoration: underline; }
.who { display: flex; gap: 8px; align-items: center; }

.btn { display: inline-block; background: var(--accent); color: var(--accent-text); border: 0; border-radius: 4px; padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { filter: brightness(1.1); text-decoration: none; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-ghost { background: transparent; color: var(--accent); border: 1px solid var(--border); }
button.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }
button.link.danger { color: var(--err-b); }

input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--border); border-radius: 4px; padding: 6px 8px; width: 100%; }
input[type=checkbox] { width: auto; }
textarea { resize: vertical; }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; flex: 1; min-width: 140px; }
label.check { flex-direction: row; align-items: center; font-weight: 400; gap: 6px; flex: none; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row-inline { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
fieldset { border: 1px solid var(--border); border-radius: 4px; display: flex; flex-direction: column; gap: 10px; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 16px; margin-bottom: 16px; }
.card.narrow { max-width: 420px; margin: 40px auto; }
.card.medium { max-width: 820px; }
.card.sign { border: 2px solid var(--warn-b); }
.flash { padding: 10px 14px; border-radius: 4px; margin-bottom: 14px; border-left: 4px solid; }
.flash.ok { background: var(--ok); border-color: var(--ok-b); }
.flash.err { background: var(--err); border-color: var(--err-b); }
.flash.warn { background: var(--warn); border-color: var(--warn-b); }

.pagehead { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters input, .filters select { width: auto; }
.filters input[type=search] { min-width: 240px; }

.board { display: grid; grid-template-columns: repeat(4, minmax(240px, 1fr)); gap: 12px; overflow-x: auto; align-items: start; }
.column { background: var(--col); border-radius: 6px; padding: 10px; min-height: 300px; }
.column.over { outline: 2px dashed var(--accent); }
.column h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.column h2 form { margin-left: auto; white-space: nowrap; }
.count { background: var(--border); border-radius: 10px; padding: 0 7px; font-size: 12px; color: var(--text); }
.dropzone { display: flex; flex-direction: column; gap: 8px; min-height: 250px; }
.tcard { display: block; background: var(--panel); border-radius: 4px; padding: 10px; color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.15); border-left: 4px solid var(--border); cursor: grab; }
.tcard:hover { text-decoration: none; background: color-mix(in srgb, var(--panel) 92%, var(--accent)); }
.tcard.dragging { opacity: .4; }
.tcard.prio-urgent { border-left-color: #de350b; } .tcard.prio-high { border-left-color: #ff8b00; }
.tcard.prio-normal { border-left-color: #0065ff; } .tcard.prio-low { border-left-color: #97a0af; }
.tkey { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }
.ttitle { font-weight: 600; margin: 4px 0 6px; }
.tmeta { font-size: 12px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }

.badge { font-size: 11px; font-weight: 700; text-transform: uppercase; padding: 1px 6px; border-radius: 3px; background: var(--border); color: var(--text); }
.badge.prio-urgent { background: #de350b; color: #fff; } .badge.prio-high { background: #ff8b00; color: #fff; }
.badge.prio-normal { background: #0065ff; color: #fff; } .badge.prio-low { background: #97a0af; color: #fff; }
.badge.internal { background: var(--warn-b); color: #000; }
.status { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 3px; white-space: nowrap; background: var(--border); }
.status.big { font-size: 14px; padding: 4px 10px; }
.s-backlog { background: #dfe1e6; color: #42526e; } .s-awaiting_parts { background: #fff0b3; color: #7a5d00; }
.s-awaiting_signature { background: #eae6ff; color: #403294; } .s-completed { background: #e3fcef; color: #006644; }
.s-archived { background: #c1c7d0; color: #42526e; }

.table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); margin-bottom: 20px; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: 12px; color: var(--muted); text-transform: uppercase; }
.table tr.inactive td { opacity: .5; }
.table input, .table select { width: auto; }

.quickstatus { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.ticket-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; }
.pre { white-space: pre-wrap; word-wrap: break-word; }
.fields { display: grid; grid-template-columns: 140px 1fr; gap: 6px; margin: 0 0 14px; }
.fields dt { color: var(--muted); }
.fields dd { margin: 0; }
.comment { border-bottom: 1px solid var(--border); padding: 10px 0; }
.comment.internal { background: var(--warn); padding: 10px; border-radius: 4px; }
.cmeta { margin-bottom: 4px; display: flex; gap: 8px; align-items: center; }
.events { list-style: none; padding: 0; margin: 0; font-size: 12px; display: flex; flex-direction: column; gap: 6px; max-height: 500px; overflow-y: auto; }

}

.sigpad-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.sigpad { display: block; width: 100%; height: 200px; background: #fff; border: 2px dashed var(--border); border-radius: 6px; touch-action: none; cursor: crosshair; }
.sigpad.invalid { border-color: var(--err-b); }
.card.signed { border-left: 4px solid var(--ok-b); }
.sigimg { display: block; max-width: 400px; width: 100%; margin-top: 10px; background: #fff; border: 1px solid var(--border); border-radius: 4px; }

.filters select.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.filters .clear { font-size: 13px; white-space: nowrap; }

/* ---------- board: column tabs + touch "Move to" ---------- */
.coltabs { display: none; }
.tcard { padding: 0; }
.tlink { display: block; padding: 10px; color: inherit; }
.tlink:hover { text-decoration: none; }
.tcard .move { display: none; width: calc(100% - 20px); margin: 0 10px 10px; font-size: 13px; padding: 4px 6px; }
/* Touch screens (phones, iPads): drag-and-drop is unreliable, so show the Move dropdown instead. */
@media (pointer: coarse) {
  .tcard .move { display: block; }
  .hint-drag { display: none; }
  .tcard { cursor: default; }
}

/* ---------- tablets (iPad portrait, small laptops) ---------- */
@media (max-width: 1100px) {
  main { padding: 12px; }
  .board { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
  .column { padding: 8px; }
  .tlink { padding: 8px; }
  .ticket-layout { grid-template-columns: 1fr; }
  .filters input[type=search] { min-width: 0; flex: 1 1 220px; }
  .pagehead .filters { flex: 1 1 100%; }
}

/* ---------- phones ---------- */
@media (max-width: 700px) {
  /* 16px inputs stop iOS Safari zooming the page when a field is focused. */
  input, select, textarea { font-size: 16px; }
  .topbar { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; padding: 8px 12px; }
  .topbar .brand { grid-column: 1; }
  .topbar .who { grid-column: 2; grid-row: 1; font-size: 13px; }
  .topbar .who .role { display: none; }
  .topbar nav { grid-column: 1; grid-row: 2; gap: 14px; overflow-x: auto; white-space: nowrap; flex-wrap: nowrap; }
  .topbar .newbtn { grid-column: 2; grid-row: 2; }
  main { padding: 10px; }
  h1 { font-size: 20px; }
  .pagehead { margin-bottom: 10px; }
  .filters { width: 100%; }
  .filters input[type=search] { flex: 1 1 100%; }
  .filters select { flex: 1 1 40%; }

  /* Board: one column at a time, picked with tabs. */
  .coltabs { display: flex; gap: 4px; margin-bottom: 8px; overflow-x: auto; }
  .coltabs button { flex: 1 1 auto; font: inherit; font-size: 13px; font-weight: 600; padding: 8px 4px; border: 1px solid var(--border);
    background: var(--panel); color: var(--text); border-radius: 6px; white-space: nowrap; }
  .coltabs button.current { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
  .coltabs button.current .count { background: rgba(255,255,255,.3); color: inherit; }
  .board { display: block; }
  .column { display: none; min-height: 0; }
  .column.current { display: block; }
  .dropzone { min-height: 60px; }

  /* Tables become a stack of cards. */
  .table.stack-mobile, .table.stack-mobile tbody, .table.stack-mobile tr, .table.stack-mobile td { display: block; width: 100%; }
  .table.stack-mobile { border: 0; background: none; }
  .table.stack-mobile thead { display: none; }
  .table.stack-mobile tr { background: var(--panel); border: 1px solid var(--border); border-radius: 6px; margin-bottom: 8px; padding: 6px 10px; }
  .table.stack-mobile td { border: 0; padding: 3px 0; display: flex; gap: 10px; }
  .table.stack-mobile td::before { content: attr(data-label); flex: 0 0 105px; color: var(--muted); font-size: 12px; text-transform: uppercase; padding-top: 2px; }
  .table.stack-mobile td[data-label=""]::before { content: none; }
  .table.stack-mobile td.cell-title { font-weight: 600; font-size: 15px; }
  .table.stack-mobile td.cell-title::before { content: none; }
  .table.stack-mobile td.cell-title { order: -1; }
  .table.stack-mobile tr { display: flex; flex-direction: column; }

  .card { padding: 12px; }
  .card.narrow { margin: 16px auto; }
  .row-inline { flex-wrap: wrap; }
  .fields { grid-template-columns: 110px 1fr; }
  .sigpad { height: 220px; }
}

/* ---------- photos ---------- */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.photo { margin: 0; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: var(--bg); }
.photo.internal { border-color: var(--warn-b); }
.photo img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: var(--col); }
.photo figcaption { padding: 6px 8px; display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
.filepick { flex-direction: row; min-width: 0; flex: none; cursor: pointer; }
.filepick input[type=file] { position: absolute; opacity: 0; width: 1px; height: 1px; }
.filepick:focus-within .btn { outline: 2px solid var(--accent); }
.photo-preview { display: flex; gap: 6px; flex-wrap: wrap; }
.photo-preview:empty { display: none; }
.photo-preview img { width: 72px; height: 72px; object-fit: cover; border-radius: 4px; border: 1px solid var(--border); }
#photo-status.error { color: var(--err-b); font-weight: 600; }
@media (max-width: 700px) { .photo-grid { grid-template-columns: repeat(2, 1fr); } }

/* ---------- branding ---------- */
.brand-sub { font-weight: 400; color: var(--muted); font-size: 13px; margin-left: 4px; }
.portal-head { text-align: center; padding-bottom: 14px; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
.portal-name { font-size: 22px; font-weight: 700; }
@media (max-width: 700px) { .brand-sub { display: none; } }
