/* =========================================================
   Helpdesk — UI stylesheet
   Palette: deep-indigo sidebar, slate canvas, indigo primary,
   status-driven accent colours.
   ========================================================= */

:root {
  --bg:          #f1f4f9;
  --surface:     #ffffff;
  --surface-2:   #f8fafc;
  --border:      #e5e9f0;
  --ink:         #1e2537;
  --ink-soft:    #5b6580;
  --ink-faint:   #939db4;

  --primary:     #1a56db;
  --primary-600: #1747b8;
  --primary-tint:#e8f0fe;

  --sidebar:     #0b1b3f;
  --sidebar-2:   #14295c;
  --sidebar-ink: #b6c3e0;
  --sidebar-active:#ffffff;

  --open:     #2563eb;  --open-bg:     #e7efff;
  --pending:  #d97706;  --pending-bg:  #fdf1dd;
  --resolved: #16a34a;  --resolved-bg: #e5f6ec;
  --closed:   #64748b;  --closed-bg:   #eef1f6;
  --waiting_reply: #d97706; --waiting_reply-bg: #fdf1dd;
  --replied:        #0891b2; --replied-bg:        #e0f7fa;
  --in_progress:    #7c3aed; --in_progress-bg:    #f1e9fe;
  --on_hold:        #b45309; --on_hold-bg:        #fdedd6;
  --reopened:       #dc2626; --reopened-bg:       #fde8e8;

  --radius:   12px;
  --radius-sm:8px;
  --shadow:   0 1px 2px rgba(20,25,45,.04), 0 6px 20px rgba(20,25,45,.05);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

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

a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }

/* ---------- App shell ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: var(--sidebar);
  color: var(--sidebar-ink);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 11px;
  padding: 22px 22px 20px;
  color: #fff; font-weight: 700; font-size: 17px;
  letter-spacing: -.02em;
}
.brand .logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, #3b82f6, #1a56db);
  display: grid; place-items: center; color: #fff;
  box-shadow: 0 4px 12px rgba(26,86,219,.45);
}
.nav-section {
  padding: 6px 14px;
  font-size: 11px; font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: #6f83b3; margin-top: 14px;
}
.nav { padding: 4px 12px; display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--sidebar-ink); font-weight: 500;
  transition: background .12s, color .12s;
}
.nav a svg { width: 18px; height: 18px; opacity: .85; flex-shrink: 0; }
.nav a:hover { background: var(--sidebar-2); color: #fff; }
.nav a.active { background: var(--primary); color: #fff; box-shadow: 0 4px 14px rgba(26,86,219,.4); }
.nav a.active svg { opacity: 1; }
.nav .count {
  margin-left: auto; font-size: 12px; font-weight: 600;
  background: rgba(255,255,255,.14); color: #fff;
  padding: 1px 8px; border-radius: 999px;
}
.sidebar-foot {
  margin-top: auto; padding: 16px; border-top: 1px solid rgba(255,255,255,.07);
  display: flex; align-items: center; gap: 11px;
}

/* ---------- Main column ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 66px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 18px;
  padding: 0 26px; position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 18px; }
.topbar .subtitle { color: var(--ink-faint); font-size: 13px; }
.search {
  margin-left: auto; position: relative; width: 300px; max-width: 40vw;
}
.search input {
  width: 100%; padding: 9px 14px 9px 38px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface-2); font-family: inherit; font-size: 14px;
}
.search svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--ink-faint); }
.search input:focus { outline: none; border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px var(--primary-tint); }

.content { padding: 26px; flex: 1; }

/* ---------- Avatar chip ---------- */
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary-tint); color: var(--primary-600);
  display: grid; place-items: center; font-weight: 650; font-size: 13px;
  flex-shrink: 0;
}
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.avatar.dark { background: rgba(255,255,255,.12); color: #fff; }
.user-meta { line-height: 1.25; }
.user-meta .name { color: #fff; font-weight: 600; font-size: 13.5px; }
.user-meta .role { color: var(--sidebar-ink); font-size: 12px; }

/* ---------- Stat cards ---------- */
.stat-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 18px; margin-bottom: 24px;
}
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow);
}
.stat .label { color: var(--ink-soft); font-size: 13px; font-weight: 500; }
.stat .value { font-size: 30px; font-weight: 700; letter-spacing: -.02em; margin-top: 6px; }
.stat .foot { font-size: 12.5px; color: var(--ink-faint); margin-top: 4px; }
.stat .icon {
  float: right; width: 42px; height: 42px; border-radius: 11px;
  display: grid; place-items: center;
}
.stat .icon svg { width: 21px; height: 21px; }
.i-open     { background: var(--open-bg);     color: var(--open); }
.i-pending  { background: var(--pending-bg);  color: var(--pending); }
.i-resolved { background: var(--resolved-bg); color: var(--resolved); }
.i-total    { background: var(--primary-tint);color: var(--primary-600); }

/* ---------- Panel / table ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.panel-head h3 { font-size: 15px; }
.panel-head .spacer { margin-left: auto; }

table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-soft);
  padding: 12px 20px; background: var(--surface-2);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody td { padding: 13px 20px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: var(--surface-2); }
.ticket-ref { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 12.5px; color: var(--ink-faint); }
.ticket-subj { font-weight: 600; color: var(--ink); }
.cell-sub { display: block; font-size: 12.5px; color: var(--ink-faint); }

/* ---------- Badges ---------- */
.badge, .prio {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-open     { color: var(--open);     background: var(--open-bg); }
.badge-pending  { color: var(--pending);  background: var(--pending-bg); }
.badge-resolved { color: var(--resolved); background: var(--resolved-bg); }
.badge-closed   { color: var(--closed);   background: var(--closed-bg); }
.badge-waiting_reply { color: var(--waiting_reply); background: var(--waiting_reply-bg); }
.badge-replied        { color: var(--replied);        background: var(--replied-bg); }
.badge-in_progress    { color: var(--in_progress);    background: var(--in_progress-bg); }
.badge-on_hold        { color: var(--on_hold);        background: var(--on_hold-bg); }
.badge-reopened       { color: var(--reopened);       background: var(--reopened-bg); }
.prio-low    { color: #64748b; background: #eef1f6; }
.prio-medium { color: #2563eb; background: #e7efff; }
.prio-high   { color: #d97706; background: #fdf1dd; }
.prio-urgent { color: #dc2626; background: #fdeaea; }
.cat-dot { display:inline-block; width:9px; height:9px; border-radius:50%; margin-right:7px; vertical-align:middle; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: inherit; font-size: 14px; font-weight: 600;
  padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid transparent; cursor: pointer; transition: .13s;
  background: var(--surface-2); color: var(--ink); border-color: var(--border);
}
.btn:hover { background: #eef1f6; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-600); }
.btn-danger  { background: #fef2f2; color: #dc2626; border-color: #fbd5d5; }
.btn-danger:hover { background: #fde3e3; }
.btn-success { background: #f0fdf4; color: #16a34a; border-color: #bbf7d0; }
.btn-success:hover { background: #dcfce7; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; justify-content: center; }

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--ink); }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 13px; font-family: inherit; font-size: 14.5px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: #fff; color: var(--ink);
}
.field textarea { resize: vertical; min-height: 120px; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-tint);
}
.field .hint { font-size: 12px; color: var(--ink-faint); margin-top: 5px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ---------- Alerts ---------- */
.alert { padding: 12px 15px; border-radius: var(--radius-sm); font-size: 14px; margin-bottom: 18px; border: 1px solid transparent; }
.alert-error   { background: #fdeaea; color: #b42318; border-color: #f6c9c9; }
.alert-success { background: #e5f6ec; color: #166534; border-color: #bfe6cc; }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 22px; }
.page-head .spacer { margin-left: auto; }
.page-head p { color: var(--ink-soft); margin-top: 2px; }

/* ---------- Ticket conversation ---------- */
.thread { display: flex; flex-direction: column; gap: 16px; }
.msg { display: flex; gap: 13px; }
.msg .bubble { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; flex: 1; box-shadow: var(--shadow); }
.msg .bubble .head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.msg .bubble .who { font-weight: 650; }
.msg .bubble .when { color: var(--ink-faint); font-size: 12.5px; margin-left: auto; }
.msg.internal .bubble { background: #fffbeb; border-color: #fde9b8; }
.tag-internal { font-size: 11px; font-weight: 700; color: #b45309; background: #fef3c7; padding: 2px 8px; border-radius: 6px; }

/* Custom fields shown inline at the top of a ticket's opening message */
.ticket-fields { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.ticket-fields li { font-size: 13.5px; line-height: 1.5; }
.ticket-fields .k { color: var(--ink-faint); }
.ticket-fields .v { color: var(--ink); font-weight: 650; }
.ticket-desc { padding-top: 10px; border-top: 1px solid var(--border); }
.ticket-fields + .ticket-desc { margin-top: 2px; }

.detail-grid { display: grid; grid-template-columns: 1fr 300px; gap: 22px; align-items: start; }
.meta-list { list-style: none; }
.meta-list li { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.meta-list li:last-child { border-bottom: none; }
.meta-list .k { color: var(--ink-soft); }
.link-btn { background: none; border: none; padding: 0; color: var(--primary); font-size: 13px; cursor: pointer; text-decoration: underline; }
.link-btn:hover { opacity: .8; }

/* ---------- Login ---------- */
.auth {
  min-height: 100vh; display: grid; grid-template-columns: 1.05fr .95fr;
}
.auth-aside {
  background: linear-gradient(150deg, #0b1b3f 0%, #12336e 55%, #1a56db 100%);
  color: #fff; padding: 54px; display: flex; flex-direction: column; position: relative; overflow: hidden;
}
.auth-aside::after {
  content: ""; position: absolute; right: -120px; bottom: -120px;
  width: 360px; height: 360px; border-radius: 50%;
  background: radial-gradient(circle, rgba(56,163,245,.5), transparent 70%);
}
.auth-aside .brand { padding: 0; margin-bottom: auto; }
.auth-aside h2 { font-size: 34px; line-height: 1.2; letter-spacing: -.02em; max-width: 15ch; }
.auth-aside p { color: rgba(255,255,255,.75); margin-top: 16px; max-width: 40ch; }
.auth-points { margin-top: 30px; display: flex; flex-direction: column; gap: 13px; }
.auth-points div { display: flex; align-items: center; gap: 11px; color: rgba(255,255,255,.9); font-size: 14.5px; }
.auth-points svg { width: 20px; height: 20px; color: #7dd3fc; flex-shrink: 0; }

/* ---------- Animated helpdesk scene (login aside) ---------- */
.auth-scene {
  position: relative;
  flex: 1;                 /* fills the blank space between brand and heading */
  min-height: 260px;
  margin: 30px 0;
  display: grid;
  place-items: center;
}

/* pulsing concentric rings */
.scene-ring {
  position: absolute;
  border-radius: 50%;
  border: 1px solid rgba(125, 211, 252, .35);
  animation: scene-pulse 4s ease-out infinite;
}
.scene-ring-1 { width: 120px; height: 120px; animation-delay: 0s; }
.scene-ring-2 { width: 190px; height: 190px; animation-delay: 1.3s; }
.scene-ring-3 { width: 260px; height: 260px; animation-delay: 2.6s; }
@keyframes scene-pulse {
  0%   { transform: scale(.6); opacity: 0; }
  30%  { opacity: .9; }
  100% { transform: scale(1.15); opacity: 0; }
}

/* central support badge */
.scene-core {
  position: relative;
  z-index: 2;
  width: 92px; height: 92px;
  border-radius: 24px;
  display: grid; place-items: center;
  color: #fff;
  background: linear-gradient(145deg, #1a56db, #38a3f5);
  box-shadow: 0 18px 40px rgba(26, 86, 219, .45), inset 0 1px 0 rgba(255,255,255,.25);
  animation: scene-float 5s ease-in-out infinite;
}
.scene-core svg { width: 44px; height: 44px; }
@keyframes scene-float {
  0%,100% { transform: translateY(0); }
  50%     { transform: translateY(-10px); }
}

/* floating ticket / status cards */
.scene-card {
  position: absolute; z-index: 3;
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px;
  border-radius: 12px;
  background: rgba(255,255,255,.10);
  border: 1px solid rgba(255,255,255,.16);
  backdrop-filter: blur(6px);
  box-shadow: 0 10px 24px rgba(0,0,0,.22);
  animation: scene-bob 6s ease-in-out infinite;
}
.scene-card .dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.dot-open     { background: #f59e0b; box-shadow: 0 0 0 0 rgba(245,158,11,.6); animation: scene-blink 2.4s ease-out infinite; }
.dot-progress { background: #38bdf8; box-shadow: 0 0 0 0 rgba(56,189,248,.6); animation: scene-blink 2.4s ease-out infinite .8s; }
.dot-done     { background: #34d399; box-shadow: 0 0 0 0 rgba(52,211,153,.6); animation: scene-blink 2.4s ease-out infinite 1.6s; }
@keyframes scene-blink {
  0%   { box-shadow: 0 0 0 0 currentColor; }
  70%  { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
.scene-card .bars { display: flex; flex-direction: column; gap: 4px; }
.scene-card .bars i { display: block; height: 4px; border-radius: 2px; background: rgba(255,255,255,.55); }
.scene-card .bars i:first-child { width: 46px; }
.scene-card .bars i:last-child  { width: 30px; background: rgba(255,255,255,.3); }

.scene-card-1 { top: 8%;  left: 4%;  animation-delay: 0s;   }
.scene-card-2 { top: 30%; right: 2%; animation-delay: 1.5s; }
.scene-card-3 { bottom: 10%; left: 12%; animation-delay: 3s; }
@keyframes scene-bob {
  0%,100% { transform: translateY(0) rotate(-1deg); }
  50%     { transform: translateY(-14px) rotate(1deg); }
}

/* drifting sparks */
.scene-spark {
  position: absolute;
  width: 5px; height: 5px; border-radius: 50%;
  background: rgba(125, 211, 252, .8);
  animation: scene-drift 7s linear infinite;
}
.scene-spark-1 { left: 18%; bottom: 0;  animation-delay: 0s;   }
.scene-spark-2 { left: 70%; bottom: 0;  animation-delay: 2s;   }
.scene-spark-3 { left: 45%; bottom: 0;  animation-delay: 3.5s; }
.scene-spark-4 { left: 88%; bottom: 0;  animation-delay: 5s;   }
@keyframes scene-drift {
  0%   { transform: translateY(0) scale(1);   opacity: 0; }
  15%  { opacity: 1; }
  85%  { opacity: .6; }
  100% { transform: translateY(-230px) scale(.4); opacity: 0; }
}

/* respect users who prefer less motion */
@media (prefers-reduced-motion: reduce) {
  .scene-ring, .scene-core, .scene-card, .dot, .scene-spark { animation: none; }
  .scene-spark { opacity: .6; }
}

.auth-main { display: grid; place-items: center; padding: 40px; background: var(--surface); }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h1 { font-size: 25px; }
.auth-card > p { color: var(--ink-soft); margin: 6px 0 26px; }
.demo-note { margin-top: 22px; padding: 13px 15px; background: var(--surface-2); border: 1px dashed var(--border); border-radius: var(--radius-sm); font-size: 12.5px; color: var(--ink-soft); }
.demo-note b { color: var(--ink); }
.demo-note code { font-family: ui-monospace, Menlo, monospace; background:#fff; border:1px solid var(--border); padding:1px 5px; border-radius:5px; }

/* ---------- Misc ---------- */
.empty { text-align: center; padding: 56px 20px; color: var(--ink-faint); }
.empty svg { width: 42px; height: 42px; margin-bottom: 10px; opacity: .5; }
.flex { display: flex; align-items: center; gap: 10px; }
.mt-0{margin-top:0}.mb-0{margin-bottom:0}
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar select { padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; font-family: inherit; font-size: 14px; }
.menu-toggle { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1000px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } .detail-grid { grid-template-columns: 1fr; } }
@media (max-width: 820px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 60; transform: translateX(-100%); transition: transform .22s; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .sidebar.open { transform: none; }
  .menu-toggle { display: inline-grid; place-items: center; width: 40px; height: 40px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; cursor: pointer; }
  .search { display: none; }
  .auth { grid-template-columns: 1fr; } .auth-aside { display: none; }
  .row-2 { grid-template-columns: 1fr; }
}
@media (max-width: 560px) { .stat-grid { grid-template-columns: 1fr; } .content { padding: 18px; } }

/* ---------- Additions for the multi-role portal ---------- */
.sidebar { overflow-y: auto; }
.src-tag { display: inline-block; margin-left: 8px; font-size: 10.5px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; color: #0e7490; background: #e0f7fb; padding: 1px 7px; border-radius: 5px; vertical-align: middle; }
.role-tag { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; }
.role-super_admin { background: #fee2e2; color: #b91c1c; }
.role-admin       { background: #e0e7ff; color: #3730a3; }
.role-user        { background: #eef1f6; color: #475569; }
.role-customer    { background: #dcfce7; color: #166534; }
.pager { display: flex; align-items: center; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); color: var(--ink-soft); font-size: 13px; }
.pager .spacer { margin-left: auto; }
.perm-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.perm-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.perm-card h4 { font-size: 15px; margin-bottom: 8px; }
.perm-card ul { margin: 0 0 0 18px; color: var(--ink-soft); font-size: 13.5px; }
.perm-card li { margin: 3px 0; }
@media (max-width: 1000px) { .perm-grid { grid-template-columns: 1fr; } }
