/* ==========================================================================
   BASE  (assets/css/base.css)
   --------------------------------------------------------------------------
   Loaded first on every page. Everything else reads these tokens.

   1. Tokens - light      5. Links
   2. Tokens - dark       6. Buttons      (.btn-crm + modifiers)
   3. Reset              7. Icon button  (.icon-btn)
   4. Typography         8. Forms        (.field .input .input-group .check)
                          9. Helpers      (iconSize-*, h-*, w-*, skip-link, theme icons)

   Dark mode: <html data-theme="dark">. Set before paint in header.php,
   toggled by base.js, saved in localStorage('crm-theme').
   ========================================================================== */

/* ==========================================================================
   1. TOKENS - LIGHT
   Palette: cool neutral greys + blue primary + deep navy panels.
   The orange accent echoes the dot in the logo (use sparingly).
   ========================================================================== */
:root {
  color-scheme: light;

  /* spacing (utilities.css uses sp-1/2/4/6/12) */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;
  --sp-16: 64px;

  /* radius */
  --radius-sm: 8px;
  --radius: 10px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-pill: 999px;

  /* surfaces */
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --surface-3: #eef1f5;
  --surface-hover: #f2f4f7;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;

  /* text */
  --text: #101828;
  --text-muted: #475467;
  --text-subtle: #8a94a6;

  /* brand (primary actions, links, focus) */
  --brand: #2456e6;
  --brand-hover: #1c46c4;
  --brand-contrast: #ffffff;
  --brand-soft: #edf2ff;
  --brand-ink: #1f4bd0;
  --focus-ring: 0 0 0 3px rgba(36, 86, 230, 0.22);

  /* accent (logo orange) */
  --accent: #f28f23;
  --accent-soft: #fff4e6;

  /* dark side panels (sidebar, login panel) - dark in both themes */
  --panel: #0e1629;
  --panel-2: #1a2440;
  --panel-text: #f2f4f8;
  --panel-muted: #a3adc2;
  --panel-subtle: #6b7690;
  --panel-accent: #8fb0ff;
  --panel-hover: rgba(255, 255, 255, 0.05);
  --panel-active: rgba(143, 176, 255, 0.14);

  /* status */
  --success: #067647;
  --success-bg: #ecfdf3;
  --warning: #b54708;
  --warning-bg: #fffaeb;
  --danger: #c01048;
  --danger-bg: #fff1f3;
  --info: #175cd3;
  --info-bg: #eff8ff;
  --neutral-bg: #f2f4f7;

  /* palette (utilities.css color helpers) */
  --teal: #0e7c86;
  --teal-bg: #e6f6f7;
  --cyan: #0e7490;
  --cyan-bg: #e0f2f7;
  --indigo: #444ce7;
  --indigo-bg: #eef4ff;
  --pink: #c11574;
  --pink-bg: #fdf2fa;
  --orange: #e04f16;
  --orange-bg: #fef6ee;
  --yellow: #a15c07;
  --yellow-bg: #fefbe8;
  --gray: #667085;
  --gray-bg: #f2f4f7;

  --gradient-1: linear-gradient(135deg, #2456e6, #5b7ff0);
  --gradient-2: linear-gradient(160deg, #0e1629, #1a2a52);
  --gradient-3: linear-gradient(135deg, #fea818, #dd6435);
  --gradient-4: linear-gradient(135deg, #edf2ff, #f5f7fa);

  /* elevation */
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow:
    0 4px 12px -2px rgba(16, 24, 40, 0.08),
    0 2px 4px -2px rgba(16, 24, 40, 0.04);
  --shadow-lg:
    0 20px 40px -8px rgba(16, 24, 40, 0.18),
    0 6px 12px -4px rgba(16, 24, 40, 0.06);
  --shadow-brand: 0 10px 24px -6px rgba(36, 86, 230, 0.45);

  /* motion */
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --fast: 0.15s;
  --slow: 0.3s;

  /* layout */
  --header-h: 64px;
  --sidebar-w: 256px;
  --mobile-nav-h: 64px;

  /* type */
  --font:
    "Lexend Deca", "Helvetica Neue", Helvetica, Arial, system-ui, -apple-system,
    "Segoe UI", Roboto, sans-serif;
}

/* ==========================================================================
   2. TOKENS - DARK
   ========================================================================== */
[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0a0f1c;
  --surface: #111827;
  --surface-2: #151d2e;
  --surface-3: #1c2538;
  --surface-hover: #182133;
  --border: #222c40;
  --border-strong: #334058;

  --text: #eef1f6;
  --text-muted: #a7b0c2;
  --text-subtle: #6f7a91;

  --brand: #5b8cff;
  --brand-hover: #7aa2ff;
  --brand-contrast: #06102a;
  --brand-soft: rgba(91, 140, 255, 0.14);
  --brand-ink: #8fb0ff;
  --focus-ring: 0 0 0 3px rgba(91, 140, 255, 0.35);

  --accent: #f7a440;
  --accent-soft: rgba(247, 164, 64, 0.12);

  --panel: #070b16;
  --panel-2: #141c30;

  --success: #47cd89;
  --success-bg: rgba(71, 205, 137, 0.12);
  --warning: #fdb022;
  --warning-bg: rgba(253, 176, 34, 0.12);
  --danger: #fd6f8e;
  --danger-bg: rgba(253, 111, 142, 0.12);
  --info: #53b1fd;
  --info-bg: rgba(83, 177, 253, 0.12);
  --neutral-bg: #1c2538;

  --teal: #2ed3b7;
  --teal-bg: rgba(46, 211, 183, 0.12);
  --cyan: #38bdf8;
  --cyan-bg: rgba(56, 189, 248, 0.12);
  --indigo: #8098f9;
  --indigo-bg: rgba(128, 152, 249, 0.13);
  --pink: #f670c7;
  --pink-bg: rgba(246, 112, 199, 0.12);
  --orange: #f38744;
  --orange-bg: rgba(243, 135, 68, 0.12);
  --yellow: #fac515;
  --yellow-bg: rgba(250, 197, 21, 0.12);
  --gray: #98a2b3;
  --gray-bg: rgba(152, 162, 179, 0.12);

  --gradient-4: linear-gradient(135deg, #151d2e, #0a0f1c);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 24px 50px rgba(0, 0, 0, 0.55);
  --shadow-brand: 0 10px 24px -6px rgba(91, 140, 255, 0.4);
}

/* ==========================================================================
   3. RESET
   ========================================================================== */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition:
    background-color var(--slow) var(--ease),
    color var(--slow) var(--ease);
}
h1,
h2,
h3,
h4,
h5,
h6,
p,
ul,
ol,
figure {
  margin: 0;
}
ul,
ol {
  padding: 0;
  list-style: none;
}
img,
svg,
video {
  display: block;
  max-width: 100%;
}
img {
  height: auto;
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0;
}
[hidden] {
  display: none !important;
}
:focus {
  outline: none;
}
/*:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }*/
[tabindex="-1"]:focus,
[tabindex="-1"]:focus-visible {
  outline: none;
}
::selection {
  background: var(--brand-soft);
  color: var(--text);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* ==========================================================================
   4. TYPOGRAPHY
   ========================================================================== */
h1,
h2,
h3,
h4 {
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--text);
}
strong,
b {
  font-weight: 700;
}
small {
  font-size: 12.5px;
}
kbd {
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-subtle);
}
.eyebrow {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-subtle);
}

/* ==========================================================================
   5. LINKS
   ========================================================================== */
a {
  color: inherit;
  text-decoration: none;
}
.link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--brand-ink);
  font-weight: 600;
  text-underline-offset: 3px;
  transition: color var(--fast) var(--ease);
}
.link:hover {
  text-decoration: underline;
}
.link--muted {
  color: var(--text-muted);
  font-weight: 500;
}
button.link {
  font-size: inherit;
}

/* ==========================================================================
   6. BUTTONS
   .btn-crm            base (neutral surface)
   .btn-crm--primary   teal fill              .btn-crm--dark   dark fill
   .btn-crm--outline   bordered surface       .btn-crm--ghost  transparent
   .btn-crm--sm / --lg size                   .btn-crm--block  full width
   .is-loading        shows .btn-crm__spinner, hides nothing, disables clicks
   ========================================================================== */
.btn-crm {
  --btn-h: 42px;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: var(--btn-h);
  padding: 0 18px;
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition:
    background-color var(--fast) var(--ease),
    border-color var(--fast) var(--ease),
    color var(--fast) var(--ease),
    box-shadow var(--fast) var(--ease),
    transform var(--fast) var(--ease);
  user-select: none;
}
.btn-crm:hover {
  background: var(--surface-hover);
}
.btn-crm:active {
  transform: translateY(1px);
}
.btn-crm:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
.btn-crm[disabled],
.btn-crm.is-disabled {
  opacity: 0.55;
  pointer-events: none;
}

.btn-crm--primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-contrast);
  box-shadow:
    0 1px 2px rgba(16, 24, 40, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.14);
}
.btn-crm--primary:hover {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
}
.btn-crm--dark {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
}
.btn-crm--dark:hover {
  background: var(--text);
  opacity: 0.9;
}
.btn-crm--outline {
  background: var(--surface);
  border-color: var(--border-strong);
}
.btn-crm--outline:hover {
  border-color: var(--text-subtle);
  background: var(--surface-hover);
}
.btn-crm--danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.1);
}
.btn-crm--danger:hover {
  background: var(--danger);
  border-color: var(--danger);
  filter: brightness(0.9);
}
.btn-crm--ghost {
  background: transparent;
  border-color: transparent;
}
.btn-crm--ghost:hover {
  background: var(--surface-hover);
}

.btn-crm--sm {
  --btn-h: 34px;
  padding: 0 12px;
  font-size: 13.5px;
}
.btn-crm--lg {
  --btn-h: 48px;
  padding: 0 22px;
  font-size: 15px;
}
.btn-crm--block {
  display: flex;
  width: 100%;
}

.btn-crm__spinner {
  display: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: spin 0.7s linear infinite;
}
.btn-crm.is-loading {
  pointer-events: none;
}
.btn-crm.is-loading .btn-crm__spinner {
  display: inline-block;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ==========================================================================
   7. ICON BUTTON
   ========================================================================== */
.icon-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  transition:
    background-color var(--fast) var(--ease),
    color var(--fast) var(--ease),
    border-color var(--fast) var(--ease);
}
.icon-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}
.icon-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
.icon-btn--ghost {
  border-color: transparent;
  background: transparent;
}
/* unread dot */
.icon-btn.has-dot::after {
  content: "";
  position: absolute;
  top: 8px;
  right: 9px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 2px var(--surface);
}

/* ==========================================================================
   8. FORMS
   <div class="field">
     <label class="field__label">  <input class="input">  <p class="field__error">
   </div>
   .field.is-invalid shows the error text + red border (set by base.js)
   ========================================================================== */
.field {
  display: grid;
  gap: 6px;
}
.field__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
}
.field__label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.field__hint {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--warning);
}
.field__error {
  display: none;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--danger);
}
.field.is-invalid .field__error {
  display: block;
}
.field.is-invalid .input {
  border-color: var(--danger);
}
.field.is-invalid .input:focus {
  box-shadow: 0 0 0 3px var(--danger-bg);
}
* input:focus {
  box-shadow: none !important;
  outline: none !important;
}
.input {
  width: 100%;
  height: 46px;
  padding: 0 14px;
  font-size: 15px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition:
    border-color var(--fast) var(--ease),
    box-shadow var(--fast) var(--ease),
    background-color var(--slow) var(--ease);
  appearance: none;
}
.input::placeholder {
  color: var(--text-subtle);
}
.input:hover {
  border-color: var(--text-subtle);
}
.input:focus {
  border-color: var(--brand);
}
/* Chrome autofill in dark mode */
.input:-webkit-autofill {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 100px var(--surface) inset;
  caret-color: var(--text);
}
/* input with trailing button (show / hide password) */
.input-group {
  position: relative;
}
.input-group .input {
  padding-right: 48px;
}
.input-group__btn {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  color: var(--text-subtle);
}
.input-group__btn:hover {
  color: var(--text);
  background: var(--surface-hover);
}
.input-group__btn .icon-hide {
  display: none;
}
.input-group__btn[aria-pressed="true"] .icon-show {
  display: none;
}
.input-group__btn[aria-pressed="true"] .icon-hide {
  display: block;
}

/* custom checkbox: <label class="check"><input type="checkbox"><span class="check__box"></span>Text</label> */
.check {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
.check input {
  position: absolute;
  opacity: 0;
  width: 20px;
  height: 20px;
  margin: 0;
  cursor: pointer;
}
.check__box {
  flex: none;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border: 1.5px solid var(--border-strong);
  border-radius: 5px;
  background: var(--surface);
  transition:
    background-color var(--fast) var(--ease),
    border-color var(--fast) var(--ease);
}
.check__box::after {
  content: "";
  width: 10px;
  height: 6px;
  border: 2px solid var(--brand-contrast);
  border-top: 0;
  border-right: 0;
  transform: rotate(-45deg) translate(1px, -1px) scale(0);
  transition: transform var(--fast) var(--ease);
}
.check:hover .check__box {
  border-color: var(--brand);
}
.check input:checked + .check__box {
  background: var(--brand);
  border-color: var(--brand);
}
.check input:checked + .check__box::after {
  transform: rotate(-45deg) translate(1px, -1px) scale(1);
}
.check input:focus-visible + .check__box {
  box-shadow: var(--focus-ring);
}

/* ==========================================================================
   9. HELPERS
   ========================================================================== */
.icon {
  flex: none;
}
.iconSize-14 {
  width: 14px;
  height: 14px;
}
.iconSize-16 {
  width: 16px;
  height: 16px;
}
.iconSize-18 {
  width: 18px;
  height: 18px;
}
.iconSize-20 {
  width: 20px;
  height: 20px;
}
.iconSize-24 {
  width: 24px;
  height: 24px;
}
.iconSize-28 {
  width: 28px;
  height: 28px;
}

.h-32 {
  height: 32px !important;
}
.w-32 {
  width: 32px !important;
}
.h-36 {
  height: 36px !important;
}
.w-36 {
  width: 36px !important;
}
.h-40 {
  height: 40px !important;
}
.w-40 {
  width: 40px !important;
}
.h-48 {
  height: 48px !important;
}
.w-48 {
  width: 48px !important;
}

/* keyboard users: jump past the sidebar */
.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 1000;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: var(--brand);
  color: var(--brand-contrast);
  font-weight: 600;
  transform: translateY(-150%);
  transition: transform var(--fast) var(--ease);
}
.skip-link:focus {
  transform: none;
}

/* theme icons: show sun in light, moon in dark */
.icon-moon {
  display: none;
}
[data-theme="dark"] .icon-sun {
  display: none;
}
[data-theme="dark"] .icon-moon {
  display: block;
}

/* logo swap by theme */
.brand__logo--dark {
  display: none;
}
[data-theme="dark"] .brand__logo--light {
  display: none;
}
[data-theme="dark"] .brand__logo--dark {
  display: block;
}
