:root {
    --im-primary: #5b4bff;
    --im-primary-dark: #4338ca;
    --im-accent: #14b8a6;
    --im-bg: #0f172a;
    --im-surface: #1e293b;
    --im-surface-raised: #243044;
    --im-text: #f1f5f9;
    --im-muted: #94a3b8;
    --im-border: rgba(148, 163, 184, 0.2);

    /* Bootstrap 5 dark-surface overrides */
    --bs-body-color: var(--im-text);
    --bs-body-bg: var(--im-bg);
    --bs-secondary-color: var(--im-muted);
    --bs-tertiary-color: #cbd5e1;
    --bs-heading-color: var(--im-text);
    --bs-link-color: #a5b4fc;
    --bs-link-hover-color: #c7d2fe;
    --bs-border-color: var(--im-border);
    --bs-emphasis-color: #fff;
}

/* Force light text on dark UI (Bootstrap defaults fight this) */
.im-body,
.im-body .card,
.im-body .card-body,
.im-body .card-footer,
.im-body .table,
.im-body .table td,
.im-body .table th,
.im-body .form-label,
.im-body .form-check-label,
.im-body .navbar-text,
.im-body .list-group-item,
.im-body h1,
.im-body h2,
.im-body h3,
.im-body h4,
.im-body h5,
.im-body h6,
.im-body p,
.im-body li,
.im-body label,
.im-body small:not(.badge) {
    color: var(--im-text);
}

.im-body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: linear-gradient(160deg, #0f172a 0%, #1e1b4b 45%, #0f172a 100%);
    color: var(--im-text);
    color-scheme: dark;
}

.im-body .text-muted,
.im-body .text-secondary {
    color: var(--im-muted) !important;
}

.im-body a:not(.btn):not(.nav-link):not(.navbar-brand) {
    color: var(--bs-link-color);
}

.im-body a:not(.btn):not(.nav-link):not(.navbar-brand):hover {
    color: var(--bs-link-hover-color);
}

.im-body code {
    color: #e2e8f0;
    background: rgba(15, 23, 42, 0.65);
    padding: 0.1rem 0.35rem;
    border-radius: 0.25rem;
}

.im-navbar {
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--im-border);
}

.im-navbar .navbar-brand,
.im-navbar .nav-link,
.im-navbar .navbar-text {
    color: var(--im-text) !important;
}

.im-navbar .nav-link:hover,
.im-navbar .nav-link:focus {
    color: var(--im-accent) !important;
}

.im-navbar .navbar-toggler {
    border-color: rgba(248, 250, 252, 0.35);
}

.im-navbar .navbar-toggler-icon {
    filter: invert(1) grayscale(1) brightness(1.8);
}

.im-main {
    flex: 1;
    max-width: 1200px;
}

.im-card {
    background: var(--im-surface);
    border: 1px solid var(--im-border);
    border-radius: 1rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    color: var(--im-text);
}

.im-card .card-header {
    background: transparent;
    border-bottom-color: var(--im-border);
    color: var(--im-text);
}

.im-card .card-footer {
    border-top-color: var(--im-border);
    background: transparent;
}

.im-stat {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--im-accent);
}

.im-footer {
    color: var(--im-muted);
    border-top: 1px solid var(--im-border);
}

.btn-im-primary {
    background: var(--im-primary);
    border-color: var(--im-primary);
    color: #fff;
}

.btn-im-primary:hover,
.btn-im-primary:focus {
    background: var(--im-primary-dark);
    border-color: var(--im-primary-dark);
    color: #fff;
}

.im-body .btn-outline-light {
    color: var(--im-text);
    border-color: rgba(248, 250, 252, 0.45);
}

.im-body .btn-outline-light:hover,
.im-body .btn-outline-light:focus {
    color: var(--im-bg);
    background: var(--im-text);
    border-color: var(--im-text);
}

.im-body .btn-outline-danger {
    color: #fca5a5;
    border-color: rgba(248, 113, 113, 0.55);
}

.im-body .btn-outline-danger:hover {
    color: #fff;
    background: #dc2626;
    border-color: #dc2626;
}

.form-control,
.form-select {
    background-color: #0b1220;
    border-color: rgba(148, 163, 184, 0.35);
    color: var(--im-text);
}

.form-control::placeholder {
    color: #64748b;
    opacity: 1;
}

.form-control:focus,
.form-select:focus {
    background-color: #0b1220;
    color: var(--im-text);
    border-color: var(--im-primary);
    box-shadow: 0 0 0 0.2rem rgba(91, 75, 255, 0.25);
}

.form-select option {
    background: #0f172a;
    color: var(--im-text);
}

.form-check-input {
    background-color: #0b1220;
    border-color: rgba(148, 163, 184, 0.45);
}

.form-check-input:checked {
    background-color: var(--im-primary);
    border-color: var(--im-primary);
}

.table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--im-text);
    --bs-table-striped-color: var(--im-text);
    --bs-table-active-color: var(--im-text);
    --bs-table-hover-color: var(--im-text);
    --bs-table-border-color: var(--im-border);
}

/* Tables flush to card edges without card-body — add gutter */
.im-card > .table-responsive,
.im-card > .table {
    padding: 0 1rem 1rem;
}

.im-body .table > :not(caption) > * > * {
    padding: 0.65rem 0.85rem;
    vertical-align: middle;
}

.im-body .table.table-sm > :not(caption) > * > * {
    padding: 0.55rem 0.85rem;
}

.im-body .table thead th {
    color: #cbd5e1;
    border-bottom-color: var(--im-border);
    padding-top: 0.75rem;
}

.im-body .table thead th:first-child,
.im-body .table tbody td:first-child {
    padding-left: 1rem;
}

.im-body .table thead th:last-child,
.im-body .table tbody td:last-child {
    padding-right: 1rem;
}

.table tbody td {
    color: var(--im-text);
    border-color: var(--im-border);
}

.list-group-item {
    background-color: transparent;
    border-color: var(--im-border);
    color: var(--im-text);
}

.im-body .alert {
    border-width: 1px;
}

.im-body .alert-success {
    background: rgba(20, 184, 166, 0.15);
    border-color: rgba(20, 184, 166, 0.45);
    color: #99f6e4;
}

.im-body .alert-danger {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.45);
    color: #fecaca;
}

.im-body .alert-warning {
    background: rgba(245, 158, 11, 0.18);
    border-color: rgba(245, 158, 11, 0.45);
    color: #fde68a;
}

.im-body .badge.bg-warning.text-dark {
    color: #1e293b !important;
}

.im-body .badge.bg-secondary {
    color: #e2e8f0;
}

@media (max-width: 576px) {
    .im-stat {
        font-size: 1.35rem;
    }
}

/* Public storefront */
.im-storefront .im-main {
    max-width: 1100px;
}

.im-hero {
    border-radius: 1rem;
    overflow: hidden;
    border: 1px solid var(--im-border);
    background: linear-gradient(135deg, rgba(91, 75, 255, 0.25), rgba(20, 184, 166, 0.12));
}

.im-hero-inner {
    padding: 2.5rem 1.5rem;
}

.im-hero-title {
    font-size: clamp(1.6rem, 4vw, 2.25rem);
    font-weight: 700;
    margin-bottom: 0.75rem;
}

.im-hero-lead {
    color: var(--im-muted);
    max-width: 42rem;
    margin-bottom: 1.25rem;
}

.im-product-card {
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.im-product-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 36px rgba(0, 0, 0, 0.35);
}

.im-body .alert-info {
    background: rgba(91, 75, 255, 0.12);
    border-color: rgba(91, 75, 255, 0.35);
    color: #c7d2fe;
}

/* Product image upload (admin) */
.im-image-dropzone {
    border: 2px dashed var(--im-border);
    border-radius: 0.75rem;
    padding: 2rem 1.5rem;
    text-align: center;
    cursor: pointer;
    color: var(--im-muted);
    transition: border-color 0.15s ease, background 0.15s ease;
}

.im-image-dropzone:hover,
.im-image-dropzone.is-dragover,
.im-image-dropzone:focus {
    border-color: var(--im-accent);
    background: rgba(91, 75, 255, 0.08);
    outline: none;
}

.im-image-thumb {
    position: relative;
    border-radius: 0.5rem;
    overflow: hidden;
    border: 2px solid transparent;
    background: rgba(0, 0, 0, 0.25);
}

.im-image-thumb.is-primary {
    border-color: var(--im-teal);
}

.im-image-thumb img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
}

.im-image-actions {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    gap: 0.35rem;
    justify-content: center;
    padding: 0.5rem;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
}

/* Shop product images */
.im-product-card-img-link {
    display: block;
}

.im-product-card-img {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border-bottom: 1px solid var(--im-border);
}

.im-product-gallery {
    position: relative;
    border-radius: 0.5rem;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.2);
    aspect-ratio: 1;
}

.im-product-gallery-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.im-product-gallery-img.is-active {
    opacity: 1;
}

.im-product-gallery-thumbs {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.im-product-gallery-thumb {
    border: 2px solid transparent;
    border-radius: 0.35rem;
    padding: 0;
    width: 56px;
    height: 56px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.25);
    cursor: pointer;
}

.im-product-gallery-thumb.is-active {
    border-color: var(--im-teal);
}

.im-product-gallery-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.im-audit-meta {
    font-size: 0.75rem;
    max-height: 6rem;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
    background: rgba(0, 0, 0, 0.2);
    padding: 0.5rem;
    border-radius: 0.35rem;
}

/* Product costing mode toggle */
.im-cost-mode-picker {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.75rem;
}

.im-cost-mode-option {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.85rem 1rem;
    border: 2px solid var(--im-border);
    border-radius: 0.65rem;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
    margin: 0;
}

.im-cost-mode-option:hover {
    border-color: rgba(91, 75, 255, 0.45);
}

.im-cost-mode-option.is-active {
    border-color: var(--im-teal);
    background: rgba(20, 184, 166, 0.1);
    box-shadow: 0 0 0 1px rgba(20, 184, 166, 0.35);
}

.im-cost-mode-radio {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.im-cost-mode-title {
    font-weight: 600;
    color: var(--im-text, #e2e8f0);
}

.im-cost-mode-desc {
    font-size: 0.8rem;
    color: var(--im-muted);
}

.im-cost-panel.is-active-panel .form-label {
    color: var(--im-teal);
}

.im-bom-section {
    padding-top: 0.25rem;
    border-top: 1px solid var(--im-border);
    margin-top: 0.25rem;
}

/* Product edit accordion */
.im-accordion.accordion {
    --bs-accordion-color: var(--im-text);
    --bs-accordion-bg: var(--im-surface);
    --bs-accordion-border-color: var(--im-border);
    --bs-accordion-btn-color: var(--im-text);
    --bs-accordion-btn-bg: var(--im-surface-raised);
    --bs-accordion-active-color: var(--im-text);
    --bs-accordion-active-bg: rgba(20, 184, 166, 0.12);
    --bs-accordion-btn-focus-box-shadow: 0 0 0 0.2rem rgba(20, 184, 166, 0.25);
}

.im-accordion .accordion-item {
    background: var(--im-surface);
    border: 1px solid var(--im-border);
    border-radius: 0.65rem;
    overflow: hidden;
    margin-bottom: 0.75rem;
}

.im-accordion .accordion-item:last-of-type {
    margin-bottom: 0;
}

.im-accordion .accordion-button {
    font-weight: 600;
    padding: 0.85rem 1rem;
    box-shadow: none;
}

.im-accordion .accordion-button:not(.collapsed) {
    border-bottom: 1px solid var(--im-border);
}

.im-accordion .accordion-button::after {
    filter: invert(1) brightness(1.15);
}

.im-accordion .accordion-body {
    padding: 1rem 1.1rem 1.15rem;
}

.im-file-list .list-group-item {
    border-color: var(--im-border);
}
