/* ============================================================
   AENT dashboard theme — dark (default) + light ("soft tinted").

   Usage:
     <html data-theme="dark">   or   <html data-theme="light">
     (theme-toggle.js persists the choice and flips this attribute)

   Palette is intentionally constrained. Five semantic roles plus
   neutrals; nothing outside this set:
     primary -> --blue      success -> --green
     danger  -> --red       warning -> --yellow
     accent  -> --purple
   ============================================================ */

:root,
:root[data-theme="dark"] {
  --bg: #0d111c;
  --panel: #161c2b;
  --panel-2: #1a2235;
  --border: #2a3348;
  --text: #e6ebf5;
  --muted: #8a96ad;

  --green: #5fce8e;
  --blue: #5b8def;
  --red: #e06c75;
  --yellow: #e7b85c;
  --purple: #9d7fe6;

  --grid: rgba(138, 150, 173, 0.15);
  --row-divider: rgba(42, 51, 72, 0.5);
  --hover-tint: rgba(91, 141, 239, 0.06);
  --shadow-card: 0 0 0 1px rgba(13, 17, 28, 0.12), 0 18px 40px rgba(0, 0, 0, 0.18);
  --banner-bg: rgba(91, 141, 239, 0.08);
  --banner-border: rgba(91, 141, 239, 0.35);
  --banner-text: #c7d2e8;
  --focus-ring: rgba(91, 141, 239, 0.25);
  --clear-hover: rgba(230, 235, 245, 0.1);

  /* Soft tints — used for KPI card washes and soft button/badge fills. */
  --tint-blue: rgba(91, 141, 239, 0.14);
  --tint-green: rgba(95, 206, 142, 0.14);
  --tint-red: rgba(224, 108, 117, 0.14);
  --tint-yellow: rgba(231, 184, 92, 0.14);
  --tint-purple: rgba(157, 127, 230, 0.14);
}

:root[data-theme="light"] {
  --bg: #eef1f8;
  --panel: #ffffff;
  --panel-2: #f6f8fc;
  --border: #e2e6f0;
  --text: #232a3d;
  --muted: #7b8399;

  --green: #3fb37c;
  --blue: #4f7ce8;
  --red: #dd5a63;
  --yellow: #d29a3a;
  --purple: #8b6de0;

  --grid: rgba(35, 42, 61, 0.07);
  --row-divider: rgba(35, 42, 61, 0.1);
  --hover-tint: rgba(79, 124, 232, 0.06);
  --shadow-card: 0 2px 4px rgba(35, 42, 61, 0.03), 0 14px 28px rgba(35, 42, 61, 0.06);
  --banner-bg: rgba(79, 124, 232, 0.08);
  --banner-border: rgba(79, 124, 232, 0.22);
  --banner-text: #3a4664;
  --focus-ring: rgba(79, 124, 232, 0.16);
  --clear-hover: rgba(35, 42, 61, 0.06);

  --tint-blue: rgba(79, 124, 232, 0.1);
  --tint-green: rgba(63, 179, 124, 0.1);
  --tint-red: rgba(221, 90, 99, 0.1);
  --tint-yellow: rgba(210, 154, 58, 0.1);
  --tint-purple: rgba(139, 109, 224, 0.1);
}

/* ---------------- Page shell ---------------- */
* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-family);
  /* No transition here on purpose: cards, tables and charts all repaint
     instantly on a theme switch, so animating only the page background
     makes it visibly lag behind everything else. */
}

.page-shell { min-height: 100vh; padding: 1.25rem 0 3rem; }
.page-title {
  font-size: clamp(1.35rem, 1.1rem + 1vw, 1.9rem);
  font-weight: var(--fw-bold);
  margin: 0;
  letter-spacing: -0.02em;
}
.page-subtitle { color: var(--muted); font-size: 0.95rem; margin: 0.25rem 0 0; }

/* ---------------- Banner ---------------- */
.banner {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  background: var(--banner-bg);
  border: 1px solid var(--banner-border);
  border-radius: 1rem;
  padding: 1rem 1.1rem;
  font-size: 0.92rem;
  color: var(--banner-text);
  line-height: 1.55;
}
.banner .i {
  flex: 0 0 auto;
  width: 1.3rem;
  height: 1.3rem;
  margin-top: 0.1rem;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  font-size: 0.75rem;
  font-weight: var(--fw-bold);
  display: grid;
  place-items: center;
}
.banner b { color: var(--text); }

/* ---------------- Cards ---------------- */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 1.1rem;
  color: var(--text);
  box-shadow: var(--shadow-card);
}
.card-body { padding: 1rem 1rem 1.15rem; }
.card h2 {
  font-size: 0.95rem;
  font-weight: var(--fw-bold);
  margin: 0 0 0.95rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.card h2::before {
  content: '';
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--blue);
}

/* ---------------- KPI cards ---------------- */
.kpi {
  border: 1px solid var(--border);
  border-radius: 1.1rem;
  padding: 1.2rem 1.05rem;
  text-align: center;
  height: 100%;
  background: var(--panel);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.03);
}
.kpi .val { font-size: clamp(1.4rem, 1rem + 1vw, 1.9rem); font-weight: var(--fw-bold); line-height: 1.1; }
.kpi .val.val-sm { font-size: clamp(1rem, 0.8rem + 0.6vw, 1.25rem); padding-top: 0.35rem; white-space: nowrap; }
.kpi .lbl {
  margin-top: 0.4rem;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Per-metric soft wash. Apply .kpi-blue/.kpi-green/etc. to the .kpi element. */
.kpi-blue   { background: linear-gradient(180deg, var(--tint-blue),   var(--panel) 65%); }
.kpi-green  { background: linear-gradient(180deg, var(--tint-green),  var(--panel) 65%); }
.kpi-red    { background: linear-gradient(180deg, var(--tint-red),    var(--panel) 65%); }
.kpi-yellow { background: linear-gradient(180deg, var(--tint-yellow), var(--panel) 65%); }
.kpi-purple { background: linear-gradient(180deg, var(--tint-purple), var(--panel) 65%); }

/* ---------------- Charts ---------------- */
.chart-wrap { position: relative; min-height: 280px; }
.chart-wrap.tall { min-height: 340px; }

/* ---------------- Table toolbar ---------------- */
.table-tools {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.9rem;
}
.table-tools-left { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; color: var(--muted); }
.table-tools-left select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  color: var(--text);
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
  outline: none;
}
.table-tools-center { display: flex; justify-content: center; gap: 0.5rem; }
.table-tools-right { display: flex; justify-content: flex-end; }

.search-wrap { position: relative; width: min(100%, 320px); }
.search-wrap input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 0.8rem;
  color: var(--text);
  padding: 0.65rem 2.2rem 0.65rem 0.85rem;
  font-size: 0.92rem;
  width: 100%;
  outline: none;
}
.search-wrap input::placeholder { color: var(--muted); }
.search-wrap input:focus {
  background: var(--panel);
  border-color: var(--blue);
  box-shadow: 0 0 0 0.2rem var(--focus-ring);
}
.search-clear {
  position: absolute;
  right: 0.45rem;
  top: 50%;
  transform: translateY(-50%);
  display: none;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
}
.search-clear:hover { background: var(--clear-hover); color: var(--text); }
.search-wrap.has-value .search-clear { display: flex; }

.count { color: var(--muted); font-size: 0.86rem; }

/* ---------------- Table scroll container ---------------- */
.table-scroll {
  max-height: 460px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 0.9rem;
  scrollbar-width: thin;
  scrollbar-color: var(--blue) var(--panel-2);
}
.table-scroll::-webkit-scrollbar { width: 8px; height: 8px; }
.table-scroll::-webkit-scrollbar-track { background: var(--panel-2); }
.table-scroll::-webkit-scrollbar-thumb { background: var(--blue); border-radius: 999px; }

/* ---------------- Sortable header affordance ---------------- */
thead th { cursor: pointer; white-space: nowrap; }
thead th:hover { color: var(--text); }
.th-label { position: relative; display: block; width: 100%; padding-right: 1.2rem; }
.sort-icon {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 0.9rem;
  color: var(--muted);
  opacity: 0.9;
  text-align: center;
  transition: color 0.15s ease, opacity 0.15s ease;
}
thead th.is-sorted .sort-icon { color: var(--blue); opacity: 1; }
tbody td { white-space: nowrap; }

/* ---------------- Pagination ---------------- */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.9rem;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: var(--muted);
}
.page-nav { display: flex; align-items: center; gap: 0.6rem; }
.page-nav .btn-tool { padding: 0.4rem 0.6rem; }

/* ---------------- Toolbar buttons ---------------- */
.btn-tool {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 0.8rem;
  color: var(--text);
  padding: 0.55rem 0.9rem;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn-tool:hover { background: var(--tint-blue); border-color: var(--blue); color: var(--blue); }
.btn-tool:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-tool.copied { border-color: var(--green); color: var(--green); }

/* ---------------- Filter bar ---------------- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem 1rem;
  margin-bottom: 1.25rem;
}
.filter-bar .flt { display: flex; flex-direction: column; gap: 0.3rem; margin: 0; }
.filter-bar .flt > span {
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: var(--fw-medium);
}
.filter-bar input[type="date"],
.filter-bar input[type="number"],
.filter-bar select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  color: var(--text);
  padding: 0.45rem 0.65rem;
  font-size: 0.86rem;
  font-family: var(--font-family);
  outline: none;
  min-width: 9rem;
  color-scheme: dark;
}
:root[data-theme="light"] .filter-bar input[type="date"] { color-scheme: light; }
.filter-bar input:focus, .filter-bar select:focus { border-color: var(--blue); box-shadow: 0 0 0 0.2rem var(--focus-ring); }
.filter-bar .ui-btn-group .ui-btn { padding: 0.45rem 0.75rem; font-size: 0.82rem; }

/* Empty-state / loading / error placeholder inside any panel */
.panel-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 280px;
  color: var(--muted);
  font-size: 0.9rem;
}
.panel-state.error { color: var(--red); }
.panel-state.compact { min-height: 0; padding: 1.5rem 0; }

/* ---------------- Sidebar nav ---------------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  flex: 0 0 15rem;
  width: 15rem;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 1rem 0.75rem;
  overflow-y: auto;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.65rem 1rem;
  font-weight: var(--fw-bold);
  font-size: 1rem;
  letter-spacing: -0.01em;
}
.sidebar-brand .mark {
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 0.45rem;
  background: var(--blue);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
}
.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-list a {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.65rem;
  border-radius: 0.6rem;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.88rem;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-list a:hover { background: var(--tint-blue); color: var(--text); }
.nav-list a.active { background: var(--blue); color: #fff; }
.nav-list a.active .nav-icon { color: #fff; }
.nav-list a.disabled { opacity: 0.45; pointer-events: none; }
.nav-icon { width: 1.1rem; text-align: center; flex: 0 0 auto; }
/* Links still pointing at the un-migrated Classic ASP app are marked so it is
   obvious which modules have not been converted yet. */
.nav-list a.legacy::after {
  content: 'ASP';
  margin-left: auto;
  font-size: 0.6rem;
  letter-spacing: 0.04em;
  padding: 1px 5px;
  border-radius: 999px;
  background: var(--tint-yellow);
  color: var(--yellow);
}
.sidebar-toggle { display: none; }

.app-main { flex: 1 1 auto; min-width: 0; }

@media (max-width: 991.98px) {
  .app-shell { display: block; }
  .sidebar {
    width: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .nav-list { display: flex; flex-wrap: wrap; gap: 0.25rem; }
  .nav-list a { padding: 0.45rem 0.6rem; }
  .nav-list a.legacy::after { display: none; }
}

/* ---------------- Theme toggle ---------------- */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem;
}
.theme-toggle button {
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  font-weight: var(--fw-semibold);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: background 0.15s ease, color 0.15s ease;
}
.theme-toggle button.active { background: var(--blue); color: #fff; }
.theme-toggle button:not(.active):hover { color: var(--text); }

@media (max-width: 575.98px) {
  .page-shell { padding-top: 0.75rem; }
  .banner { padding: 0.9rem 0.95rem; }
  .table-tools { grid-template-columns: 1fr; justify-items: stretch; }
  .table-tools-left { order: 1; }
  .table-tools-center { order: 2; }
  .table-tools-right { order: 3; }
  .search-wrap { width: 100%; }
  .pagination-bar { justify-content: center; }
}

/* KPI values never push the card wider than its column. */
.kpi { min-width: 0; }
.kpi .val { max-width: 100%; white-space: nowrap; }
.kpi .val.val-xs { font-size: clamp(0.9rem, 0.7rem + 0.45vw, 1.05rem); padding-top: 0.45rem; letter-spacing: -0.01em; }

/* ---------------- Date range picker (single input, like the ASP daterangepicker) ---------------- */
.flt-daterange { position: relative; }
.daterange-input {
  display: inline-flex; align-items: center; gap: 0.55rem; min-width: 19rem;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.45rem 0.75rem; font: inherit; font-size: 0.9rem; cursor: pointer; text-align: left; white-space: nowrap;
}
.daterange-input:hover { border-color: var(--blue); }
.daterange-input .daterange-caption { flex: 1; }
.daterange-input i:last-child { color: var(--muted); font-size: 0.75rem; }
.daterange-pop {
  position: absolute; z-index: 1050; top: calc(100% + 6px); left: 0; display: flex;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-card);
  min-width: 30rem;
}
.daterange-ranges { list-style: none; margin: 0; padding: 0.4rem 0; min-width: 12rem; border-right: 1px solid var(--border); }
.daterange-ranges li { padding: 0.42rem 1rem; cursor: pointer; font-size: 0.9rem; color: var(--text); white-space: nowrap; }
.daterange-ranges li:hover { background: var(--tint-blue, rgba(91,141,239,0.12)); }
.daterange-ranges li.active { background: var(--blue); color: #fff; }
.daterange-ranges li.custom { border-top: 1px solid var(--border); margin-top: 0.3rem; color: var(--muted); }
.daterange-custom { padding: 0.9rem 1rem; display: flex; flex-direction: column; gap: 0.6rem; min-width: 15rem; }
.daterange-custom label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.daterange-custom input[type="date"] { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 0.4rem 0.6rem; font: inherit; font-size: 0.9rem; }
.daterange-actions { display: flex; gap: 0.5rem; margin-top: 0.25rem; }
@media (max-width: 640px) { .daterange-pop { flex-direction: column; min-width: 0; } .daterange-ranges { border-right: 0; border-bottom: 1px solid var(--border); } }
