/* ============================================
   HelpDesk — Dark Theme
   ============================================ */

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #222536;
  --border: #2e3347;
  --text: #e8eaf0;
  --text-muted: #7c82a0;
  --primary: #4f8ef7;
  --primary-hover: #3b7af5;
  --primary-light: #1a2540;
  --success: #34d399;
  --success-bg: #0d2b22;
  --danger: #f87171;
  --danger-bg: #2b1212;
  --warning: #fbbf24;
  --warning-bg: #2b2010;
  --info: #38bdf8;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
  --shadow-lg: 0 4px 24px rgba(0,0,0,.5);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'Cascadia Code', 'Fira Code', monospace;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
}

/* ---- Navbar ---- */
.navbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.navbar-brand a {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  letter-spacing: -.02em;
}

.navbar-menu {
  display: flex;
  align-items: center;
  gap: .25rem;
}

.nav-link {
  padding: .4rem .8rem;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 13px;
  transition: all .15s;
}
.nav-link:hover, .nav-link.active { color: var(--primary); background: var(--primary-light); }

.btn-new {
  background: var(--primary);
  color: #fff !important;
  border-radius: var(--radius);
  padding: .4rem .9rem;
  font-weight: 600;
}
.btn-new:hover { background: var(--primary-hover); }

.nav-user {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-left: .75rem;
  padding-left: .75rem;
  border-left: 1px solid var(--border);
}

.user-badge {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.btn-change-password {
  font-size: 12px;
  color: var(--text-muted);
  text-decoration: none;
  padding: .3rem .7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: all .15s;
}
.btn-change-password:hover { color: var(--primary); border-color: var(--primary); }

.btn-logout {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .3rem .7rem;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-muted);
  transition: all .15s;
}
.btn-logout:hover { color: var(--danger); border-color: var(--danger); }

/* ---- Main ---- */
.main-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem;
}

/* ---- Alerts ---- */
.alert {
  padding: .75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 13px;
  font-weight: 500;
}
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid #065f46; }
.alert-error   { background: var(--danger-bg);  color: var(--danger);  border: 1px solid #7f1d1d; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1rem;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  border: none;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-ghost    { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-full     { width: 100%; justify-content: center; padding: .65rem; font-size: 14px; }
.btn-sm       { padding: .3rem .65rem; font-size: 12px; }

/* ---- Page Header ---- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}
.page-header h1 { font-size: 1.4rem; font-weight: 700; }

/* ---- Stats Grid ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-number {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1;
  margin-bottom: .25rem;
}

.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: .05em; }

.stat-open .stat-number     { color: var(--primary); }
.stat-progress .stat-number { color: var(--warning); }
.stat-resolved .stat-number { color: var(--success); }
.stat-critical .stat-number { color: var(--danger); }

/* ---- Section ---- */
.section { margin-bottom: 2rem; }
.section h2 { font-size: 1rem; font-weight: 700; margin-bottom: 1rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }

/* ---- Table ---- */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  margin-bottom: 1rem;
}

.table th {
  background: var(--surface-2);
  padding: .65rem 1rem;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.table td {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--surface-2); }
.table a { color: var(--primary); text-decoration: none; font-weight: 500; }
.table a:hover { text-decoration: underline; }

/* ---- Badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: .2rem .55rem;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  text-transform: capitalize;
  white-space: nowrap;
}

.badge-open        { background: #1e3a5f; color: #93c5fd; }
.badge-pending     { background: #3b2f0a; color: #fde68a; }
.badge-in_progress { background: #3b1f0a; color: #fdba74; }
.badge-resolved    { background: #0d2e1a; color: #6ee7b7; }
.badge-closed      { background: #1e2130; color: #7c82a0; }

.badge-priority-low      { background: #1e2130; color: #7c82a0; }
.badge-priority-medium   { background: #1e3a5f; color: #93c5fd; }
.badge-priority-high     { background: #3b1f0a; color: #fdba74; }
.badge-priority-critical { background: #3b0f0f; color: #fca5a5; }

.badge-role-admin  { background: #2e1a47; color: #c4b5fd; }
.badge-role-agent  { background: #1e3a5f; color: #93c5fd; }
.badge-role-user   { background: #1e2130; color: #7c82a0; }

.badge-active   { background: var(--success-bg); color: var(--success); }
.badge-inactive { background: var(--danger-bg);  color: var(--danger); }
.badge-internal { background: #3b2f0a; color: #fde68a; font-size: 10px; }
.badge-category { background: #1e2130; color: #7c82a0; }

/* ---- Forms ---- */
.form-container { max-width: 680px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; box-shadow: var(--shadow); }

.form-group { margin-bottom: 1.25rem; }
.form-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: .4rem; color: var(--text); }
.required   { color: var(--danger); }

.form-input {
  width: 100%;
  padding: .55rem .8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--font);
  color: var(--text);
  background: var(--surface-2);
  transition: border-color .15s, box-shadow .15s;
  appearance: none;
}
.form-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,142,247,.15); }
.form-input::placeholder { color: #4a5070; }
.form-input-sm { width: auto; padding: .35rem .65rem; }

.form-textarea { resize: vertical; min-height: 120px; }
.form-hint     { font-size: 11px; color: var(--text-muted); margin-top: .3rem; display: block; }

.form-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.form-row-actions { align-items: end; }

.form-actions { display: flex; gap: .75rem; margin-top: 1.5rem; }

.checkbox-group .checkbox-label { display: flex; align-items: center; gap: .5rem; font-size: 13px; font-weight: 500; cursor: pointer; }

/* ---- Filter bar ---- */
.filter-bar {
  display: flex;
  gap: .5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.filter-search { flex: 1; min-width: 200px; }
.filter-select { width: auto; }

/* ---- Ticket detail ---- */
.ticket-detail { max-width: 900px; }
.ticket-header { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem 1.5rem; margin-bottom: 1.25rem; box-shadow: var(--shadow); }
.ticket-title-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: .75rem; }
.ticket-title-row h1 { font-size: 1.2rem; font-weight: 700; }
.ticket-badges { display: flex; gap: .4rem; flex-wrap: wrap; }
.ticket-meta { display: flex; gap: .75rem; flex-wrap: wrap; font-size: 12px; color: var(--text-muted); }

.agent-controls { display: flex; gap: .75rem; margin-bottom: 1rem; }
.inline-form { display: flex; align-items: center; gap: .5rem; }

.ticket-thread { display: flex; flex-direction: column; gap: .75rem; margin-bottom: 1.5rem; }

.reply-item {
  display: flex;
  gap: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
}

.reply-agent    { border-left: 3px solid var(--primary); }
.reply-internal { border-left: 3px solid var(--warning); background: #1e1a0a; }

.reply-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.reply-body { flex: 1; min-width: 0; }
.reply-header { display: flex; align-items: center; gap: .6rem; margin-bottom: .5rem; flex-wrap: wrap; }
.reply-header strong { font-size: 13px; }
.reply-role { font-size: 11px; color: var(--primary); font-weight: 600; text-transform: uppercase; }
.reply-time { font-size: 11px; color: var(--text-muted); margin-left: auto; }
.reply-content { font-size: 13px; line-height: 1.7; white-space: pre-wrap; word-wrap: break-word; }

.reply-form { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); }
.reply-form h3 { font-size: 14px; font-weight: 700; margin-bottom: 1rem; }

.reset-target {
  background: var(--primary-light);
  border: 1px solid #1e3a5f;
  border-radius: var(--radius);
  padding: .75rem 1rem;
  margin-bottom: 1.25rem;
  font-size: 13px;
}

.closed-notice { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; text-align: center; color: var(--text-muted); font-size: 13px; }
.closed-notice a { color: var(--primary); }

/* ---- Audit log ---- */
.audit-list { display: flex; flex-direction: column; gap: .4rem; }
.audit-item { display: flex; gap: 1rem; align-items: center; padding: .5rem .75rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); font-size: 12px; flex-wrap: wrap; }
.audit-action { font-weight: 600; font-family: var(--font-mono); color: var(--primary); }
.audit-user   { color: var(--text); }
.audit-time   { color: var(--text-muted); margin-left: auto; }
.audit-ip     { color: var(--text-muted); font-family: var(--font-mono); }

/* ---- Empty state ---- */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  margin: 1rem 0;
}
.empty-icon { font-size: 2.5rem; margin-bottom: .75rem; opacity: .5; }
.empty-state p { margin-bottom: 1.25rem; font-size: 15px; }
.empty-state .btn { display: inline-block; }

/* ---- Auth / Login ---- */
.auth-body { display: flex; min-height: 100vh; align-items: center; justify-content: center; background: radial-gradient(ellipse at 50% 0%, #1a2540 0%, #0f1117 60%); }
.auth-container { width: 100%; max-width: 400px; padding: 1.5rem; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 2.5rem 2rem; box-shadow: var(--shadow-lg); }
.auth-logo { font-size: 2.5rem; text-align: center; margin-bottom: .5rem; }
.auth-title { text-align: center; font-size: 1.4rem; font-weight: 800; margin-bottom: .25rem; }
.auth-subtitle { text-align: center; color: var(--text-muted); font-size: 13px; margin-bottom: 1.5rem; }

/* ---- Footer ---- */
.footer { text-align: center; padding: 1.5rem; font-size: 11px; color: var(--text-muted); border-top: 1px solid var(--border); margin-top: 2rem; }

/* ---- Code ---- */
code { font-family: var(--font-mono); font-size: 12px; background: var(--surface-2); padding: .15rem .4rem; border-radius: 3px; color: var(--primary); }

/* ---- Priority row highlight ---- */
.priority-row-critical td:first-child { border-left: 3px solid var(--danger); }
.priority-row-high td:first-child     { border-left: 3px solid var(--warning); }

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row   { grid-template-columns: 1fr; }
  .ticket-title-row { flex-direction: column; }
  .navbar-menu { gap: .1rem; }
  .nav-user { display: none; }
}
/* ---- Navbar layout ---- */
.navbar-links {
  display: flex;
  align-items: center;
  gap: .25rem;
  margin-left: 1rem;
}
.navbar-right {
  display: flex;
  align-items: center;
  gap: .25rem;
  margin-left: auto;
}
.nav-user-toggle { gap: .5rem; }
.caret { font-size: 9px; opacity: .5; }

/* ---- Dropdowns ---- */
.nav-dropdown { position: relative; }

.nav-dropdown-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: .4rem .75rem;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: .4rem;
  transition: color .15s, background .15s;
  font-family: var(--font);
}
.nav-dropdown-toggle:hover,
.nav-dropdown.open .nav-dropdown-toggle {
  color: var(--primary);
  background: var(--primary-light);
}

.user-avatar {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.user-name { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 175px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  overflow: hidden;
}
.nav-dropdown-menu.nav-dropdown-right { left: auto; right: 0; }
.nav-dropdown.open .nav-dropdown-menu { display: block; }

.nav-dropdown-menu a,
.nav-dropdown-menu .dropdown-logout {
  display: block; width: 100%;
  padding: .55rem 1rem;
  font-size: 13px; color: var(--text);
  text-decoration: none; text-align: left;
  background: none; border: none;
  cursor: pointer; font-family: var(--font);
  transition: background .1s;
  box-sizing: border-box;
}
.nav-dropdown-menu a:hover,
.nav-dropdown-menu .dropdown-logout:hover { background: var(--surface-2); }
.nav-dropdown-menu a.active { color: var(--primary); font-weight: 600; }
.nav-dropdown-menu .dropdown-logout { color: var(--danger); }

.dropdown-header {
  padding: .6rem 1rem;
  font-size: 12px; font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  justify-content: space-between; gap: .5rem;
}
.role-tag {
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em;
  background: var(--primary-light); color: var(--primary);
  padding: .15rem .4rem; border-radius: 99px;
}
.dropdown-divider { height: 1px; background: var(--border); margin: .25rem 0; }

/* ---- Attachments ---- */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  transition: border-color .15s, background .15s;
}
.upload-area.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
}
.upload-area-sm { padding: .75rem 1rem; }
/* Input is hidden — triggered only by the label */
.upload-input { display: none; }
.upload-prompt {
  display: flex;
  align-items: center;
  gap: .5rem;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  padding: .25rem 0;
}
.upload-prompt:hover { color: var(--primary); }
.upload-icon { font-size: 1.1rem; }
.upload-preview {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}
.upload-preview img {
  max-height: 160px;
  max-width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.upload-clear {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .25rem .6rem;
  font-size: 12px;
  color: var(--danger);
  cursor: pointer;
  white-space: nowrap;
}
.upload-clear:hover { background: var(--surface-2); }

.attachment-list {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  margin-top: .85rem;
}
.attachment-thumb {
  cursor: zoom-in;
  display: block;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  transition: border-color .15s, box-shadow .15s;
}
.attachment-thumb:hover {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}
.attachment-thumb img {
  height: 120px;
  width: auto;
  max-width: 240px;
  display: block;
  object-fit: cover;
  transition: opacity .15s;
}
.attachment-thumb:hover img { opacity: .9; }

/* Lightbox */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,.88);
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}
.lightbox.open { display: flex; }
.lightbox img {
  max-width: 92vw;
  max-height: 88vh;
  border-radius: var(--radius);
  box-shadow: 0 8px 40px rgba(0,0,0,.6);
  cursor: default;
  object-fit: contain;
}
.lightbox-close {
  position: fixed;
  top: 1.25rem;
  right: 1.5rem;
  background: none;
  border: none;
  color: #fff;
  font-size: 1.75rem;
  cursor: pointer;
  line-height: 1;
  opacity: .7;
  transition: opacity .15s;
}
.lightbox-close:hover { opacity: 1; }

.form-hint { font-size: 11px; color: var(--text-muted); font-weight: 400; margin-left: .35rem; }