:root {
  /* Mana Traders brand on warm graphite: the logo orange is the one accent, the surfaces are neutral
     charcoal. Orange is a fill (primary buttons, badges, meters) with --on-brand text; orange text
     uses --brand-light. */
  --brand: #ed7a05;
  --brand-hover: #de7205;
  --brand-light: #f7a808;
  --brand-deep: #e75412;
  --brand-gradient: linear-gradient(135deg, #f7a808, #ed7a05 55%, #e75412);
  --brand-tint: rgba(237, 122, 5, 0.14);
  --on-brand: #141312;
  --link-hover: #ffc04d;
  --focus-ring: rgba(247, 168, 8, 0.2);

  /* Surfaces, darkest to lightest: chrome (sidebar), sunken, page, card, elevated. A card is told
     from the page by its border more than by its fill. */
  --bg-page: #1b1917;
  --bg-chrome: #141312;
  --bg-sunken: #171514;
  --bg-card: #25221f;
  --bg-card-hover: #302c28;
  --border: #46403a;
  --border-strong: #5f574e;

  /* Text, measured on --bg-card: 14.1 / 10.6 / 6.1 : 1 */
  --text: #f5f1eb;
  --text-secondary: #d9d2c9;
  --text-muted: #a8a097;

  /* Status. Fills use the base colour; text on a tinted chip uses the -text shade. */
  --success: #4ade80;
  --warning: #facc15;
  --danger: #f87171;
  --info: #60a5fa;
  --success-text: #86efac;
  --warning-text: #fde047;
  --danger-text: #fca5a5;
  --info-text: #93c5fd;
  --success-tint: rgba(74, 222, 128, 0.16);
  --warning-tint: rgba(250, 204, 21, 0.16);
  --danger-tint: rgba(248, 113, 113, 0.16);
  --info-tint: rgba(96, 165, 250, 0.16);

  /* Behind dialogs and the phone menu drawer */
  --overlay: rgba(10, 9, 8, 0.7);

  /* Categorical chart series, brand orange first; --chart-7 is the violet for secondary data.
     ChartDefaults mirrors these. */
  --chart-1: #ed7a05;
  --chart-2: #60a5fa;
  --chart-3: #f7a808;
  --chart-4: #4ade80;
  --chart-5: #2dd4bf;
  --chart-6: #e75412;
  --chart-7: #a78bfa;
  --chart-8: #b8b0a6;

  /* Spacing System */
  --space-1: 0.25rem;   /* 4px */
  --space-2: 0.5rem;    /* 8px */
  --space-3: 0.75rem;   /* 12px */
  --space-4: 1rem;      /* 16px */
  --space-5: 1.25rem;   /* 20px */
  --space-6: 1.5rem;    /* 24px */
  --space-8: 2rem;      /* 32px */
  --space-10: 2.5rem;   /* 40px */
  --space-12: 3rem;     /* 48px */
  --space-16: 4rem;     /* 64px */

  /* Border Radius */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 8px;
  --radius-xl: 8px;

  /* Shadows: only what floats (menus, dialogs, the phone drawer) casts one. Surfaces at rest use a border. */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 8px 20px rgba(0, 0, 0, 0.3);
  --shadow-xl: 0 16px 32px rgba(0, 0, 0, 0.35);

  /* Typography: the system stack users already see (Inter was named but never loaded) */
  --font-body: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  --font-heading: var(--font-body);
  --font-mono: Consolas, 'Cascadia Mono', ui-monospace, Menlo, monospace;

  /* Font Sizes */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;
  --text-4xl: 2.25rem;

  /* Font Weights */
  --font-normal: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-base: 0.2s ease;
  --transition-slow: 0.3s ease;

  /* Z-Index Scale */
  --z-dropdown: 1000;
  --z-sticky: 1020;
  --z-fixed: 1030;
  --z-modal-backdrop: 1040;
  --z-modal: 1050;
  --z-toast: 1080;

  /* Bootstrap runs in its own dark mode (data-bs-theme="dark" on <html>), coloured from the tokens
     above, so its components need no !important overrides to look right. */
  --bs-body-bg: var(--bg-page);
  --bs-body-color: var(--text);
  --bs-secondary-color: var(--text-secondary);
  --bs-tertiary-color: var(--text-muted);
  --bs-border-color: var(--border);
  --bs-link-color: var(--brand-light);
  --bs-link-hover-color: var(--link-hover);
  --bs-link-color-rgb: 247, 168, 8;
  --bs-primary: var(--brand);
  --bs-primary-rgb: 237, 122, 5;
  --bs-success-rgb: 74, 222, 128;
  --bs-warning-rgb: 250, 204, 21;
  --bs-danger-rgb: 248, 113, 113;
  --bs-info-rgb: 96, 165, 250;
  --bs-body-font-family: var(--font-body);
}

[data-bs-theme="dark"] {
  --bs-body-bg: var(--bg-page);
  --bs-body-color: var(--text);
  --bs-secondary-bg: var(--bg-card);
  --bs-tertiary-bg: var(--bg-sunken);
  --bs-border-color: var(--border);
  --bs-emphasis-color: var(--text);
  --bs-secondary-color: var(--text-secondary);
  --bs-tertiary-color: var(--text-muted);
  --bs-link-color: var(--brand-light);
  --bs-link-hover-color: var(--link-hover);
  --bs-link-color-rgb: 247, 168, 8;
  --bs-primary-rgb: 237, 122, 5;
}

/* Base Styles */
* {
  box-sizing: border-box;
}

html, body {
  font-family: var(--font-body);
  color: var(--text);
  background: var(--bg-page);
  line-height: 1.5;
  font-size: var(--text-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}

/* Scrollbar Styling for Dark Mode */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-sunken);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-strong);
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  color: var(--text);
  font-weight: var(--font-semibold);
  line-height: 1.3;
  margin: 0 0 var(--space-4) 0;
}

h1 { font-size: var(--text-3xl); }

/* FocusOnNavigate puts focus on the page title for screen readers; a title is not a control, so no ring. */
h1:focus {
  outline: none;
}
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }
h5 { font-size: var(--text-base); font-weight: var(--font-semibold); }
h6 { font-size: var(--text-sm); font-weight: var(--font-semibold); }

/* Layout */
.page {
  display: flex;
  min-height: 100vh;
  background: var(--bg-page);
}

.sidebar {
  background: var(--bg-sunken);
  color: var(--text);
  width: 280px;
  transition: all var(--transition-base);
  z-index: var(--z-sticky);
  border-right: 1px solid var(--border);
}

.main-content {
  padding: var(--space-6);
}

.content-wrapper {
  max-width: none;
  width: 100%;
}

/* Mobile Layout */
.mobile-header {
  display: none;
  background: var(--bg-sunken);
  color: var(--text);
  padding: var(--space-4);
  align-items: center;
  border-bottom: 1px solid var(--border);
}

.mobile-menu-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  margin-right: var(--space-4);
  font-size: var(--text-lg);
  transition: all var(--transition-base);
}

.mobile-menu-btn:hover {
  background: var(--bg-card-hover);
  color: var(--brand-light);
}

.mobile-brand {
  font-size: var(--text-xl);
  font-weight: var(--font-semibold);
  display: flex;
  align-items: center;
  color: var(--text);
}

/* Form controls: every native field, on the elevated surface */
input[type="text"],
input[type="search"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="url"],
input[type="date"],
input[type="datetime-local"],
input[type="month"],
input[type="week"],
input[type="time"],
textarea,
select {
  background: var(--bg-card-hover) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  color: var(--text) !important;
  transition: all var(--transition-base);
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--brand-light) !important;
  box-shadow: 0 0 0 3px var(--focus-ring);
  background: var(--bg-card-hover) !important;
  color: var(--text) !important;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-muted) !important;
}

/* Ensure date picker text is white */
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator,
input[type="month"]::-webkit-calendar-picker-indicator,
input[type="week"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator {
  filter: invert(1);
}

/* Links */
a {
  color: var(--brand);
  text-decoration: none;
  transition: color var(--transition-base);
}

a:hover {
  color: var(--brand);
}

/* Blazor's field state on EditForm inputs (the login form) */
.valid.modified:not([type=checkbox]) {
  outline: 2px solid var(--success);
}

.invalid {
  outline: 2px solid var(--danger);
}

/* Blazor shows this bar on an unhandled error. Every layout carries one, so it is styled here, not in one layout's scoped sheet. */
#blazor-error-ui {
  position: fixed;
  bottom: 0;
  left: 0;
  z-index: 1000;
  display: none;
  width: 100%;
  padding: 0.6rem 1.25rem 0.7rem;
  background: var(--bg-card);
  border-top: 1px solid var(--danger);
  box-shadow: var(--shadow-lg);
  color: var(--text);
}

#blazor-error-ui .dismiss {
  position: absolute;
  top: 0.5rem;
  right: 0.75rem;
  color: var(--text-muted);
  cursor: pointer;
}

#blazor-error-ui .dismiss:hover {
  color: var(--danger);
}

/* ==========================================================================
   Phone layout (≤ 768px): the sidebar becomes a drawer over the page, and the headings shrink.
   ========================================================================== */
@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    transform: translateX(-100%);
    position: fixed;
    top: 0;
    left: 0;
    z-index: var(--z-modal);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--overlay);
    z-index: var(--z-modal-backdrop);
  }

  .mobile-header {
    display: flex;
  }

  .main-content {
    padding: var(--space-4);
  }

  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.35rem; }
  h3 { font-size: 1.2rem; }
  h4 { font-size: 1.1rem; }
  h5 { font-size: 1rem; }
}

@media (max-width: 576px) {
  .main-content {
    padding: var(--space-3);
  }
}

/* ==========================================================================
   Phone card view for wide tables. Opt in with `mobile-cards` on the <table>; mobileTables.js
   copies each header's text onto the cells as data-label. Below 576px the row becomes a card
   and each cell a "label · value" line, so a 12-column table reads top to bottom instead of
   as a 3-screen-wide scroller. Desktop is untouched.
   ========================================================================== */
@media (max-width: 576px) {
  table.mobile-cards {
    display: block;
    width: 100%;
    min-width: 0 !important;
    border: 0 !important;
    box-shadow: none !important;
    background: transparent !important;
    overflow: visible;
  }

  table.mobile-cards > thead {
    display: none;
  }

  /* A footer's totals row (tr.is-total) is the one footer row worth a card of its own. */
  table.mobile-cards > tfoot > tr:not(.is-total) {
    display: none;
  }

  table.mobile-cards > tbody,
  table.mobile-cards > tfoot {
    display: block;
  }

  table.mobile-cards > tbody > tr,
  table.mobile-cards > tfoot > tr {
    display: block;
    margin-bottom: 0.6rem;
    padding: 0.35rem 0.7rem;
    border: 1px solid var(--border) !important;
    border-radius: var(--radius-md);
    background: var(--bg-card) !important;
    box-shadow: none;
    transform: none !important;
  }

  table.mobile-cards > :is(tbody, tfoot) > tr.is-total {
    border-color: var(--border-strong) !important;
    background: var(--bg-sunken) !important;
  }

  table.mobile-cards > :is(tbody, tfoot) > tr > td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    padding: 0.35rem 0 !important;
    border: 0 !important;
    border-bottom: 1px solid var(--border) !important;
    text-align: right;
    font-size: 0.85rem;
    white-space: normal;
    min-width: 0 !important;
    width: auto !important;
    max-width: none !important;
    background: transparent !important;
  }

  table.mobile-cards > :is(tbody, tfoot) > tr > td:last-child {
    border-bottom: 0 !important;
  }

  table.mobile-cards > :is(tbody, tfoot) > tr > td::before {
    content: attr(data-label);
    flex: 0 0 38%;
    text-align: left;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
  }

  table.mobile-cards > :is(tbody, tfoot) > tr > td:not([data-label])::before {
    content: none;
  }

  /* The first column is usually the row's identity (card, user, order) — make it the title */
  table.mobile-cards > :is(tbody, tfoot) > tr > td:first-child[data-label] {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
  }

  table.mobile-cards > :is(tbody, tfoot) > tr > td:first-child[data-label]::before {
    flex-basis: 30%;
  }

  /* A cell spanning the row (expanded detail, empty state) keeps its natural width */
  table.mobile-cards > :is(tbody, tfoot) > tr > td.mc-span {
    display: block;
    text-align: left;
  }

  table.mobile-cards > :is(tbody, tfoot) > tr > td.mc-span::before {
    content: none;
  }

  table.mobile-cards > :is(tbody, tfoot) > tr > td:empty {
    display: none;
  }
}

/* Painted by App.razor before the circuit connects, so the first thing on screen is the app's shape
   rather than a blank page. Removed by Ab_Server.lib.module.js when the circuit starts; the :has rule
   hides it as soon as the layout has rendered, whichever comes first. */
.app-boot {
  position: fixed;
  inset: 0;
  z-index: var(--z-fixed);
  display: flex;
  background: var(--bg-page);
}

body:has(.page) .app-boot {
  display: none;
}

.app-boot-nav {
  width: 240px;
  flex-shrink: 0;
  background: var(--bg-chrome);
  border-right: 1px solid var(--border);
}

.app-boot-main {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-6) var(--space-8);
}

.app-boot-line {
  height: 1rem;
  max-width: 60rem;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--bg-card) 0%, var(--bg-card-hover) 50%, var(--bg-card) 100%);
  background-size: 200% 100%;
  animation: app-boot-shimmer 1.4s ease-in-out infinite;
}

.app-boot-line.is-title {
  width: 18rem;
  height: 1.75rem;
}

.app-boot-line.is-block {
  height: 7rem;
}

@keyframes app-boot-shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

@media (max-width: 992px) {
  .app-boot-nav {
    display: none;
  }

  .app-boot-main {
    padding: var(--space-4);
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-boot-line {
    animation: none;
  }
}
