/* ===========================================================================
   Helpdesk interface
   ---------------------------------------------------------------------------
   Built for people who live in a ticket queue: dense, quiet, and organised so
   that status is the loudest thing on the screen. One accent colour (petrol
   blue) carries the interface; every other colour is reserved for meaning.
   =========================================================================== */

/* --- Tokens -------------------------------------------------------------- */

:root {
  --bg:            #f2f5f7;
  --surface:       #ffffff;
  --surface-2:     #f7f9fa;
  --surface-3:     #eef2f5;
  --line:          #e0e6ec;
  --line-strong:   #c9d3dc;

  --ink:           #101820;
  --ink-2:         #4a5866;
  --ink-3:         #7b8794;

  --primary:       #0e4f63;
  --primary-hover: #0a3f50;
  --primary-ink:   #ffffff;
  --primary-soft:  #e2eff3;

  --ok:            #15803d;
  --ok-soft:       #e6f4ea;
  --warn:          #a45908;
  --warn-soft:     #fdf0df;
  --danger:        #b42318;
  --danger-hover:  #97180f;
  --danger-soft:   #fdeceb;
  --info:          #6d28d9;
  --info-soft:     #f2ebfe;
  --muted:         #5b6875;
  --muted-soft:    #eaeef2;

  --focus:         #1a86a8;

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 2px rgba(16, 24, 32, .06);
  --shadow:    0 4px 14px rgba(16, 24, 32, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 32, .16);

  --topbar-h: 56px;
  --sidenav-w: 232px;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

[data-theme="dark"] {
  --bg:            #0c1116;
  --surface:       #141b22;
  --surface-2:     #1a222b;
  --surface-3:     #212b35;
  --line:          #253039;
  --line-strong:   #35434f;

  --ink:           #e6edf3;
  --ink-2:         #a6b3c0;
  --ink-3:         #7a8896;

  --primary:       #4fb3ce;
  --primary-hover: #6cc4dc;
  --primary-ink:   #06222c;
  --primary-soft:  #10323d;

  --ok:            #4ade80;
  --ok-soft:       #102c1c;
  --warn:          #f0a35e;
  --warn-soft:     #33230f;
  --danger:        #f78b82;
  --danger-hover:  #ffa79f;
  --danger-soft:   #3a1512;
  --info:          #b18cf5;
  --info-soft:     #241a3b;
  --muted:         #9aa7b4;
  --muted-soft:    #1f2831;

  --focus:         #6cc4dc;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow:    0 4px 14px rgba(0, 0, 0, .45);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .6);
}

/* --- Base ---------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

/* The role-driven fields rely on the hidden attribute, so make sure no layout
   rule can accidentally out-specify it. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
p  { margin: 0 0 12px; }
p:last-child { margin-bottom: 0; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

code, kbd, .mono {
  font-family: var(--mono);
  font-size: .92em;
}

code {
  background: var(--surface-3);
  padding: 1px 5px;
  border-radius: 4px;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 3px;
}

.icon { flex: none; vertical-align: -.15em; }

.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  z-index: 200;
  background: var(--primary);
  color: var(--primary-ink);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
}
.skip-link:focus { left: 8px; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* --- Top bar ------------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--topbar-h);
  padding: 0 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar__menu { display: none; }

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
  font-weight: 650;
  letter-spacing: -.015em;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }

.brand__mark {
  display: grid;
  place-items: center;
  width: 28px; height: 28px;
  border-radius: 7px;
  background: var(--primary);
  color: var(--primary-ink);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .02em;
}

.searchbar {
  flex: 1;
  max-width: 420px;
  margin-left: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  height: 36px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-3);
}
.searchbar:focus-within {
  border-color: var(--primary);
  background: var(--surface);
}
.searchbar input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
}
.searchbar input:focus { outline: none; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px; height: 36px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--ink-2);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }

/* Default to the light-mode icon so the button is correct even before the
   theme script runs, or when JavaScript is switched off entirely. */
.only-dark { display: none; }
[data-theme="dark"] .only-dark { display: inline-flex; }
[data-theme="dark"] .only-light { display: none; }

.avatar {
  display: grid;
  place-items: center;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
  flex: none;
}

/* --- User menu ----------------------------------------------------------- */

.usermenu { position: relative; }

.usermenu__trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.usermenu__trigger:hover { background: var(--surface-2); }
.usermenu__name { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.usermenu__panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 236px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.usermenu__panel[hidden] { display: none; }

.usermenu__meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 12px 12px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 6px;
}
.usermenu__meta span { color: var(--ink-3); font-size: 13px; }
.usermenu__meta .badge { align-self: flex-start; margin-top: 5px; }

.usermenu__panel a {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-size: 14px;
}
.usermenu__panel a:hover { background: var(--surface-3); text-decoration: none; }

/* --- Shell --------------------------------------------------------------- */

.shell {
  display: grid;
  grid-template-columns: var(--sidenav-w) minmax(0, 1fr);
  align-items: start;
}

.sidenav {
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  padding: 16px 12px;
  border-right: 1px solid var(--line);
  background: var(--surface);
  overflow-y: auto;
}

.sidenav__group { list-style: none; margin: 0 0 4px; padding: 0; }

.sidenav__group a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 11px;
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 500;
}
.sidenav__group a:hover { background: var(--surface-3); color: var(--ink); text-decoration: none; }
.sidenav__group a[aria-current="page"] {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

.sidenav__label {
  margin: 20px 0 8px;
  padding: 0 11px;
  color: var(--ink-3);
  font-size: 12.5px;
  font-weight: 600;
}

.drawer-scrim { display: none; }

.main {
  min-width: 0;
  padding: 24px 28px 64px;
  max-width: 1180px;
}

.auth-main {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 20px 56px;
  gap: 14px;
}

/* --- Page header --------------------------------------------------------- */

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 20px;
}
.page-head__title { font-size: 22px; }
.page-head__sub { margin: 4px 0 0; color: var(--ink-3); font-size: 14px; }
.page-head__actions { display: flex; gap: 8px; flex-wrap: wrap; }

.backlink {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 14px;
  color: var(--ink-3);
  font-size: 13.5px;
}

/* --- Buttons ------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color .12s ease, border-color .12s ease;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn--primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-ink);
}
.btn--primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

.btn--danger { color: var(--danger); border-color: var(--line-strong); }
.btn--danger:hover { background: var(--danger-soft); border-color: var(--danger); }

.btn--ghost { border-color: transparent; background: none; color: var(--ink-2); }
.btn--ghost:hover { background: var(--surface-3); color: var(--ink); }

.btn--sm { padding: 6px 11px; font-size: 13px; }
.btn--block { width: 100%; }

/* --- Badges -------------------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}

.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }

.badge--status.is-open     { background: var(--warn-soft);  color: var(--warn); }
.badge--status.is-in_progress { background: var(--info-soft); color: var(--info); }
.badge--status.is-resolved { background: var(--ok-soft);    color: var(--ok); }
.badge--status.is-closed   { background: var(--muted-soft); color: var(--muted); }

.badge--priority { background: var(--surface-3); color: var(--ink-2); }
.badge--priority.is-high   { background: var(--warn-soft);   color: var(--warn); }
.badge--priority.is-urgent { background: var(--danger-soft); color: var(--danger); }

.badge--role { background: var(--primary-soft); color: var(--primary); }
.badge--muted { background: var(--surface-3); color: var(--ink-3); font-weight: 500; }

.badge--internal { background: var(--warn-soft); color: var(--warn); }

/* --- Alerts -------------------------------------------------------------- */

.alert {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  margin-bottom: 18px;
  border: 1px solid;
  border-radius: var(--radius);
  font-size: 14px;
}
.alert span { flex: 1; }

.alert--success { background: var(--ok-soft);     border-color: var(--ok);     color: var(--ok); }
.alert--error   { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.alert--info    { background: var(--primary-soft);border-color: var(--primary);color: var(--primary); }

.alert__close {
  border: 0;
  background: none;
  color: inherit;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  opacity: .6;
  padding: 0 2px;
}
.alert__close:hover { opacity: 1; }

/* --- Panels -------------------------------------------------------------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.panel + .panel { margin-top: 18px; }

.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.panel__head h2 { font-size: 15px; }
.panel__head p { margin: 2px 0 0; color: var(--ink-3); font-size: 13px; }

.panel__body { padding: 18px; }
.panel__foot {
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}

/* --- Filters ------------------------------------------------------------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.filters .field { margin: 0; min-width: 150px; }
.filters .field label { font-size: 12.5px; }
.filters__spacer { flex: 1; }

/* --- Ticket list --------------------------------------------------------- */

.ticket-list { display: flex; flex-direction: column; }

.ticket-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px 18px;
  padding: 15px 18px 15px 22px;
  border-bottom: 1px solid var(--line);
  color: inherit;
}
.ticket-row:last-child { border-bottom: 0; }
.ticket-row:hover { background: var(--surface-2); text-decoration: none; }

/* A colour bar on the leading edge gives status at a glance while scanning. */
.ticket-row::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--muted);
}
.ticket-row.is-open::before     { background: var(--warn); }
.ticket-row.is-in_progress::before { background: var(--info); }
.ticket-row.is-resolved::before { background: var(--ok); }
.ticket-row.is-closed::before   { background: var(--line-strong); }

.ticket-row__main { min-width: 0; }

.ticket-row__title {
  display: block;
  font-weight: 600;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ticket-row__ref {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink-3);
  margin-right: 8px;
  font-weight: 500;
}

.ticket-row__excerpt {
  display: block;
  margin-top: 3px;
  color: var(--ink-3);
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ticket-row__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 9px;
  font-size: 12.5px;
  color: var(--ink-3);
}

.ticket-row__side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 7px;
  text-align: right;
}
.ticket-row__time { color: var(--ink-3); font-size: 12.5px; white-space: nowrap; }


/* --- Live ticket age ------------------------------------------------------ */
/* Counts up from when the ticket was raised. Colour escalates with age, at a
   rate that depends on priority, so a queue can be triaged at a glance. The
   numbers are tabular so the row does not twitch every second. */

.age {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.age__dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

.age--done {
  border-style: dashed;
  color: var(--ink-3);
  font-weight: 500;
}

.age[data-level="fresh"]    { border-color: var(--ok);     background: var(--ok-soft);     color: var(--ok); }
.age[data-level="due"]      { border-color: var(--warn);   background: var(--warn-soft);   color: var(--warn); }
.age[data-level="late"]     { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
.age[data-level="critical"] {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
}
[data-theme="dark"] .age[data-level="critical"] { color: #2a0b08; }

/* One slow pulse on the worst ones. Anything faster is just irritating. */
.age[data-level="critical"] .age__dot { animation: age-pulse 2s ease-in-out infinite; }

@keyframes age-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .35; }
}

@media (prefers-reduced-motion: reduce) {
  .age[data-level="critical"] .age__dot { animation: none; }
}

/* --- Empty states -------------------------------------------------------- */

.empty-state {
  padding: 52px 24px;
  text-align: center;
  color: var(--ink-3);
}
.empty-state h2, .empty-state h1 { color: var(--ink); margin-bottom: 8px; }
.empty-state p { max-width: 44ch; margin-left: auto; margin-right: auto; }
.empty-state .btn { margin-top: 16px; }

.empty-state--page {
  max-width: 520px;
  margin: 48px auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

/* --- Pagination ---------------------------------------------------------- */

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 18px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 13.5px;
  color: var(--ink-3);
}
.pagination__links { display: flex; gap: 6px; }

/* --- Forms --------------------------------------------------------------- */

.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }

.field label,
.form-label {
  display: block;
  margin-bottom: 6px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-2);
}

.field .hint {
  margin: 6px 0 0;
  font-size: 12.5px;
  color: var(--ink-3);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="date"],
input[type="file"],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
}

textarea { min-height: 130px; resize: vertical; line-height: 1.6; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

input::placeholder, textarea::placeholder { color: var(--ink-3); }

input[type="file"] { padding: 8px; background: var(--surface-2); }

select {
  appearance: none;
  padding-right: 34px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 17px) 52%, calc(100% - 12px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.fixed-value {
  margin: 0;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  color: var(--ink);
  font-size: 14px;
  font-weight: 550;
}

.field-row { display: flex; flex-wrap: wrap; gap: 14px; }
.field-row > .field { flex: 1 1 200px; margin-bottom: 16px; }

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 18px;
}

.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; }

.check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13.5px;
  color: var(--ink-2);
  cursor: pointer;
}
.check input { width: auto; margin: 0; accent-color: var(--primary); }

fieldset { border: 0; margin: 0 0 22px; padding: 0; }
fieldset legend {
  padding: 0;
  margin-bottom: 4px;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}
fieldset .legend-hint { margin: 0 0 14px; color: var(--ink-3); font-size: 13.5px; }

.form-narrow { max-width: 620px; }

/* --- Auth card ----------------------------------------------------------- */

.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 30px 30px 26px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.auth-card h1 { font-size: 20px; margin-bottom: 6px; }
.auth-card .lede { color: var(--ink-3); font-size: 14px; margin-bottom: 22px; }
.auth-card .form-actions { margin-top: 22px; }

.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 650;
  color: var(--ink);
  margin-bottom: 4px;
}
.auth-brand .brand__mark { width: 32px; height: 32px; font-size: 13px; }

.auth-switch {
  margin: 18px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 14px;
  color: var(--ink-3);
  text-align: center;
}

/* --- Ticket detail ------------------------------------------------------- */

.ticket-detail {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 288px;
  gap: 20px;
  align-items: start;
}

.ticket-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.ticket-title-row h1 { font-size: 21px; }
.ticket-ref {
  font-family: var(--mono);
  font-size: 14px;
  color: var(--ink-3);
  font-weight: 500;
}

.rail { display: flex; flex-direction: column; gap: 16px; position: sticky; top: calc(var(--topbar-h) + 20px); }

.prop-list { display: flex; flex-direction: column; gap: 13px; }
.prop { display: flex; flex-direction: column; gap: 3px; font-size: 13.5px; }
.prop__label { color: var(--ink-3); font-size: 12.5px; font-weight: 600; }
.prop__value { color: var(--ink); }

.thread { display: flex; flex-direction: column; }

.message {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.message:last-child { border-bottom: 0; }

.message--first { background: var(--surface-2); }

.message--internal {
  background: var(--warn-soft);
  border-left: 3px solid var(--warn);
}

.message__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 5px;
}
.message__author { font-weight: 600; font-size: 14px; }
.message__time { color: var(--ink-3); font-size: 12.5px; }

.message__body {
  margin: 0;
  font-size: 14.5px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.event {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
  margin: 0;
  padding: 9px 18px 9px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink-3);
  font-size: 13px;
}
.event strong { color: var(--ink-2); font-weight: 600; }
.event time { margin-left: auto; white-space: nowrap; }

.attachments { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.attachments a {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 13px;
  color: var(--ink-2);
}
.attachments a:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.attachments .size { color: var(--ink-3); font-size: 12px; }

.reply-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.reply-tabs button {
  padding: 7px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-2);
  font: inherit;
  font-size: 13.5px;
  font-weight: 550;
  cursor: pointer;
}
.reply-tabs button[aria-pressed="true"] {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
}

.locked-note {
  padding: 16px 18px;
  color: var(--ink-3);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 9px;
}

/* --- Tables -------------------------------------------------------------- */

.table-wrap { overflow-x: auto; }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table.data th,
table.data td {
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
table.data th {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-3);
  background: var(--surface-2);
  white-space: nowrap;
}
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data input, table.data select { font-size: 13.5px; padding: 7px 10px; }
table.data td.actions { white-space: nowrap; text-align: right; }
table.data td.actions .btn + .btn { margin-left: 6px; }
table.data .checks { gap: 4px 12px; }

.not-applicable { font-size: 12.5px; }

.cell-stack { display: flex; flex-direction: column; gap: 2px; }
.cell-stack .sub { color: var(--ink-3); font-size: 12.5px; }


/* --- People list ---------------------------------------------------------- */
/* A grid that wraps rather than a wide table: nine editable columns could
   never fit a laptop screen, and a horizontal scrollbar is miserable to use.
   Editing happens in a focused panel instead of inline. */

.people-list { display: flex; flex-direction: column; }

.person {
  display: grid;
  grid-template-columns: 34px minmax(160px, 1.4fr) minmax(180px, 1.6fr) minmax(150px, 1.2fr) auto auto;
  align-items: center;
  gap: 6px 16px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--line);
}
.person:last-child { border-bottom: 0; }
.person:hover { background: var(--surface-2); }
.person.is-off { background: repeating-linear-gradient(
    -45deg, transparent, transparent 9px, var(--surface-2) 9px, var(--surface-2) 18px); }

.person__avatar { grid-row: span 1; }

.person__who,
.person__contact { display: flex; flex-direction: column; min-width: 0; }

.person__name { font-weight: 600; font-size: 14.5px; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.person__sub { color: var(--ink-3); font-size: 12.5px; }
.person__contact span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13.5px; }

.person__tags { display: flex; flex-wrap: wrap; gap: 6px; }

.person__seen { color: var(--ink-3); font-size: 12.5px; white-space: nowrap; text-align: right; }

.person__actions { display: flex; gap: 6px; justify-content: flex-end; }

@media (max-width: 1100px) {
  .person {
    grid-template-columns: 34px minmax(0, 1fr) auto;
    row-gap: 8px;
  }
  .person__contact { grid-column: 2 / -1; }
  .person__tags    { grid-column: 2 / -1; }
  .person__seen    { grid-column: 2; text-align: left; }
  .person__actions { grid-column: 3; grid-row: 4; }
}

@media (max-width: 560px) {
  .person { grid-template-columns: 34px minmax(0, 1fr); }
  .person__actions { grid-column: 1 / -1; grid-row: auto; justify-content: flex-start; flex-wrap: wrap; }
  .person__seen { grid-column: 2 / -1; }
}

/* --- Stats --------------------------------------------------------------- */

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

.stat {
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.stat__num { display: block; font-size: 28px; font-weight: 650; letter-spacing: -.02em; line-height: 1.15; }
.stat__label { display: block; margin-top: 3px; color: var(--ink-3); font-size: 13px; }
.stat.is-warn .stat__num   { color: var(--warn); }
.stat.is-danger .stat__num { color: var(--danger); }
.stat.is-ok .stat__num     { color: var(--ok); }

/* Simple horizontal bars for the per-department breakdown. */
.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.bar-row:last-child { border-bottom: 0; }
.bar-row__name { font-size: 14px; font-weight: 550; }
.bar-row__count { font-size: 13px; color: var(--ink-3); font-family: var(--mono); }
.bar { grid-column: 1 / -1; height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--primary); border-radius: 999px; }


/* Daily volume bars. Plain CSS: no charting library for one sparkline. */
.daybars {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 130px;
  padding-top: 6px;
}
.daybar {
  flex: 1 1 0;
  min-width: 6px;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: stretch;
  gap: 4px;
}
.daybar__fill {
  display: block;
  background: var(--primary);
  border-radius: 3px 3px 0 0;
  min-height: 2px;
  transition: none;
}
.daybar:hover .daybar__fill { background: var(--primary-hover); }
.daybar__label {
  font-size: 9.5px;
  color: var(--ink-3);
  text-align: center;
  font-family: var(--mono);
}

/* Tone variants shared by the report bars. */
.bar span.is-warn   { background: var(--warn); }
.bar span.is-danger { background: var(--danger); }

.bar-row__name .sub { display: block; color: var(--ink-3); font-size: 12px; font-weight: 400; }

@media (max-width: 700px) {
  .daybars { height: 100px; }
  .daybar__label { display: none; }
}

/* --- Live refresh -------------------------------------------------------- */

.live-toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 120;
  padding: 9px 15px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 550;
  box-shadow: var(--shadow-lg);
  opacity: 1;
  transition: opacity .35s ease, transform .35s ease;
}
.live-toast.is-going { opacity: 0; transform: translateY(6px); }

.live-stale { margin: 0 0 0; border-radius: 0; }

/* A row that was not there a moment ago, marked just long enough to notice. */
.ticket-row.is-arrived { animation: arrived 2.4s ease-out 1; }

@keyframes arrived {
  0%   { background: var(--primary-soft); }
  100% { background: transparent; }
}

@media (prefers-reduced-motion: reduce) {
  .ticket-row.is-arrived { animation: none; box-shadow: inset 3px 0 0 var(--primary); }
  .live-toast { transition: none; }
}

/* --- Utilities ----------------------------------------------------------- */

.stack > * + * { margin-top: 16px; }
.muted { color: var(--ink-3); }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; }
.mb-16 { margin-bottom: 16px; }
.inline-form { display: inline; }

/* --- Responsive ---------------------------------------------------------- */

@media (max-width: 1040px) {
  .ticket-detail { grid-template-columns: minmax(0, 1fr); }
  .rail { position: static; }
}

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }

  .topbar__menu { display: grid; }

  .sidenav {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    z-index: 60;
    width: 254px;
    height: calc(100vh - var(--topbar-h));
    transform: translateX(-100%);
    transition: transform .18s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidenav.is-open { transform: translateX(0); }

  .drawer-scrim {
    display: block;
    position: fixed;
    inset: var(--topbar-h) 0 0 0;
    z-index: 55;
    background: rgba(10, 16, 22, .5);
  }
  .drawer-scrim[hidden] { display: none; }

  .main { padding: 18px 16px 56px; }
  .brand__name { display: none; }
  .usermenu__name { display: none; }
  .searchbar { margin-left: 4px; }
}

@media (max-width: 560px) {
  .ticket-row { grid-template-columns: minmax(0, 1fr); }
  .ticket-row__side { flex-direction: row; align-items: center; justify-content: flex-start; text-align: left; flex-wrap: wrap; }
  .page-head { flex-direction: column; align-items: stretch; }
  .page-head__actions .btn { flex: 1; }
  .filters .field { min-width: 100%; }
  .panel { border-radius: var(--radius); }
  .message { grid-template-columns: minmax(0, 1fr); }
  .message .avatar { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}

@media print {
  .topbar, .sidenav, .reply-tabs, .form-actions, .filters, .pagination { display: none !important; }
  .shell { grid-template-columns: 1fr; }
  .panel { box-shadow: none; }
}
