:root {
  --blue: #1a56db;
  --blue-dark: #1544ad;
  --bg: #f5f6fa;
  --border: #e0e3ea;
  --text: #1f2430;
  --muted: #6b7280;
  --open: #1a56db;
  --progress: #b45309;
  --resolved: #7c3aed;
  --closed: #15803d;
  --danger: #b91c1c;
  --internal-bg: #fff8e6;
  --internal-border: #f5d58a;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
header {
  background: var(--blue);
  color: #fff;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
header h1 { margin: 0; font-size: 1.2rem; }
header h1 a { color: inherit; text-decoration: none; }
header h1 .brand { display: inline-flex; align-items: center; gap: 0.6rem; }
header h1 .brand img { display: block; width: 40px; height: 40px; }
nav { display: flex; gap: 0.25rem; flex-wrap: wrap; flex: 1; }
nav a {
  color: #fff;
  text-decoration: none;
  font-size: 0.9rem;
  padding: 0.35rem 0.7rem;
  border-radius: 4px;
}
nav a:hover, nav a.active { background: rgba(255,255,255,0.18); }
#whoami { font-size: 0.9rem; display: flex; align-items: center; gap: 0.75rem; }
#whoami button {
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.35);
  border-radius: 4px;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  font-size: 0.85rem;
}
main { max-width: 1150px; margin: 0 auto; padding: 1.25rem; }
.hidden { display: none !important; }
.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.card h2 { margin-top: 0; font-size: 1.05rem; }
.card h3 { font-size: 0.95rem; margin: 1.25rem 0 0.5rem; }
.narrow { max-width: 520px; margin: 2rem auto; }
.muted { color: var(--muted); font-size: 0.85rem; }
.user-option {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 0.5rem;
  cursor: pointer;
  gap: 0.5rem;
}
.user-option:hover { border-color: var(--blue); background: #f0f5ff; }
.pill {
  font-size: 0.72rem;
  text-transform: uppercase;
  color: var(--muted);
  background: #eef0f4;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  white-space: nowrap;
}
.pill.internal { background: var(--internal-border); color: #7a5200; }
.pill.overdue { background: #fde8e8; color: var(--danger); }
/* Block-level messages (warnings, banners): unlike .pill these wrap */
.notice { display: block; font-size: 0.85rem; line-height: 1.45; padding: 0.6rem 0.8rem; border-radius: 6px; margin: 0.5rem 0; overflow-wrap: anywhere; }
.notice.warn { background: #fde8e8; color: var(--danger); }
.notice.info { background: var(--internal-bg); color: #7a5200; border: 1px solid var(--internal-border); }
#task-reminder .notice { margin: 0 0 1rem; }
#task-reminder ul { margin: 0.4rem 0; padding-left: 1.2rem; }
#task-reminder li { margin: 0.15rem 0; }
@media print { #task-reminder { display: none !important; } }
.toolbar { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
select, input, textarea, button {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: #fff;
  color: var(--text);
}
button { cursor: pointer; }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--blue); color: #fff; border-color: var(--blue); }
button.primary:hover:not(:disabled) { background: var(--blue-dark); }
button.danger { color: var(--danger); border-color: #f0b4b4; }
button.link { border: none; background: none; color: var(--blue); padding: 0; }
.table-wrap { overflow-x: auto; }
details.rooms > summary { cursor: pointer; margin: 0.4rem 0; color: var(--blue); }
.space-row input { width: 100%; min-width: 6rem; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.5rem; border-bottom: 1px solid var(--border); font-size: 0.88rem; vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 0.76rem; text-transform: uppercase; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #f7f9fc; }
tr.overdue td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
.status-badge {
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  color: #fff;
  display: inline-block;
  white-space: nowrap;
}
.status-open { background: var(--open); }
.status-in-progress { background: var(--progress); }
.status-on-hold { background: #0e7490; }
.status-resolved { background: var(--resolved); }
.status-cancelled { background: #6b7280; }
.status-closed { background: var(--closed); }
.priority-high { color: var(--danger); font-weight: 600; }
.priority-medium { color: #b45309; }
.priority-low { color: var(--muted); }
.form .field { margin-bottom: 0.7rem; display: flex; flex-direction: column; gap: 0.25rem; }
.form label, .field > label { font-size: 0.8rem; color: var(--muted); }
.form input:not([type=checkbox]):not([type=radio]), .form select, .form textarea { width: 100%; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem; }
@media (max-width: 700px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
.checks { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; font-size: 0.88rem; }
.checks label { color: var(--text); font-size: 0.88rem; display: flex; gap: 0.3rem; align-items: center; }
/* Files on tickets */
.filebox { margin-top: 0.4rem; border: 1px dashed transparent; border-radius: 6px; }
.filebox.dragging { border-color: var(--blue); background: #eef4ff; }
.filebox-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.filebox-hint { font-size: 0.8rem; }
.filebox-list { list-style: none; margin: 0.3rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.25rem; }
.filebox-list li { font-size: 0.88rem; display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: baseline; }
.filebox-list li.blocked .filebox-name { text-decoration: line-through; }
.filebox-name { font-weight: 600; overflow-wrap: anywhere; }
.ok { color: #1a7f37; }
.bad { color: #b42318; }
.small { font-size: 0.8rem; }
.file-list { list-style: none; margin: 0.5rem 0 0.8rem; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0.6rem; }
.file-item { display: flex; gap: 0.6rem; align-items: flex-start; border: 1px solid var(--border); border-radius: 6px; padding: 0.5rem; overflow-wrap: anywhere; }
.file-thumb { flex: 0 0 72px; width: 72px; height: 72px; border-radius: 4px; overflow: hidden; background: #f2f4f7; display: flex; align-items: center; justify-content: center; text-decoration: none; }
.file-thumb img { width: 100%; height: 100%; object-fit: cover; }
.file-icon { font-size: 2rem; }
.file-infected, .file-removed { opacity: 0.75; }
.comment-files { margin-top: 0.35rem; display: flex; flex-wrap: wrap; gap: 0.3rem 0.8rem; font-size: 0.85rem; }
.assignee-checks { flex-direction: column; flex-wrap: nowrap; max-height: 14rem; overflow-y: auto; }
/* Queue bulk assign: the people list gets its own full-width row in the action bar */
.bulk-people { flex: 0 0 100%; order: 10; }
.bulk-people .assignee-checks { max-height: 11rem; }
.comments { display: flex; flex-direction: column; gap: 0.6rem; margin: 0.75rem 0; }
.comment { background: #f7f9fc; border: 1px solid transparent; border-radius: 6px; padding: 0.6rem 0.75rem; }
.comment-body { white-space: pre-wrap; }
.comment.internal { background: var(--internal-bg); border-color: var(--internal-border); }
.comment .meta { font-size: 0.78rem; color: var(--muted); margin-bottom: 0.2rem; display: flex; gap: 0.5rem; align-items: center; }
#flash { display: none; padding: 0.6rem 0.9rem; border-radius: 6px; margin-bottom: 1rem; font-size: 0.9rem; }
.back-link { color: var(--blue); font-size: 0.85rem; margin-bottom: 0.75rem; display: inline-block; text-decoration: none; }
.panel { border-top: 1px solid var(--border); margin-top: 0.9rem; padding-top: 0.9rem; }
.panel-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; }
.panel-grid > div { display: flex; flex-direction: column; gap: 0.4rem; }
.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0.35rem 1rem; font-size: 0.86rem; margin: 0.6rem 0; }
.meta-grid span { color: var(--muted); }
.pager { display: flex; gap: 0.5rem; align-items: center; justify-content: flex-end; margin-top: 0.75rem; font-size: 0.85rem; }
.history { list-style: none; padding: 0; margin: 0; font-size: 0.85rem; }
.history li { padding: 0.35rem 0; border-bottom: 1px dashed var(--border); }
.history .when { color: var(--muted); font-size: 0.78rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.stat { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 0.8rem 1rem; }
.stat .value { font-size: 1.5rem; font-weight: 600; }
.stat .label { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; }
.bar { height: 0.55rem; background: var(--blue); border-radius: 3px; min-width: 2px; }

/* Queue: selection checkboxes for bulk actions */
th.sel, td.sel { width: 2rem; text-align: center; }
td.sel input, th.sel input { cursor: pointer; }

/* Queue filters: on wide screens the extra filters sit inline with the search box */
.filter-more { display: contents; }
#f-q { min-width: 220px; }
.menu-btn, .mobile-only { display: none; }

/* ---- Phones and narrow windows ---- */
@media (max-width: 760px) {
  header { padding: 0.6rem 1rem; gap: 0.5rem; }
  header h1 { font-size: 1.05rem; flex: 1; min-width: 0; }
  header h1 .brand img { width: 34px; height: 34px; }
  .menu-btn {
    display: inline-block; background: rgba(255,255,255,0.15); color: #fff;
    border: 1px solid rgba(255,255,255,0.4); font-size: 0.95rem; padding: 0.45rem 0.8rem;
  }
  /* The menu folds behind the Menu button */
  nav, #whoami { display: none; flex: 0 0 100%; }
  header.menu-open nav { display: flex; flex-direction: column; gap: 0; border-top: 1px solid rgba(255,255,255,0.25); padding-top: 0.3rem; }
  header.menu-open nav a { font-size: 1rem; padding: 0.7rem 0.6rem; }
  header.menu-open #whoami { display: flex; justify-content: space-between; border-top: 1px solid rgba(255,255,255,0.25); padding-top: 0.6rem; }

  main { padding: 0.75rem; }
  .card { padding: 1rem; }

  /* Queue filters: + New Ticket and Filters on one row, search below, the rest behind Filters */
  .mobile-only { display: inline-block; }
  .desktop-only { display: none; }
  #queue-filters { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
  #queue-filters > a button, #filters-toggle { width: 100%; }
  #f-q { grid-column: 1 / -1; min-width: 0; width: 100%; }
  #queue-filters .filter-more { display: none; }
  #queue-filters.filters-open .filter-more { display: grid; grid-column: 1 / -1; grid-template-columns: 1fr 1fr; gap: 0.5rem; grid-auto-flow: dense; }
  .filter-more select, .filter-more button { width: 100%; min-width: 0; }
  .filter-more .checks { flex-wrap: nowrap; align-items: center; gap: 0.4rem; padding: 0.3rem 0; }
  input[type=checkbox], input[type=radio] { padding: 0; }
  #f-department { grid-column: 1 / -1; }

  /* Tables become one card per row, two values side by side, each labelled with its column
     (set by app.js); the subject (or first column) is the card's title */
  .table-wrap { overflow-x: visible; }
  .table-wrap table, .table-wrap tbody { display: block; width: 100%; }
  .table-wrap thead { display: none; }
  .table-wrap tr {
    display: grid; grid-template-columns: 1fr 1fr; gap: 0.35rem 0.9rem; position: relative;
    border: 1px solid var(--border); border-radius: 8px; margin-bottom: 0.6rem; padding: 0.6rem 0.75rem; background: #fff;
  }
  .table-wrap td { display: block; border: none; padding: 0; min-width: 0; overflow-wrap: anywhere; }
  .table-wrap td::before { content: attr(data-label); display: block; color: var(--muted); font-size: 0.68rem; font-weight: 600; text-transform: uppercase; }
  .table-wrap td[data-label=""] { grid-column: 1 / -1; }
  .table-wrap td[data-label=""]::before { content: none; }
  .table-wrap td[data-label="Subject"] { grid-column: 1 / -1; order: -1; font-weight: 600; font-size: 0.98rem; padding-right: 2rem; }
  .table-wrap td[data-label="Subject"]::before { content: none; }
  /* Lists without a subject (e.g. Users): the first column is the title; email addresses get a full line */
  .table-wrap tr:not(:has(td[data-label="Subject"])) > td:first-child:not(.sel):not([data-label=""]) { grid-column: 1 / -1; font-weight: 600; font-size: 0.98rem; }
  .table-wrap tr:not(:has(td[data-label="Subject"])) > td:first-child:not(.sel)::before { content: none; }
  .table-wrap td[data-label="Email"] { grid-column: 1 / -1; }
  .table-wrap td.sel { position: absolute; top: 0.55rem; right: 0.6rem; width: auto; grid-column: auto; }
  .table-wrap td.sel input { width: 1.2rem; height: 1.2rem; }
  .table-wrap td.toolbar { grid-column: 1 / -1; justify-content: flex-end; display: flex; }
  .panel-grid button.primary { width: 100%; }
  tr.overdue td:first-child { box-shadow: none; }
  .table-wrap tr.overdue { border-left: 4px solid var(--danger); }

  .panel-grid { grid-template-columns: 1fr; }
  .pager { justify-content: space-between; }
  .toolbar input, .toolbar select { max-width: 100%; }
}

/* How-to guides (Help page) */
.guide-body h3 { margin-top: 1.3rem; }
.guide-body li { margin-bottom: 0.3rem; }
.guide-table { border-collapse: collapse; margin: 0.4rem 0 0.8rem; width: 100%; }
.guide-table td { border-top: 1px solid var(--border); padding: 0.35rem 0.6rem 0.35rem 0; vertical-align: top; font-size: 0.9rem; }
@media print {
  header, #nav, #flash, .no-print { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: none; max-width: none !important; }
}

/* Tasks: a checklist */
.task-list { list-style: none; margin: 0.8rem 0; padding: 0; }
.task-list li { border-bottom: 1px solid var(--border); padding: 0.6rem 0.2rem 0.6rem 0.6rem; }
.task-list li.task { display: flex; gap: 0.7rem; align-items: flex-start; }
.task-list li.late { box-shadow: inset 3px 0 0 var(--danger); }
.task-check { width: 1.3rem; height: 1.3rem; margin-top: 0.1rem; flex: none; cursor: pointer; }
.task-body { flex: 1; min-width: 0; }
.task-title { font-weight: 600; overflow-wrap: anywhere; }
.task-meta { font-size: 0.82rem; color: var(--muted); margin-top: 0.15rem; }
.task-notes { font-size: 0.88rem; margin-top: 0.3rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.task-actions { display: flex; gap: 0.8rem; flex: none; font-size: 0.85rem; }
.task.done .task-title { text-decoration: line-through; color: var(--muted); font-weight: 400; }
@media (max-width: 760px) {
  .task-list li.task { flex-wrap: wrap; }
  .task-actions { width: 100%; padding-left: 2rem; }
}

/* Equipment Controls */
.eq-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; flex-wrap: wrap; }
.eq-head h2 { margin: 0 0 0.2rem; }
.eq-head h2 a { color: inherit; text-decoration: none; }
.eq-status { text-align: right; }
.eq-state { display: inline-block; font-weight: 700; font-size: 0.85rem; padding: 0.2rem 0.7rem; border-radius: 999px; border: 1px solid transparent; }
.eq-on { background: #e6f4ea; color: #166534; border-color: #9fd3ae; }
.eq-off { background: #eef0f4; color: var(--text); border-color: var(--border); }
.eq-offline { background: #fde8e8; color: var(--danger); border-color: #f0b4b4; }
.eq-stale { background: var(--internal-bg); color: #7a5200; border-color: var(--internal-border); }
.eq-unknown { background: #fff; color: var(--muted); border-color: var(--border); border-style: dashed; }
.notice.eq-running { background: #e6f4ea; color: #166534; }
.eq-next { margin: 0.6rem 0; font-size: 0.9rem; }
.eq-actions { margin: 0.4rem 0; }
.eq-runfor { display: flex; gap: 0.3rem; align-items: center; font-size: 0.88rem; }
.eq-runfor .eq-amount { width: 5rem; }
.eq-days label { font-size: 0.88rem; color: var(--text); }
.eq-row-actions { white-space: nowrap; }
.eq-row-actions .link { margin-right: 0.6rem; }
.eq-upcoming { margin: 0.3rem 0; padding-left: 1.2rem; font-size: 0.88rem; }
.eq-result { font-weight: 600; white-space: nowrap; }
.eq-result-running, .eq-result-completed { color: #166534; }
.eq-result-failed, .eq-result-uncertain { color: var(--danger); }
.eq-result-skipped, .eq-result-unconfirmed { color: #7a5200; }
@media (max-width: 700px) { .eq-status { text-align: left; } }

/* Printer requests (web/printers.js) */
.status-badge.pr-denied { background: var(--danger); }
.pr-types { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0.7rem; margin-bottom: 0.9rem; }
.pr-type { position: relative; display: flex; flex-direction: column; gap: 0.2rem; border: 2px solid var(--border); border-radius: 8px; padding: 0.7rem 0.9rem; cursor: pointer; background: #fff; }
.pr-type input { position: absolute; opacity: 0; pointer-events: none; }
.pr-type:has(input:checked) { border-color: var(--blue); background: #f0f5ff; }
.pr-type:has(input:focus-visible) { outline: 2px solid var(--blue); outline-offset: 2px; }
.pr-grid input { width: 100%; min-width: 4rem; }
.pr-grid td:nth-child(2) { width: 6.5rem; }
.pr-modal { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); overflow-y: auto; z-index: 50; padding: 2rem 1rem; }
.pr-modal > .card { max-width: 860px; margin: 0 auto; }
.pr-details { display: grid; grid-template-columns: max-content 1fr; gap: 0.35rem 1rem; margin: 0.8rem 0; font-size: 0.9rem; }
.pr-details dt { color: var(--muted); }
.pr-details dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 640px) {
  .pr-details { grid-template-columns: 1fr; }
  .pr-details dd { margin-bottom: 0.4rem; }
  .pr-modal { padding: 0.5rem; }
}
