:root {
  --app-bg: #eceef0;
  --card-bg: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #eef0f3;
  --border: #e5e7eb;
  --hover-bg: #f5f6f8;
  --active-bg: #f1f2f4;
  --nav-text: #4b5563;
  --nav-icon: #6b7280;
  --accent-ink: #6d28d9;
  --track: #f1f0f7;
  --kbd-bg: #f3f4f6;
  --accent: #7c3aed;
  --accent-soft: #ede9fe;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --sidebar-w: 250px;
  --sidebar-w-collapsed: 76px;

  --chart-line: #7c3aed;
  --chart-grid: #e5e7eb;
  --chart-text: #6b7280;

  --bs-primary: #7c3aed;
  --bs-primary-rgb: 124, 58, 237;
  --bs-link-color: #6d28d9;
  --bs-link-color-rgb: 109, 40, 217;
  --bs-link-hover-color: #5b21b6;
  --bs-link-hover-color-rgb: 91, 33, 182;
}

html {
  position: relative;
  min-height: 100%;
}

body {
  background-color: var(--app-bg);
  color: var(--ink);
}

/* Purple accent for primary buttons, matching the dashboard design. */
.btn-primary {
  --bs-btn-bg: #7c3aed;
  --bs-btn-border-color: #7c3aed;
  --bs-btn-hover-bg: #6d28d9;
  --bs-btn-hover-border-color: #6d28d9;
  --bs-btn-active-bg: #5b21b6;
  --bs-btn-active-border-color: #5b21b6;
  --bs-btn-disabled-bg: #7c3aed;
  --bs-btn-disabled-border-color: #7c3aed;
  --bs-btn-focus-shadow-rgb: 124, 58, 237;
}

.btn-outline-primary {
  --bs-btn-color: #6d28d9;
  --bs-btn-border-color: #7c3aed;
  --bs-btn-hover-bg: #7c3aed;
  --bs-btn-hover-border-color: #7c3aed;
  --bs-btn-active-bg: #6d28d9;
  --bs-btn-active-border-color: #6d28d9;
  --bs-btn-focus-shadow-rgb: 124, 58, 237;
}

.form-control:focus, .form-select:focus {
  border-color: #a78bfa;
  box-shadow: 0 0 0 .2rem rgba(124, 58, 237, .15);
}

/* Hide the empty red box ASP.NET renders when a validation summary has no errors. */
.validation-summary-valid {
  display: none;
}

.table > :not(caption) > * > * {
  vertical-align: middle;
}


/* ---------------------------------------------------------------- dark theme */
[data-bs-theme="dark"] {
  --app-bg: #0e1014;
  --card-bg: #171a20;
  --ink: #e7e9ee;
  --muted: #9aa3b2;
  --line: #252a33;
  --border: #2c313b;
  --hover-bg: #1f232b;
  --active-bg: #272c36;
  --nav-text: #b4bcc9;
  --nav-icon: #8b94a4;
  --accent-soft: #2e2150;
  --accent-ink: #c4b5fd;
  --track: #272c36;
  --kbd-bg: #272c36;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 1px 3px rgba(0, 0, 0, .35);

  --chart-line: #a78bfa;
  --chart-grid: #2c313b;
  --chart-text: #9aa3b2;

  --bs-body-bg: #171a20;
  --bs-body-color: #e7e9ee;
  --bs-border-color: #2c313b;
  --bs-link-color: #a78bfa;
  --bs-link-color-rgb: 167, 139, 250;
  --bs-link-hover-color: #c4b5fd;
  --bs-link-hover-color-rgb: 196, 181, 253;
  color-scheme: dark;
}

[data-bs-theme="dark"] .table-light {
  --bs-table-bg: #20242c;
  --bs-table-color: #e7e9ee;
  --bs-table-border-color: #2c313b;
}
[data-bs-theme="dark"] .bg-light,
[data-bs-theme="dark"] .text-bg-light {
  background-color: #20242c !important;
  color: #e7e9ee !important;
}
[data-bs-theme="dark"] .bg-white { background-color: var(--card-bg) !important; }
[data-bs-theme="dark"] .btn-outline-primary { --bs-btn-color: #c4b5fd; }
[data-bs-theme="dark"] .form-control:focus,
[data-bs-theme="dark"] .form-select:focus { box-shadow: 0 0 0 .2rem rgba(167, 139, 250, .25); }

/* Sun/moon icon: moon in light mode (click for dark), sun in dark mode. */
.theme-icon-dark { display: none; }
[data-bs-theme="dark"] .theme-icon-dark { display: inline; }
[data-bs-theme="dark"] .theme-icon-light { display: none; }

/* ------------------------------------------------------------------ app shell */
.app-shell {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 16px;
  min-height: 100vh;
}

.app-content {
  flex: 1 1 auto;
  min-width: 0;            /* wide tables scroll instead of stretching the page */
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .8rem 1.25rem;
}

.page-title {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0;
}

.app-main { margin-top: 16px; }

.page-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

.app-footer {
  color: var(--muted);
  font-size: .8rem;
  padding: 1rem .5rem 0;
}

.user-link {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  color: var(--ink);
  text-decoration: none;
  font-size: .9rem;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
.avatar.sm { width: 28px; height: 28px; font-size: .8rem; }

.icon-btn {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--card-bg);
  border-radius: 10px;
  color: var(--nav-text);
  flex: 0 0 auto;
  padding: 0;
}
.icon-btn:hover { background: var(--hover-bg); color: var(--ink); }

/* -------------------------------------------------------------------- sidebar */
.sidebar {
  flex: 0 0 var(--sidebar-w);
  width: var(--sidebar-w);
  position: sticky;
  top: 16px;
  height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 12px;
  overflow: hidden;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: 0 .25rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
  min-width: 0;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, #7c3aed, #a78bfa);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.sidebar-search {
  display: flex;
  align-items: center;
  gap: .5rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 .6rem;
  height: 38px;
  margin: 12px 0 4px;
  color: var(--muted);
}
.sidebar-search input {
  border: 0;
  outline: 0;
  background: transparent;
  flex: 1 1 auto;
  min-width: 0;
  font-size: .85rem;
  color: var(--ink);
}
.sidebar-search kbd {
  background: var(--kbd-bg);
  color: var(--muted);
  font-size: .7rem;
  padding: .05rem .4rem;
}

/* The menu is grouped and only one group is open, so it fits without scrolling.
   If a very short screen still overflows, it scrolls without showing a scrollbar. */
.sidebar-nav {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: none;
  padding-top: 2px;
}
.sidebar-nav::-webkit-scrollbar { display: none; }

.nav-title {
  font-size: .68rem;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: #9ca3af;
  padding: .55rem .75rem .25rem;
}

.nav-item-link,
.nav-group-btn {
  display: flex;
  align-items: center;
  gap: .7rem;
  width: 100%;
  padding: .45rem .75rem;
  border: 0;
  background: transparent;
  border-radius: 10px;
  color: var(--nav-text);
  font-size: .9rem;
  text-decoration: none;
  text-align: left;
}
.nav-item-link i:first-child,
.nav-group-btn i:first-child {
  font-size: 1.05rem;
  width: 1.2rem;
  text-align: center;
  color: var(--nav-icon);
}
.nav-item-link:hover,
.nav-group-btn:hover { background: var(--hover-bg); color: var(--ink); }

.nav-item-link.active {
  background: var(--active-bg);
  color: var(--ink);
  font-weight: 600;
}
.nav-item-link.active i:first-child,
.nav-group-btn:not(.collapsed) i:first-child { color: var(--ink); }
.nav-group-btn:not(.collapsed) { color: var(--ink); font-weight: 600; }

.nav-group-btn .chev {
  margin-left: auto;
  font-size: .75rem;
  transition: transform .15s ease;
}
.nav-group-btn:not(.collapsed) .chev { transform: rotate(180deg); }

.sub-link {
  display: block;
  padding: .32rem .75rem .32rem 2.55rem;
  border-radius: 8px;
  font-size: .86rem;
  color: var(--muted);
  text-decoration: none;
}
.sub-link:hover { background: var(--hover-bg); color: var(--ink); }
.sub-link.active { background: var(--active-bg); color: var(--ink); font-weight: 600; }

.nav-empty { padding: .75rem; color: var(--muted); font-size: .85rem; }

.sidebar-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  border-top: 1px solid var(--line);
  margin-top: 8px;
  padding: 10px .25rem 0;
}
.user-chip { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.user-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.user-name { font-size: .85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: .72rem; color: var(--muted); }

.sidebar-backdrop { display: none; }

/* Icon-only mode (large screens). */
@media (min-width: 992px) {
  html.sidebar-collapsed .sidebar {
    flex-basis: var(--sidebar-w-collapsed);
    width: var(--sidebar-w-collapsed);
  }
  html.sidebar-collapsed .sidebar .label,
  html.sidebar-collapsed .sidebar .brand { display: none !important; }
  html.sidebar-collapsed .sidebar .collapse { display: none !important; }
  html.sidebar-collapsed .sidebar-head { justify-content: center; }
  html.sidebar-collapsed .nav-item-link,
  html.sidebar-collapsed .nav-group-btn { justify-content: center; padding: .6rem 0; }
  html.sidebar-collapsed .sidebar-foot { justify-content: center; }
  html.sidebar-collapsed .nav-title { display: none; }
}

/* Small screens: the sidebar is a drawer. */
@media (max-width: 991.98px) {
  .app-shell { padding: 10px; gap: 0; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1050;
    border-radius: 0 var(--radius) var(--radius) 0;
    transform: translateX(-105%);
    transition: transform .2s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.show {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, .4);
    z-index: 1040;
  }
  .page-card { padding: 1rem; }
}

/* ------------------------------------------------------------------ dashboard */
.stat-card {
  display: block;
  height: 100%;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem;
  color: inherit;
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.25rem;
  flex: 0 0 auto;
  box-shadow: inset 0 -2px 4px rgba(0, 0, 0, .12);
}
.bg-orange { background: linear-gradient(135deg, #fdba74, #f59e0b); }
.bg-green  { background: linear-gradient(135deg, #34d399, #059669); }
.bg-blue   { background: linear-gradient(135deg, #60a5fa, #2563eb); }
.bg-yellow { background: linear-gradient(135deg, #fde047, #eab308); color: #422006; }
.bg-red    { background: linear-gradient(135deg, #fca5a5, #dc2626); }

.stat-value { font-size: 1.4rem; font-weight: 600; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: .8rem; }

.stat-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: .85rem;
  padding-top: .6rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: .8rem;
  text-decoration: none;
}
a.stat-card:hover .stat-link,
.stat-link:hover { color: var(--accent); }

.panel {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.25rem;
}
.panel-title { font-weight: 600; font-size: .9rem; }

.sales-chart { width: 100%; height: auto; display: block; }

.bar-track { height: 8px; background: var(--track); border-radius: 99px; margin-top: .3rem; }
.bar-fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #7c3aed, #a78bfa);
}

/* ---------------------------------------------------------------------- print */
@media print {
  body { background: #fff; }
  .no-print, .sidebar, .sidebar-backdrop, .page-header, .app-footer, .toast-container,
  .alert-dismissible .btn-close { display: none !important; }
  .app-shell { padding: 0; display: block; }
  .app-main { margin-top: 0; }
  .page-card { box-shadow: none; padding: 0; }
}

/* ---- Names for the icons when the menu is collapsed (hover or keyboard focus) ---- */
.nav-tip {
  position: fixed;
  z-index: 1070;
  display: none;
  min-width: 120px;
  max-width: 240px;
  padding: .45rem .75rem;
  border-radius: 10px;
  background: #111827;
  color: #fff;
  font-size: .85rem;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .25);
}
[data-bs-theme="dark"] .nav-tip { background: #2a2f3a; border: 1px solid #3a4150; }
.nav-tip.show { display: block; }
.nav-tip .tip-title { font-weight: 600; }
.nav-tip .tip-links { margin-top: .3rem; padding-top: .3rem; border-top: 1px solid rgba(255, 255, 255, .15); }
.nav-tip .tip-links a {
  display: block;
  padding: .22rem 0;
  color: #d1d5db;
  text-decoration: none;
}
.nav-tip .tip-links a:hover { color: #fff; text-decoration: underline; }
.nav-tip .tip-links a.active { color: #fff; font-weight: 600; }

/* ---- Tables (AWS-style): resizable and movable columns ---- */
.table-tools th { position: relative; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.table-tools td { overflow-wrap: anywhere; }
.table-tools th.col-draggable { cursor: grab; }
.table-tools th.col-dragging { opacity: .45; }
.table-tools th.col-drop-before { box-shadow: inset 3px 0 0 var(--bs-primary); }
.table-tools th.col-drop-after { box-shadow: inset -3px 0 0 var(--bs-primary); }
.col-resizer { position: absolute; top: 0; right: 0; width: 9px; height: 100%; cursor: col-resize; user-select: none; touch-action: none; z-index: 2; }
.col-resizer::after { content: ""; position: absolute; top: 25%; bottom: 25%; right: 3px; width: 2px; border-radius: 2px; background: var(--bs-border-color); opacity: .0; transition: opacity .12s; }
.table-tools th:hover .col-resizer::after, .table-tools.is-resizing .col-resizer::after { opacity: 1; }
.col-resizer:hover::after { background: var(--bs-primary); }
.table-tools.is-resizing { user-select: none; cursor: col-resize; }
.table-responsive.is-dragging { cursor: grabbing; user-select: none; }

/* ---- Live search / pager ---- */
.app-main.is-loading .page-card { opacity: .65; transition: opacity .15s; }
.pager-bar { padding-top: .75rem; }
@media print { .pager-bar { display: none !important; } }
