/* =========================================================
   CATEGORIES SURFACE CSS
   ---------------------------------------------------------
   PURPOSE
   - Styles the Categories surface only
   - Matches the current categories.js render contract
   - Uses clearly labeled sections for easier maintenance

   FILE MAP
   01. Theme Tokens
   02. Global Resets
   03. Page Shell
   04. Shared Panel Styling
   05. Control Bar
   06. Surface Frame + Loading State
   07. Category List Container
   08. Category Card Shell
   09. Category Summary Row
   10. Summary Content Blocks
   11. Workflow / Status Pills
   12. Chevron / Expand Indicator
   13. Expanded Detail Body
   14. Logic Block Styling
   15. Empty State
   16. Responsive Breakpoints
   ========================================================= */


/* =========================================================
   01. THEME TOKENS
   ---------------------------------------------------------
   Centralized colors, radii, shadows, width limits.
   Edit here first if you want to shift the look of the page.
   ========================================================= */
:root {
  --bg-top: #131a23;
  --bg-bottom: #0d1218;

  --panel: rgba(19, 27, 37, 0.92);
  --panel-border: rgba(138, 180, 255, 0.14);
  --panel-strong: rgba(138, 180, 255, 0.28);

  --text: #eaf1fb;
  --muted: #aab9cd;
  --soft: #7f92aa;

  --success-soft: rgba(84, 208, 154, 0.16);
  --success-text: #8de4bc;

  --warning-soft: rgba(255, 181, 76, 0.16);
  --warning-text: #ffca7f;

  --shadow: 0 18px 48px rgba(0, 0, 0, 0.34);

  --radius-lg: 24px;
  --radius-md: 18px;
  --radius-sm: 12px;

  --max: 1680px;
}


/* =========================================================
   02. GLOBAL RESETS
   ---------------------------------------------------------
   Safe baseline behavior for sizing and the body background.
   ========================================================= */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(110, 168, 255, 0.14), transparent 30%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
}


/* =========================================================
   03. PAGE SHELL
   ---------------------------------------------------------
   Outer page wrapper below the shared inventory header.
   ========================================================= */
.categories-shell {
  max-width: var(--max);
  margin: 0 auto;
  padding: 28px 12px 36px;
}


/* =========================================================
   04. SHARED PANEL STYLING
   ---------------------------------------------------------
   Common panel look for:
   - control bar
   - surface frame
   - each category card
   ========================================================= */
.control-bar,
.surface-frame,
.category-card {
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: var(--shadow);
}


/* =========================================================
   05. CONTROL BAR
   ---------------------------------------------------------
   Search, workflow filter, and expand/collapse actions.
   ========================================================= */
.control-bar {
  display: grid;
  grid-template-columns: minmax(280px, 1.5fr) minmax(220px, 0.9fr) auto;
  gap: 14px;
  padding: 18px 20px;
  margin-bottom: 18px;
  align-items: end;
}

/* Each control group stacks label above field */
.control-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Allows the search box area to shrink safely */
.control-group-grow {
  min-width: 0;
}

/* Uppercase field labels */
.control-group label {
  color: var(--soft);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}

/* Unified field/button look inside control bar */
.control-bar input,
.control-bar select,
.control-bar button {
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(8, 14, 22, 0.82);
  color: var(--text);
  min-height: 42px;
  padding: 0 14px;
  font: inherit;
}

/* Focus treatment for usability */
.control-bar input:focus,
.control-bar select:focus,
.control-bar button:focus {
  outline: none;
  border-color: var(--panel-strong);
  box-shadow: 0 0 0 3px rgba(138, 180, 255, 0.12);
}

/* Expand / Collapse button row */
.compact-actions .button-row {
  display: flex;
  gap: 10px;
}

/* Button hover feedback */
.compact-actions button {
  cursor: pointer;
  background: rgba(255, 255, 255, 0.05);
  transition: background 0.16s ease, border-color 0.16s ease;
}

.compact-actions button:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.18);
}


/* =========================================================
   06. SURFACE FRAME + LOADING STATE
   ---------------------------------------------------------
   Frame that holds the loading state and the live category list.
   ========================================================= */
.surface-frame {
  padding: 18px;
}

/* Initial loading panel shown before cards render */
.load-state {
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  border: 1px dashed rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.02);
  text-align: center;
  padding: 24px;
}

/* Hard-hide both load state and list when JS toggles [hidden] */
.load-state[hidden],
.category-list[hidden] {
  display: none !important;
}


/* =========================================================
   07. CATEGORY LIST CONTAINER
   ---------------------------------------------------------
   IMPORTANT
   - This must remain a vertical stack
   - Use flex here, not grid, to avoid odd <details> behavior
   ========================================================= */
.category-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}


/* =========================================================
   08. CATEGORY CARD SHELL
   ---------------------------------------------------------
   Each category record renders as a <details> card.
   ========================================================= */
.category-card {
  overflow: hidden;
}

/* Remove native details marker styling */
.category-card > summary {
  list-style: none;
}

.category-card > summary::-webkit-details-marker {
  display: none;
}


/* =========================================================
   09. CATEGORY SUMMARY ROW
   ---------------------------------------------------------
   Top row visible when the card is collapsed.
   Layout columns:
   1. Main category text
   2. Workflow column
   3. Status column
   4. Chevron
   ========================================================= */
.category-summary {
  cursor: pointer;
  padding: 20px 22px;
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(190px, auto) minmax(190px, auto) 22px;
  gap: 18px;
  align-items: start;
  transition: background 0.16s ease;
}

/* Hover feedback for the full summary row */
.category-card > summary:hover {
  background: rgba(138, 180, 255, 0.04);
}


/* =========================================================
   10. SUMMARY CONTENT BLOCKS
   ---------------------------------------------------------
   Main text + right-side metadata blocks
   ========================================================= */

/* Prevent text overflow issues inside grid columns */
.category-main,
.category-meta {
  min-width: 0;
}

/* Category name */
.category-name {
  margin: 0 0 6px;
  font-size: 1.08rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.25;
}

/* Short preview description shown in collapsed row */
.category-preview {
  color: var(--muted);
  line-height: 1.45;
  font-size: 0.96rem;
}

/* Small uppercase labels like Workflow / Surface Status */
.summary-label {
  display: block;
  margin-bottom: 8px;
  color: var(--soft);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}

/* Container for pills or value badges */
.summary-value {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}


/* =========================================================
   11. WORKFLOW / STATUS PILLS
   ---------------------------------------------------------
   Chips used on the right side of summary rows.
   ========================================================= */
.workflow-pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
  line-height: 1.2;
}

/* Positive workflow assignment */
.workflow-pill {
  background: var(--success-soft);
  color: var(--success-text);
}

/* Positive surface status */
.status-pill.status-ok {
  background: var(--success-soft);
  color: var(--success-text);
}

/* Missing workflow or missing filter state */
.status-pill.status-missing {
  background: var(--warning-soft);
  color: var(--warning-text);
}


/* =========================================================
   12. CHEVRON / EXPAND INDICATOR
   ---------------------------------------------------------
   Rotates when the <details> card is open.
   ========================================================= */
.chevron {
  align-self: center;
  justify-self: end;
  width: 12px;
  height: 12px;
  border-right: 2px solid var(--soft);
  border-bottom: 2px solid var(--soft);
  transform: rotate(45deg);
  transition: transform 0.18s ease;
  margin-top: 4px;
}

/* Rotate chevron when details card is open */
.category-card[open] .chevron {
  transform: rotate(225deg);
}


/* =========================================================
   13. EXPANDED DETAIL BODY
   ---------------------------------------------------------
   Area revealed when the details card opens.
   Contains one or more detail panels.
   ========================================================= */
.category-body {
  padding: 0 22px 22px;
  display: grid;
  gap: 16px;
}

/* Individual detail blocks inside expanded region */
.detail-panel {
  border: 1px solid rgba(138, 180, 255, 0.08);
  border-radius: var(--radius-md);
  background: rgba(8, 14, 22, 0.55);
  padding: 16px 18px;
}

/* Panel heading */
.detail-title {
  margin: 0 0 10px;
  font-size: 0.98rem;
  font-weight: 800;
  color: var(--text);
}

/* Body copy within detail panel */
.detail-copy {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}


/* =========================================================
   14. LOGIC BLOCK STYLING
   ---------------------------------------------------------
   Used for the decoded category filter definition.
   ========================================================= */
.logic-block {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--muted);
}

/* Highlight boolean operators */
.logic-op {
  font-weight: 800;
}

.logic-and {
  color: var(--success-text);
}

.logic-or {
  color: var(--warning-text);
}


/* =========================================================
   15. EMPTY STATE
   ---------------------------------------------------------
   Used when search/filter returns no category rows.
   ========================================================= */
.empty-state {
  border: 1px dashed rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.02);
  color: var(--muted);
  padding: 28px 20px;
  text-align: center;
}


/* =========================================================
   16. RESPONSIVE BREAKPOINTS
   ---------------------------------------------------------
   Collapse layout progressively for tablet and mobile.
   ========================================================= */

/* Tablet-wide: stack control bar; slightly tighten summary columns */
@media (max-width: 1180px) {
  .control-bar {
    grid-template-columns: 1fr;
  }

  .category-summary {
    grid-template-columns: minmax(0, 1fr) minmax(170px, auto) minmax(170px, auto) 22px;
  }
}

/* Narrow tablet / small laptop:
   stack summary content into one column */
@media (max-width: 900px) {
  .category-summary {
    grid-template-columns: 1fr;
  }

  .chevron {
    justify-self: start;
    margin-top: 0;
  }
}

/* Mobile:
   tighten shell padding and stack action buttons */
@media (max-width: 760px) {
  .categories-shell {
    padding: 16px 8px 28px;
  }

  .compact-actions .button-row {
    flex-direction: column;
  }

  .category-summary {
    padding: 18px;
    gap: 14px;
  }

  .category-body {
    padding: 0 18px 18px;
    gap: 14px;
  }
}