/* ============================================================
   DESIGN SYSTEM — source of truth for all UI work
   See UX-ARCHITECTURE.md for full specification.
   ============================================================ */

/* ── §2.1 Color Palette ───────────────────────────────────── */
:root {
  --color-navy:      #1B2A4A;
  --color-blue:      #3B6CB4;
  --color-lightBlue: #E8F0FA;
  --color-black:     #111827;
  --color-green:     #2E7D32;
  --color-amber:     #D4860A;
  --color-red:       #C62828;
  --color-gray:      #6B7280;
  --color-surface:   #F3F4F6;
  --color-border:    #D1D5DB;

  /* ── Sidebar dimensions ───────────────────────────────── */
  --sidebar-width:           240px;
  --sidebar-width-collapsed: 56px;

  /* Derived tints used for badge backgrounds */
  --color-blue-tint:   #EBF1FA;
  --color-green-tint:  #E8F5E9;
  --color-amber-tint:  #FFF3E0;
  --color-red-tint:    #FEECEC;
  --color-gray-tint:   #F3F4F6;

  /* ── §2.2 Typography ──────────────────────────────────── */
  --fs-page-title:     24px;  --fw-page-title:     700;
  --fs-section-header: 18px;  --fw-section-header: 600;
  --fs-card-title:     15px;  --fw-card-title:     600;
  --fs-body:           14px;  --fw-body:           400;
  --fs-meta:           13px;  --fw-meta:           400;
  --fs-badge:          12px;  --fw-badge:          500;
  --fs-button:         14px;  --fw-button:         500;

  /* ── §2.3 Spacing & Layout ────────────────────────────── */
  --page-px:           24px;
  --page-py:           20px;
  --card-padding:      16px;
  --card-gap:          12px;
  --section-spacing:   24px;
  --radius-card:       8px;
  --radius-button:     6px;
  --radius-badge:      4px;
  --max-content-width: 1200px;

  /* ── Shadows ──────────────────────────────────────────── */
  --shadow-card:       0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-card-hover: 0 2px 6px rgba(0, 0, 0, 0.12);
}

/* ============================================================
   SEMANTIC TYPOGRAPHY UTILITIES
   ============================================================ */
.ds-page-title {
  font-size:   var(--fs-page-title);
  font-weight: var(--fw-page-title);
  color:       var(--color-navy);
  line-height: 1.25;
}
.ds-section-header {
  font-size:   var(--fs-section-header);
  font-weight: var(--fw-section-header);
  color:       var(--color-navy);
  line-height: 1.3;
}
.ds-card-title {
  font-size:   var(--fs-card-title);
  font-weight: var(--fw-card-title);
  color:       #1F2937;
  line-height: 1.3;
}
.ds-body {
  font-size:   var(--fs-body);
  font-weight: var(--fw-body);
  color:       #1F2937;
  line-height: 1.5;
}
.ds-meta {
  font-size:   var(--fs-meta);
  font-weight: var(--fw-meta);
  color:       var(--color-gray);
  line-height: 1.4;
}

/* ============================================================
   LAYOUT
   ============================================================ */
/* Wraps page content to max 1200px centered */
.ds-content-wrap {
  max-width: var(--max-content-width);
  margin:    0 auto;
  padding:   var(--page-py) var(--page-px);
  width:     100%;
}

/* ============================================================
   BUTTON HIERARCHY  (§2.4)
   ============================================================ */
.btn-primary {
  display:          inline-flex;
  align-items:      center;
  gap:              6px;
  padding:          6px 14px;
  font-size:        var(--fs-button);
  font-weight:      var(--fw-button);
  color:            #fff;
  background-color: var(--color-blue);
  border:           1px solid var(--color-blue);
  border-radius:    var(--radius-button);
  cursor:           pointer;
  transition:       background-color 0.15s, opacity 0.15s;
  white-space:      nowrap;
}
.btn-primary:hover  { background-color: #2f5a9e; border-color: #2f5a9e; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  display:          inline-flex;
  align-items:      center;
  gap:              6px;
  padding:          6px 14px;
  font-size:        var(--fs-button);
  font-weight:      var(--fw-button);
  color:            var(--color-blue);
  background-color: transparent;
  border:           1px solid var(--color-blue);
  border-radius:    var(--radius-button);
  cursor:           pointer;
  transition:       background-color 0.15s;
  white-space:      nowrap;
}
.btn-secondary:hover  { background-color: var(--color-blue-tint); }
.btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-tertiary {
  display:          inline-flex;
  align-items:      center;
  gap:              6px;
  padding:          6px 10px;
  font-size:        var(--fs-button);
  font-weight:      var(--fw-button);
  color:            var(--color-gray);
  background-color: transparent;
  border:           none;
  border-radius:    var(--radius-button);
  cursor:           pointer;
  transition:       color 0.15s, background-color 0.15s;
  white-space:      nowrap;
}
.btn-tertiary:hover  { color: #374151; background-color: var(--color-surface); }
.btn-tertiary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-destructive {
  display:          inline-flex;
  align-items:      center;
  gap:              6px;
  padding:          6px 14px;
  font-size:        var(--fs-button);
  font-weight:      var(--fw-button);
  color:            var(--color-red);
  background-color: transparent;
  border:           1px solid var(--color-red);
  border-radius:    var(--radius-button);
  cursor:           pointer;
  transition:       background-color 0.15s;
  white-space:      nowrap;
}
.btn-destructive:hover  { background-color: var(--color-red-tint); }
.btn-destructive:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============================================================
   UNIFIED CARD PATTERN  (§2.5)
   ============================================================ */
.ds-card {
  background:    #fff;
  border:        1px solid var(--color-border);
  border-radius: var(--radius-card);
  box-shadow:    var(--shadow-card);
  padding:       var(--card-padding);
  overflow:      hidden;
  transition:    box-shadow 0.15s;
}
.ds-card:hover { box-shadow: var(--shadow-card-hover); }

.ds-card-top {
  display:         flex;
  align-items:     flex-start;
  justify-content: space-between;
  gap:             8px;
  margin-bottom:   8px;
}
.ds-card-middle {
  margin-bottom: 10px;
  font-size:     var(--fs-body);
  color:         #1F2937;
  line-height:   1.5;
}
.ds-card-bottom {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  gap:             8px;
  margin-top:      10px;
}
.ds-card-meta {
  display:     flex;
  align-items: center;
  gap:         8px;
  flex-shrink: 0;
}

/* ============================================================
   BADGE / PILL PATTERN  (§2.8)
   ============================================================ */
.ds-badge {
  display:       inline-flex;
  align-items:   center;
  gap:           4px;
  padding:       2px 8px;
  font-size:     var(--fs-badge);
  font-weight:   var(--fw-badge);
  border-radius: var(--radius-badge);
  white-space:   nowrap;
  line-height:   1.4;
}
/* Category tags */
.ds-badge-category  { background: var(--color-blue-tint);  color: var(--color-navy); }
/* Status colors */
.ds-badge-success   { background: var(--color-green-tint); color: var(--color-green); }
.ds-badge-warning   { background: var(--color-amber-tint); color: var(--color-amber); }
.ds-badge-danger    { background: var(--color-red-tint);   color: var(--color-red); }
.ds-badge-neutral   { background: var(--color-gray-tint);  color: var(--color-gray); }
.ds-badge-info      { background: var(--color-blue-tint);  color: var(--color-blue); }
/* Signal tags */
.ds-badge-warm      { background: var(--color-amber-tint); color: var(--color-amber); }
.ds-badge-cold      { background: var(--color-gray-tint);  color: var(--color-gray); }

/* ============================================================
   FILTER BAR PATTERN  (§2.6)
   ============================================================ */
.ds-filter-bar {
  display:     flex;
  align-items: center;
  gap:         8px;
  flex-wrap:   wrap;
  margin-bottom: var(--card-gap);
}
.ds-filter-pill {
  display:          inline-flex;
  align-items:      center;
  padding:          5px 14px;
  font-size:        var(--fs-badge);
  font-weight:      var(--fw-badge);
  border:           1px solid var(--color-border);
  border-radius:    999px;
  background:       #fff;
  color:            var(--color-gray);
  cursor:           pointer;
  transition:       background 0.12s, color 0.12s, border-color 0.12s;
  white-space:      nowrap;
}
.ds-filter-pill:hover           { border-color: var(--color-blue); color: var(--color-blue); }
.ds-filter-pill.active,
.ds-filter-pill[aria-selected="true"] {
  background:    var(--color-blue);
  border-color:  var(--color-blue);
  color:         #fff;
}

/* ============================================================
   ENGAGEMENT DISPLAY PATTERN  (§2.7)
   ============================================================ */
.ds-engagement {
  display:     flex;
  align-items: center;
  gap:         12px;
  font-size:   var(--fs-meta);
  color:       var(--color-gray);
}
.ds-engagement-item {
  display:     inline-flex;
  align-items: center;
  gap:         3px;
}

/* ============================================================
   UTILITIES
   ============================================================ */
/* Line clamp */
.line-clamp-2 {
  display:            -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow:           hidden;
}
.line-clamp-3 {
  display:            -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow:           hidden;
}

/* HTMX request indicator */
.htmx-request .htmx-indicator { display: inline-block; }
.htmx-indicator { display: none; }

/* Spinning loader */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  display:          inline-block;
  width:            14px;
  height:           14px;
  border:           2px solid currentColor;
  border-top-color: transparent;
  border-radius:    50%;
  animation:        spin 0.6s linear infinite;
}

/* ============================================================
   LEFT SIDEBAR NAVIGATION
   ============================================================ */

/* Sidebar container */
#sidebar {
  width:          var(--sidebar-width);
  flex-shrink:    0;
  display:        flex;
  flex-direction: column;
  background:     #fff;
  border-right:   1px solid var(--color-border);
  overflow:       hidden;
  transition:     width 0.2s ease;
  position:       relative;
  z-index:        20;
}
#sidebar.collapsed { width: var(--sidebar-width-collapsed); }

/* Logo header area */
.sidebar-header {
  display:          flex;
  align-items:      center;
  padding:          11px 12px;
  background-color: var(--color-navy);
  flex-shrink:      0;
  min-height:       50px;
}
.sidebar-logo {
  display:         flex;
  align-items:     center;
  gap:             10px;
  text-decoration: none;
  overflow:        hidden;
  flex: 1;
}
.sidebar-logo-icon {
  width:            28px;
  height:           28px;
  background-color: var(--color-blue);
  border-radius:    6px;
  display:          flex;
  align-items:      center;
  justify-content:  center;
  color:            white;
  font-size:        11px;
  font-weight:      700;
  flex-shrink:      0;
}
.sidebar-logo-text {
  color:       rgba(255,255,255,0.9);
  font-size:   13px;
  font-weight: 600;
  white-space: nowrap;
}

/* Scrollable nav area */
.sidebar-nav {
  flex:       1;
  overflow-y: auto;
  padding:    4px 0 8px;
}

/* Section groupings */
.sidebar-section { margin-top: 24px; }
.sidebar-section:first-child { margin-top: 8px; }

.sidebar-section-header {
  font-size:      11px;
  font-weight:    600;
  color:          var(--color-gray);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding:        0 16px 4px;
  white-space:    nowrap;
}

/* Nav items */
.sidebar-nav-item {
  display:         flex;
  align-items:     center;
  gap:             10px;
  margin:          1px 8px;
  padding:         8px 8px;
  font-size:       14px;
  font-weight:     400;
  color:           #1F2937;
  text-decoration: none;
  border-radius:   4px;
  transition:      background-color 0.12s, color 0.12s;
  white-space:     nowrap;
}
.sidebar-nav-item:hover  { background-color: var(--color-surface); }
.sidebar-nav-item.active {
  background-color: var(--color-lightBlue);
  color:            var(--color-blue);
  font-weight:      500;
}

/* Icons (sized SVGs from Lucide) */
.sidebar-icon {
  width:       18px;
  height:      18px;
  flex-shrink: 0;
}

/* Labels */
.sidebar-label {
  flex:          1;
  overflow:      hidden;
  text-overflow: ellipsis;
}

/* Count badges */
.sidebar-badge {
  background-color: var(--color-blue);
  color:            white;
  font-size:        11px;
  font-weight:      600;
  padding:          1px 6px;
  border-radius:    999px;
  min-width:        18px;
  text-align:       center;
  flex-shrink:      0;
}

/* Footer (theme toggle + collapse button) */
.sidebar-footer {
  flex-shrink:    0;
  border-top:     1px solid var(--color-border);
  padding:        8px;
  display:        flex;
  flex-direction: column;
  gap:            2px;
}
.sidebar-theme-btn {
  display:       flex;
  align-items:   center;
  gap:           10px;
  width:         100%;
  padding:       7px 8px;
  border:        none;
  background:    transparent;
  border-radius: 4px;
  cursor:        pointer;
  font-size:     13px;
  color:         var(--color-gray);
  transition:    background-color 0.12s;
  text-align:    left;
}
.sidebar-theme-btn:hover { background-color: var(--color-surface); }

.sidebar-collapse-toggle {
  display:          flex;
  align-items:      center;
  justify-content:  center;
  width:            100%;
  padding:          6px;
  border:           none;
  background:       transparent;
  border-radius:    4px;
  cursor:           pointer;
  color:            var(--color-gray);
  transition:       background-color 0.12s;
}
.sidebar-collapse-toggle:hover { background-color: var(--color-surface); }

/* ── Collapsed state ──────────────────────────────────────── */
#sidebar.collapsed .sidebar-logo-text      { display: none; }
#sidebar.collapsed .sidebar-section-header { display: none; }
#sidebar.collapsed .sidebar-label          { display: none; }
#sidebar.collapsed .sidebar-badge          { display: none !important; }
#sidebar.collapsed .sidebar-section        { margin-top: 12px; }
#sidebar.collapsed .sidebar-nav-item {
  justify-content: center;
  padding:         8px 0;
  margin:          1px 4px;
}
#sidebar.collapsed .sidebar-theme-btn {
  justify-content: center;
  padding:         7px 0;
}

/* ── Mobile top bar ───────────────────────────────────────── */
#mobile-topbar {
  display:          none;
  align-items:      center;
  padding:          0 16px;
  height:           48px;
  background-color: var(--color-navy);
  flex-shrink:      0;
}
.mobile-hamburger {
  display:       flex;
  align-items:   center;
  justify-content: center;
  background:    transparent;
  border:        none;
  color:         rgba(255,255,255,0.9);
  cursor:        pointer;
  padding:       6px;
  border-radius: 4px;
  transition:    background-color 0.12s;
}
.mobile-hamburger:hover { background-color: rgba(255,255,255,0.1); }

/* ── Responsive breakpoints ───────────────────────────────── */
@media (max-width: 767px) {
  #sidebar {
    position:  fixed;
    left:      0;
    top:       0;
    bottom:    0;
    height:    100%;
    width:     var(--sidebar-width) !important;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index:   40;
  }
  #sidebar.mobile-open { transform: translateX(0); }
  #mobile-topbar        { display: flex; }
}
@media (min-width: 768px) {
  #mobile-topbar    { display: none !important; }
  #sidebar-backdrop { display: none !important; }
  #sidebar          { transform: none !important; position: relative; }
}
