/* ─── Base ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    background: #f1f5f9;
    color: #0f172a;
}

a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

.text-muted { color: #64748b; }
.text-danger { color: #dc2626; }
.text-warning { color: #d97706; font-weight: 600; }

/* ─── App shell (sidebar layout) ───────────────────────────────────────────── */
.shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: #0f172a;
    color: #e2e8f0;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.25rem 1rem;
    border-bottom: 1px solid #1e293b;
}

.brand-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: #2563eb;
    color: #fff;
    font-weight: 700;
    font-size: 0.875rem;
}

.brand-title {
    font-weight: 700;
    font-size: 1rem;
    color: #f8fafc;
}

.brand-sub {
    font-size: 0.75rem;
    color: #94a3b8;
}

.sidebar-nav {
    flex: 1;
    padding: 0.75rem 0;
    overflow-y: auto;
}

.nav-section {
    padding: 0.75rem 1rem 0.25rem;
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #64748b;
}

.sidebar-nav .nav-link {
    display: block;
    padding: 0.5rem 1rem;
    margin: 0 0.5rem;
    border-radius: 6px;
    color: #cbd5e1;
    text-decoration: none;
    font-size: 0.875rem;
    transition: background 0.15s, color 0.15s;
}

.sidebar-nav .nav-link:hover {
    background: #1e293b;
    color: #f8fafc;
    text-decoration: none;
}

.sidebar-nav .nav-link.active {
    background: #1e40af;
    color: #fff;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid #1e293b;
    margin: 0;
}

.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    padding: 0.875rem 1.5rem;
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.topbar-title {
    font-weight: 600;
    font-size: 0.9375rem;
    color: #334155;
}

.content {
    flex: 1;
    padding: 1.5rem;
    overflow-x: auto;
}

/* ─── Page header ──────────────────────────────────────────────────────────── */
.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.page-header h1 {
    margin: 0 0 0.25rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: #0f172a;
}

.page-header p {
    margin: 0;
}

.page-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* ─── Cards ────────────────────────────────────────────────────────────────── */
.card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.card-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
    font-weight: 600;
    font-size: 0.875rem;
}

.row-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.table-card {
    margin-top: 1rem;
    overflow: hidden;
}

.toolbar {
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
}

.toolbar-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 1rem;
}

.toolbar-row-secondary {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid #f1f5f9;
}

.toolbar-meta {
    margin-top: 0.75rem;
    font-size: 0.8125rem;
    color: #64748b;
}

.toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.batch-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
}

.batch-nav-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: #334155;
}

.session-stats {
    font-size: 0.8125rem;
    margin-bottom: 0.75rem;
}

.compare-header {
    padding: 0.75rem 1rem;
    margin-top: 1rem;
    font-size: 0.875rem;
}

.compare-empty {
    padding: 1rem;
    font-size: 0.875rem;
}

.log-card {
    margin-top: 1.25rem;
}

/* ─── Dashboard ────────────────────────────────────────────────────────────── */
.dashboard-grid {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.dashboard-section-title {
    margin: 0 0 1rem;
    font-size: 1rem;
    font-weight: 700;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.dashboard-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.dashboard-card {
    display: flex;
    gap: 1rem;
    padding: 1.25rem;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
    color: inherit;
    text-decoration: none;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.dashboard-card:hover {
    border-color: #93c5fd;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.12);
    transform: translateY(-1px);
    text-decoration: none;
}

.dashboard-card-icon {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: #eff6ff;
    color: #2563eb;
    font-weight: 700;
    font-size: 1.125rem;
}

.dashboard-card strong {
    display: block;
    margin-bottom: 0.25rem;
    color: #0f172a;
}

.dashboard-card p {
    margin: 0;
    font-size: 0.8125rem;
    color: #64748b;
    line-height: 1.4;
}

/* ─── Forms ────────────────────────────────────────────────────────────────── */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 120px;
}

.form-group-wide {
    flex: 1;
    min-width: 200px;
}

.form-label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: #475569;
}

.form-control {
    display: block;
    width: 100%;
    padding: 0.4375rem 0.75rem;
    font-size: 0.875rem;
    line-height: 1.5;
    color: #0f172a;
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-control:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.form-control-sm {
    max-width: 140px;
}

.form-control:disabled {
    background: #f1f5f9;
    color: #94a3b8;
    cursor: not-allowed;
}

.mb-3 { margin-bottom: 1rem; }

/* ─── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0.4375rem 0.875rem;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.5;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.btn-primary {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
}

.btn-primary:hover:not(:disabled) {
    background: #1d4ed8;
    border-color: #1d4ed8;
}

.btn-outline-primary {
    background: #fff;
    color: #2563eb;
    border-color: #2563eb;
}

.btn-outline-primary:hover:not(:disabled) {
    background: #eff6ff;
}

.btn-outline-danger {
    background: #fff;
    color: #dc2626;
    border-color: #fca5a5;
}

.btn-outline-danger:hover:not(:disabled) {
    background: #fef2f2;
}

.btn-ghost {
    background: transparent;
    color: #475569;
    border-color: #e2e8f0;
}

.btn-ghost:hover:not(:disabled) {
    background: #f1f5f9;
}

.sidebar .btn-ghost {
    color: #cbd5e1;
    border-color: #334155;
}

.sidebar .btn-ghost:hover:not(:disabled) {
    background: #1e293b;
    color: #f8fafc;
}

.btn-block {
    width: 100%;
}

.btn-sm {
    padding: 0.25rem 0.625rem;
    font-size: 0.8125rem;
}

/* ─── Alerts ───────────────────────────────────────────────────────────────── */
.alert {
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
    border: 1px solid transparent;
}

.alert-info {
    background: #eff6ff;
    color: #1e40af;
    border-color: #bfdbfe;
}

.alert-danger {
    background: #fef2f2;
    color: #b91c1c;
    border-color: #fecaca;
}

/* ─── Progress ─────────────────────────────────────────────────────────────── */
.progress-strip {
    height: 6px;
    background: #e2e8f0;
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 0.375rem;
}

.progress-strip .progress-bar {
    height: 100%;
    background: #2563eb;
    border-radius: 999px;
    transition: width 0.2s ease;
}

.progress-strip.indeterminate .progress-bar {
    width: 40% !important;
    animation: progress-indeterminate 1.2s ease-in-out infinite;
}

@keyframes progress-indeterminate {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(350%); }
}

.progress-label {
    font-size: 0.8125rem;
    color: #64748b;
    margin-bottom: 1rem;
}

/* ─── Tables ───────────────────────────────────────────────────────────────── */
.table-responsive {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.table th,
.table td {
    padding: 0.5625rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid #e2e8f0;
    vertical-align: middle;
}

.table th {
    background: #f8fafc;
    font-weight: 600;
    color: #475569;
    white-space: nowrap;
}

.table-striped tbody tr:nth-child(even) {
    background: #f8fafc;
}

.table-selectable tbody tr {
    cursor: pointer;
}

.table-dblclick tbody tr {
    cursor: default;
}

.table-hint {
    margin: 0;
    padding: 0.75rem 1rem 0;
    font-size: 0.8125rem;
}

.table-selectable tbody tr:hover {
    background: #f1f5f9 !important;
}

.table-row-selected {
    outline: 2px solid #2563eb;
    outline-offset: -2px;
}

.table-success { background: #dcfce7 !important; }
.table-info { background: #e0f2fe !important; }
.table-warning { background: #fef9c3 !important; }
.table-danger { background: #fee2e2 !important; }

.table-striped tbody tr.table-success:nth-child(even),
.table-striped tbody tr.table-info:nth-child(even),
.table-striped tbody tr.table-warning:nth-child(even),
.table-striped tbody tr.table-danger:nth-child(even) {
    filter: brightness(0.97);
}

/* ─── Modal / confirm overlay ──────────────────────────────────────────────── */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(2px);
}

.modal-card {
    width: 100%;
    max-width: 440px;
    padding: 1.5rem;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(15, 23, 42, 0.2);
}

.modal-card-wide {
    max-width: min(1200px, 96vw);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
}

.modal-variants {
    max-width: min(480px, 94vw);
    padding: 0;
    overflow: hidden;
}

.modal-variants-expanded {
    max-width: min(760px, 94vw);
}

.modal-variants-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 1rem 1.25rem 0.75rem;
    border-bottom: 1px solid #e2e8f0;
}

.modal-variants-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: #0f172a;
}

.modal-variants-body {
    padding: 0.875rem 1.25rem 0.5rem;
}

.variant-product-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem 1rem;
    margin: 0 0 0.875rem;
    font-size: 0.8125rem;
}

.variant-product-meta > div {
    min-width: 0;
}

.variant-product-meta dt {
    margin: 0 0 0.125rem;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #94a3b8;
}

.variant-product-meta dd {
    margin: 0;
    color: #334155;
    line-height: 1.35;
    word-break: break-word;
}

.table-compact {
    font-size: 0.75rem;
}

.table-compact th,
.table-compact td {
    padding: 0.4375rem 0.5rem;
}

.variant-summary-table {
    margin-bottom: 0.875rem;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
}

.variant-summary-table th,
.variant-summary-table td {
    text-align: center;
}

.variant-summary-table th:first-child,
.variant-summary-table td:first-child,
.variant-summary-table th:last-child,
.variant-summary-table td:last-child {
    text-align: center;
}

.variant-table-wrap {
    max-height: min(42vh, 320px);
    overflow: auto;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
}

.variant-detail-table {
    margin: 0;
}

.variant-detail-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #f8fafc;
}

.cell-primary {
    display: block;
    color: #1e293b;
    line-height: 1.3;
}

.cell-secondary {
    display: block;
    margin-top: 0.125rem;
    font-size: 0.6875rem;
    color: #64748b;
    font-family: Consolas, "Courier New", monospace;
}

.cell-qty {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.qty-mismatch {
    color: #b45309;
    font-weight: 600;
}

.cell-change {
    max-width: 11rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #475569;
}

.status-pill {
    display: inline-block;
    padding: 0.125rem 0.4375rem;
    border-radius: 999px;
    font-size: 0.6875rem;
    font-weight: 600;
    line-height: 1.3;
    white-space: nowrap;
}

.status-pill-muted {
    background: #f1f5f9;
    color: #64748b;
}

.status-pill-info {
    background: #dbeafe;
    color: #1d4ed8;
}

.status-pill-success {
    background: #dcfce7;
    color: #15803d;
}

.status-pill-warning {
    background: #fef9c3;
    color: #a16207;
}

.status-pill-danger {
    background: #fee2e2;
    color: #b91c1c;
}

.modal-empty-note {
    margin: 0;
    padding: 0.75rem 0.875rem;
    font-size: 0.8125rem;
    color: #64748b;
    text-align: center;
    background: #f8fafc;
    border: 1px dashed #cbd5e1;
    border-radius: 8px;
}

.modal-variants .modal-actions {
    padding: 0.625rem 1.25rem 1rem;
    border-top: 1px solid #e2e8f0;
}

.modal-header-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.25rem 1.5rem 0.75rem;
    border-bottom: 1px solid #e2e8f0;
}

.modal-header-row h3 {
    margin: 0 0 0.25rem;
}

.modal-subtitle {
    margin: 0 0 0.35rem;
    font-size: 0.9375rem;
    color: #334155;
}

.modal-meta {
    margin: 0;
    font-size: 0.8125rem;
}

.modal-close {
    flex-shrink: 0;
    min-width: 2rem;
    padding: 0.25rem 0.5rem;
    font-size: 1rem;
    line-height: 1;
}

.modal-table-wrap {
    flex: 1;
    overflow: auto;
    padding: 0 1rem;
    margin: 0.75rem 0;
}

.modal-card-wide .modal-actions {
    padding: 0.75rem 1.5rem 1.25rem;
    border-top: 1px solid #e2e8f0;
}

.modal-card h3 {
    margin: 0 0 0.75rem;
    font-size: 1.125rem;
    color: #0f172a;
}

.modal-body {
    margin: 0 0 1.25rem;
    font-size: 0.875rem;
    color: #475569;
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* ─── Log panel ────────────────────────────────────────────────────────────── */
.log-panel {
    margin: 0;
    padding: 1rem;
    max-height: 320px;
    overflow: auto;
    font-family: Consolas, "Courier New", monospace;
    font-size: 0.75rem;
    line-height: 1.6;
    background: #0f172a;
    color: #e2e8f0;
    border-radius: 0 0 10px 10px;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ─── Login page ───────────────────────────────────────────────────────────── */
.login-card {
    max-width: 420px;
    margin: 4rem auto;
    padding: 2rem 2.25rem;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

.login-card h1 {
    margin: 0 0 0.5rem;
    font-size: 1.375rem;
    color: #0f172a;
}

.login-card .btn-primary {
    width: 100%;
    margin-top: 0.5rem;
    padding: 0.5625rem 1rem;
}

/* ─── Blazor error UI ──────────────────────────────────────────────────────── */
#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 2000;
    padding: 0.75rem 1.25rem;
    background: #b91c1c;
    color: #fff;
    font-size: 0.875rem;
}

#blazor-error-ui a {
    color: #fff;
    font-weight: 600;
    margin-left: 0.5rem;
}

#blazor-error-ui .dismiss {
    float: right;
    cursor: pointer;
}

/* ─── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .shell {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
    }

    .sidebar-nav {
        display: flex;
        flex-wrap: wrap;
        gap: 0.25rem;
        padding: 0.5rem;
    }

    .nav-section {
        width: 100%;
    }

    .sidebar-nav .nav-link {
        margin: 0;
        padding: 0.375rem 0.625rem;
        font-size: 0.8125rem;
    }

    .content {
        padding: 1rem;
    }

    .toolbar-actions {
        width: 100%;
    }

    .form-control-sm {
        max-width: none;
    }
}
