/**
 * NShine ERP Design System
 * ─────────────────────────────────────────────────────────────────────────────
 * Single source for new UI styling. Load after style.css in App.razor.
 *
 * Do not add per-module CSS files. Extend this file with reusable ns-* patterns
 * or semantic tokens. Legacy styles remain in style.css; new work uses tokens
 * and components defined here.
 *
 * Token naming follows shadcn/ui conventions (--background, --primary, etc.)
 * mapped to existing NShine brand variables from style.css (:root --ns-color-*).
 */

/* ═══════════════════════════════════════════════════════════════════════════
   1. Semantic design tokens
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
    /* Surfaces */
    --background: #F7F8FB;
    --foreground: var(--ns-color-blue, #212B36);
    --card: var(--ns-color-white, #ffffff);
    --card-foreground: var(--foreground);
    --popover: var(--card);
    --popover-foreground: var(--foreground);
    /* Brand */
    --primary: var(--ns-color-primary, #ff6821);
    --primary-foreground: var(--ns-color-white, #ffffff);
    --secondary: var(--ns-color-secondary, #3068A4);
    --secondary-foreground: var(--ns-color-white, #ffffff);
    /* Muted / accent */
    --muted: var(--ns-color-bg-light, #f8f9fa);
    --muted-foreground: var(--ns-color-gray, #637381);
    --accent: var(--ns-color-light-orange, #ffded9);
    --accent-foreground: var(--ns-color-blue, #212B36);
    /* Feedback */
    --destructive: var(--ns-color-red, #F14B5B);
    --destructive-foreground: var(--ns-color-white, #ffffff);
    --warning: var(--ns-color-yellow, #ffc107);
    --warning-foreground: #664d03;
    --warning-subtle: #fff3cd;
    --success: var(--ns-color-green, #1EB386);
    --success-foreground: var(--ns-color-white, #ffffff);
    /* Borders & focus */
    --border: var(--ns-color-border-light, #e0e0e0);
    --input: var(--border);
    --ring: var(--primary);
    /* Radius */
    --radius-sm: 0.25rem;
    --radius: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-full: 9999px;
    /* Elevation */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    /* Spacing scale */
    --ns-space-1: 0.25rem;
    --ns-space-2: 0.5rem;
    --ns-space-3: 0.75rem;
    --ns-space-4: 1rem;
    --ns-space-5: 1.25rem;
    --ns-space-6: 1.5rem;
    /* Typography helpers */
    --ns-text-xs: 0.75rem;
    --ns-text-sm: 0.875rem;
    --ns-text-base: 1rem;
}

/* Dark theme hook — extend when app-wide dark mode ships */
[data-bs-theme="dark"],
[data-theme="dark"] {
    --background: #1a1d21;
    --foreground: #e8eaed;
    --card: #212529;
    --card-foreground: var(--foreground);
    --muted: #2d3238;
    --muted-foreground: #9aa0a6;
    --border: #3c4043;
    --accent: rgba(255, 104, 33, 0.15);
    --warning-subtle: rgba(255, 193, 7, 0.15);
}

/* ═══════════════════════════════════════════════════════════════════════════
   2. Layout primitives
   ═══════════════════════════════════════════════════════════════════════════ */

.ns-ops-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--ns-space-4);
    margin-bottom: var(--ns-space-4);
}

.ns-slot-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: var(--ns-space-3);
}

/* ═══════════════════════════════════════════════════════════════════════════
   3. Interactive components
   ═══════════════════════════════════════════════════════════════════════════ */

.ns-slot {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--ns-space-3);
    min-height: 100px;
    background: var(--card);
    color: var(--card-foreground);
    cursor: pointer;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

    .ns-slot:hover {
        border-color: var(--primary);
        box-shadow: var(--shadow);
    }

.ns-slot--filled {
    background: color-mix(in srgb, var(--success) 9%, var(--card));
    border-color: color-mix(in srgb, var(--success) 36%, var(--border));
    border-style: solid;
}

.ns-slot--empty {
    border-style: dashed;
    background: var(--background);
    border-color: color-mix(in srgb, var(--muted-foreground) 18%, var(--border));
}

.ns-slot:focus-visible {
    outline: 2px solid var(--ring);
    outline-offset: 2px;
}

/* Chip / pill selector (reason codes, filters, tags) */
.ns-chip-group {
    display: flex;
    flex-wrap: wrap;
    gap: var(--ns-space-2);
}

.ns-chip {
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    padding: var(--ns-space-1) var(--ns-space-3);
    background: var(--card);
    color: var(--foreground);
    cursor: pointer;
    font-size: var(--ns-text-sm);
    line-height: 1.4;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

    .ns-chip:hover {
        border-color: var(--primary);
        background: var(--accent);
    }

.ns-chip--selected {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--primary-foreground);
}

    .ns-chip--selected:hover {
        background: var(--ns-color-primary-2, #e05c1d);
        border-color: var(--ns-color-primary-2, #e05c1d);
        color: var(--primary-foreground);
    }

/* Badges & status pills */
.ns-badge {
    display: inline-flex;
    align-items: center;
    font-size: var(--ns-text-sm);
    padding: var(--ns-space-1) 0.625rem;
    border-radius: var(--radius-full);
    font-weight: 500;
    line-height: 1.4;
}

.ns-badge--warning {
    background: var(--warning-subtle);
    color: var(--warning-foreground);
}

.ns-badge--success {
    background: rgba(30, 179, 134, 0.15);
    color: var(--ns-color-green-text, #1F4F2E);
}

.ns-badge--muted {
    background: var(--muted);
    color: var(--muted-foreground);
}

/* ═══════════════════════════════════════════════════════════════════════════
   4. Surface helpers (optional card-in-card patterns)
   ═══════════════════════════════════════════════════════════════════════════ */

.ns-surface {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.ns-surface--muted {
    background: var(--muted);
}

/* ═══════════════════════════════════════════════════════════════════════════
   5. Vehicle assets — stacked category sections + axle diagram
   ═══════════════════════════════════════════════════════════════════════════ */

.ns-vehicle-assets {
    display: flex;
    flex-direction: column;
    gap: var(--ns-space-5);
}

.ns-asset-section {
    display: flex;
    flex-direction: column;
    gap: var(--ns-space-3);
}

.ns-asset-section__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--ns-space-3);
    flex-wrap: wrap;
}

.ns-asset-section__title {
    margin: 0;
    font-size: var(--ns-text-base);
    font-weight: 600;
}

.ns-asset-section__meta {
    display: block;
    font-size: var(--ns-text-xs);
    color: var(--muted-foreground);
}

.ns-asset-empty {
    padding: var(--ns-space-4);
    font-size: var(--ns-text-sm);
    color: var(--muted-foreground);
    background: var(--card);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
}

.ns-axle-diagram {
    display: flex;
    flex-direction: column;
    gap: var(--ns-space-6);
    padding: var(--ns-space-5);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.ns-axle-row__label {
    font-size: var(--ns-text-xs);
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted-foreground);
    text-align: center;
    margin-bottom: var(--ns-space-3);
}

.ns-axle-row__track {
    display: grid;
    grid-template-columns: 1fr minmax(56px, 96px) 1fr;
    align-items: center;
    gap: var(--ns-space-3);
}

.ns-axle-row__wheels {
    display: flex;
    flex-wrap: wrap;
    gap: var(--ns-space-2);
    align-items: stretch;
}

.ns-axle-row__wheels--left {
    justify-content: flex-end;
}

.ns-axle-row__wheels--right {
    justify-content: flex-start;
}

.ns-axle-row__center {
    align-self: center;
    width: 100%;
    height: 10px;
    border-radius: var(--radius-full);
    background: linear-gradient(90deg, var(--border), var(--muted-foreground), var(--border));
    opacity: 0.35;
}

.ns-axle-slot {
    display: flex;
    flex-direction: column;
    flex: 0 1 132px;
    min-width: 112px;
    max-width: 148px;
    min-height: 128px;
    padding: var(--ns-space-3);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
    cursor: pointer;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}

    .ns-axle-slot:hover {
        border-color: var(--primary);
        box-shadow: var(--shadow);
    }

.ns-axle-slot--empty {
    border-style: dashed;
    background: var(--background);
    border-color: color-mix(in srgb, var(--muted-foreground) 18%, var(--border));
    min-height: 136px;
}

    .ns-axle-slot--empty:hover {
        background: var(--accent);
        border-color: color-mix(in srgb, var(--primary) 40%, var(--border));
    }

.ns-axle-slot--filled {
    background: color-mix(in srgb, var(--success) 9%, var(--card));
    border-color: color-mix(in srgb, var(--success) 36%, var(--border));
    border-style: solid;
}

.ns-axle-slot--selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(var(--ns-color-primary-rgb, 255, 104, 33), 0.2);
}

.ns-axle-mobile-row--selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(var(--ns-color-primary-rgb, 255, 104, 33), 0.2);
}

.ns-vehicle-assets--readonly .ns-axle-slot,
.ns-vehicle-assets--readonly .ns-axle-mobile-row {
    cursor: default;
}

.ns-vehicle-assets--readonly .ns-axle-slot--filled,
.ns-vehicle-assets--readonly .ns-axle-mobile-row--filled {
    cursor: pointer;
}

.ns-vehicle-assets--readonly .ns-axle-slot a,
.ns-vehicle-assets--readonly .ns-axle-mobile-row a {
    pointer-events: auto;
    cursor: pointer;
}

.ns-axle-slot__label {
    font-weight: 700;
    font-size: var(--ns-text-sm);
    line-height: 1.2;
}

.ns-axle-slot__code {
    font-size: var(--ns-text-xs);
    color: var(--muted-foreground);
}

.ns-axle-slot__body {
    flex: 1;
    margin-top: var(--ns-space-2);
    font-size: var(--ns-text-xs);
    line-height: 1.35;
}

.ns-axle-slot__cta {
    margin-top: var(--ns-space-2);
    font-size: var(--ns-text-sm);
    font-weight: 600;
    color: var(--muted-foreground);
}

.ns-axle-slot--empty:hover .ns-axle-slot__cta {
    color: var(--primary);
}

.ns-axle-slot__actions {
    display: flex;
    gap: var(--ns-space-1);
    margin-top: var(--ns-space-2);
    padding-top: var(--ns-space-2);
    border-top: 1px solid var(--border);
}

.ns-axle-slot__action-btn {
    border: 1px solid var(--border);
    background: var(--card);
    border-radius: var(--radius-sm);
    padding: 2px 8px;
    font-size: var(--ns-text-xs);
    line-height: 1.4;
    cursor: pointer;
    color: var(--foreground);
}

    .ns-axle-slot__action-btn:hover {
        border-color: var(--primary);
        color: var(--primary);
    }

.ns-axle-slot__action-btn--danger:hover {
    border-color: var(--destructive);
    color: var(--destructive);
}

/* Mobile: list instead of diagram */
.ns-axle-diagram--desktop {
    display: flex;
}

.ns-axle-mobile-list {
    display: none;
}

@media (max-width: 991.98px) {
    .ns-axle-diagram--desktop {
        display: none;
    }

    .ns-axle-mobile-list {
        display: block;
        background: var(--card);
        border: 1px solid var(--border);
        border-radius: var(--radius-lg);
        overflow: hidden;
    }

    .ns-axle-mobile-row {
        display: grid;
        grid-template-columns: 1fr auto;
        gap: var(--ns-space-3);
        align-items: center;
        padding: var(--ns-space-3) var(--ns-space-4);
        border-bottom: 1px solid var(--border);
        min-height: 52px;
    }

    .ns-axle-mobile-row--filled {
        background: color-mix(in srgb, var(--success) 7%, var(--card));
    }

    .ns-axle-mobile-row--empty {
        background: var(--background);
    }

        .ns-axle-mobile-row--empty:active {
            background: var(--accent);
        }

    .ns-axle-mobile-row:last-child {
        border-bottom: none;
    }

    .ns-axle-mobile-row--filled:active {
        background: color-mix(in srgb, var(--success) 12%, var(--card));
    }
}

/* Non-axle positional layouts render as a simple wrap of slot cards */
.ns-slot-grid {
    display: flex;
    flex-wrap: wrap;
    gap: var(--ns-space-3);
    padding: var(--ns-space-5);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

/* Non-positional categories render as a flat installed list */
.ns-asset-list {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.ns-asset-list__row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--ns-space-3);
    padding: var(--ns-space-3) var(--ns-space-4);
    background: var(--card);
}

    .ns-asset-list__row:not(:last-child) {
        border-bottom: 1px solid var(--border);
    }

/* Dialog footers */
.dialog-footer.ns-dialog-footer,
.ns-dialog-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--ns-space-2);
    width: 100%;
    margin-top: var(--ns-space-3);
    padding-top: var(--ns-space-3);
    border-top: 1px solid var(--border);
}

/* Slot-assign dialog */
.ns-slot-assign {
    display: flex;
    flex-direction: column;
    gap: var(--ns-space-3);
}

    .ns-slot-assign .dialog-footer,
    .ns-slot-assign .ns-dialog-footer {
        margin-top: auto;
    }

.ns-slot-assign__odo {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

    .ns-slot-assign__odo > label {
        font-size: var(--ns-text-xs);
        font-weight: 600;
        color: var(--muted-foreground);
    }

.ns-slot-assign__list {
    display: flex;
    flex-direction: column;
    max-height: 320px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.ns-slot-assign__item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--ns-space-3);
    width: 100%;
    padding: var(--ns-space-3) var(--ns-space-4);
    border: none;
    border-bottom: 1px solid var(--border);
    background: var(--card);
    text-align: left;
    cursor: pointer;
    transition: background 0.12s ease;
}

    .ns-slot-assign__item:last-child {
        border-bottom: none;
    }

    .ns-slot-assign__item:hover:not(:disabled) {
        background: var(--accent);
    }

    .ns-slot-assign__item:disabled {
        opacity: 0.55;
        cursor: not-allowed;
    }

.ns-slot-assign__item-main {
    display: flex;
    flex-direction: column;
    line-height: 1.3;
}

.ns-slot-assign__item-code {
    font-weight: 600;
    font-size: var(--ns-text-sm);
}

.ns-slot-assign__item-serial {
    font-size: var(--ns-text-xs);
    color: var(--muted-foreground);
}

.ns-slot-assign__item-cta {
    font-size: var(--ns-text-sm);
    font-weight: 600;
    color: var(--primary);
    white-space: nowrap;
}

.ns-slot-assign__item:disabled .ns-slot-assign__item-cta {
    color: var(--muted-foreground);
}

.ns-slot-assign__empty {
    text-align: center;
    padding: var(--ns-space-5) var(--ns-space-3);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
}

.ns-slot-assign__tabs {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: var(--muted);
    border-radius: var(--radius);
}

.ns-slot-assign__tab {
    flex: 1;
    border: none;
    background: transparent;
    padding: 6px 10px;
    border-radius: calc(var(--radius) - 2px);
    font-size: var(--ns-text-sm);
    font-weight: 600;
    color: var(--muted-foreground);
    cursor: pointer;
}

.ns-slot-assign__tab--active {
    background: var(--card);
    color: var(--foreground);
    box-shadow: 0 1px 2px rgb(0 0 0 / 0.06);
}

.ns-slot-assign__field-label {
    display: block;
    font-size: var(--ns-text-xs);
    font-weight: 600;
    color: var(--muted-foreground);
    margin-bottom: 4px;
}

.ns-slot-assign__serial-grid {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-height: 280px;
    overflow-y: auto;
}

.ns-slot-assign__serial-head,
.ns-slot-assign__serial-row {
    display: grid;
    grid-template-columns: minmax(88px, 1fr) 2fr;
    gap: var(--ns-space-2);
    align-items: center;
    padding: 8px 12px;
}

.ns-slot-assign__serial-head {
    font-size: var(--ns-text-xs);
    font-weight: 600;
    color: var(--muted-foreground);
    background: var(--muted);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
}

.ns-slot-assign__serial-row:not(:last-child) {
    border-bottom: 1px solid var(--border);
}

.ns-slot-assign__serial-pos {
    font-size: var(--ns-text-sm);
    font-weight: 600;
}

.ns-slot-assign__serial-input {
    display: flex;
    align-items: center;
    min-width: 0;
}

    .ns-slot-assign__serial-input .custom-w-90 {
        flex: 1;
        min-width: 0;
    }

.ns-asset-bulk-banner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--ns-space-2);
    margin-bottom: var(--ns-space-3);
    padding: var(--ns-space-3) var(--ns-space-4);
    background: var(--accent);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: var(--ns-text-sm);
}

/* ═══════════════════════════════════════════════════════════════════════════
   6. Generic layout builder (Settings > Position Layouts)
   Domain-agnostic: driven by the LayoutProfile (row/lane/slot nouns + render style).
   ═══════════════════════════════════════════════════════════════════════════ */

.ns-layout-builder {
    display: flex;
    flex-direction: column;
    gap: var(--ns-space-4);
}

.ns-layout-builder__toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--ns-space-3);
    padding: var(--ns-space-4);
    background: var(--muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.ns-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1 1 220px;
    min-width: 160px;
}

.ns-field--sm {
    flex: 0 1 170px;
}

.ns-field > label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--muted-foreground);
}

.ns-layout-builder__count {
    display: flex;
    gap: var(--ns-space-2);
    margin-left: auto;
    align-self: center;
}

.ns-layout-builder__canvas {
    display: flex;
    flex-direction: column;
    gap: var(--ns-space-4);
    padding: var(--ns-space-4);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    max-height: 55vh;
    overflow-y: auto;
}

.ns-layout-builder__empty {
    text-align: center;
    color: var(--muted-foreground);
    padding: var(--ns-space-5);
}

.ns-builder-row {
    border: 1px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: var(--ns-space-3) var(--ns-space-4);
    background: var(--background);
}

.ns-builder-row__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--ns-space-3);
    margin-bottom: var(--ns-space-3);
}

.ns-builder-row__title {
    font-weight: 600;
    color: var(--foreground);
}

.ns-builder-row__tools {
    display: flex;
    gap: var(--ns-space-2);
    align-items: center;
}

.ns-builder-row__remove {
    border: none;
    background: transparent;
    color: var(--destructive);
    font-size: 0.9rem;
    cursor: pointer;
    line-height: 1;
    padding: 4px 6px;
    border-radius: var(--radius);
}

    .ns-builder-row__remove:hover {
        background: color-mix(in srgb, var(--destructive) 12%, transparent);
    }

.ns-slot--edit {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 118px;
    padding: var(--ns-space-3);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm, 0 1px 2px rgba(0,0,0,0.05));
}

.ns-slot__remove {
    position: absolute;
    top: 4px;
    right: 4px;
    border: none;
    background: transparent;
    color: var(--muted-foreground);
    cursor: pointer;
    font-size: 0.75rem;
    line-height: 1;
    padding: 2px 4px;
    border-radius: var(--radius);
}

    .ns-slot__remove:hover {
        color: var(--destructive);
        background: color-mix(in srgb, var(--destructive) 12%, transparent);
    }

.ns-slot__input {
    width: 100%;
    font-size: 0.8rem;
    padding: 4px 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--background);
    color: var(--foreground);
}

.ns-slot__toggle {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    color: var(--muted-foreground);
    margin: 0;
}

.ns-builder-add-row {
    align-self: flex-start;
    border: 1px dashed var(--primary);
    background: color-mix(in srgb, var(--primary) 8%, transparent);
    color: var(--primary);
    font-weight: 600;
    padding: var(--ns-space-2) var(--ns-space-4);
    border-radius: var(--radius);
    cursor: pointer;
}

    .ns-builder-add-row:hover {
        background: color-mix(in srgb, var(--primary) 16%, transparent);
    }
