/*
 * Service board.
 *
 * Read at a desk and from across the room on a wall monitor, so: high
 * contrast, generous row height, tabular numerals on anything that is a
 * duration. No web fonts and no CDN — the board has to render even when the
 * office link is having a bad morning.
 */

:root {
  --ink: #12202e;
  --ink-soft: #3d4f60;
  --muted: #77879a;
  --paper: #f5f6f8;
  --card: #ffffff;
  --rule: #dde3e9;

  --waiting: #b46b12;
  --waiting-bg: #fdf3e5;
  --running: #1c7a56;
  --running-bg: #e8f4ef;
  --done: #71818f;
  --done-bg: #eef1f4;
  --alert: #a8321f;
  --customer-wait: #2f5fa8;
  --customer-wait-bg: #eaf1fb;

  --radius: 6px;
  --gap: 20px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 20px;
  background: var(--ink);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 40;
}

.brand { display: flex; align-items: center; gap: 11px; text-decoration: none; color: #fff; }
.brand img { height: 30px; width: auto; max-width: 150px; object-fit: contain; display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 15px; font-weight: 600; }
.brand-text em { font-style: normal; font-size: 11.5px; color: #9fb0c1; }

.nav { display: flex; gap: 4px; margin-left: 14px; }
.nav-link {
  padding: 7px 13px; border-radius: 5px; font-size: 14px;
  color: #b6c4d1; text-decoration: none; white-space: nowrap;
}
.nav-link:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.nav-link.on { background: rgba(255, 255, 255, 0.14); color: #fff; }
.nav-only-mobile { display: none; }

.burger { display: none; background: none; border: 0; padding: 8px 6px; cursor: pointer; }
.burger span { display: block; width: 20px; height: 2px; background: #fff; margin: 4px 0; border-radius: 2px; }

.topbar .spacer { flex: 1; }
.stamp { font-size: 12.5px; color: #8fa2b4; font-variant-numeric: tabular-nums; white-space: nowrap; }

.who { display: flex; align-items: center; gap: 12px; }
.who-name { font-size: 13px; color: #cdd8e2; white-space: nowrap; }
.who-link { font-size: 13px; color: #8fa2b4; text-decoration: none; white-space: nowrap; }
.who-link:hover { color: #fff; text-decoration: underline; }

/* --- notifications -------------------------------------------------- */

.bell-wrap { position: relative; }
.bell {
  position: relative; background: none; border: 0; color: #b6c4d1;
  padding: 7px; cursor: pointer; border-radius: 5px; line-height: 0;
}
.bell:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.bell:focus-visible { outline: 2px solid #6fd3a8; outline-offset: 1px; }
.bell .dot {
  position: absolute; top: 1px; right: 0;
  background: #d4552f; color: #fff; font-size: 10.5px; font-weight: 600;
  min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px;
  display: grid; place-items: center; line-height: 1;
}

.panel-pop {
  position: absolute; right: 0; top: calc(100% + 9px); width: 340px; max-width: 92vw;
  background: var(--card); color: var(--ink); border: 1px solid var(--rule);
  border-radius: var(--radius); box-shadow: 0 12px 32px rgba(18, 32, 46, 0.18);
  overflow: hidden; z-index: 50;
}
.pop-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 11px 14px; border-bottom: 1px solid var(--rule);
  font-size: 13px; font-weight: 600;
}
.pop-head .link { background: none; border: 0; color: var(--running); font-size: 12.5px; cursor: pointer; padding: 0; }
.pop-head .link:hover { text-decoration: underline; }
.pop-body { max-height: 60vh; overflow-y: auto; }
.pop-item {
  display: block; padding: 12px 14px; border-bottom: 1px solid #eef1f4;
  text-decoration: none; color: inherit;
}
.pop-item:last-child { border-bottom: 0; }
.pop-item:hover { background: #fafbfc; }
.pop-item.unread { background: #f3f8f6; border-left: 3px solid var(--running); padding-left: 11px; }
.pop-title { display: block; font-size: 13.5px; font-weight: 600; }
.pop-body-text { display: block; font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }
.pop-when { display: block; font-size: 11.5px; color: var(--muted); margin-top: 4px; font-variant-numeric: tabular-nums; }
.pop-empty { padding: 26px 14px; text-align: center; color: var(--muted); font-size: 13px; margin: 0; }

.wrap { padding: 24px 28px 60px; max-width: 1600px; margin: 0 auto; }

.notice {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: var(--gap);
  font-size: 14px;
  border: 1px solid;
}
.notice.ok { background: var(--running-bg); border-color: #bcd9cd; color: #145c40; }
.notice.bad { background: #fbecea; border-color: #eccac3; color: var(--alert); }

/* --- summary ------------------------------------------------------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: var(--gap);
}

.card {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.card .label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 8px;
}

.card .value {
  font-size: 34px;
  line-height: 1;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.card.attention .value { color: var(--waiting); }
.card .value .unit { font-size: 17px; font-weight: 500; color: var(--ink-soft); margin-left: 3px; }

/* --- filters ------------------------------------------------------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
}

.chip {
  display: inline-block;
  padding: 7px 15px;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--card);
  color: var(--ink-soft);
  font-size: 13px;
  text-decoration: none;
  white-space: nowrap;
}
.chip:hover { border-color: #b9c4cf; }
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }

.filters .divider { width: 1px; height: 22px; background: var(--rule); margin: 0 6px; }

.search {
  margin-left: auto;
  padding: 8px 12px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  font-size: 14px;
  min-width: 220px;
  background: var(--card);
  color: var(--ink);
}
.search:focus { outline: 2px solid var(--ink); outline-offset: 1px; }

/* --- board --------------------------------------------------------- */

.board {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
}

table { width: 100%; border-collapse: separate; border-spacing: 0; }

thead th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
  padding: 12px 16px;
  border-bottom: 1px solid var(--rule);
  background: #fafbfc;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
thead th.plain { cursor: default; }
thead th[aria-sort="ascending"]::after { content: " \2191"; }
thead th[aria-sort="descending"]::after { content: " \2193"; }

tbody td {
  padding: 13px 16px;
  border-bottom: 1px solid #eef1f4;
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfc; }

/* The signature: a status rule down the left edge, so the shape of the
   board is readable before a single word is. */
tbody td:first-child { border-left: 4px solid transparent; padding-left: 14px; }
tbody tr.is-open td:first-child { border-left-color: var(--waiting); }
tbody tr.is-progress td:first-child { border-left-color: var(--running); }
tbody tr.is-waiting td:first-child { border-left-color: var(--customer-wait); }
tbody tr.is-closed td:first-child { border-left-color: #d5dbe1; }

.customer { font-weight: 600; }
.customer a { text-decoration: none; }
.customer a:hover { text-decoration: underline; }
.sub { display: block; font-weight: 400; font-size: 12.5px; color: var(--muted); margin-top: 2px; }

.tag {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 4px;
  font-size: 12.5px;
  background: #eef1f4;
  color: var(--ink-soft);
  white-space: nowrap;
}

.state {
  display: inline-block;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
}
.state.open { background: var(--waiting-bg); color: var(--waiting); }
.state.progress { background: var(--running-bg); color: var(--running); }
.state.waiting { background: var(--customer-wait-bg); color: var(--customer-wait); }
.state.closed { background: var(--done-bg); color: var(--done); }

.mr { font-variant-numeric: tabular-nums; }
.mr.pending { color: var(--muted); font-style: italic; }

/* Waiting time is the column that answers the only urgent question. */
.waited {
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  white-space: nowrap;
}
.waited.stale { color: var(--alert); font-weight: 600; }

/* How long the ticket has existed, not how long since the last activity
   -- deliberately quieter than .waited so the two are never mistaken for
   each other at a glance. */
.opened {
  font-variant-numeric: tabular-nums;
  font-size: 13.5px;
  color: var(--ink-soft);
  white-space: nowrap;
}

.empty { padding: 56px 20px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink-soft); font-size: 16px; margin-bottom: 6px; }

/* --- ticket detail -------------------------------------------------- */

.split { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: var(--gap); align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }

.panel { background: var(--card); border: 1px solid var(--rule); border-radius: var(--radius); }
.panel h2 { margin: 0; padding: 14px 18px; font-size: 14px; border-bottom: 1px solid var(--rule); }
.panel .body { padding: 18px; }

.facts { margin: 0; }
.facts dt { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-top: 14px; }
.facts dt:first-child { margin-top: 0; }
.facts dd { margin: 4px 0 0; }

.call-history { list-style: none; margin: 0; padding: 0; }
.call-history li { padding: 10px 0; border-bottom: 1px solid #eef1f4; }
.call-history li:last-child { border-bottom: 0; padding-bottom: 0; }
.call-line { font-size: 14px; }
.call-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.call-notes { font-size: 13px; color: var(--ink-soft); margin-top: 4px; white-space: pre-wrap; }

.thread { max-height: 62vh; overflow-y: auto; padding: 18px; }
.msg { margin-bottom: 16px; max-width: 78%; }
.msg .who { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.msg .bubble { padding: 10px 13px; border-radius: 10px; background: #eef1f4; white-space: pre-wrap; word-break: break-word; }
.msg.staff { margin-left: auto; }
.msg.staff .who { text-align: right; }
.msg.staff .bubble { background: var(--running-bg); }
.msg.system .bubble { background: transparent; border: 1px dashed var(--rule); color: var(--muted); font-size: 13px; }

.media-photo { display: block; margin-bottom: 6px; }
.media-photo img { max-width: 260px; max-height: 260px; border-radius: 6px; display: block; object-fit: cover; }
.media-file {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 12px; border-radius: 6px; background: #fff;
  border: 1px solid var(--rule); color: var(--ink); text-decoration: none; font-size: 13.5px;
  margin-bottom: 4px;
}
.media-file:hover { border-color: #b9c4cf; }
.media-note { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.media-note a { color: var(--running); text-decoration: none; }
.media-note a:hover { text-decoration: underline; }
.media-caption { font-style: italic; color: var(--ink-soft); margin-bottom: 4px; }

.field { display: flex; gap: 8px; margin-top: 8px; }
.field input {
  flex: 1; padding: 9px 12px; border: 1px solid var(--rule);
  border-radius: var(--radius); font-size: 14px; color: var(--ink);
}
.field input:focus { outline: 2px solid var(--ink); outline-offset: 1px; }

.btn {
  padding: 9px 16px; border: 1px solid var(--ink); background: var(--ink);
  color: #fff; border-radius: var(--radius); font-size: 14px; cursor: pointer;
}
.btn:hover { background: #1c3348; }
.btn.quiet { background: transparent; color: var(--ink); }
.btn.quiet:hover { background: #eef1f4; }
.btn:focus-visible { outline: 2px solid var(--running); outline-offset: 2px; }

.back { display: inline-block; margin-bottom: 14px; font-size: 14px; color: var(--ink-soft); text-decoration: none; }
.back:hover { text-decoration: underline; }

/* --- sign in -------------------------------------------------------- */

.signin { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.signin .box { width: 100%; max-width: 360px; background: var(--card); border: 1px solid var(--rule); border-radius: var(--radius); padding: 30px; }
.signin h1 { margin: 0 0 4px; font-size: 19px; }
.signin p.sub { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
.signin label { display: block; font-size: 13px; color: var(--ink-soft); margin: 14px 0 5px; }
.signin input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--rule);
  border-radius: var(--radius); font-size: 15px; color: var(--ink);
}
.signin input:focus { outline: 2px solid var(--ink); outline-offset: 1px; }
.signin .btn { width: 100%; margin-top: 22px; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* --- page furniture -------------------------------------------------- */

.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 18px;
}
.page-head h1 { margin: 0; font-size: 21px; font-weight: 600; }
.page-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.page-actions form { margin: 0; }

.hint { font-size: 13px; color: var(--muted); margin: 6px 0 16px; }
.hint.wide { max-width: 62ch; }
.lbl { display: block; font-size: 13px; color: var(--ink-soft); margin: 16px 0 6px; font-weight: 500; }
.sub-head { font-size: 14px; margin: 26px 0 0; padding-top: 20px; border-top: 1px solid var(--rule); }
.rule { border: 0; border-top: 1px solid var(--rule); margin: 26px 0; }

.panel.narrow { max-width: 560px; }
.panel input[type="text"], .panel input[type="password"], .panel input[type="number"],
.panel input[type="file"], .panel input:not([type]), .panel select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--rule);
  border-radius: var(--radius); font-size: 14.5px; color: var(--ink); background: #fff;
}
.panel input:focus, .panel select:focus { outline: 2px solid var(--ink); outline-offset: 1px; }
.panel .btn { margin-top: 20px; }

.check { display: flex; align-items: center; gap: 9px; margin: 20px 0 0; font-size: 14px; }
.check input { width: auto; }

.code {
  background: #f2f5f7; border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 11px 13px; font-size: 12.5px; overflow-x: auto; margin: 8px 0 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.logo-preview {
  border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 18px; background: #fafbfc; margin-bottom: 14px; text-align: center;
}
.logo-preview img { max-height: 70px; max-width: 100%; object-fit: contain; }

.signin-logo { display: block; max-height: 52px; max-width: 190px; margin: 0 auto 20px; object-fit: contain; }
.signin-note { font-size: 12.5px; color: var(--muted); margin: 20px 0 0; text-align: center; line-height: 1.5; }

/* --- reports --------------------------------------------------------- */

.filterbar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
  background: var(--card); border: 1px solid var(--rule);
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
}
.fset { display: flex; flex-direction: column; gap: 5px; }
.fset label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.fset input, .fset select {
  padding: 8px 11px; border: 1px solid var(--rule); border-radius: var(--radius);
  font-size: 14px; color: var(--ink); background: #fff; min-width: 130px;
}
.fset input:focus, .fset select:focus { outline: 2px solid var(--ink); outline-offset: 1px; }
.fset input[type="search"] { min-width: 240px; }
.fset.actions { flex-direction: row; gap: 8px; margin-left: auto; }

.result-count { font-size: 13px; color: var(--muted); margin: 0 0 12px; font-variant-numeric: tabular-nums; }

table.report thead th a { color: var(--muted); text-decoration: none; }
table.report thead th a:hover { color: var(--ink); }
table.report thead th a.sorted { color: var(--ink); }
table.report thead th { cursor: default; }
table.report tbody td:first-child { border-left-width: 4px; }
table.report .pending { color: var(--muted); }

.pager { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 18px; }
.pager .chip.off { opacity: 0.45; pointer-events: none; }
.pager .gap { color: var(--muted); padding: 0 2px; }

/* --- responsive ------------------------------------------------------ */

@media (max-width: 1024px) {
  .wrap { padding: 20px 16px 60px; }
  .topbar { padding: 10px 14px; }
  .stamp { display: none; }
  .fset.actions { margin-left: 0; }
}

@media (max-width: 860px) {
  .burger { display: block; }
  .who-name, .who-link { display: none; }
  .brand-text em { display: none; }

  /* The menu drops below the bar rather than pushing the logo off screen. */
  .nav {
    display: none; position: absolute; left: 0; right: 0; top: 100%;
    flex-direction: column; gap: 0; margin: 0;
    background: var(--ink); border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding: 6px; box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25);
  }
  .nav.open { display: flex; }
  .nav-link { padding: 12px 14px; border-radius: 5px; font-size: 15px; }
  .nav-only-mobile { display: block; border-top: 1px solid rgba(255, 255, 255, 0.08); margin-top: 4px; }

  .cards { grid-template-columns: repeat(2, 1fr); }
  .card .value { font-size: 27px; }

  .filterbar { padding: 14px; }
  .fset { flex: 1 1 46%; }
  .fset input, .fset select, .fset input[type="search"] { min-width: 0; width: 100%; }
  .fset.actions { flex: 1 1 100%; }
  .fset.actions .btn { flex: 1; }

  .search { margin-left: 0; width: 100%; }
  .filters { gap: 6px; }
  .filters::-webkit-scrollbar { display: none; }

  /* Tables become cards. Each cell carries its own heading, so no column
     is lost and nothing has to be scrolled sideways to be read. */
  table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table, tbody, tr, td { display: block; width: 100%; }
  tbody tr {
    border: 1px solid var(--rule); border-left-width: 4px; border-radius: var(--radius);
    margin: 0 0 10px; padding: 4px 0; background: var(--card);
  }
  tbody tr.is-open { border-left-color: var(--waiting); }
  tbody tr.is-progress { border-left-color: var(--running); }
  tbody tr.is-waiting { border-left-color: var(--customer-wait); }
  tbody tr.is-closed { border-left-color: #d5dbe1; }
  tbody td { border: 0; padding: 7px 14px; display: flex; gap: 12px; align-items: baseline; }
  tbody td:first-child { border-left: 0; padding-left: 14px; }
  tbody td::before {
    content: attr(data-label);
    flex: 0 0 40%; font-size: 11.5px; text-transform: uppercase;
    letter-spacing: 0.05em; color: var(--muted);
  }
  tbody td:not([data-label])::before { content: ''; flex: 0; }
  .board { border: 0; background: transparent; }
  tbody tr:hover { background: var(--card); }

  .msg { max-width: 92%; }
  .thread { max-height: none; }
}

@media (max-width: 520px) {
  .cards { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card { padding: 13px 14px; }
  .card .label { font-size: 11px; }
  .page-head h1 { font-size: 19px; }
  .page-actions { width: 100%; }
  .page-actions .btn, .page-actions form { flex: 1; }
  .page-actions .btn { text-align: center; }
  .fset { flex: 1 1 100%; }
  tbody td::before { flex: 0 0 44%; }
  .panel-pop { width: 94vw; position: fixed; right: 3vw; top: 58px; }
}

/* The board reads from a distance on a wall monitor. */
@media (min-width: 1600px) {
  .board table { font-size: 16px; }
  tbody td { padding: 15px 18px; }
  .card .value { font-size: 38px; }
}

@media print {
  .topbar, .filterbar, .pager, .page-actions, .filters { display: none; }
  .wrap { padding: 0; }
  .board { border: 0; }
}
