/* Primer-aligned Utility CSS Layer
   Replaces Tailwind CSS and Bootstrap utility classes.
   Based on GitHub Primer Design System tokens. */

/* ============================================
   Display
   ============================================ */
.d-none { display: none !important; }
.d-block { display: block !important; }
.d-inline { display: inline !important; }
.d-inline-block { display: inline-block !important; }
.d-flex { display: flex !important; }
.d-inline-flex { display: inline-flex !important; }
.d-grid { display: grid !important; }

/* ============================================
   Flexbox
   ============================================ */
.flex-row { flex-direction: row !important; }
.flex-column { flex-direction: column !important; }
.flex-wrap { flex-wrap: wrap !important; }
.flex-nowrap { flex-wrap: nowrap !important; }
.flex-1 { flex: 1 1 0% !important; }
.flex-auto { flex: 1 1 auto !important; }
.flex-shrink-0 { flex-shrink: 0 !important; }
.items-center { align-items: center !important; }
.items-start { align-items: flex-start !important; }
.items-end { align-items: flex-end !important; }
.items-stretch { align-items: stretch !important; }
.justify-center { justify-content: center !important; }
.justify-between { justify-content: space-between !important; }
.justify-start { justify-content: flex-start !important; }
.justify-end { justify-content: flex-end !important; }
.justify-around { justify-content: space-around !important; }
.self-center { align-self: center !important; }
.self-start { align-self: flex-start !important; }
.self-end { align-self: flex-end !important; }

/* ============================================
   Grid
   ============================================ */
.grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)) !important; }
.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
.grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; }
.grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; }
.grid-cols-6 { grid-template-columns: repeat(6, minmax(0, 1fr)) !important; }
.col-span-2 { grid-column: span 2 / span 2 !important; }
.col-span-3 { grid-column: span 3 / span 3 !important; }

/* ============================================
   Gap (Primer 4px base scale)
   ============================================ */
.gap-0 { gap: 0 !important; }
.gap-1 { gap: 4px !important; }
.gap-2 { gap: 8px !important; }
.gap-3 { gap: 16px !important; }
.gap-4 { gap: 20px !important; }
.gap-5 { gap: 24px !important; }
.gap-6 { gap: 32px !important; }
.gap-8 { gap: 36px !important; }

/* ============================================
   Spacing: Margin (Primer 4px base scale)
   0=0, 1=4px, 2=8px, 3=16px, 4=24px, 5=32px, 6=40px
   ============================================ */
.m-0  { margin: 0 !important; }
.m-1  { margin: 4px !important; }
.m-2  { margin: 8px !important; }
.m-3  { margin: 16px !important; }
.m-4  { margin: 24px !important; }
.m-5  { margin: 28px !important; }
.m-6  { margin: 32px !important; }
.m-auto { margin: auto !important; }

.mx-0  { margin-left: 0 !important; margin-right: 0 !important; }
.mx-1  { margin-left: 4px !important; margin-right: 4px !important; }
.mx-2  { margin-left: 8px !important; margin-right: 8px !important; }
.mx-3  { margin-left: 16px !important; margin-right: 16px !important; }
.mx-4  { margin-left: 24px !important; margin-right: 24px !important; }
.mx-auto { margin-left: auto !important; margin-right: auto !important; }

.my-0  { margin-top: 0 !important; margin-bottom: 0 !important; }
.my-1  { margin-top: 4px !important; margin-bottom: 4px !important; }
.my-2  { margin-top: 8px !important; margin-bottom: 8px !important; }
.my-3  { margin-top: 16px !important; margin-bottom: 16px !important; }
.my-4  { margin-top: 24px !important; margin-bottom: 24px !important; }
.my-5  { margin-top: 28px !important; margin-bottom: 28px !important; }
.my-6  { margin-top: 32px !important; margin-bottom: 32px !important; }

.mt-0  { margin-top: 0 !important; }
.mt-1  { margin-top: 4px !important; }
.mt-2  { margin-top: 8px !important; }
.mt-3  { margin-top: 16px !important; }
.mt-4  { margin-top: 24px !important; }
.mt-5  { margin-top: 28px !important; }
.mt-6  { margin-top: 32px !important; }
.mt-8  { margin-top: 36px !important; }
.mt-12 { margin-top: 48px !important; }

.mb-0  { margin-bottom: 0 !important; }
.mb-1  { margin-bottom: 4px !important; }
.mb-2  { margin-bottom: 8px !important; }
.mb-3  { margin-bottom: 16px !important; }
.mb-4  { margin-bottom: 24px !important; }
.mb-5  { margin-bottom: 28px !important; }
.mb-6  { margin-bottom: 32px !important; }
.mb-8  { margin-bottom: 36px !important; }
.mb-12 { margin-bottom: 48px !important; }

.ml-0  { margin-left: 0 !important; }
.ml-1  { margin-left: 4px !important; }
.ml-2  { margin-left: 8px !important; }
.ml-3  { margin-left: 16px !important; }

.mr-0  { margin-right: 0 !important; }
.mr-1  { margin-right: 4px !important; }
.mr-2  { margin-right: 8px !important; }
.mr-3  { margin-right: 16px !important; }

/* ============================================
   Spacing: Padding (Primer 4px base scale)
   ============================================ */
.p-0  { padding: 0 !important; }
.p-1  { padding: 4px !important; }
.p-2  { padding: 8px !important; }
.p-3  { padding: 16px !important; }
.p-4  { padding: 24px !important; }
.p-5  { padding: 28px !important; }
.p-6  { padding: 32px !important; }
.p-8  { padding: 36px !important; }

.px-0  { padding-left: 0 !important; padding-right: 0 !important; }
.px-1  { padding-left: 4px !important; padding-right: 4px !important; }
.px-2  { padding-left: 8px !important; padding-right: 8px !important; }
.px-3  { padding-left: 16px !important; padding-right: 16px !important; }
.px-4  { padding-left: 24px !important; padding-right: 24px !important; }
.px-5  { padding-left: 28px !important; padding-right: 28px !important; }
.px-6  { padding-left: 32px !important; padding-right: 32px !important; }

.py-0  { padding-top: 0 !important; padding-bottom: 0 !important; }
.py-1  { padding-top: 4px !important; padding-bottom: 4px !important; }
.py-2  { padding-top: 8px !important; padding-bottom: 8px !important; }
.py-3  { padding-top: 16px !important; padding-bottom: 16px !important; }
.py-4  { padding-top: 24px !important; padding-bottom: 24px !important; }
.py-5  { padding-top: 28px !important; padding-bottom: 28px !important; }
.py-6  { padding-top: 32px !important; padding-bottom: 32px !important; }
.py-8  { padding-top: 36px !important; padding-bottom: 36px !important; }
.py-12 { padding-top: 48px !important; padding-bottom: 48px !important; }
.py-16 { padding-top: 64px !important; padding-bottom: 64px !important; }

.pt-0  { padding-top: 0 !important; }
.pt-2  { padding-top: 8px !important; }
.pt-3  { padding-top: 16px !important; }
.pt-4  { padding-top: 20px !important; }
.pt-5  { padding-top: 28px !important; }
.pt-20 { padding-top: 64px !important; }

.pb-0  { padding-bottom: 0 !important; }
.pb-2  { padding-bottom: 8px !important; }
.pb-3  { padding-bottom: 16px !important; }
.pb-4  { padding-bottom: 20px !important; }

.pl-2  { padding-left: 8px !important; }
.pl-3  { padding-left: 16px !important; }
.pl-10 { padding-left: 40px !important; }
.pl-12 { padding-left: 48px !important; }

.pr-2  { padding-right: 8px !important; }
.pr-3  { padding-right: 16px !important; }
.pr-8  { padding-right: 28px !important; }

/* ============================================
   Sizing
   ============================================ */
.width-full { width: 100% !important; }
.width-auto { width: auto !important; }
.w-5 { width: 20px !important; }
.w-6 { width: 24px !important; }
.w-8 { width: 32px !important; }
.w-10 { width: 40px !important; }
.w-12 { width: 48px !important; }
.w-16 { width: 64px !important; }
.w-48 { width: 192px !important; }
.h-5 { height: 20px !important; }
.h-6 { height: 24px !important; }
.h-8 { height: 32px !important; }
.h-10 { height: 40px !important; }
.h-12 { height: 48px !important; }
.h-16 { height: 64px !important; }
.min-h-screen { min-height: 100vh !important; }

/* Containers (Primer viewport ranges) */
.container-sm { max-width: 544px; margin-left: auto; margin-right: auto; padding-left: 16px; padding-right: 16px; }
.container-md { max-width: 720px; margin-left: auto; margin-right: auto; padding-left: 16px; padding-right: 16px; }
.container-lg { max-width: 960px; margin-left: auto; margin-right: auto; padding-left: 16px; padding-right: 16px; }
.container-xl { max-width: 1120px; margin-left: auto; margin-right: auto; padding-left: 16px; padding-right: 16px; }
@media (min-width: 1280px) {
    .container-xl { padding-left: 20px; padding-right: 20px; }
    .container-lg { padding-left: 20px; padding-right: 20px; }
}

.max-w-sm { max-width: 480px !important; }
.max-w-md { max-width: 720px !important; }
.max-w-lg { max-width: 920px !important; }
.max-w-xl { max-width: 1120px !important; }
.max-w-4xl { max-width: 840px !important; }
.max-w-6xl { max-width: 1152px !important; }

/* ============================================
   Typography (Primer scale)
   ============================================ */
.f0 { font-size: 1.75rem !important; }
.f1 { font-size: 1.375rem !important; }
.f2 { font-size: 1.125rem !important; }
.f3 { font-size: 1.125rem !important; }
.f4 { font-size: 1rem !important; }
.f5 { font-size: 0.875rem !important; }
.f6 { font-size: 0.75rem !important; }
.f00 { font-size: 2.2rem !important; }

.text-bold { font-weight: 600 !important; }
.text-semibold { font-weight: 500 !important; }
.text-normal { font-weight: 400 !important; }
.text-light { font-weight: 300 !important; }

.text-center { text-align: center !important; }
.text-left { text-align: left !important; }
.text-right { text-align: right !important; }

.text-uppercase { text-transform: uppercase !important; }
.text-no-decoration { text-decoration: none !important; }
.text-underline { text-decoration: underline !important; }

.lh-condensed { line-height: 1.25 !important; }
.lh-default { line-height: 1.5 !important; }
.lh-relaxed { line-height: 1.75 !important; }

.wb-break-word { word-break: break-word !important; overflow-wrap: break-word !important; }
.text-mono { font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace !important; }

.line-clamp-1 { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; }
.line-clamp-2 { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.line-clamp-3 { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }

/* ============================================
   Colors (Primer semantic)
   ============================================ */
.color-fg-default { color: var(--fgColor-default) !important; }
.color-fg-muted { color: var(--fgColor-muted) !important; }
.color-fg-subtle { color: var(--fgColor-subtle) !important; }
.color-fg-accent { color: var(--fgColor-accent) !important; }
.color-fg-success { color: var(--fgColor-success) !important; }
.color-fg-danger { color: var(--fgColor-danger) !important; }
.color-fg-attention { color: var(--fgColor-attention) !important; }
.color-fg-onEmphasis { color: var(--fgColor-onEmphasis) !important; }

.color-bg-default { background-color: var(--bgColor-default) !important; }
.color-bg-subtle { background-color: var(--bgColor-muted) !important; }
.color-bg-inset { background-color: var(--bgColor-inset) !important; }
.color-bg-emphasis { background-color: var(--bgColor-emphasis) !important; }
.color-bg-accent-emphasis { background-color: var(--bgColor-accent-emphasis) !important; }
.color-bg-accent-muted { background-color: var(--bgColor-accent-muted) !important; }
.color-bg-success-emphasis { background-color: var(--bgColor-success-emphasis) !important; }
.color-bg-success-muted { background-color: var(--bgColor-success-muted) !important; }
.color-bg-danger-emphasis { background-color: var(--bgColor-danger-emphasis) !important; }
.color-bg-danger-muted { background-color: var(--bgColor-danger-muted) !important; }
.color-bg-attention-muted { background-color: var(--bgColor-attention-muted) !important; }

.color-border-default { border-color: var(--borderColor-default) !important; }
.color-border-muted { border-color: var(--borderColor-muted) !important; }
.color-border-accent { border-color: var(--borderColor-accent-emphasis) !important; }
.color-border-success { border-color: var(--borderColor-success-emphasis) !important; }
.color-border-danger { border-color: var(--borderColor-danger-emphasis) !important; }

/* ============================================
   Borders & Radius
   ============================================ */
.border { border: 1px solid var(--borderColor-default) !important; }
.border-0 { border: 0 !important; }
.border-top { border-top: 1px solid var(--borderColor-default) !important; }
.border-bottom { border-bottom: 1px solid var(--borderColor-default) !important; }
.border-left { border-left: 1px solid var(--borderColor-default) !important; }
.border-right { border-right: 1px solid var(--borderColor-default) !important; }

.rounded-0 { border-radius: 0 !important; }
.rounded-1 { border-radius: var(--borderRadius-small) !important; }
.rounded-2 { border-radius: var(--borderRadius-medium) !important; }
.rounded-3 { border-radius: var(--borderRadius-large) !important; }
.circle { border-radius: 50% !important; }
.rounded-full { border-radius: var(--borderRadius-full) !important; }

/* ============================================
   Shadows
   ============================================ */
.shadow-none { box-shadow: none !important; }
.shadow-sm { box-shadow: var(--shadow-resting-small) !important; }
.shadow-md { box-shadow: var(--shadow-resting-medium) !important; }
.shadow-lg { box-shadow: var(--shadow-floating-small) !important; }
.shadow-xl { box-shadow: var(--shadow-floating-medium) !important; }

/* ============================================
   Position
   ============================================ */
.position-static { position: static !important; }
.position-relative { position: relative !important; }
.position-absolute { position: absolute !important; }
.position-fixed { position: fixed !important; }
.position-sticky { position: sticky !important; }
.top-0 { top: 0 !important; }
.right-0 { right: 0 !important; }
.bottom-0 { bottom: 0 !important; }
.left-0 { left: 0 !important; }
.inset-0 { top: 0 !important; right: 0 !important; bottom: 0 !important; left: 0 !important; }

.z-0 { z-index: 0 !important; }
.z-1 { z-index: 1 !important; }
.z-10 { z-index: 10 !important; }
.z-40 { z-index: 40 !important; }
.z-50 { z-index: 50 !important; }
.z-100 { z-index: 100 !important; }

/* ============================================
   Overflow
   ============================================ */
.overflow-hidden { overflow: hidden !important; }
.overflow-auto { overflow: auto !important; }
.overflow-visible { overflow: visible !important; }
.overflow-x-auto { overflow-x: auto !important; }
.overflow-y-auto { overflow-y: auto !important; }

/* ============================================
   Object fit
   ============================================ */
.object-cover { object-fit: cover !important; }
.object-contain { object-fit: contain !important; }

/* ============================================
   Cursor
   ============================================ */
.cursor-pointer { cursor: pointer !important; }
.cursor-default { cursor: default !important; }
.user-select-none { user-select: none !important; }

/* ============================================
   Opacity
   ============================================ */
.opacity-0 { opacity: 0 !important; }
.opacity-50 { opacity: 0.5 !important; }
.opacity-70 { opacity: 0.7 !important; }
.opacity-100 { opacity: 1 !important; }

/* ============================================
   Transitions
   ============================================ */
.transition-colors { transition: color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease !important; }
.transition-opacity { transition: opacity 0.15s ease !important; }
.transition-all { transition: all 0.15s ease !important; }

/* ============================================
   Primer Box Component
   ============================================ */
.Box {
    background-color: var(--bgColor-default);
    border: 1px solid var(--borderColor-default);
    border-radius: var(--borderRadius-medium);
}

.Box--condensed .Box-row {
    padding: 8px 16px;
}

.Box-header {
    padding: 14px;
    margin: -1px -1px 0 -1px;
    background-color: var(--bgColor-muted);
    border: 1px solid var(--borderColor-default);
    border-top-left-radius: var(--borderRadius-medium);
    border-top-right-radius: var(--borderRadius-medium);
}

.Box-body {
    padding: 14px;
    border-bottom: 1px solid var(--borderColor-default);
}

.Box-body:last-of-type {
    border-bottom: 0;
    border-bottom-right-radius: var(--borderRadius-medium);
    border-bottom-left-radius: var(--borderRadius-medium);
}

.Box-row {
    padding: 14px;
    border-top: 1px solid var(--borderColor-default);
}

.Box-row:first-of-type {
    border-top: 0;
}

.Box-row:hover {
    background-color: var(--bgColor-muted);
}

.Box-footer {
    padding: 14px;
    margin: 0 -1px -1px -1px;
    border-top: 1px solid var(--borderColor-default);
    border-bottom-left-radius: var(--borderRadius-medium);
    border-bottom-right-radius: var(--borderRadius-medium);
}

/* ============================================
   Primer Label Component
   ============================================ */
.Label {
    display: inline-block;
    padding: 0 7px;
    font-size: 12px;
    font-weight: 500;
    line-height: 18px;
    white-space: nowrap;
    border: 1px solid transparent;
    border-radius: var(--borderRadius-full);
}

.Label--primary {
    color: var(--fgColor-onEmphasis);
    background-color: var(--bgColor-accent-emphasis);
}

.Label--secondary {
    color: var(--fgColor-muted);
    background-color: var(--bgColor-muted);
    border-color: var(--borderColor-default);
}

.Label--success {
    color: var(--fgColor-onEmphasis);
    background-color: var(--bgColor-success-emphasis);
}

.Label--danger {
    color: var(--fgColor-onEmphasis);
    background-color: var(--bgColor-danger-emphasis);
}

.Label--attention {
    color: var(--fgColor-onEmphasis);
    background-color: var(--bgColor-attention-emphasis);
}
.Label--accent {
    color: var(--fgColor-onEmphasis);
    background-color: var(--bgColor-accent-emphasis);
}

/* ============================================
   Primer Flash/Banner
   ============================================ */
.flash {
    position: relative;
    padding: 14px;
    color: var(--fgColor-default);
    border: 1px solid var(--borderColor-default);
    border-radius: var(--borderRadius-medium);
    background-color: var(--bgColor-accent-muted);
}

.flash-success {
    color: var(--fgColor-success);
    background-color: var(--bgColor-success-muted);
    border-color: var(--borderColor-success-emphasis);
}

.flash-danger {
    color: var(--fgColor-danger);
    background-color: var(--bgColor-danger-muted);
    border-color: var(--borderColor-danger-emphasis);
}

.flash-warning {
    color: var(--fgColor-attention);
    background-color: var(--bgColor-attention-muted);
    border-color: var(--borderColor-default);
}

/* ============================================
   Form Controls (Primer style)
   ============================================ */
.form-control {
    display: block;
    width: 100%;
    padding: 5px 12px;
    font-size: 14px;
    line-height: 20px;
    color: var(--fgColor-default);
    background-color: var(--bgColor-default);
    border: 1px solid var(--borderColor-default);
    border-radius: var(--borderRadius-medium);
    box-shadow: var(--shadow-resting-xsmall);
    transition: border-color 0.15s ease;
}

.form-control:focus {
    border-color: var(--focus-outlineColor);
    outline: none;
    box-shadow: 0 0 0 3px rgba(9, 105, 218, 0.3);
}

.form-control::placeholder {
    color: var(--fgColor-subtle);
}

.form-label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--fgColor-default);
}

.form-select {
    display: block;
    width: 100%;
    padding: 5px 12px;
    font-size: 14px;
    line-height: 20px;
    color: var(--fgColor-default);
    background-color: var(--bgColor-default);
    border: 1px solid var(--borderColor-default);
    border-radius: var(--borderRadius-medium);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath fill='%23586069' d='M4.427 7.427l3.396 3.396a.25.25 0 00.354 0l3.396-3.396A.25.25 0 0011.396 7H4.604a.25.25 0 00-.177.427z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 16px;
    padding-right: 32px;
}

/* ============================================
   Responsive: Regular (>=768px)
   ============================================ */
@media (min-width: 768px) {
    .d-regular-none { display: none !important; }
    .d-regular-block { display: block !important; }
    .d-regular-flex { display: flex !important; }
    .d-regular-inline-flex { display: inline-flex !important; }
    .d-regular-grid { display: grid !important; }
    .grid-regular-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
    .grid-regular-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; }
    .grid-regular-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; }
    .hide-regular { display: none !important; }
    .flex-regular-row { flex-direction: row !important; }
    .items-regular-center { align-items: center !important; }
    .items-regular-end { align-items: flex-end !important; }
    .mb-regular-0 { margin-bottom: 0 !important; }
    .mt-regular-0 { margin-top: 0 !important; }
    .pr-regular-4 { padding-right: 20px !important; }
    .space-regular-x-3 > * + * { margin-left: 16px !important; }
    .space-regular-x-4 > * + * { margin-left: 20px !important; }
    .space-regular-y-0 > * + * { margin-top: 0 !important; }
    .w-regular-2\/3 { width: 66.666667% !important; }
    .w-regular-1\/3 { width: 33.333333% !important; }
    .w-regular-3\/4 { width: 75% !important; }
    .w-regular-1\/4 { width: 25% !important; }
    .f-regular-0 { font-size: 1.9rem !important; }
    .f-regular-00 { font-size: 2.2rem !important; }
}

/* Narrow only (below 768px) */
.hide-narrow { display: none !important; }
@media (min-width: 768px) {
    .hide-narrow { display: revert !important; }
}
@media (max-width: 767px) {
    .hide-regular-down { display: none !important; }
}

/* ============================================
   Responsive: Large (>=1012px)
   ============================================ */
@media (min-width: 1012px) {
    .d-large-none { display: none !important; }
    .d-large-block { display: block !important; }
    .d-large-flex { display: flex !important; }
    .grid-large-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; }
    .grid-large-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; }
    .w-large-3\/4 { width: 75% !important; }
    .w-large-1\/4 { width: 25% !important; }
    .col-large-span-2 { grid-column: span 2 / span 2 !important; }
}

/* ============================================
   Misc Utilities
   ============================================ */
.v-hidden { visibility: hidden !important; }
.v-visible { visibility: visible !important; }
.list-style-none { list-style: none !important; }
.no-underline { text-decoration: none !important; }
.no-wrap { white-space: nowrap !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Space between children */
.space-x-2 > * + * { margin-left: 8px; }
.space-x-3 > * + * { margin-left: 16px; }
.space-x-4 > * + * { margin-left: 24px; }
.space-x-6 > * + * { margin-left: 32px; }
.space-y-2 > * + * { margin-top: 8px; }
.space-y-3 > * + * { margin-top: 16px; }
.space-y-4 > * + * { margin-top: 24px; }
.space-y-6 > * + * { margin-top: 32px; }
