/* ==========================================================================
   CipherX — Design System
   --------------------------------------------------------------------------
   Single source of truth for the application's visual language. Loaded once,
   after Bootstrap, in templates/base.html. Rebrands Bootstrap via its CSS
   custom properties (so existing .btn-primary / .card / .table markup picks
   up the theme with no per-page edits) and adds a small set of reusable
   CipherX components (.cx-*).

   See design.md for the full rationale, palette and usage guidelines.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Brand tokens
   -------------------------------------------------------------------------- */
:root {
  /* Core ink / black — sidebar matches the logo_black.png background (#151515) */
  --cx-black:        #151515;   /* sidebar, logo backdrop */
  --cx-ink:          #1A1D1F;   /* primary text & headings on light surfaces */
  --cx-ink-soft:     #3A4042;   /* secondary headings */

  /* Orange — Pantone Orange 021 build (C0 M45 Y86 K0). Primary accent. */
  --cx-orange:       #FF8C24;   /* fills: buttons, active states, highlights */
  --cx-orange-600:   #ED7611;   /* hover  */
  --cx-orange-700:   #D8640A;   /* active / pressed */
  --cx-orange-text:  #C2611A;   /* orange used as text/links (AA on white) */
  --cx-orange-soft:  #FFF1E2;   /* tint background */
  --cx-orange-rgb:   255, 140, 36;

  /* Warm white / sand — Pantone Warm Grey 1 U build (C2 M3 Y7 K8) */
  --cx-bg:           #F6F4EE;   /* app background */
  --cx-surface:      #FFFFFF;   /* cards, panels */
  --cx-sand:         #E6E4DA;   /* muted surfaces, hover rows */
  --cx-border:       #E2DFD4;   /* warm hairline borders */

  /* Steel grey — Pantone 7544 U. Secondary / muted. */
  --cx-steel:        #76858B;   /* muted icons & meta */
  --cx-steel-600:    #5C6A70;   /* secondary text (AA on white) */
  --cx-steel-100:    #EDF0F0;   /* subtle steel tint */
  --cx-steel-rgb:    118, 133, 139;

  /* Geometry & elevation */
  --cx-radius-sm: 8px;
  --cx-radius:    12px;
  --cx-radius-lg: 18px;
  --cx-shadow-sm: 0 1px 2px rgba(21, 21, 21, .06);
  --cx-shadow:    0 2px 10px rgba(21, 21, 21, .06), 0 1px 2px rgba(21, 21, 21, .04);
  --cx-shadow-lg: 0 12px 32px rgba(21, 21, 21, .12);
  --cx-sidebar-width: 250px;
}

/* --------------------------------------------------------------------------
   2. Bootstrap variable overrides (rebrands existing components)
   -------------------------------------------------------------------------- */
:root {
  --bs-primary:           var(--cx-orange);
  --bs-primary-rgb:       var(--cx-orange-rgb);
  --bs-link-color:        var(--cx-orange-text);
  --bs-link-color-rgb:    194, 97, 26;
  --bs-link-hover-color:  var(--cx-orange-700);

  --bs-secondary:         var(--cx-steel);
  --bs-secondary-rgb:     var(--cx-steel-rgb);

  --bs-dark:              var(--cx-black);
  --bs-dark-rgb:          21, 21, 21;

  --bs-body-bg:           var(--cx-bg);
  --bs-body-color:        var(--cx-ink);
  --bs-body-color-rgb:    26, 29, 31;
  --bs-border-color:      var(--cx-border);

  --bs-border-radius:     var(--cx-radius-sm);
  --bs-border-radius-sm:  6px;
  --bs-border-radius-lg:  var(--cx-radius);

  --bs-font-sans-serif: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* --------------------------------------------------------------------------
   3. Base & typography
   -------------------------------------------------------------------------- */
body {
  font-family: var(--bs-font-sans-serif);
  background-color: var(--cx-bg);
  color: var(--cx-ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6,
.h1, .h2, .h3, .h4, .h5, .h6 {
  color: var(--cx-ink);
  font-weight: 650;
  letter-spacing: -0.01em;
}

a { text-decoration: none; }
a:hover { text-decoration: none; }

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

/* Selection + focus ring in brand orange */
::selection { background: rgba(var(--cx-orange-rgb), .25); }
:focus-visible {
  outline: 2px solid rgba(var(--cx-orange-rgb), .55);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   4. Layout — black sidebar
   -------------------------------------------------------------------------- */
.sidebar {
  min-height: 100vh;
  background: var(--cx-black);
  border-right: none;
  color: rgba(255, 255, 255, .72);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.2) transparent;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.18); border-radius: 8px; }

.sidebar .logo,
.sidebar .cx-brand img { max-width: 150px; height: auto; display: block; }
.sidebar .cx-brand {
  padding-bottom: 1rem;
  margin-bottom: .5rem;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}

/* Nav links inside the dark sidebar */
.sidebar .nav-link {
  color: rgba(255, 255, 255, .72);
  border-radius: var(--cx-radius-sm);
  padding: .5rem .7rem;
  font-size: .9rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  transition: background-color .12s ease, color .12s ease;
}
.sidebar .nav-link:hover,
.sidebar .nav-link:focus {
  color: #fff;
  background: rgba(255, 255, 255, .08);
}
.sidebar .nav-link[aria-expanded="true"] { color: #fff; }

/* Section sub-links */
.sidebar .collapse .nav-link { font-weight: 450; font-size: .86rem; color: rgba(255,255,255,.62); }
.sidebar .collapse .nav-link:hover { color: #fff; background: rgba(255,255,255,.06); }

/* Active page link — orange accent bar */
.sidebar .nav-link.active {
  color: #fff;
  background: rgba(var(--cx-orange-rgb), .16);
  box-shadow: inset 3px 0 0 var(--cx-orange);
}

/* Sub-headings within sections (e.g. "Formulations", "Inbound") */
.sidebar .nav-link.fw-bold.text-muted,
.sidebar .text-muted {
  color: rgba(255, 255, 255, .4) !important;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-size: .68rem !important;
}

.sidebar .btn-outline-secondary {
  color: rgba(255,255,255,.85);
  border-color: rgba(255,255,255,.25);
}
.sidebar .btn-outline-secondary:hover {
  background: var(--cx-orange);
  border-color: var(--cx-orange);
  color: var(--cx-black);
}

@media (max-width: 767.98px) {
  .sidebar { min-height: auto; height: auto; position: static; border-bottom: 1px solid rgba(255,255,255,.08); }
}

/* Main content breathing room */
main { background: var(--cx-bg); }

/* --------------------------------------------------------------------------
   5. Buttons
   -------------------------------------------------------------------------- */
.btn { font-weight: 550; border-radius: var(--cx-radius-sm); white-space: nowrap; }
.btn-sm, .btn-group-sm > .btn { font-size: .8rem; }

/* Primary = orange with ink text (the brand's orange-on-black signature) */
.btn-primary,
.btn-accent {
  --bs-btn-bg:            var(--cx-orange);
  --bs-btn-border-color:  var(--cx-orange);
  --bs-btn-color:         var(--cx-black);
  --bs-btn-hover-bg:      var(--cx-orange-600);
  --bs-btn-hover-border-color: var(--cx-orange-600);
  --bs-btn-hover-color:   var(--cx-black);
  --bs-btn-active-bg:     var(--cx-orange-700);
  --bs-btn-active-border-color: var(--cx-orange-700);
  --bs-btn-active-color:  #fff;
  --bs-btn-disabled-bg:   var(--cx-orange);
  --bs-btn-disabled-border-color: var(--cx-orange);
  --bs-btn-disabled-color: var(--cx-black);
}

.btn-outline-primary {
  --bs-btn-color:         var(--cx-orange-text);
  --bs-btn-border-color:  var(--cx-orange);
  --bs-btn-hover-bg:      var(--cx-orange);
  --bs-btn-hover-border-color: var(--cx-orange);
  --bs-btn-hover-color:   var(--cx-black);
  --bs-btn-active-bg:     var(--cx-orange-600);
  --bs-btn-active-border-color: var(--cx-orange-600);
  --bs-btn-active-color:  var(--cx-black);
}

/* Secondary = steel */
.btn-secondary {
  --bs-btn-bg:            var(--cx-steel);
  --bs-btn-border-color:  var(--cx-steel);
  --bs-btn-color:         #fff;
  --bs-btn-hover-bg:      var(--cx-steel-600);
  --bs-btn-hover-border-color: var(--cx-steel-600);
  --bs-btn-active-bg:     var(--cx-steel-600);
}
.btn-outline-secondary {
  --bs-btn-color:         var(--cx-steel-600);
  --bs-btn-border-color:  var(--cx-steel);
  --bs-btn-hover-bg:      var(--cx-ink);
  --bs-btn-hover-border-color: var(--cx-ink);
  --bs-btn-hover-color:   #fff;
  --bs-btn-active-bg:     var(--cx-ink);
  --bs-btn-active-border-color: var(--cx-ink);
}

/* Dark = ink */
.btn-dark {
  --bs-btn-bg:            var(--cx-black);
  --bs-btn-border-color:  var(--cx-black);
  --bs-btn-hover-bg:      #000;
  --bs-btn-hover-border-color: #000;
}

/* --------------------------------------------------------------------------
   6. Forms
   -------------------------------------------------------------------------- */
.form-control, .form-select {
  border-color: var(--cx-border);
  border-radius: var(--cx-radius-sm);
}
.form-control:focus, .form-select:focus {
  border-color: var(--cx-orange);
  box-shadow: 0 0 0 .2rem rgba(var(--cx-orange-rgb), .2);
}
.form-check-input:checked {
  background-color: var(--cx-orange);
  border-color: var(--cx-orange);
}
.form-check-input:focus { border-color: var(--cx-orange); box-shadow: 0 0 0 .2rem rgba(var(--cx-orange-rgb), .2); }
.form-label { font-weight: 550; color: var(--cx-ink-soft); font-size: .875rem; }

/* --------------------------------------------------------------------------
   7. Cards & panels
   -------------------------------------------------------------------------- */
.card {
  --bs-card-bg: var(--cx-surface);
  --bs-card-border-color: var(--cx-border);
  --bs-card-border-radius: var(--cx-radius);
  --bs-card-inner-border-radius: calc(var(--cx-radius) - 1px);
  box-shadow: var(--cx-shadow);
}
.card-header {
  background: var(--cx-surface);
  border-bottom: 1px solid var(--cx-border);
  font-weight: 600;
  color: var(--cx-ink);
}
.card-header.bg-light { background: var(--cx-bg) !important; }

/* --------------------------------------------------------------------------
   8. Tables
   -------------------------------------------------------------------------- */
.table {
  --bs-table-hover-bg: rgba(var(--cx-orange-rgb), .06);
  --bs-table-border-color: var(--cx-border);
  color: var(--cx-ink);
}
.table > thead {
  --bs-table-bg: var(--cx-bg);
}
.table > thead th {
  text-transform: uppercase;
  letter-spacing: .04em;
  font-size: .74rem;
  font-weight: 650;
  color: var(--cx-steel-600);
  border-bottom: 2px solid var(--cx-border);
  white-space: nowrap;
}
.table-light { --bs-table-bg: var(--cx-bg); }

/* --------------------------------------------------------------------------
   9. Badges, pills, chips
   -------------------------------------------------------------------------- */
.badge { font-weight: 600; letter-spacing: .01em; padding: .4em .6em; border-radius: 999px; }
.badge.bg-secondary { background-color: var(--cx-steel) !important; }
.badge.bg-light { background-color: var(--cx-sand) !important; color: var(--cx-ink) !important; }

/* Soft status chip — reusable component */
.cx-chip {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .25rem .6rem;
  font-size: .76rem;
  font-weight: 600;
  border-radius: 999px;
  background: var(--cx-steel-100);
  color: var(--cx-steel-600);
  line-height: 1.2;
}
.cx-chip--accent  { background: var(--cx-orange-soft); color: var(--cx-orange-700); }
.cx-chip--success { background: #E4F4E9; color: #1E7A3D; }
.cx-chip--warning { background: #FBF0D6; color: #946200; }
.cx-chip--danger  { background: #FBE3E3; color: #B02A2A; }
.cx-chip--ink     { background: rgba(21,21,21,.08); color: var(--cx-ink); }

/* --------------------------------------------------------------------------
   10. Nav tabs & pills (in-page)
   -------------------------------------------------------------------------- */
.nav-tabs { --bs-nav-tabs-border-color: var(--cx-border); }
.nav-tabs .nav-link { color: var(--cx-steel-600); font-weight: 550; }
.nav-tabs .nav-link.active {
  color: var(--cx-ink);
  border-bottom: 2px solid var(--cx-orange);
  background: transparent;
  border-top-color: transparent;
  border-left-color: transparent;
  border-right-color: transparent;
}
.nav-pills .nav-link.active { background: var(--cx-orange); color: var(--cx-black); }

/* Alerts keep semantic colours; just soften corners */
.alert { border-radius: var(--cx-radius-sm); border: 1px solid transparent; }

/* --------------------------------------------------------------------------
   11. Reusable CipherX components
   -------------------------------------------------------------------------- */

/* Page header (used by base.html page_header block) — orange accent bar left of the title block */
.cx-page-header { border-bottom: 1px solid var(--cx-border); }
.cx-page-header > div:first-child {
  border-left: 4px solid var(--cx-orange);
  padding-left: .8rem;
}
.cx-page-header .cx-page-title { font-size: 1.5rem; font-weight: 700; margin-bottom: .15rem; }
.cx-page-header .cx-page-subtitle { color: var(--cx-steel-600); font-size: .875rem; margin: 0; }

/* Pagination — brand the active page orange */
.pagination {
  --bs-pagination-color: var(--cx-steel-600);
  --bs-pagination-hover-color: var(--cx-orange-700);
  --bs-pagination-focus-color: var(--cx-orange-700);
  --bs-pagination-focus-box-shadow: 0 0 0 .2rem rgba(var(--cx-orange-rgb), .2);
  --bs-pagination-active-bg: var(--cx-orange);
  --bs-pagination-active-border-color: var(--cx-orange);
}
.pagination .page-item.active .page-link { color: var(--cx-black); }

/* Stat / KPI tile */
.cx-stat {
  background: var(--cx-surface);
  border: 1px solid var(--cx-border);
  border-radius: var(--cx-radius);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--cx-shadow);
  display: flex;
  flex-direction: column;
  gap: .25rem;
  height: 100%;
}
.cx-stat__label { font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--cx-steel-600); font-weight: 600; }
.cx-stat__value { font-size: 1.8rem; font-weight: 700; color: var(--cx-ink); line-height: 1.1; }
.cx-stat__meta  { font-size: .8rem; color: var(--cx-steel-600); }
.cx-stat--accent { border-top: 3px solid var(--cx-orange); }

/* Empty state */
.cx-empty {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--cx-steel-600);
  background: var(--cx-surface);
  border: 1px dashed var(--cx-border);
  border-radius: var(--cx-radius);
}
.cx-empty__icon { color: var(--cx-steel); opacity: .6; margin-bottom: .75rem; }
.cx-empty__title { color: var(--cx-ink); font-weight: 600; margin-bottom: .25rem; }

/* Accent left-border highlight for callout cards */
.cx-callout { border-left: 4px solid var(--cx-orange); background: var(--cx-orange-soft); }

/* --------------------------------------------------------------------------
   12. Auth / sign-in screen (full-bleed, no sidebar)
   -------------------------------------------------------------------------- */
.cx-auth {
  min-height: 100vh;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: #0E0E0E;
  background-image:
    radial-gradient(60rem 60rem at 50% -20%, rgba(var(--cx-orange-rgb), .12), transparent 60%);
}
.cx-auth__card {
  width: 100%;
  max-width: 400px;
  aspect-ratio: 1 / 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: .35rem;
  padding: 2.5rem 2rem;
  /* matches logo_black.png backdrop so the logo blends seamlessly; sits on a
     darker page so the card still reads as a distinct square */
  background: var(--cx-black);
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: var(--cx-radius-lg);
  box-shadow: var(--cx-shadow-lg);
}
.cx-auth__logo { width: 130px; height: auto; margin-bottom: .25rem; }
.cx-auth__title { color: #fff; font-size: 1.5rem; font-weight: 700; margin: 0; }
.cx-auth__subtitle { color: rgba(255, 255, 255, .55); font-size: .9rem; margin: 0 0 1.75rem; }

/* Google sign-in button */
.cx-google-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .65rem;
  width: 100%;
  padding: .7rem 1rem;
  font-weight: 600;
  border-radius: var(--cx-radius-sm);
  background: var(--cx-orange);
  color: var(--cx-black);
  border: none;
  transition: background-color .12s ease, transform .04s ease;
}
.cx-google-btn:hover  { background: var(--cx-orange-600); color: var(--cx-black); }
.cx-google-btn:active { background: var(--cx-orange-700); transform: translateY(1px); }
.cx-google-btn__g {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px; height: 24px;
  background: #fff;
  border-radius: 5px;
  flex: none;
}
@media (max-width: 460px) {
  .cx-auth__card { aspect-ratio: auto; }
}

/* Generic surface helpers */
.cx-surface { background: var(--cx-surface); border: 1px solid var(--cx-border); border-radius: var(--cx-radius); }
.bg-cx-sand { background: var(--cx-sand) !important; }
.text-cx-orange { color: var(--cx-orange-text) !important; }
.text-cx-steel { color: var(--cx-steel-600) !important; }
