/* ==========================================================================
   Employee Complaint Categorization System - interface styles

   Built on Bootstrap 5.3. Dark mode rides on Bootstrap's own
   [data-bs-theme] attribute, which base.html sets before first paint, so the
   tokens below only have to restate the values Bootstrap does not own.
   ========================================================================== */

:root {
  --brand: #3b5bdb;
  --brand-soft: #edf0fd;
  --brand-contrast: #ffffff;
  --accent: #7048e8;

  --surface: #f4f6fb;
  --card-bg: #ffffff;
  --border: rgba(15, 23, 42, 0.09);
  --muted: #64748b;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow-md: 0 6px 16px rgba(16, 24, 40, 0.10);
  --shadow-lg: 0 18px 40px rgba(16, 24, 40, 0.16);

  --radius: 14px;
  --radius-sm: 10px;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

[data-bs-theme="dark"] {
  --brand: #748ffc;
  --brand-soft: rgba(116, 143, 252, 0.14);
  --brand-contrast: #0b1020;
  --accent: #9775fa;

  --surface: #0e131c;
  --card-bg: #161d29;
  --border: rgba(255, 255, 255, 0.09);
  --muted: #94a3b8;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 16px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 18px 40px rgba(0, 0, 0, 0.55);
}

/* Anyone who has asked their OS to reduce motion gets none of it. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

html {
  scroll-behavior: smooth;
}

body {
  background-color: var(--surface);
  transition: background-color 0.3s var(--ease), color 0.3s var(--ease);
}

.text-muted {
  color: var(--muted) !important;
}

/* ---------- Navbar ------------------------------------------------------ */

.app-navbar {
  background: linear-gradient(100deg, #1f3a5f 0%, #2c4a7c 55%, #3b5bdb 100%);
  box-shadow: var(--shadow-sm);
}

[data-bs-theme="dark"] .app-navbar {
  background: linear-gradient(100deg, #10192b 0%, #15203a 55%, #1e2c56 100%);
}

.navbar-brand {
  font-weight: 700;
  letter-spacing: 0.2px;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.navbar-brand .brand-mark {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.16);
  font-size: 0.95rem;
  transition: transform 0.35s var(--ease);
}

.navbar-brand:hover .brand-mark {
  transform: rotate(-8deg) scale(1.08);
}

/* An underline that grows out from the centre of the hovered nav item. */
.app-navbar .nav-link {
  position: relative;
  transition: color 0.2s var(--ease);
}

.app-navbar .nav-link::after {
  content: "";
  position: absolute;
  left: 50%;
  right: 50%;
  bottom: 0.25rem;
  height: 2px;
  border-radius: 2px;
  background: #fff;
  opacity: 0.9;
  transition: left 0.25s var(--ease), right 0.25s var(--ease);
}

.app-navbar .nav-link:hover::after,
.app-navbar .nav-link.active::after {
  left: 0.5rem;
  right: 0.5rem;
}

.app-navbar .nav-link.active {
  font-weight: 600;
}

.theme-toggle {
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: inline-grid;
  place-items: center;
  font-size: 1rem;
  line-height: 1;
  transition: background 0.2s var(--ease), transform 0.2s var(--ease);
}

.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
  color: #fff;
}

.theme-toggle .icon-sun { display: none; }
[data-bs-theme="dark"] .theme-toggle .icon-sun { display: inline; }
[data-bs-theme="dark"] .theme-toggle .icon-moon { display: none; }

.nav-avatar {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
}

/* ---------- Cards ------------------------------------------------------- */

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background-color: var(--card-bg);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.25s var(--ease), transform 0.25s var(--ease);
}

.card-header {
  background-color: transparent;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

/* ---------- Dashboard stat cards ---------------------------------------- */

.stat-card {
  position: relative;
  overflow: hidden;
  border-left: 4px solid #adb5bd;
  text-decoration: none;
  color: inherit;
  display: block;
}

/* A tint that sweeps in from the left on hover. */
.stat-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, currentColor 0%, transparent 70%);
  opacity: 0;
  transform: translateX(-100%);
  transition: transform 0.45s var(--ease), opacity 0.45s var(--ease);
  pointer-events: none;
}

a.stat-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
  color: inherit;
}

a.stat-card:hover::after {
  opacity: 0.06;
  transform: translateX(0);
}

a.stat-card:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.stat-card .stat-value {
  font-size: 1.9rem;
  font-weight: 700;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}

.stat-card .stat-label {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  font-weight: 600;
}

.stat-card .stat-hint {
  font-size: 0.72rem;
  color: var(--muted);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
}

a.stat-card:hover .stat-hint {
  opacity: 1;
  transform: translateY(0);
}

.stat-card.is-active {
  border-left-width: 6px;
  box-shadow: var(--shadow-md);
}

.stat-total    { border-left-color: #3b5bdb; color: #3b5bdb; }
.stat-pending  { border-left-color: #64748b; color: #64748b; }
.stat-progress { border-left-color: #0d6efd; color: #0d6efd; }
.stat-resolved { border-left-color: #198754; color: #198754; }
.stat-high     { border-left-color: #dc3545; color: #dc3545; }
.stat-assigned { border-left-color: #0dcaf0; color: #22a7c2; }
.stat-rejected { border-left-color: #e35d6a; color: #e35d6a; }

/* The share-of-total bar under each counter. */
.stat-bar {
  height: 4px;
  border-radius: 4px;
  background: var(--border);
  overflow: hidden;
  margin-top: 0.6rem;
}

.stat-bar > span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 4px;
  background: currentColor;
  transition: width 0.9s var(--ease);
}

/* ---------- Priority and status badges ---------------------------------- */

.badge-priority,
.badge-status {
  font-weight: 600;
  padding: 0.38em 0.7em;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  font-size: 0.74rem;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.badge-priority::before,
.badge-status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.85;
}

.priority-high   { background-color: #dc3545; color: #fff; }
.priority-medium { background-color: #fd7e14; color: #fff; }
.priority-low    { background-color: #6c757d; color: #fff; }

/* High priority quietly pulses so it is the first thing the eye lands on. */
.priority-high::before {
  animation: pulse-dot 1.8s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 0.35; transform: scale(0.85); }
  50%      { opacity: 1;    transform: scale(1.25); }
}

.status-pending     { background-color: #64748b; color: #fff; }
.status-assigned    { background-color: #0dcaf0; color: #05323b; }
.status-in-progress { background-color: #0d6efd; color: #fff; }
.status-resolved    { background-color: #198754; color: #fff; }
.status-rejected    { background-color: #343a40; color: #fff; }

/* Applied by JS when a badge's value changes without a page reload. */
.badge-flash {
  animation: badge-flash 1s var(--ease);
}

@keyframes badge-flash {
  0%   { transform: scale(1);    box-shadow: 0 0 0 0 rgba(59, 91, 219, 0.55); }
  35%  { transform: scale(1.18); box-shadow: 0 0 0 8px rgba(59, 91, 219, 0); }
  100% { transform: scale(1);    box-shadow: 0 0 0 0 rgba(59, 91, 219, 0); }
}

/* ---------- Live classification preview --------------------------------- */

.analysis-panel {
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--brand-soft);
  padding: 1rem;
  transition: border-color 0.3s var(--ease), background 0.3s var(--ease);
}

.analysis-panel.is-live {
  border-style: solid;
  border-color: var(--brand);
}

.analysis-panel .analysis-title {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 700;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.analysis-result {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.analysis-chip {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  min-width: 120px;
  box-shadow: var(--shadow-sm);
  animation: chip-in 0.35s var(--ease) both;
}

.analysis-chip .chip-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  font-weight: 600;
}

.analysis-chip .chip-value {
  font-weight: 600;
  margin-top: 0.15rem;
}

.analysis-chip .chip-source {
  font-size: 0.66rem;
  color: var(--muted);
}

@keyframes chip-in {
  from { opacity: 0; transform: translateY(6px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}

/* Three bouncing dots shown while the classifier is thinking. */
.thinking-dots {
  display: inline-flex;
  gap: 3px;
}

.thinking-dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--brand);
  animation: thinking 1.1s ease-in-out infinite;
}

.thinking-dots i:nth-child(2) { animation-delay: 0.15s; }
.thinking-dots i:nth-child(3) { animation-delay: 0.3s; }

@keyframes thinking {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40%           { opacity: 1;    transform: translateY(-4px); }
}

/* ---------- Character counters ------------------------------------------ */

.char-counter {
  font-size: 0.74rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  transition: color 0.2s var(--ease);
}

.char-counter.is-near { color: #fd7e14; font-weight: 600; }
.char-counter.is-over { color: #dc3545; font-weight: 700; }

/* ---------- Complaint timeline ------------------------------------------ */

.timeline {
  list-style: none;
  margin: 0;
  padding-left: 1.35rem;
  border-left: 2px solid var(--border);
}

.timeline li {
  position: relative;
  padding-bottom: 1.35rem;
  animation: timeline-in 0.4s var(--ease) both;
}

.timeline li:last-child {
  padding-bottom: 0;
}

.timeline li::before {
  content: "";
  position: absolute;
  left: -1.72rem;
  top: 0.3rem;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  background-color: var(--brand);
  border: 2px solid var(--card-bg);
  box-shadow: 0 0 0 2px var(--border);
  transition: transform 0.2s var(--ease);
}

.timeline li:hover::before {
  transform: scale(1.3);
}

/* The newest entry sits at the bottom and gets a halo. */
.timeline li:last-child::before {
  box-shadow: 0 0 0 4px var(--brand-soft);
}

@keyframes timeline-in {
  from { opacity: 0; transform: translateX(-10px); }
  to   { opacity: 1; transform: none; }
}

.timeline-remarks {
  margin-top: 0.4rem;
  font-size: 0.9rem;
}

.timeline-meta {
  margin-top: 0.25rem;
  font-size: 0.76rem;
  color: var(--muted);
}

/* The timeline follows the admin down the page while they work the forms. */
@media (min-width: 992px) {
  .timeline-card {
    position: sticky;
    top: 5rem;
    max-height: calc(100vh - 7rem);
    overflow-y: auto;
  }
}

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

.table > thead th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  border-bottom-width: 1px;
  white-space: nowrap;
}

.table-sticky > thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background-color: var(--card-bg);
}

/* Sortable headers: a chevron that appears on hover and locks in once sorted. */
th[data-sort] {
  cursor: pointer;
  user-select: none;
  transition: color 0.2s var(--ease);
}

th[data-sort]:hover {
  color: var(--brand);
}

th[data-sort]::after {
  content: "\2195";
  margin-left: 0.35rem;
  opacity: 0.25;
  font-size: 0.85em;
}

th[data-sort][data-direction="asc"]::after  { content: "\2191"; opacity: 1; }
th[data-sort][data-direction="desc"]::after { content: "\2193"; opacity: 1; }

tbody tr {
  transition: background-color 0.15s var(--ease);
}

.table-hover > tbody > tr:hover > * {
  background-color: var(--brand-soft);
}

tr.row-hidden {
  display: none;
}

/* Search hits are highlighted, not merely left un-filtered. */
mark.search-hit {
  background: rgba(255, 214, 10, 0.5);
  color: inherit;
  padding: 0 2px;
  border-radius: 3px;
}

[data-bs-theme="dark"] mark.search-hit {
  background: rgba(255, 214, 10, 0.3);
}

.table-empty td {
  text-align: center;
  color: var(--muted);
  padding: 2.5rem 1rem;
}

/* ---------- Filter chips ------------------------------------------------ */

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--brand-soft);
  color: var(--brand);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.22rem 0.6rem;
  font-size: 0.76rem;
  font-weight: 600;
  text-decoration: none;
  transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.filter-chip:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
  color: var(--brand);
}

/* An unselected choice in a chip-style filter row. */
.filter-chip.is-dim {
  background: transparent;
  color: var(--muted);
  font-weight: 500;
}

.filter-chip.is-dim:hover {
  background: var(--brand-soft);
  color: var(--brand);
}

.filter-chip .chip-x {
  font-size: 0.95rem;
  line-height: 1;
  opacity: 0.65;
}

/* ---------- Toasts ------------------------------------------------------ */

.toast-stack {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1090;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: min(380px, calc(100vw - 2rem));
}

.app-toast {
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand);
  background: var(--card-bg);
  overflow: hidden;
  animation: toast-in 0.35s var(--ease) both;
}

.app-toast.tone-success { border-left-color: #198754; }
.app-toast.tone-danger  { border-left-color: #dc3545; }
.app-toast.tone-warning { border-left-color: #fd7e14; }
.app-toast.tone-info    { border-left-color: #0dcaf0; }

.app-toast .toast-body {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
}

/* A thin bar that drains to show how long the toast has left. */
.app-toast .toast-timer {
  height: 3px;
  background: var(--brand);
  opacity: 0.55;
  animation: toast-timer linear forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(28px) scale(0.96); }
  to   { opacity: 1; transform: none; }
}

@keyframes toast-timer {
  from { width: 100%; }
  to   { width: 0%; }
}

/* ---------- Buttons ----------------------------------------------------- */

.btn {
  border-radius: var(--radius-sm);
  font-weight: 500;
  transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease),
              filter 0.15s var(--ease);
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: linear-gradient(120deg, var(--brand), var(--accent));
  border: none;
  color: var(--brand-contrast);
}

.btn-primary:hover,
.btn-primary:focus {
  filter: brightness(1.08);
  box-shadow: var(--shadow-md);
  color: var(--brand-contrast);
}

.btn.is-busy {
  pointer-events: none;
  opacity: 0.75;
}

/* ---------- Password strength meter ------------------------------------- */

.strength-meter {
  display: flex;
  gap: 4px;
  margin-top: 0.45rem;
}

.strength-meter span {
  flex: 1;
  height: 4px;
  border-radius: 4px;
  background: var(--border);
  transition: background-color 0.3s var(--ease);
}

.strength-meter[data-score="1"] span:nth-child(-n+1) { background: #dc3545; }
.strength-meter[data-score="2"] span:nth-child(-n+2) { background: #fd7e14; }
.strength-meter[data-score="3"] span:nth-child(-n+3) { background: #ffc107; }
.strength-meter[data-score="4"] span:nth-child(-n+4) { background: #198754; }

/* ---------- Reveal-on-scroll -------------------------------------------- */

[data-reveal] {
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.5s var(--ease), transform 0.5s var(--ease);
}

[data-reveal].is-revealed {
  opacity: 1;
  transform: none;
}

/* ---------- Scroll-to-top ----------------------------------------------- */

.scroll-top {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--brand);
  box-shadow: var(--shadow-md);
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px);
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease),
              visibility 0.25s;
  z-index: 1050;
}

.scroll-top.is-visible {
  opacity: 1;
  visibility: visible;
  transform: none;
}

.scroll-top:hover {
  transform: translateY(-3px);
}

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

kbd {
  background: var(--border);
  color: inherit;
  border-radius: 5px;
  padding: 0.1rem 0.35rem;
  font-size: 0.75rem;
  font-family: inherit;
  font-weight: 600;
}

.empty-state-icon {
  font-size: 2.5rem;
  opacity: 0.35;
  display: block;
  margin-bottom: 0.5rem;
}

.copy-btn.is-copied {
  background: #198754;
  border-color: #198754;
  color: #fff;
}

.form-control,
.form-select {
  border-radius: var(--radius-sm);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.form-control:focus,
.form-select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 0.2rem var(--brand-soft);
}

footer {
  border-top: 1px solid var(--border);
  margin-top: 2rem;
}
