/* ==========================================================================
   Helpdesk design system
   Tokens first, then layout, then components. Change colours in :root only.
   ========================================================================== */

:root {
  --hd-brand: #2563eb;
  --hd-brand-ink: #1d4ed8;
  --hd-brand-soft: #eff6ff;

  --hd-bg: #f5f7fb;
  --hd-surface: #ffffff;
  --hd-border: #e2e8f0;
  --hd-ink: #0f172a;
  --hd-ink-2: #334155;
  --hd-muted: #64748b;

  --hd-sidebar: #0f172a;
  --hd-sidebar-ink: #cbd5e1;
  --hd-sidebar-hover: #1e293b;

  --hd-radius: 12px;
  --hd-radius-sm: 8px;
  --hd-shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .06);
  --hd-focus: 0 0 0 3px rgba(37, 99, 235, .35);

  --hd-open: #dc2626;      --hd-open-soft: #fef2f2;
  --hd-progress: #b45309;  --hd-progress-soft: #fffbeb;
  --hd-resolved: #15803d;  --hd-resolved-soft: #f0fdf4;
  --hd-closed: #475569;    --hd-closed-soft: #f1f5f9;

  --hd-low: #15803d;
  --hd-medium: #1d4ed8;
  --hd-high: #c2410c;
  --hd-critical: #b91c1c;
}

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

body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: .95rem;
  color: var(--hd-ink);
  background: var(--hd-bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--hd-brand-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: none; box-shadow: var(--hd-focus); border-radius: 6px; }
.text-muted { color: var(--hd-muted) !important; }
code { color: var(--hd-ink-2); }

/* ---------- Layout ---------- */

.hd-shell { min-height: 100vh; }

.hd-sidebar {
  width: 260px;
  background: var(--hd-sidebar);
  color: var(--hd-sidebar-ink);
  display: flex;
  flex-direction: column;
}
@media (min-width: 992px) {
  /* Bootstrap's .offcanvas-lg forces a transparent background on desktop; restore ours. */
  .hd-sidebar.offcanvas-lg {
    position: sticky; top: 0; height: 100vh;
    background: var(--hd-sidebar) !important;
    color: var(--hd-sidebar-ink) !important;
    border: 0 !important;
  }
}
.hd-sidebar .offcanvas-body { display: flex; flex-direction: column; padding: 0; }

.hd-brand {
  display: flex; align-items: center; gap: .65rem;
  padding: 1.25rem 1.25rem 1.1rem;
  color: #fff; font-weight: 700; font-size: 1.05rem; letter-spacing: -.01em;
}
.hd-brand:hover { color: #fff; text-decoration: none; }
.hd-brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: #fff; font-size: 1.05rem;
}

.hd-nav-label {
  padding: 1rem 1.25rem .4rem;
  font-size: .72rem; font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: #64748b;
}
.hd-nav { list-style: none; margin: 0; padding: 0 .75rem; }
.hd-nav a {
  display: flex; align-items: center; gap: .7rem;
  padding: .55rem .7rem; margin-bottom: 2px;
  border-radius: var(--hd-radius-sm);
  color: var(--hd-sidebar-ink); font-weight: 500;
}
.hd-nav a i { font-size: 1.05rem; opacity: .85; }
.hd-nav a:hover { background: var(--hd-sidebar-hover); color: #fff; text-decoration: none; }
.hd-nav a.is-active { background: var(--hd-brand); color: #fff; }
.hd-nav .hd-count {
  margin-left: auto; font-size: .75rem; font-weight: 600;
  background: rgba(255,255,255,.14); color: #fff;
  border-radius: 999px; padding: .05rem .5rem;
}

.hd-sidebar-foot {
  margin-top: auto; padding: 1rem;
  border-top: 1px solid #1e293b;
}
.hd-me { display: flex; align-items: center; gap: .7rem; }
.hd-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; flex: 0 0 36px;
  background: #1e293b; color: #e2e8f0; font-weight: 600; font-size: .8rem;
}
.hd-me-name { color: #fff; font-weight: 600; line-height: 1.2; }
.hd-me-role { font-size: .78rem; color: #94a3b8; }

.hd-main { min-width: 0; flex: 1 1 auto; }

.hd-topbar {
  position: sticky; top: 0; z-index: 1020;
  display: flex; align-items: center; gap: 1rem;
  padding: .85rem 1.75rem;
  background: rgba(255,255,255,.9);
  backdrop-filter: saturate(160%) blur(8px);
  border-bottom: 1px solid var(--hd-border);
}
.hd-topbar h1 { font-size: 1.2rem; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.hd-crumb { font-size: .78rem; color: var(--hd-muted); }

.hd-content { padding: 1.75rem; max-width: 1280px; }
@media (max-width: 575.98px) {
  .hd-content { padding: 1rem; }
  .hd-topbar { padding: .75rem 1rem; }
}

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

.hd-page-head {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 1rem; margin-bottom: 1.25rem;
}
.hd-page-head h2 { font-size: 1.35rem; font-weight: 700; margin: 0; letter-spacing: -.02em; }
.hd-page-head p { margin: .2rem 0 0; color: var(--hd-muted); }

/* ---------- Surfaces ---------- */

.hd-card {
  background: var(--hd-surface);
  border: 1px solid var(--hd-border);
  border-radius: var(--hd-radius);
  box-shadow: var(--hd-shadow);
}
.hd-card-head {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--hd-border);
}
.hd-card-head h3 { font-size: .95rem; font-weight: 600; margin: 0; }
.hd-card-body { padding: 1.25rem; }
.hd-card-body.flush { padding: 0; }

/* KPI tiles */
.hd-kpi {
  position: relative; overflow: hidden;
  padding: 1.1rem 1.2rem;
  height: 100%;
}
.hd-kpi::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--kpi, var(--hd-brand));
}
.hd-kpi-label { font-size: .8rem; font-weight: 500; color: var(--hd-muted); }
.hd-kpi-value { font-size: 1.85rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; margin-top: .25rem; }
.hd-kpi-icon {
  position: absolute; right: 1rem; top: 1rem;
  width: 38px; height: 38px; border-radius: 10px;
  display: grid; place-items: center; font-size: 1.1rem;
  background: var(--kpi-soft, var(--hd-brand-soft)); color: var(--kpi, var(--hd-brand));
}

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

.hd-badge {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .2rem .6rem; border-radius: 999px;
  font-size: .75rem; font-weight: 600; line-height: 1.4; white-space: nowrap;
  background: var(--hd-closed-soft); color: var(--hd-closed);
}
.hd-badge::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor;
}
.hd-status-open         { background: var(--hd-open-soft);     color: var(--hd-open); }
.hd-status-in_progress  { background: var(--hd-progress-soft); color: var(--hd-progress); }
.hd-status-resolved     { background: var(--hd-resolved-soft); color: var(--hd-resolved); }
.hd-status-closed       { background: var(--hd-closed-soft);   color: var(--hd-closed); }

.hd-priority-low        { background: var(--hd-resolved-soft); color: var(--hd-low); }
.hd-priority-medium     { background: var(--hd-brand-soft);    color: var(--hd-medium); }
.hd-priority-high       { background: #fff7ed;                 color: var(--hd-high); }
.hd-priority-critical   { background: var(--hd-open-soft);     color: var(--hd-critical); font-weight: 700; }

.hd-role-admin          { background: #f3e8ff; color: #7e22ce; }
.hd-role-technician     { background: var(--hd-brand-soft); color: var(--hd-brand-ink); }
.hd-role-staff          { background: var(--hd-closed-soft); color: var(--hd-closed); }

.hd-tag {
  display: inline-block; padding: .15rem .5rem; border-radius: 6px;
  font-size: .75rem; font-weight: 500;
  background: #f1f5f9; color: var(--hd-ink-2);
}
.hd-ref { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem; color: var(--hd-muted); }

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

.hd-table { margin: 0; }
.hd-table thead th {
  font-size: .72rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
  color: var(--hd-muted); background: #f8fafc;
  border-bottom: 1px solid var(--hd-border); padding: .7rem 1rem; white-space: nowrap;
}
.hd-table tbody td { padding: .85rem 1rem; vertical-align: middle; border-color: var(--hd-border); }
.hd-table tbody tr.is-link { cursor: pointer; }
.hd-table tbody tr.is-link:hover { background: #f8fafc; }
.hd-table .hd-title { font-weight: 600; color: var(--hd-ink); }
.hd-table .hd-title:hover { color: var(--hd-brand-ink); }

.hd-person { display: flex; align-items: center; gap: .55rem; white-space: nowrap; }
.hd-person .hd-avatar { width: 28px; height: 28px; flex-basis: 28px; font-size: .68rem; background: #e2e8f0; color: var(--hd-ink-2); }

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

.hd-toolbar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; padding: 1rem 1.25rem; border-bottom: 1px solid var(--hd-border); }
.hd-toolbar .form-control, .hd-toolbar .form-select { font-size: .9rem; }
.hd-search { position: relative; flex: 1 1 260px; min-width: 200px; }
.hd-search i { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); color: var(--hd-muted); }
.hd-search input { padding-left: 2.2rem; }
.hd-segmented { display: inline-flex; background: #f1f5f9; border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.hd-segmented a {
  padding: .35rem .75rem; border-radius: 8px; font-size: .85rem; font-weight: 500; color: var(--hd-ink-2);
}
.hd-segmented a:hover { text-decoration: none; color: var(--hd-ink); }
.hd-segmented a.is-active { background: #fff; color: var(--hd-ink); box-shadow: var(--hd-shadow); }

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

.form-label { font-weight: 600; font-size: .85rem; color: var(--hd-ink-2); margin-bottom: .35rem; }
.form-control, .form-select {
  border-color: #cbd5e1; border-radius: var(--hd-radius-sm); padding: .55rem .75rem;
}
.form-control:focus, .form-select:focus { border-color: var(--hd-brand); box-shadow: var(--hd-focus); }
.form-text { color: var(--hd-muted); font-size: .8rem; }
.hd-required::after { content: " *"; color: var(--hd-critical); }

.btn { border-radius: var(--hd-radius-sm); font-weight: 600; padding: .5rem 1rem; font-size: .9rem; }
.btn:focus-visible { box-shadow: var(--hd-focus); }
.btn-primary { background: var(--hd-brand); border-color: var(--hd-brand); }
.btn-primary:hover { background: var(--hd-brand-ink); border-color: var(--hd-brand-ink); }
.btn-outline-secondary { color: var(--hd-ink-2); border-color: #cbd5e1; }
.btn-outline-secondary:hover { background: #f1f5f9; color: var(--hd-ink); border-color: #cbd5e1; }
.btn-sm { padding: .35rem .7rem; font-size: .82rem; }

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

.hd-alerts { margin-bottom: 1.25rem; }
.hd-alerts .alert { border: 0; border-radius: var(--hd-radius-sm); font-weight: 500; box-shadow: var(--hd-shadow); }
.alert-success { background: var(--hd-resolved-soft); color: #166534; }
.alert-danger  { background: var(--hd-open-soft); color: #991b1b; }

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

.hd-empty { text-align: center; padding: 3rem 1.5rem; color: var(--hd-muted); }
.hd-empty i { font-size: 2.2rem; color: #94a3b8; display: block; margin-bottom: .6rem; }
.hd-empty strong { display: block; color: var(--hd-ink-2); font-size: 1rem; margin-bottom: .25rem; }

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

.hd-ticket-title { font-size: 1.4rem; font-weight: 700; letter-spacing: -.02em; margin: .35rem 0 .6rem; }
.hd-prose { white-space: pre-wrap; line-height: 1.65; color: var(--hd-ink-2); word-break: break-word; }

.hd-facts { display: grid; grid-template-columns: auto 1fr; gap: .6rem 1rem; margin: 0; font-size: .9rem; }
.hd-facts dt { font-weight: 500; color: var(--hd-muted); }
.hd-facts dd { margin: 0; }

.hd-timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.hd-timeline li { position: relative; padding: 0 0 1.25rem 1.6rem; }
.hd-timeline li:last-child { padding-bottom: 0; }
.hd-timeline li::before {
  content: ""; position: absolute; left: 6px; top: 6px; bottom: -2px; width: 2px; background: var(--hd-border);
}
.hd-timeline li:last-child::before { display: none; }
.hd-timeline li::after {
  content: ""; position: absolute; left: 0; top: 4px; width: 14px; height: 14px; border-radius: 50%;
  background: #fff; border: 2px solid #94a3b8;
}
.hd-timeline .is-comment::after { border-color: var(--hd-brand); }
.hd-timeline .is-change::after { border-color: var(--hd-progress); }
.hd-timeline .is-created::after { border-color: var(--hd-resolved); }
.hd-timeline-meta { font-size: .8rem; color: var(--hd-muted); }
.hd-comment-body { margin-top: .35rem; background: #f8fafc; border: 1px solid var(--hd-border); border-radius: var(--hd-radius-sm); padding: .7rem .85rem; white-space: pre-wrap; word-break: break-word; }

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

.pagination .page-link { color: var(--hd-ink-2); border-color: var(--hd-border); font-weight: 500; font-size: .88rem; }
.pagination .page-item.active .page-link { background: var(--hd-brand); border-color: var(--hd-brand); color: #fff; }

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

.hd-auth {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background:
    radial-gradient(1000px 500px at 10% -10%, #dbeafe 0%, transparent 60%),
    radial-gradient(800px 400px at 110% 110%, #e0e7ff 0%, transparent 60%),
    var(--hd-bg);
}
.hd-auth-card { width: 100%; max-width: 420px; padding: 2rem; }
.hd-auth-card .hd-brand-mark { width: 44px; height: 44px; font-size: 1.25rem; margin-bottom: 1rem; }
.hd-auth-card h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; margin: 0 0 .25rem; }
.hd-demo { background: var(--hd-brand-soft); border-radius: var(--hd-radius-sm); padding: .8rem 1rem; font-size: .82rem; color: var(--hd-ink-2); }
.hd-demo table { margin: .4rem 0 0; width: 100%; }
.hd-demo td { padding: .15rem 0; }

/* ---------- Misc ---------- */

.hd-skip { position: absolute; left: -999px; }
.hd-skip:focus { left: 1rem; top: 1rem; z-index: 2000; background: #fff; padding: .5rem 1rem; border-radius: 8px; }
.hd-stack > * + * { margin-top: 1rem; }
.hd-divider { height: 1px; background: var(--hd-border); margin: 1rem 0; }

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

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

.hd-title-cell { min-width: 240px; }
.hd-nav a span, .hd-nav a { white-space: nowrap; }
.hd-toolbar .form-select { min-width: 150px; }
.hd-search { min-width: 220px; }
