/* ==========================================================================
   Support Ticketing System — design system
   Self-contained, no build step (plain PHP + cPanel constraint). Tokens are
   CSS custom properties so Admin > Portal Settings branding (FR-SUP-071)
   can override --brand / --brand-dark per customer without touching this file.
   ========================================================================== */

:root {
  /* ERP.COM.BD brand blue, sampled from the company logo */
  --brand: #0075bf;
  --brand-dark: #005489;
  --brand-light: #e5f1f8;
  --ink: #0f172a;
  --ink-soft: #475569;
  --ink-faint: #94a3b8;
  --line: #e2e8f0;
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;

  --green: #16a34a; --green-bg: #f0fdf4;
  --amber: #d97706; --amber-bg: #fffbeb;
  --red: #dc2626;   --red-bg: #fef2f2;
  --blue: #2563eb;  --blue-bg: #eff6ff;
  --slate: #64748b; --slate-bg: #f1f5f9;
  --purple: #7c3aed; --purple-bg: #f5f3ff;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 1px 3px rgba(15,23,42,.08);
  --shadow-lg: 0 8px 24px rgba(15,23,42,.12);
  --sidebar-w: 240px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 8px; font-weight: 650; letter-spacing: -0.01em; }
p { margin: 0 0 10px; }
ul { margin: 0; padding: 0; list-style: none; }
table { border-collapse: collapse; width: 100%; }
img { max-width: 100%; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--surface);
  border-right: 1px solid var(--line); display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.brand-logo-img { display: block; height: 30px; width: auto; }
.sidebar-brand .logo-sub { font-size: 10px; color: var(--ink-faint); letter-spacing: .08em; text-transform: uppercase; margin-top: 3px; }

.nav-group { padding: 14px 12px 4px; }
.nav-group-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); padding: 0 10px 6px; font-weight: 600; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius-sm); color: var(--ink-soft); font-size: 13.5px; font-weight: 500; margin-bottom: 2px; }
.nav-link:hover { background: var(--surface-alt); text-decoration: none; color: var(--ink); }
.nav-link.active { background: var(--brand-light); color: var(--brand-dark); font-weight: 650; }
.nav-link .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .5; flex-shrink: 0; }
.nav-link .count { margin-left: auto; font-size: 11px; background: var(--surface-alt); color: var(--ink-soft); padding: 1px 7px; border-radius: 999px; font-weight: 600; }
.nav-link.active .count { background: var(--brand); color: #fff; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.topbar-title { font-size: 16px; font-weight: 650; }
.topbar-meta { font-size: 12px; color: var(--ink-faint); }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--brand); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 650; font-size: 12px; }

.content { padding: 22px 24px 60px; max-width: 1400px; width: 100%; margin: 0 auto; }

/* ---------- Cards / stat tiles ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-header { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.card-header h2, .card-header h3 { margin: 0; font-size: 14.5px; }
.card-body { padding: 18px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); transition: box-shadow .15s, transform .15s; }
.stat-card.stat-card-hover:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
a.stat-card-link { display: block; color: inherit; text-decoration: none; cursor: pointer; }
a.stat-card-link:hover { text-decoration: none; }
.stat-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.stat-label { font-size: 11.5px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .04em; font-weight: 650; margin-bottom: 6px; }
.stat-card-head .stat-label { margin-bottom: 0; }
.stat-value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: proportional-nums; }
.stat-value.stat-red { color: var(--red); }
.stat-value.stat-amber { color: var(--amber); }
.stat-value.stat-green { color: var(--green); }
.stat-sub { font-size: 11.5px; color: var(--ink-faint); margin-top: 4px; }

/* Stat tile icon chip — pairs a status color with an icon + label, never color alone */
.stat-icon { width: 32px; height: 32px; border-radius: 9px; display: flex; align-items: center; justify-content: center; font-size: 15px; flex-shrink: 0; }
.stat-icon-blue { background: var(--blue-bg); }
.stat-icon-amber { background: var(--amber-bg); }
.stat-icon-red { background: var(--red-bg); }
.stat-icon-green { background: var(--green-bg); }
.stat-icon-purple { background: var(--purple-bg); }
.stat-icon-slate { background: var(--slate-bg); }

/* Delta pill: direction is visual (arrow), "good/bad" is a separate signal from "up/down" */
.stat-delta { display: inline-flex; align-items: center; gap: 3px; font-size: 11px; font-weight: 650; margin-top: 6px; }
.stat-delta.is-good { color: var(--green); }
.stat-delta.is-bad { color: var(--red); }
.stat-delta.is-flat { color: var(--ink-faint); }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 650; border: 1px solid transparent; white-space: nowrap; }
.badge-new { background: var(--blue-bg); color: var(--blue); }
.badge-assigned { background: var(--purple-bg); color: var(--purple); }
.badge-progress { background: var(--amber-bg); color: var(--amber); }
.badge-pending { background: var(--slate-bg); color: var(--slate); }
.badge-escalated { background: var(--red-bg); color: var(--red); }
.badge-resolved { background: var(--green-bg); color: var(--green); }
.badge-closed { background: var(--surface-alt); color: var(--ink-faint); }
.badge-reopened { background: var(--amber-bg); color: var(--amber); }
.badge-rejected { background: var(--red-bg); color: var(--red); }
.badge-priority { font-weight: 700; border-width: 1px; border-style: solid; }
.badge-outline { background: transparent; border-color: var(--line); color: var(--ink-soft); }
.badge-breach { background: var(--red); color: #fff; }
.badge-oe { background: var(--amber-bg); color: var(--amber); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 16px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-size: 13.5px; font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--surface-alt); text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { filter: brightness(.92); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-alt); }
.btn-sm { padding: 5px 11px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
label { display: block; font-size: 12.5px; font-weight: 650; color: var(--ink-soft); margin-bottom: 5px; }
label .req { color: var(--red); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=datetime-local], input[type=file], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: 13.5px; font-family: inherit; color: var(--ink); background: var(--surface);
}
textarea { resize: vertical; min-height: 90px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-light); }
.help-text { font-size: 11.5px; color: var(--ink-faint); margin-top: 4px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }

/* ---------- Alerts / flash ---------- */
.alert { padding: 11px 14px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 16px; border: 1px solid transparent; }
.alert-success { background: var(--green-bg); color: #166534; border-color: #bbf7d0; }
.alert-error { background: var(--red-bg); color: #991b1b; border-color: #fecaca; }
.alert-info { background: var(--blue-bg); color: #1e40af; border-color: #bfdbfe; }
.alert-warn { background: var(--amber-bg); color: #92400e; border-color: #fde68a; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-faint); padding: 10px 14px; border-bottom: 1px solid var(--line); font-weight: 650; white-space: nowrap; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--line); font-size: 13.5px; vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--surface-alt); }
.table a.row-link { color: var(--ink); font-weight: 600; }
.table a.row-link:hover { color: var(--brand); }
.text-faint { color: var(--ink-faint); }
.text-sm { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filter-bar select, .filter-bar input { width: auto; min-width: 130px; }
.pill-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.pill-tab { padding: 6px 13px; border-radius: 999px; font-size: 12.5px; font-weight: 600; background: var(--surface-alt); color: var(--ink-soft); border: 1px solid transparent; }
.pill-tab.active { background: var(--brand); color: #fff; }

/* ---------- Ticket detail ---------- */
.ticket-header { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.ticket-grid { display: grid; grid-template-columns: 1fr 320px; gap: 18px; align-items: start; }
@media (max-width: 980px) { .ticket-grid { grid-template-columns: 1fr; } }

.thread { display: flex; flex-direction: column; gap: 12px; }
.msg { border-radius: var(--radius); padding: 12px 14px; border: 1px solid var(--line); background: var(--surface); }
.msg-public { border-left: 3px solid var(--blue); }
.msg-internal { background: var(--amber-bg); border-color: #fde68a; border-left: 3px solid var(--amber); }
.msg-system { background: var(--surface-alt); border-style: dashed; }
.msg-inbound_email { border-left: 3px solid var(--slate); }
.msg-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; font-size: 12px; }
.msg-author { font-weight: 650; color: var(--ink); }
.msg-tag { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; font-weight: 700; padding: 1px 7px; border-radius: 999px; margin-left: 6px; }
.msg-tag.public { background: var(--blue-bg); color: var(--blue); }
.msg-tag.internal { background: var(--amber); color: #fff; }
.msg-body { white-space: pre-wrap; font-size: 13.5px; }
.msg-time { color: var(--ink-faint); }
.msg-attachments { margin-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; }
.attachment-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; background: var(--surface-alt); padding: 4px 10px; border-radius: 999px; color: var(--ink-soft); }

.reply-box { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 14px; margin-top: 14px; }
.reply-actions { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; flex-wrap: wrap; gap: 8px; }
.reply-actions-left { display: flex; gap: 8px; flex-wrap: wrap; }

.side-panel { display: flex; flex-direction: column; gap: 14px; }
.sla-row { display: flex; justify-content: space-between; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.sla-row:last-child { border-bottom: none; }
.progress { height: 6px; background: var(--surface-alt); border-radius: 999px; overflow: hidden; margin-top: 4px; }
.progress-bar { height: 100%; border-radius: 999px; }
.kv { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--ink-faint); }
.kv .v { font-weight: 600; text-align: right; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tab { padding: 9px 14px; font-size: 13px; font-weight: 600; color: var(--ink-soft); border-bottom: 2px solid transparent; }
.tab.active { color: var(--brand); border-color: var(--brand); }

.timeline { display: flex; flex-direction: column; gap: 0; }
.timeline-item { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.timeline-item:last-child { border-bottom: none; }
.timeline-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--brand); margin-top: 5px; flex-shrink: 0; }

/* ---------- Login pages ---------- */
.auth-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(160deg, var(--brand-dark), var(--brand) 60%, #38a3e0); padding: 20px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: 16px; padding: 32px 30px; box-shadow: var(--shadow-lg); }
.auth-card .brand-logo-img { height: 40px; margin-bottom: 16px; }
.auth-card h1 { font-size: 19px; margin-bottom: 4px; }
.auth-card .sub { color: var(--ink-faint); font-size: 13px; margin-bottom: 22px; }
.auth-footer { text-align: center; margin-top: 18px; font-size: 12.5px; color: var(--ink-faint); }
.demo-creds { margin-top: 18px; padding: 10px 12px; background: var(--surface-alt); border-radius: var(--radius-sm); font-size: 11.5px; color: var(--ink-soft); }

/* ---------- Portal theme (customer-facing) ---------- */
.portal-body { background: var(--bg); }
.portal-header { background: var(--surface); border-bottom: 1px solid var(--line); padding: 14px 24px; display: flex; align-items: center; justify-content: space-between; }
.portal-shell { display: flex; min-height: 100vh; }
.portal-content { flex: 1; padding: 22px 24px 60px; max-width: 1200px; margin: 0 auto; width: 100%; }
.kb-suggestion { display: block; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 8px; background: var(--surface); }
.kb-suggestion:hover { border-color: var(--brand); text-decoration: none; }
.kb-suggestion .title { font-weight: 650; font-size: 13px; color: var(--ink); }
.kb-suggestion .excerpt { font-size: 12px; color: var(--ink-faint); margin-top: 2px; }
.deflect-box { border: 1px solid #bbf7d0; background: var(--green-bg); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; }

.csat-stars { display: flex; gap: 6px; font-size: 26px; }
.csat-stars button { background: none; border: none; cursor: pointer; color: var(--line); padding: 0; }
.csat-stars button.selected, .csat-stars button:hover { color: var(--amber); }

.empty-state { text-align: center; padding: 50px 20px; color: var(--ink-faint); }
.empty-state .icon { font-size: 34px; margin-bottom: 10px; }

/* ---------- Modal (replaces the old position:absolute popup pattern —
   that broke inside scrollable tables and on narrow screens; a fixed,
   viewport-centered overlay can't be clipped by an ancestor's overflow
   and reflows to a full-width sheet on mobile instead of overlapping content) ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .55); z-index: 200; display: none; align-items: center; justify-content: center; padding: 20px; }
.modal-overlay.open { display: flex; }
.modal-box { background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 420px; max-height: 85vh; overflow-y: auto; box-shadow: var(--shadow-lg); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); border-radius: var(--radius) var(--radius) 0 0; }
.modal-header h3 { margin: 0; font-size: 14.5px; }
.modal-close { background: none; border: none; font-size: 20px; line-height: 1; color: var(--ink-faint); cursor: pointer; padding: 4px; }
.modal-close:hover { color: var(--ink); }
.modal-body { padding: 18px; }
@media (max-width: 480px) {
  .modal-box { max-width: 100%; max-height: 90vh; }
}

/* ---------- Dashboard: volume-by-day bar chart ----------
   Single series (ticket volume) → one hue, no legend needed. Today reads at
   full strength; the rest recede via opacity, not a second color. */
.vol-chart { display: flex; align-items: flex-end; gap: 6px; height: 100px; border-bottom: 1px solid var(--line); padding-bottom: 0; }
.vol-bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.vol-bar-value { font-size: 10.5px; color: var(--ink-faint); font-weight: 650; margin-bottom: 3px; height: 13px; }
.vol-bar { width: 100%; max-width: 22px; border-radius: 4px 4px 0 0; background: var(--brand); opacity: .45; transition: opacity .15s; }
.vol-bar-col.is-today .vol-bar { opacity: 1; }
.vol-bar-col.is-today .vol-bar-value { color: var(--ink); }
.vol-bar-col:hover .vol-bar { opacity: .8; }
.vol-bar-col.is-today:hover .vol-bar { opacity: 1; }
.vol-bar-day { font-size: 10px; color: var(--ink-faint); margin-top: 6px; font-weight: 600; }
.vol-bar-col.is-today .vol-bar-day { color: var(--brand); }

/* ---------- Dashboard: category magnitude list ----------
   Nominal categories (no natural order) → one fixed hue for every bar,
   never a value-ramp on the bars themselves. */
.mini-bar-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; }
a.mini-bar-row { color: inherit; text-decoration: none; border-radius: 6px; margin: 0 -6px; padding: 7px 6px; }
a.mini-bar-row:hover { background: var(--surface-alt); text-decoration: none; }
a.mini-bar-row:hover .mini-bar-label { color: var(--brand); }
.mini-bar-label { font-size: 12.5px; color: var(--ink-soft); flex: 0 0 108px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-bar-track { flex: 1; height: 6px; background: var(--blue-bg); border-radius: 999px; overflow: hidden; }
.mini-bar-fill { height: 100%; background: var(--blue); border-radius: 999px; }
.mini-bar-value { font-size: 12px; font-weight: 650; flex: 0 0 20px; text-align: right; }

/* ---------- Kanban board ---------- */
.kanban-board { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 10px; align-items: flex-start; }
.kanban-col { flex: 0 0 270px; width: 270px; background: var(--surface-alt); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 220px); }
.kanban-col.drag-over { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-light); }
.kanban-col.drag-reject { border-color: var(--red); box-shadow: 0 0 0 3px var(--red-bg); }
.kanban-col-head { display: flex; align-items: center; justify-content: space-between; padding: 11px 13px; font-size: 12.5px; font-weight: 700; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface-alt); border-radius: var(--radius) var(--radius) 0 0; }
.kanban-col-head .count { background: var(--surface); border: 1px solid var(--line); color: var(--ink-soft); font-size: 11px; padding: 1px 8px; border-radius: 999px; font-weight: 650; }
.kanban-col-body { padding: 10px; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }
.kanban-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; box-shadow: var(--shadow); cursor: grab; }
.kanban-card[draggable="true"]:active { cursor: grabbing; }
.kanban-card[draggable="false"] { cursor: default; opacity: .85; }
.kanban-card.dragging { opacity: .4; }
.kanban-card-subject { display: block; font-size: 13px; font-weight: 600; color: var(--ink); margin: 4px 0 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kanban-card-subject:hover { color: var(--brand); text-decoration: none; }
.kanban-empty { text-align: center; color: var(--ink-faint); font-size: 12px; padding: 18px 0; }

/* Utility */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mb-0 { margin-bottom: 0; }
.w-full { width: 100%; }

@media (max-width: 900px) {
  .sidebar { position: fixed; z-index: 50; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  .content, .portal-content { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
}
