/**
 * CoreSense Components
 * ====================
 * Reusable UI components.
 * Requires: tokens.css, base.css
 *
 * Usage:
 *   <link rel="stylesheet" href="/design-system/tokens.css">
 *   <link rel="stylesheet" href="/design-system/base.css">
 *   <link rel="stylesheet" href="/design-system/components.css">
 */

/* ============================================
   CARDS
   ============================================ */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}

.card-title {
  font-size: var(--text-base);
  font-weight: var(--font-medium);
  color: var(--text-secondary);
}

.card-subtitle {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-top: var(--space-1);
}

.card-body {
  padding: var(--space-4);
}

.card-footer {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
}

/* Card variants */
.card-elevated {
  box-shadow: var(--shadow-md);
}

.card-interactive {
  cursor: pointer;
  transition: border-color var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out);
}

.card-interactive:hover {
  border-color: var(--border-default);
  box-shadow: var(--shadow-md);
}

/* ============================================
   STAT CARDS
   ============================================ */

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}

.stat-label {
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  margin-bottom: var(--space-2);
}

.stat-value {
  font-family: var(--font-mono);
  font-size: var(--text-2xl);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  line-height: var(--leading-tight);
  margin-bottom: var(--space-1);
}

.stat-change {
  font-size: var(--text-xs);
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

.stat-change-positive { color: var(--color-success); }
.stat-change-negative { color: var(--color-error); }
.stat-change-neutral { color: var(--text-muted); }

/* ============================================
   BUTTONS
   ============================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: var(--height-button);
  padding: 0 var(--space-4);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  line-height: 1;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
  white-space: nowrap;
  user-select: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Primary (outlined — fills on hover) */
.btn-primary {
  background: transparent;
  color: var(--color-accent);
  border-color: var(--color-accent);
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-accent);
  color: white;
  border-color: var(--color-accent);
}

.btn-primary:active:not(:disabled) {
  background: var(--color-accent-strong);
  color: white;
}

/* Primary filled (solid — for modal confirms, CTAs) */
.btn-primary-filled {
  background: var(--color-accent);
  color: white;
  border-color: var(--color-accent);
}

.btn-primary-filled:hover:not(:disabled) {
  background: var(--color-accent-hover);
  border-color: var(--color-accent-hover);
}

.btn-primary-filled:active:not(:disabled) {
  background: var(--color-accent-strong);
}

/* Secondary */
.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border-color: var(--border-default);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-active);
  border-color: var(--border-strong);
}

/* Ghost */
.btn-ghost {
  background: transparent;
  color: var(--text-tertiary);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-secondary);
}

/* Danger (outlined — fills on hover) */
.btn-danger {
  background: transparent;
  color: var(--color-error);
  border-color: var(--color-error);
}

.btn-danger:hover:not(:disabled) {
  background: var(--color-error);
  color: white;
  border-color: var(--color-error);
}

.btn-danger:active:not(:disabled) {
  background: #991B1B;
  color: white;
}

/* Danger filled (solid — for destructive confirms) */
.btn-danger-filled {
  background: var(--color-error);
  color: white;
  border-color: var(--color-error);
}

.btn-danger-filled:hover:not(:disabled) {
  background: #B91C1C;
  border-color: #B91C1C;
}

.btn-danger-filled:active:not(:disabled) {
  background: #991B1B;
}

/* Icon button */
.btn-icon {
  width: var(--height-button);
  padding: 0;
}

/* Size variants */
.btn-sm {
  height: var(--height-button-sm);
  padding: 0 var(--space-3);
  font-size: var(--text-xs);
}

.btn-lg {
  height: 48px;
  padding: 0 var(--space-6);
  font-size: var(--text-base);
}

/* ============================================
   INPUTS
   ============================================ */

.input {
  display: block;
  width: 100%;
  height: var(--height-input);
  padding: 0 var(--space-3);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color var(--duration-fast),
              box-shadow var(--duration-fast);
}

.input::placeholder {
  color: var(--text-muted);
}

.input:hover {
  border-color: var(--border-default);
}

.input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 var(--ring-offset) var(--bg-page),
              0 0 0 calc(var(--ring-offset) + var(--ring-width)) var(--ring-color);
}

.input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Prevent iOS Safari auto-zoom on input focus (requires font-size >= 16px) */
@media (max-width: 768px) {
  .input, textarea, select {
    font-size: max(1rem, var(--text-base));
  }
}

/* Input with icon */
.input-group {
  position: relative;
}

.input-group .input {
  padding-left: var(--space-10);
}

.input-group-icon {
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

/* Monospace input */
.input-mono {
  font-family: var(--font-mono);
  font-size: var(--text-data);
  letter-spacing: 0.02em;
}

/* Size variants */
.input-sm {
  height: var(--height-input-sm);
  font-size: var(--text-sm);
}

/* Error state */
.input-error {
  border-color: var(--color-error);
}

.input-error:focus {
  box-shadow: var(--shadow-focus-error);
}

/* ============================================
   SELECT
   ============================================ */

.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23858585' d='M2.5 4.5L6 8l3.5-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  padding-right: var(--space-10);
}

/* ============================================
   BADGES
   ============================================ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  line-height: 1;
}

.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

/* Status badges */
.badge-in-stock { color: var(--color-in-stock); }
.badge-in-stock::before { background: var(--color-in-stock); }

.badge-low-stock { color: var(--color-low-stock); }
.badge-low-stock::before { background: var(--color-low-stock); }

.badge-out-of-stock { color: var(--color-out-of-stock); }
.badge-out-of-stock::before { background: var(--color-out-of-stock); }

.badge-backordered { color: var(--color-backordered); }
.badge-backordered::before { background: var(--color-backordered); }

/* Type badges (pill style) */
.type-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-0-5) var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  border-radius: var(--radius-full);
  line-height: var(--leading-normal);
}

.type-badge-default {
  background: var(--color-type-default-bg);
  color: var(--color-type-default);
  border: 1px solid var(--color-type-default-border);
}

.type-badge-internal {
  background: var(--color-type-internal-bg);
  color: var(--color-type-internal);
  border: 1px solid var(--color-type-internal-border);
  font-weight: var(--font-semibold);
}

.type-badge-clearance {
  background: var(--color-type-clearance-bg);
  color: var(--color-type-clearance);
  border: 1px solid var(--color-type-clearance-border);
  font-weight: var(--font-semibold);
}

.type-badge-initiator {
  background: var(--color-type-initiator-bg);
  color: var(--color-type-initiator);
  border: 1px solid var(--color-type-initiator-border);
}

.type-badge-consignment {
  background: var(--color-type-consignment-bg);
  color: var(--color-type-consignment);
  border: 1px dashed var(--color-type-consignment-border);
}

/* Scenario badge */
.badge-proposed {
  background: var(--color-proposed-muted);
  color: var(--color-proposed);
  padding: var(--space-0-5) var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
}

/* ============================================
   TABLES
   ============================================ */

.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-base);
}

.table th {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
}

.table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  vertical-align: middle;
}

.table tr:last-child td {
  border-bottom: none;
}

.table tbody tr {
  transition: background-color var(--duration-instant);
}

.table tbody tr:hover {
  background: var(--bg-hover);
}

/* Alignment */
.table .align-right {
  text-align: right;
}

.table .align-center {
  text-align: center;
}

/* Compact variant */
.table-compact th,
.table-compact td {
  padding: var(--space-2) var(--space-3);
}

/* Bordered variant */
.table-bordered th,
.table-bordered td {
  border: 1px solid var(--border-subtle);
}

/* Striped variant (use sparingly) */
.table-striped tbody tr:nth-child(even) {
  background: var(--bg-elevated);
}

/* ============================================
   TOOLTIPS
   ============================================ */

.tooltip {
  position: relative;
  display: inline-block;
}

.tooltip-content {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  min-width: 200px;
  max-width: 320px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--duration-fast) var(--ease-out),
              transform var(--duration-fast) var(--ease-out);
  z-index: var(--z-tooltip);
  pointer-events: none;
}

.tooltip:hover .tooltip-content,
.tooltip:focus-within .tooltip-content {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.tooltip-title {
  font-family: var(--font-mono);
  font-size: var(--text-data);
  font-weight: var(--font-medium);
  color: var(--text-primary);
  margin-bottom: var(--space-2);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border-subtle);
}

.tooltip-row {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  padding: 2px 0;
  font-size: var(--text-sm);
}

.tooltip-row-label {
  color: var(--text-muted);
}

.tooltip-row-value {
  font-family: var(--font-mono);
  color: var(--text-secondary);
}

.tooltip-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: var(--space-2) 0;
}

.tooltip-arrow {
  position: absolute;
  bottom: -5px;
  left: 50%;
  transform: translateX(-50%) rotate(45deg);
  width: 10px;
  height: 10px;
  background: var(--bg-card);
  border-right: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
}

/* ============================================
   TABS
   ============================================ */

.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--border-subtle);
}

.tab {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-tertiary);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  transition: color var(--duration-fast),
              border-color var(--duration-fast);
}

.tab:hover {
  color: var(--text-secondary);
}

/* Active tab: subtle gray approach with accent underline */
.tab.active,
.tab[aria-selected="true"] {
  color: var(--text-primary);
  font-weight: var(--font-semibold);
  border-bottom-color: var(--text-primary);
}

.tab-panel {
  padding: var(--space-4) 0;
}

.tab-panel[hidden] {
  display: none;
}

/* ============================================
   MODALS
   ============================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: var(--z-modal);
  padding: var(--space-4);
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow: hidden;
  box-shadow: var(--shadow-xl);
  /* Flex column lets .modal-body's overflow-y:auto trigger when content
     exceeds 90vh. Without this, .modal-body has no constrained height and
     content just gets clipped at the .modal boundary instead of scrolling. */
  display: flex;
  flex-direction: column;
}

.modal-sm { max-width: 400px; }
.modal-lg { max-width: 720px; }
.modal-xl { max-width: 960px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
}

.modal-title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  margin: 0;
}

.modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  font-size: var(--text-xl);
  color: var(--text-tertiary);
  background: none;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: color var(--duration-fast),
              background var(--duration-fast);
}

.modal-close:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.modal-body {
  padding: var(--space-5);
  overflow-y: auto;
  /* min-height:0 lets this child shrink below its content height so the
     parent's max-height:90vh can clamp it; flex:1 makes it absorb the
     remaining space between header and footer. Without these two, the
     body expands to content height and overflow-y:auto never engages. */
  flex: 1 1 auto;
  min-height: 0;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
}

/* ============================================
   CHANGELOG MODAL
   ============================================ */

.changelog-modal-body {
  max-height: 70vh;
}

.changelog-entry {
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--border-subtle);
}

.changelog-entry:last-child {
  border-bottom: none;
}

.changelog-entry-header {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.changelog-entry-version {
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.changelog-entry-date {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
}

.changelog-section {
  margin-top: var(--space-2);
}

.changelog-section-title {
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 var(--space-2);
}

.changelog-items {
  margin: 0;
  padding-left: var(--space-4);
}

.changelog-items li {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-bottom: var(--space-1);
  line-height: 1.5;
}

/* ============================================
   WORKFLOW STEPS
   ============================================ */

.workflow-steps {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-4);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-subtle);
  flex-wrap: wrap;
}

.workflow-step {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  cursor: pointer;
  transition: color var(--duration-fast),
              background var(--duration-fast);
}

.workflow-step:hover {
  color: var(--text-secondary);
  background: var(--bg-hover);
}

.workflow-step.active {
  color: var(--color-accent);
  background: var(--color-accent-muted);
}

.workflow-step.completed {
  color: var(--color-success);
}

.workflow-step-number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  transition: background var(--duration-fast),
              border-color var(--duration-fast),
              color var(--duration-fast);
}

.workflow-step.active .workflow-step-number {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: white;
}

.workflow-step.completed .workflow-step-number {
  background: var(--color-success);
  border-color: var(--color-success);
  color: white;
}

.workflow-step-label {
  font-weight: var(--font-medium);
}

/* Connector line between steps */
.workflow-connector {
  width: 24px;
  height: 2px;
  background: var(--border-subtle);
}

.workflow-connector.completed {
  background: var(--color-success);
}

/* ============================================
   LOADING STATES
   ============================================ */

/* Skeleton loader */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-elevated) 25%,
    var(--bg-active) 50%,
    var(--bg-elevated) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-text {
  height: 14px;
  margin-bottom: var(--space-2);
}

.skeleton-text:last-child {
  width: 60%;
  margin-bottom: 0;
}

.skeleton-heading {
  height: 24px;
  width: 40%;
  margin-bottom: var(--space-4);
}

.skeleton-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
}

/* Spinner */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-subtle);
  border-top-color: var(--color-accent);
  border-radius: var(--radius-full);
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner-sm { width: 16px; height: 16px; }
.spinner-lg { width: 32px; height: 32px; border-width: 3px; }

/* ============================================
   EMPTY STATES
   ============================================ */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-12);
  text-align: center;
}

.empty-state-icon {
  width: 48px;
  height: 48px;
  color: var(--text-muted);
  margin-bottom: var(--space-4);
}

.empty-state-title {
  font-size: var(--text-lg);
  font-weight: var(--font-medium);
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

.empty-state-description {
  font-size: var(--text-base);
  color: var(--text-muted);
  max-width: 400px;
  margin-bottom: var(--space-6);
}

/* ============================================
   SCENARIO/SIMULATION COMPONENTS
   ============================================ */

/* Scenario indicator bar */
.scenario-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--color-proposed-muted);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-4);
}

.scenario-bar-label {
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--color-proposed);
}

.scenario-bar-actions {
  margin-left: auto;
  display: flex;
  gap: var(--space-2);
}

/* Comparison table styling */
.table .cell-actual {
  color: var(--text-secondary);
}

.table .cell-proposed {
  color: var(--color-proposed);
  background: var(--color-proposed-muted);
}

.table .cell-diff-positive {
  color: var(--color-diff-positive);
}

.table .cell-diff-negative {
  color: var(--color-diff-negative);
}

/* Inline comparison */
.value-comparison {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.value-actual {
  font-family: var(--font-mono);
  font-size: var(--text-data);
  color: var(--text-muted);
  text-decoration: line-through;
}

.value-proposed {
  font-family: var(--font-mono);
  font-size: var(--text-data);
  color: var(--color-proposed);
}

/* Diff indicator */
.diff-indicator {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
}

.diff-indicator-positive {
  color: var(--color-diff-positive);
}

.diff-indicator-negative {
  color: var(--color-diff-negative);
}

/* ============================================
   THEME TOGGLE
   ============================================ */

.theme-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
}

.theme-toggle-option {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
}

.theme-toggle-option:hover {
  color: var(--text-secondary);
}

.theme-toggle-option.active {
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* ============================================
   SIDEBAR HEADER
   ============================================ */

.sidebar-header {
  flex-shrink: 0;
  padding: var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: 0;
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  letter-spacing: var(--tracking-tight);
}

.sidebar-logo-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  color: var(--text-primary);
  flex-shrink: 0;
}

.sidebar-logo-icon svg {
  width: 68px;
  height: 68px;
}

.sidebar-logo-text {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
}

.sidebar-logo-brand {
  font-size: var(--text-2xl);
  font-weight: var(--font-bold);
  letter-spacing: var(--tracking-tight);
}

.sidebar-logo-product {
  font-size: var(--text-lg);
  font-weight: var(--font-medium);
  color: var(--text-secondary);
}

/* ============================================
   ENVIRONMENT INDICATOR
   ============================================ */

/* Environment colors */
:root {
  --env-dev-color: #3B82F6;       /* Blue */
  --env-dev-bg: rgba(59, 130, 246, 0.1);
  --env-staging-color: #F59E0B;   /* Orange */
  --env-staging-bg: rgba(245, 158, 11, 0.1);
}

.env-indicator {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.env-badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-0-5) var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  border-radius: var(--radius-full);
  line-height: var(--leading-normal);
}

.env-badge-dev {
  background: var(--env-dev-bg);
  color: var(--env-dev-color);
  border: 1px solid var(--env-dev-color);
}

.env-badge-staging {
  background: var(--env-staging-bg);
  color: var(--env-staging-color);
  border: 1px solid var(--env-staging-color);
}

.env-version {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* Environment-specific logo coloring */
cn-shell[data-environment="development"] .sidebar-logo-icon {
  color: var(--env-dev-color);
}

cn-shell[data-environment="staging"] .sidebar-logo-icon {
  color: var(--env-staging-color);
}

/* Production keeps default color (no override needed) */

/* Hide env indicator on very compact displays */
@media (min-width: 768px) and (max-width: 1024px) {
  .env-indicator {
    display: none;
  }
}

/* ============================================
   SIDEBAR NAVIGATION
   ============================================ */

.nav {
  padding: var(--space-4) 0;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.nav-section {
  margin-bottom: var(--space-4);
}

.nav-section-title {
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-tertiary);
  border-radius: 0;
  transition: all var(--duration-fast) var(--ease-out);
  cursor: pointer;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
}

/* Active state: subtle gray bg + semibold (no color accent) */
.nav-item.active {
  background: var(--bg-active);
  color: var(--text-primary);
  font-weight: var(--font-semibold);
}

.nav-item-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.nav-item > svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

/* ============================================
   NAV SEARCH
   ============================================ */

.nav-search {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
  position: relative;
}

.nav-search-icon {
  flex-shrink: 0;
  color: var(--text-tertiary);
  opacity: 0.5;
}

.nav-search-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  font-size: var(--text-sm);
  font-family: inherit;
  color: var(--text-primary);
  padding: var(--space-1) 0;
}

.nav-search-input::placeholder {
  color: var(--text-tertiary);
  opacity: 0.6;
}

.nav-search-kbd {
  flex-shrink: 0;
  font-size: 11px;
  font-family: inherit;
  padding: 1px 6px;
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  color: var(--text-tertiary);
  opacity: 0.5;
  pointer-events: none;
  line-height: 1.4;
}

/* Hide kbd when input has value */
.nav-search-input:focus ~ .nav-search-kbd,
.nav-search-kbd[hidden] {
  display: none;
}

/* Search results */
.nav-search-result {
  position: relative;
}

.nav-search-result .nav-search-cat {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-tertiary);
  opacity: 0.6;
  white-space: nowrap;
}

.nav-search-result mark {
  background: transparent;
  color: var(--accent, #3b82f6);
  font-weight: var(--font-semibold);
}

.nav-search-selected {
  background: var(--bg-hover) !important;
  color: var(--text-primary) !important;
}

.nav-search-empty {
  padding: var(--space-4);
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  text-align: center;
}

/* ============================================
   SIDEBAR FOOTER
   ============================================ */

.sidebar-footer {
  flex-shrink: 0;
  padding: var(--space-4);
  padding-bottom: max(var(--space-4), calc(var(--space-4) + env(safe-area-inset-bottom, 0px)));
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
}

/* CoreSense status indicator */
.cs-status {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 var(--space-4) var(--space-2);
  opacity: 0.45;
  font-size: 11px;
  color: var(--text-muted);
  transition: opacity 0.2s;
}
.cs-status:hover { opacity: 0.8; }
.cs-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  transition: background 0.3s;
}
.cs-dot.connected { background: var(--color-success); }
.cs-dot.warning { background: var(--color-warning, #f59e0b); }
.cs-dot.full {
  background: var(--color-danger, #ef4444);
  animation: cs-pulse 2s ease-in-out infinite;
}
@keyframes cs-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}
.cs-status[title] { cursor: help; }

/* Auth Section */
.auth-section {
  position: relative;
}

/* Sidebar responsive - Compact mode */
@media (min-width: 768px) and (max-width: 1024px) {
  .sidebar-header {
    padding: var(--space-4) var(--space-2);
    text-align: center;
  }

  .sidebar-logo {
    justify-content: center;
  }

  .sidebar-logo-icon {
    width: 40px;
    height: 40px;
  }

  .sidebar-logo-icon svg {
    width: 28px;
    height: 28px;
  }

  .sidebar-logo-text,
  .sidebar-subtitle {
    display: none;
  }

  .sidebar-footer {
    display: none;
  }
}

/* ============================================
   PAGE HEADER
   ============================================ */

.page-header {
  margin-bottom: var(--space-6);
}

.page-title {
  font-size: var(--text-2xl);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  letter-spacing: var(--tracking-tight);
  margin-bottom: var(--space-1);
}

.page-subtitle {
  font-size: var(--text-base);
  color: var(--text-muted);
}

.page-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* ============================================
   BREADCRUMBS
   ============================================ */

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-bottom: var(--space-4);
}

.breadcrumb-separator {
  color: var(--text-disabled);
}

.breadcrumb-link {
  color: var(--text-tertiary);
}

.breadcrumb-link:hover {
  color: var(--text-secondary);
}

.breadcrumb-current {
  color: var(--text-secondary);
}

/* ============================================
   THEME TOGGLE
   ============================================ */

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
}

.theme-toggle:hover {
  background: var(--bg-hover);
  border-color: var(--border-default);
  color: var(--text-primary);
}

.theme-toggle:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

.theme-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
}

.theme-icon svg {
  width: 100%;
  height: 100%;
}

/* ============================================
   USER MENU (Sidebar Bottom)
   ============================================ */

.user-menu-wrapper {
  position: relative;
}

.user-menu-trigger {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-2);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
}

.user-menu-trigger:hover {
  background: var(--bg-hover);
  border-color: var(--border-subtle);
}

.user-menu-trigger:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

.user-menu-trigger[aria-expanded="true"] {
  background: var(--bg-hover);
  border-color: var(--border-subtle);
}

.user-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--color-accent, #3b82f6);
  color: #fff;
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  letter-spacing: 0.02em;
  user-select: none;
}

.user-menu-name {
  flex: 1;
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
}

.user-menu-chevron {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  transition: transform var(--duration-fast) var(--ease-out);
}

.user-menu-trigger[aria-expanded="true"] .user-menu-chevron {
  transform: rotate(180deg);
}

/* Popover */
.user-popover {
  position: absolute;
  bottom: calc(100% + var(--space-2));
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg, var(--radius-md));
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12), 0 1px 3px rgba(0, 0, 0, 0.08);
  z-index: 50;
  overflow: hidden;
}

.user-popover[hidden] {
  display: none;
}

.user-popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-3);
}

.user-popover-email {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.user-popover-role {
  flex-shrink: 0;
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  padding: 1px var(--space-2);
  border-radius: var(--radius-full, 9999px);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.user-popover-role--admin {
  background: rgba(139, 92, 246, 0.12);
  color: #8b5cf6;
}

.user-popover-role--user {
  background: rgba(59, 130, 246, 0.12);
  color: #3b82f6;
}

.user-popover-divider {
  height: 1px;
  background: var(--border-subtle);
}

.user-popover-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: transparent;
  border: none;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
}

.user-popover-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.user-popover-item:focus-visible {
  outline: none;
  background: var(--bg-hover);
}

.user-popover-item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* Login button (logged out state) */
.auth-login-btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
}

.auth-login-btn:hover {
  background: var(--bg-hover);
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.auth-login-btn:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

.auth-login-btn .auth-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* ============================================
   NAV CATEGORIES (Collapsible)
   ============================================ */

/* Dashboard standalone item (always visible) */
.nav-item-standalone {
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
}

/* Category wrapper */
.nav-category {
  margin-bottom: var(--space-1);
}

/* Category header (clickable button) */
.nav-category-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2) var(--space-4);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  text-align: left;
  transition: color var(--duration-fast) var(--ease-out),
              background var(--duration-fast) var(--ease-out);
}

.nav-category-header:hover {
  color: var(--text-secondary);
  background: var(--bg-hover);
}

.nav-category-header:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: -2px;
}

/* Chevron icon */
.nav-category-chevron {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  transition: transform var(--duration-fast) var(--ease-out);
}

.nav-category.collapsed .nav-category-chevron {
  transform: rotate(-90deg);
}

/* Badge showing active indicator when collapsed */
.nav-category-badge {
  margin-left: auto;
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: transparent;
  transition: background var(--duration-fast) var(--ease-out);
}

.nav-category.collapsed.has-active .nav-category-badge {
  background: var(--color-accent);
}

/* Category items container */
.nav-category-items {
  overflow: hidden;
  max-height: 500px;
  opacity: 1;
  transition: max-height var(--duration-normal) var(--ease-out),
              opacity var(--duration-fast) var(--ease-out);
}

.nav-category.collapsed .nav-category-items {
  max-height: 0;
  opacity: 0;
  pointer-events: none;
}

/* Indent items within categories */
.nav-category .nav-item {
  padding-left: calc(var(--space-4) + var(--space-3));
}

/* Active category header when collapsed */
.nav-category.collapsed.has-active .nav-category-header {
  color: var(--color-accent);
}

/* ==========================================================================
   Turbo Progress Bar
   ========================================================================== */

.turbo-progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: var(--color-accent);
  z-index: 9999;
  transition: width 300ms ease;
}

/* ==========================================================================
   Checkbox & Radio
   ========================================================================== */

.checkbox,
.radio {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.checkbox input,
.radio input {
  appearance: none;
  width: 18px;
  height: 18px;
  border: 1px solid var(--border-strong);
  background: var(--bg-card);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
  flex-shrink: 0;
}

.checkbox input {
  border-radius: var(--radius-sm);
}

.radio input {
  border-radius: var(--radius-full);
}

.checkbox input:hover,
.radio input:hover {
  border-color: var(--gray-400);
}

.checkbox input:focus-visible,
.radio input:focus-visible {
  outline: none;
  box-shadow: 0 0 0 var(--ring-offset) var(--bg-page),
              0 0 0 calc(var(--ring-offset) + var(--ring-width)) var(--ring-color);
}

.checkbox input:checked,
.radio input:checked {
  background: var(--color-accent);
  border-color: var(--color-accent);
}

.checkbox input:checked {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='white' d='M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2-2a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z'/%3E%3C/svg%3E");
  background-size: 14px;
  background-position: center;
  background-repeat: no-repeat;
}

.radio input:checked {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='4' fill='white'/%3E%3C/svg%3E");
  background-size: 16px;
  background-position: center;
  background-repeat: no-repeat;
}

.checkbox input:disabled,
.radio input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ==========================================================================
   Alerts / Banners
   ========================================================================== */

.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
}

.alert-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  margin-top: 1px;
}

.alert-content {
  flex: 1;
}

.alert-title {
  font-weight: var(--font-semibold);
  margin-bottom: var(--space-1);
}

.alert-dismiss {
  padding: var(--space-1);
  margin: calc(var(--space-1) * -1);
  background: transparent;
  border: none;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity var(--duration-fast);
}

.alert-dismiss:hover {
  opacity: 1;
}

/* Alert variants */
.alert-info {
  background: var(--color-info-muted);
  color: var(--color-info);
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.alert-success {
  background: var(--result-success-bg);
  color: var(--result-success-text);
  border: 1px solid var(--result-success-border);
}

.alert-warning {
  background: var(--result-warning-bg);
  color: var(--result-warning-text);
  border: 1px solid var(--result-warning-border);
}

.alert-error {
  background: var(--result-error-bg);
  color: var(--result-error-text);
  border: 1px solid var(--result-error-border);
}

/* ==========================================================================
   Switch / Toggle
   ========================================================================== */

.switch {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.switch input {
  appearance: none;
  width: 44px;
  height: 24px;
  background: var(--gray-300);
  border-radius: var(--radius-full);
  position: relative;
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-out);
  flex-shrink: 0;
}

.switch input::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-sm);
  transition: transform var(--duration-fast) var(--ease-out);
}

.switch input:hover {
  background: var(--gray-400);
}

.switch input:focus-visible {
  outline: none;
  box-shadow: 0 0 0 var(--ring-offset) var(--bg-page),
              0 0 0 calc(var(--ring-offset) + var(--ring-width)) var(--ring-color);
}

.switch input:checked {
  background: var(--color-accent);
}

.switch input:checked:hover {
  background: var(--color-accent-hover);
}

.switch input:checked::before {
  transform: translateX(20px);
}

.switch input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ==========================================================================
   Status Badges (workflow states)
   ========================================================================== */

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-0-5) var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  border-radius: var(--radius-full);
  line-height: var(--leading-normal);
}

.status-badge-draft {
  background: var(--status-draft-bg);
  color: var(--status-draft-text);
}

.status-badge-in-progress {
  background: var(--status-in-progress-bg);
  color: var(--status-in-progress-text);
}

.status-badge-verifying {
  background: var(--status-verifying-bg);
  color: var(--status-verifying-text);
}

.status-badge-completed {
  background: var(--status-completed-bg);
  color: var(--status-completed-text);
}

.status-badge-cancelled {
  background: var(--status-cancelled-bg);
  color: var(--status-cancelled-text);
}

/* ==========================================================================
   Verification Result Boxes
   ========================================================================== */

.result-box {
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  border-width: 1px;
  border-style: solid;
}

.result-box-success {
  background: var(--result-success-bg);
  border-color: var(--result-success-border);
  color: var(--result-success-text);
}

.result-box-warning {
  background: var(--result-warning-bg);
  border-color: var(--result-warning-border);
  color: var(--result-warning-text);
}

.result-box-error {
  background: var(--result-error-bg);
  border-color: var(--result-error-border);
  color: var(--result-error-text);
}

