/* ---------------------------------------------------------------
   Design tokens — internal ops tool: dense, calm, fast to scan.
   Not a marketing surface, so restraint over flourish throughout.
   ----------------------------------------------------------------*/
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1a2233;
  --text-muted: #5b6472;
  --accent: #3454d1;
  --accent-hover: #28409e;
  --accent-soft: #e8ecfb;
  --danger: #c22b2b;
  --danger-soft: #fbe9e9;
  --success: #1f9d55;
  --success-soft: #e6f6ec;

  --status-new: #6b7280;
  --status-open: #3454d1;
  --status-pending: #b3760c;
  --status-resolved: #1f9d55;
  --status-closed: #8b93a1;

  --priority-low: #8b93a1;
  --priority-medium: #3454d1;
  --priority-high: #b3760c;
  --priority-urgent: #c22b2b;

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

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

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

/* --- Top nav --- */
.topnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topnav__brand {
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
  letter-spacing: -0.01em;
}
.topnav__links { display: flex; gap: 20px; align-items: center; }
.topnav__links a { color: var(--text-muted); font-weight: 500; }
.topnav__links a:hover { color: var(--text); text-decoration: none; }
.topnav__links a.is-active { color: var(--accent); }
/* .topnav__links a's color rule above is more specific than a bare
   .btn-primary (two classes vs. one), so without this the "New ticket"
   / "Log in" nav buttons lose their white text to the muted gray meant
   for plain nav links -- illegible against the button's navy-blue
   background. */
.topnav__links .btn-primary,
.topnav__links .btn-primary:hover { color: #fff; }
.topnav__user { color: var(--text-muted); font-size: 13px; }

/* --- App layout: sidebar (Admin section only) + main content --- */
.app-layout { display: flex; align-items: flex-start; gap: 32px; }
.app-main {
  flex: 1 1 0%;
  min-width: 0;
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 24px 60px;
}
.app-sidebar {
  flex: 0 0 200px;
  padding: 28px 0 60px 24px;
}
.app-sidebar__title { font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); margin-bottom: 12px; }
.app-sidebar__group-title { font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); margin: 14px 0 4px; }
.app-sidebar__link {
  display: block;
  padding: 7px 10px;
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text);
  margin-bottom: 2px;
}
.app-sidebar__link:hover { background: var(--bg); text-decoration: none; }
.app-sidebar__link.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.app-sidebar__link--nested { padding-left: 20px; }

h1 { font-size: 20px; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 20px;
}
.page-subtitle { color: var(--text-muted); font-size: 13px; }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.btn:hover { border-color: var(--text-muted); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--danger); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* --- Cards / tables --- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
td { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.row-link { color: var(--text); font-weight: 600; }

/* --- Badges --- */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: #fff;
}
.badge-status-new { background: var(--status-new); }
.badge-status-open { background: var(--status-open); }
.badge-status-pending { background: var(--status-pending); }
.badge-status-resolved { background: var(--status-resolved); }
.badge-status-closed { background: var(--status-closed); }

.badge-priority-low { background: var(--priority-low); }
.badge-priority-medium { background: var(--priority-medium); }
.badge-priority-high { background: var(--priority-high); }
.badge-priority-urgent { background: var(--priority-urgent); }

.badge-status-in_use { background: var(--success); }
.badge-status-in_stock { background: var(--accent); }
.badge-status-in_repair { background: var(--status-pending); }
.badge-status-retired { background: var(--status-closed); }
.badge-status-lost { background: var(--danger); }

/* --- SLA status badges (ticket detail + ticket queue) --- */
.sla-badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.02em; }
.sla-badge--met { background: var(--success-soft); color: var(--success); }
.sla-badge--breached { background: var(--danger-soft); color: var(--danger); }
.sla-badge--overdue { background: var(--danger-soft); color: var(--danger); }
.sla-badge--pending { background: var(--accent-soft); color: var(--accent); }

.pill { font-family: var(--font-mono); color: var(--text-muted); font-size: 12px; }

/* --- Forms --- */
label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin: 14px 0 4px; }
label:first-child { margin-top: 0; }
input[type=text], input[type=email], input[type=password], input[type=search],
textarea, select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
}
textarea { resize: vertical; }
.field-error { color: var(--danger); font-size: 12px; margin-top: 4px; }
.helptext { color: var(--text-muted); font-size: 12px; margin-top: 4px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; margin: 14px 0 4px; }
.checkbox-row input { width: auto; }
.checkbox-row label { margin: 0; }

.filter-bar { display: flex; gap: 12px; margin-bottom: 16px; align-items: flex-end; flex-wrap: wrap; }
.filter-bar label { margin: 0 0 4px; }
.filter-bar > div { min-width: 150px; }
.filter-bar__more { flex-basis: 100%; margin-top: 4px; }
.filter-bar__more summary { cursor: pointer; font-size: 13px; color: var(--text-muted); font-weight: 600; }
.filter-bar__more-grid { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 10px; }
.filter-bar__more-grid > div { min-width: 150px; }
.filter-bar__more-grid label { display: block; margin: 0 0 4px; font-size: 13px; }
.filter-bar__columns-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 6px; margin-top: 10px; max-width: 720px; }

/* --- Messages --- */
.message {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 13px;
  font-weight: 500;
}
.message-success { background: var(--success-soft); color: var(--success); }
.message-error { background: var(--danger-soft); color: var(--danger); }

/* --- Ticket detail --- */
.ticket-meta { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; margin: 16px 0 24px; }
.ticket-meta__item .label { font-size: 11px; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.03em; margin-bottom: 2px; }
.ticket-meta__item .value { font-size: 13px; font-weight: 600; }

.comment { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; background: var(--surface); }
.comment.is-internal { background: #fff9e8; border-color: #eddca0; }
.comment__meta { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; display: flex; gap: 8px; align-items: center; }
.comment__body { white-space: pre-wrap; }

.activity { font-size: 12px; color: var(--text-muted); padding: 6px 0; border-bottom: 1px dashed var(--border); }
.activity:last-child { border-bottom: none; }

.section { margin-top: 28px; }
.empty-state { color: var(--text-muted); font-size: 13px; padding: 24px; text-align: center; }

.status-form { display: inline-flex; gap: 8px; align-items: center; }

/* --- Report bar chart (server-rendered, no JS chart lib needed) --- */
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.bar-row__label { width: 160px; font-size: 12px; color: var(--text-muted); text-align: right; flex-shrink: 0; }
.bar-row__track { flex: 1; background: var(--bg); border-radius: 4px; overflow: hidden; height: 22px; }
.bar-row__fill { background: var(--accent); height: 100%; border-radius: 4px; display: flex; align-items: center; }
.bar-row__count { font-size: 11px; color: #fff; padding-left: 8px; font-weight: 700; white-space: nowrap; }
.bar-row__count.outside { color: var(--text); padding-left: 4px; }

/* --- Portrait (vertical column) bar chart -- same data/colors as the
   landscape .bar-row variant above, just rotated 90deg conceptually
   rather than sharing markup, since flex-direction alone can't flip
   "fill toward the label" from width to height cleanly. --- */
.bar-columns { display: flex; align-items: flex-end; gap: 14px; height: 260px; padding-top: 10px; }
.bar-column { display: flex; flex-direction: column; align-items: center; flex: 1; height: 100%; min-width: 36px; }
.bar-column__track { flex: 1; width: 100%; max-width: 56px; background: var(--bg); border-radius: 4px; overflow: hidden; display: flex; align-items: flex-end; }
.bar-column__fill { background: var(--accent); width: 100%; border-radius: 4px 4px 0 0; display: flex; align-items: flex-start; justify-content: center; }
.bar-column__count { font-size: 11px; color: #fff; padding-top: 4px; font-weight: 700; white-space: nowrap; }
.bar-column__label { font-size: 12px; color: var(--text-muted); text-align: center; margin-top: 8px; word-break: break-word; }

/* --- Ticket list bulk-select quick-adjust bar --- */
.quickadjust-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: -100px;
  background: var(--text);
  color: #fff;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.15);
  padding: 14px 24px;
  z-index: 50;
  transition: bottom 0.15s ease-out;
}
.quickadjust-bar--visible { bottom: 0; }
.quickadjust-inner { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 14px; max-width: 1400px; margin: 0 auto; }
.quickadjust-count { font-weight: 700; font-size: 13px; padding-bottom: 8px; white-space: nowrap; }
.quickadjust-field { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: #d3d7de; text-transform: uppercase; letter-spacing: 0.03em; }
.quickadjust-field select {
  font-size: 13px;
  padding: 6px 8px;
  border-radius: var(--radius);
  border: 1px solid #4a5265;
  background: #2a3142;
  color: #fff;
  min-width: 140px;
}
.quickadjust-actions { display: flex; gap: 8px; margin-left: auto; padding-bottom: 1px; }
/* Plain (non-primary) buttons here -- "Clear selection" -- keep .btn's
   own white background, so they need .btn's own dark text too. Only
   .btn-primary ("Apply to selected") sits on a navy/accent background
   and needs white text. Previously both got color:#fff here, which
   made "Clear selection" white-on-white and unreadable. */
.quickadjust-actions .btn { border-color: #4a5265; }
.quickadjust-actions .btn-primary { background: var(--accent); border-color: var(--accent); }

/* --- Knowledge Base --- */
.kb-layout { display: flex; gap: 24px; align-items: flex-start; }
.kb-sidebar { flex: 0 0 200px; }
.kb-sidebar__card { padding: 12px; }
.kb-sidebar__title { font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); margin-bottom: 8px; }
.kb-main { flex: 1; min-width: 0; }

.kb-category-link { display: block; padding: 6px 8px; border-radius: var(--radius); font-size: 13px; color: var(--text); margin-bottom: 2px; }
.kb-category-link:hover { background: var(--bg); text-decoration: none; }
.kb-category-link--active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }

.kb-article-row { margin-bottom: 12px; }
.kb-article-row__title { font-size: 16px; font-weight: 700; }

.kb-form-card { max-width: 900px; }

/* Default typography for rendered article HTML -- authors can paste
   from Word/Google Docs or hand-edit markup, and this makes either
   look reasonable without per-article styling. */
.kb-article-body { line-height: 1.6; }
.kb-article-body h1, .kb-article-body h2, .kb-article-body h3,
.kb-article-body h4, .kb-article-body h5, .kb-article-body h6 {
  margin: 1.2em 0 0.5em; line-height: 1.3;
}
.kb-article-body h1:first-child, .kb-article-body h2:first-child, .kb-article-body h3:first-child { margin-top: 0; }
.kb-article-body p { margin: 0 0 1em; }
.kb-article-body ul, .kb-article-body ol { margin: 0 0 1em; padding-left: 1.5em; }
.kb-article-body li { margin-bottom: 0.3em; }
.kb-article-body blockquote { margin: 0 0 1em; padding: 8px 16px; border-left: 3px solid var(--accent); background: var(--bg); color: var(--text-muted); }
.kb-article-body pre { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; overflow-x: auto; font-family: var(--font-mono); font-size: 13px; }
.kb-article-body code { font-family: var(--font-mono); font-size: 0.9em; background: var(--bg); padding: 1px 5px; border-radius: 4px; }
.kb-article-body pre code { background: none; padding: 0; }
.kb-article-body img, .kb-article-body iframe, .kb-article-body video { max-width: 100%; border-radius: var(--radius); }
.kb-article-body table { border-collapse: collapse; width: 100%; margin: 0 0 1em; }
.kb-article-body th, .kb-article-body td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.kb-article-body th { background: var(--bg); }
.kb-article-body hr { border: none; border-top: 1px solid var(--border); margin: 1.5em 0; }
.kb-article-body a { text-decoration: underline; }

/* --- Knowledge Base editor --- */
.kb-editor { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 4px; }
.kb-editor__toolbar { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px; background: var(--bg); border-bottom: 1px solid var(--border); }
.kb-editor__btn { padding: 5px 10px; font-size: 12px; border: 1px solid var(--border); border-radius: 4px; background: var(--surface); color: var(--text); cursor: pointer; }
.kb-editor__btn:hover { border-color: var(--text-muted); }
.kb-editor__btn--source { margin-left: auto; font-weight: 600; }
.kb-editor__surface {
  min-height: 320px;
  padding: 16px;
  background: var(--surface);
  outline: none;
  line-height: 1.6;
}
.kb-editor__surface:empty::before { content: "Start writing, or paste from Word/Google Docs..."; color: var(--text-muted); }
.kb-editor-source { width: 100%; min-height: 320px; font-family: var(--font-mono); font-size: 13px; padding: 16px; border: none; border-top: 1px solid var(--border); }

/* --- Ticket attachments --- */
.attachment-list { display: flex; flex-direction: column; gap: 10px; }
.attachment-list--comment { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--border); }

.attachment-item { display: flex; align-items: center; gap: 12px; padding: 8px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.attachment-item__thumb-link { flex-shrink: 0; }
.attachment-item__thumb { width: 48px; height: 48px; object-fit: cover; border-radius: 4px; display: block; }
.attachment-item__icon {
  width: 48px; height: 48px; flex-shrink: 0; border-radius: 4px;
  background: var(--bg); color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; letter-spacing: 0.02em;
}
.attachment-item__info { flex: 1; min-width: 0; }
.attachment-item__info a { font-weight: 600; word-break: break-word; }
.attachment-item__remove { margin-left: auto; flex-shrink: 0; }

/* File-picker feedback (attachment-picker.js) */
.attachment-picker__list { margin-top: 6px; display: flex; flex-direction: column; gap: 2px; }
.attachment-picker__item { font-size: 12px; color: var(--text-muted); }

/* --- View original email --- */
.original-email__headers {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; font-family: var(--font-mono); font-size: 12px; white-space: pre-wrap; word-break: break-word;
}
.original-email__text {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; font-family: var(--font-mono); font-size: 13px; white-space: pre-wrap; word-break: break-word;
}
.original-email__frame {
  width: 100%; min-height: 500px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff;
}

/* --- Reporting: builder + results (Phase 10 revamp) ------------------ */

.report-builder-grid {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 24px;
  align-items: start;
}
@media (max-width: 900px) {
  .report-builder-grid { grid-template-columns: 1fr; }
}

.checkbox-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 10px;
  margin: 6px 0 14px;
}

.small-label { font-size: 11px; color: var(--text-muted); margin: 0 0 2px; }

.filter-row {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 10px;
  background: var(--bg);
}
.filter-row--pinned { background: var(--accent-soft); border-color: var(--accent); }
.filter-row__top { display: flex; align-items: center; justify-content: space-between; }
.filter-row__label { font-size: 12px; font-weight: 600; color: var(--text); }
.filter-row__control { margin-top: 6px; }
.filter-row__control select,
.filter-row__control input[type="text"] { width: 100%; }
.filter-row__remove {
  border: none; background: none; color: var(--text-muted); cursor: pointer;
  font-size: 16px; line-height: 1; padding: 0 2px;
}
.filter-row__remove:hover { color: var(--danger); }
.filter-row__checks { display: flex; flex-direction: column; gap: 4px; max-height: 160px; overflow-y: auto; }
.filter-row__checks .checkbox-row { margin: 0; }

.custom-date-range { display: none; gap: 8px; margin-top: 8px; }
.custom-date-range > div { flex: 1; }

.add-filter-bar { margin: 4px 0 18px; }
.add-filter-bar select { width: 100%; }

.badge-object-type { background: var(--text-muted); }

.report-number { font-size: 56px; font-weight: 700; color: var(--accent); line-height: 1; }

.spline-chart { width: 100%; height: auto; max-width: 680px; }
.spline-chart__label { font-size: 9px; fill: var(--text-muted); }
.spline-chart__value { font-size: 10px; fill: var(--text); font-weight: 600; }

.pie-chart-wrap { display: flex; align-items: center; gap: 28px; flex-wrap: wrap; }
.pie-chart { width: 180px; height: 180px; border-radius: 50%; flex-shrink: 0; }
.pie-legend { display: flex; flex-direction: column; gap: 6px; }
.pie-legend__row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.pie-legend__swatch { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }
.pie-legend__label { min-width: 120px; }
.pie-legend__count { color: var(--text-muted); font-size: 12px; }

/* --- Dashboard: customizable pinned-report widgets --------------------- */

.dashboard-widget-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
@media (max-width: 900px) {
  .dashboard-widget-grid { grid-template-columns: 1fr; }
}
.dashboard-widget { padding: 14px 16px; }
.dashboard-widget__header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.dashboard-widget__actions { display: flex; gap: 4px; }
.dashboard-widget__actions form { display: inline; }
.dashboard-widget__actions .btn-sm { padding: 2px 8px; }
.dashboard-widget__body { overflow: auto; }

/* --- Live-updating queues / reports ------------------------------------ */

.live-indicator {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--success);
}
.live-indicator::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: var(--success); display: inline-block;
  animation: live-pulse 2s ease-in-out infinite;
}
@keyframes live-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .35; }
}

.message-info { background: var(--accent-soft); color: var(--accent); }

/* --- Customer portal --------------------------------------------------- */

.portal-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  align-items: start;
}
@media (max-width: 900px) {
  .portal-grid { grid-template-columns: 1fr; }
}
.portal-section { padding: 24px; display: flex; flex-direction: column; }
.portal-section h2 { margin: 0 0 6px; }
.portal-section__cta { margin-top: 16px; align-self: flex-start; }
.portal-form-list { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.portal-form-list__item { text-align: left; justify-content: flex-start; }
