* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #f4f7fb;
    --panel: #ffffff;
    --panel-soft: #f8fafc;
    --text: #172033;
    --muted: #667085;
    --line: #e6ebf2;
    --line-strong: #cfd8e5;
    --brand: #1f6feb;
    --brand-hover: #1858c8;
    --success: #16805a;
    --warning: #b76e00;
    --danger: #c93434;
    --focus: rgba(31, 111, 235, 0.14);
    --radius: 8px;
    --shadow: 0 10px 28px rgba(31, 42, 68, 0.08);
    --shadow-soft: 0 1px 3px rgba(31, 42, 68, 0.08);
}

body {
    min-height: 100vh;
    background: linear-gradient(180deg, #fbfdff 0, var(--bg) 270px);
    color: var(--text);
    font-family: "Segoe UI", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.45;
}

a {
    color: inherit;
}

.top-bar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 60px;
    padding: 0 24px;
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 1px 12px rgba(31, 42, 68, 0.05);
    backdrop-filter: blur(12px);
}

.top-bar h3 {
    color: var(--text);
    font-size: 17px;
    font-weight: 700;
}

.top-bar small {
    display: block;
    margin-top: 1px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
}

.top-bar span,
.user-info {
    color: var(--muted);
    font-size: 13px;
}

.brand-lockup {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 7px;
    background: #172033;
    color: #fff;
    font-size: 12px;
    font-weight: 800;
}

.sidebar {
    position: fixed;
    top: 60px;
    left: 0;
    width: 230px;
    height: calc(100vh - 60px);
    padding: 16px 12px;
    background: rgba(255, 255, 255, 0.94);
    border-right: 1px solid var(--line);
    box-shadow: 8px 0 24px rgba(31, 42, 68, 0.04);
}

.sidebar a {
    display: flex;
    align-items: center;
    min-height: 40px;
    margin-bottom: 4px;
    padding: 0 12px;
    border-radius: 7px;
    color: #344054;
    text-decoration: none;
    font-weight: 600;
    transition: background 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.sidebar a:hover,
.sidebar a.active {
    background: #eef6ff;
    color: var(--brand);
}

.sidebar a:hover {
    transform: translateX(2px);
}

.content {
    width: min(1180px, calc(100% - 270px));
    margin-left: 230px;
    padding: 30px 30px 48px;
}

.page-header,
.hero-panel {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 22px;
}

.elevated-header,
.hero-panel {
    padding: 0;
    background: transparent;
    border: 0;
    box-shadow: none;
}

.page-header h1,
.hero-panel h1,
.content > h1 {
    margin: 4px 0 6px;
    color: var(--text);
    font-size: 30px;
    line-height: 1.25;
    font-weight: 800;
    letter-spacing: 0;
}

.hero-panel p,
.page-header p {
    max-width: 680px;
    color: var(--muted);
}

.eyebrow {
    color: var(--brand);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.muted {
    color: var(--muted);
}

.layout-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 18px;
    align-items: start;
}

.dashboard-grid {
    align-items: start;
}

.card,
.stat-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card {
    margin-bottom: 18px;
    padding: 22px;
}

.card-title {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 16px;
}

.card-title h3 {
    color: var(--text);
    font-size: 18px;
    font-weight: 800;
}

.card-title p {
    margin-top: 4px;
    color: var(--muted);
    font-size: 13px;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.stat-card {
    position: relative;
    overflow: hidden;
    padding: 18px;
}

.stat-card::before {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 3px;
    background: var(--brand);
}

.stat-card span,
.metric-compact span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.stat-card strong {
    display: block;
    margin: 8px 0 3px;
    color: var(--text);
    font-size: 28px;
    line-height: 1;
    font-weight: 800;
}

.stat-card small {
    color: var(--muted);
    font-size: 12px;
}

.accent-warning,
.accent-success {
    border-top: 0;
}

.accent-warning::before {
    background: var(--warning);
}

.accent-success::before {
    background: var(--success);
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    color: #2b3b52;
    font-size: 13px;
    font-weight: 600;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    min-height: 42px;
    padding: 10px 12px;
    border: 1px solid var(--line-strong);
    border-radius: 7px;
    background: #fff;
    color: var(--text);
    font: inherit;
    transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.form-group textarea {
    resize: vertical;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 4px var(--focus);
    outline: none;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 0 15px;
    border: 1px solid transparent;
    border-radius: 7px;
    color: #fff;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    box-shadow: var(--shadow-soft);
    transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, transform 0.16s ease, box-shadow 0.16s ease;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 18px rgba(31, 42, 68, 0.12);
}

.btn:active {
    transform: translateY(0);
    box-shadow: var(--shadow-soft);
}

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

.btn-small {
    min-height: 32px;
    padding: 0 11px;
    font-size: 13px;
}

.btn-primary,
.btn-light {
    background: var(--brand);
    color: #fff;
}

.btn-primary:hover,
.btn-light:hover {
    background: var(--brand-hover);
}

.btn-secondary,
.btn-action {
    background: #fff;
    border-color: var(--line-strong);
    color: #344054;
}

.btn-secondary:hover,
.btn-action:hover {
    background: #f8fafc;
    border-color: #b9c5d4;
}

.btn-success,
.btn-action-deliver {
    background: var(--success);
}

.btn-warning,
.btn-action-cutting {
    background: var(--warning);
}

.btn-danger {
    background: var(--danger);
}

.button-row,
.controls,
.action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.controls {
    justify-content: center;
    margin-top: 16px;
}

.hidden {
    display: none !important;
}

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
}

.table-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.search-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

.search-bar input {
    flex: 1;
    min-height: 40px;
    padding: 9px 12px;
    border: 1px solid var(--line-strong);
    border-radius: 7px;
    font: inherit;
}

.search-bar input:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
    outline: none;
}

.table-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 7px;
    object-fit: cover;
    background: #f2f4f7;
    border: 1px solid var(--line);
    color: var(--muted);
    font-size: 12px;
}

.customer-image-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 150px;
    margin-bottom: 16px;
    background: #f9fafb;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    color: var(--muted);
}

.image-picker-trigger {
    cursor: pointer;
    font: inherit;
}

.image-picker-trigger:hover {
    border-color: var(--brand);
}

.customer-image-preview img {
    width: 100%;
    height: 180px;
    object-fit: cover;
}

.image-modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(15, 23, 42, 0.45);
}

.image-modal-panel {
    width: min(100%, 420px);
    padding: 20px;
    background: #fff;
    border-radius: var(--radius);
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.18);
}

.selfie-camera {
    position: relative;
    overflow: hidden;
    width: 100%;
    aspect-ratio: 4 / 3;
    background: #111827;
    border-radius: var(--radius);
}

.selfie-camera video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.data-table {
    width: 100%;
    min-width: 640px;
    border-collapse: separate;
    border-spacing: 0;
}

.data-table th {
    padding: 12px 14px;
    background: #f8fafc;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-align: left;
    border-bottom: 1px solid var(--line);
}

.data-table td {
    padding: 14px;
    color: #344054;
    border-bottom: 1px solid #edf1f6;
}

.data-table tbody tr {
    transition: background 0.14s ease;
}

.data-table tbody tr:hover {
    background: #fbfdff;
}

.data-table tbody tr:last-child td {
    border-bottom: 0;
}

.status-pill,
.status-badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 0 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}

.status-pill {
    background: #fff7ed;
    color: #9a3412;
    text-transform: capitalize;
}

.status-scanning {
    background: #eff6ff;
    color: #1d4ed8;
}

.status-matched {
    background: #dcfce7;
    color: #166534;
}

.status-new {
    background: #fef3c7;
    color: #92400e;
}

.status-error {
    background: #fee2e2;
    color: #991b1b;
}

.empty-state {
    padding: 30px 18px;
    background: #fbfdff;
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius);
    text-align: center;
}

.empty-state strong {
    display: block;
    margin-bottom: 6px;
    font-size: 16px;
}

.side-stack {
    display: grid;
    gap: 18px;
}

.side-stack .card {
    margin-bottom: 0;
}

.timeline-list,
.info-list {
    display: grid;
    gap: 10px;
}

.timeline-list div {
    display: grid;
    grid-template-columns: 28px 1fr;
    gap: 10px;
    align-items: center;
}

.timeline-list span,
.stepper-item span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 999px;
    background: #eff6ff;
    color: var(--brand);
    font-size: 12px;
    font-weight: 700;
}

.timeline-list p {
    color: #344054;
    font-weight: 600;
}

.stepper {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 0 18px;
    padding: 12px 14px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.stepper-item {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
}

.stepper-item.active {
    color: var(--text);
}

.stepper-item.active span {
    background: var(--brand);
    color: #fff;
}

.stepper-line {
    flex: 1;
    height: 1px;
    background: var(--line);
}

.camera-container {
    position: relative;
    width: min(100%, 560px);
    margin: 0 auto;
    overflow: hidden;
    background: #111827;
    border: 1px solid #111827;
    border-radius: var(--radius);
    aspect-ratio: 4 / 3;
}

.camera-container video,
.camera-container canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.scan-overlay {
    position: absolute;
    inset: 12px;
    border: 2px dashed #60a5fa;
    border-radius: 7px;
    pointer-events: none;
}

.scan-line {
    position: absolute;
    right: 0;
    left: 0;
    height: 2px;
    background: #60a5fa;
    animation: scan 2s linear infinite;
}

@keyframes scan {
    0% { top: 0; opacity: 0; }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% { top: 100%; opacity: 0; }
}

.customer-card,
.customer-summary {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px;
    background: #fbfdff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.customer-card img,
.customer-summary img {
    flex: 0 0 auto;
    width: 72px;
    height: 72px;
    border-radius: 7px;
    object-fit: cover;
    border: 1px solid var(--line);
}

.customer-info h4,
.customer-summary h4 {
    margin-bottom: 4px;
    font-size: 17px;
}

.customer-info p,
.customer-summary p {
    color: var(--muted);
    font-size: 13px;
}

.info-item {
    padding: 12px;
    background: #fbfdff;
    border: 1px solid var(--line);
    border-radius: 7px;
}

.info-item strong {
    display: block;
    margin-bottom: 3px;
}

.summary-card {
    background: #fff;
}

.metric-compact {
    padding: 12px 0;
    border-top: 1px solid var(--line);
}

.metric-compact strong {
    display: block;
    margin-top: 5px;
    color: var(--text);
    font-size: 16px;
    font-weight: 800;
}

.form-section-title {
    margin: 8px 0 12px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
    color: var(--text);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.measurement-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 14px;
}

.measurement-grid span {
    padding: 8px;
    background: #f9fafb;
    border: 1px solid var(--line);
    border-radius: 7px;
    color: #344054;
    font-size: 12px;
    font-weight: 600;
    text-align: center;
}

.job-items {
    display: grid;
    gap: 12px;
    margin-bottom: 12px;
}

.job-item {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) 120px 150px auto;
    gap: 12px;
    align-items: end;
    padding: 12px;
    background: #f9fafb;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.job-item .form-group {
    margin-bottom: 0;
}

.measurement-input-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 15px;
}

.measurement-field {
    display: grid;
    grid-template-columns: 110px minmax(0, 1fr);
    align-items: center;
    gap: 10px;
}

.measurement-field label {
    color: #344054;
    font-size: 13px;
    font-weight: 600;
}

.measurement-field input {
    width: 100%;
    min-height: 40px;
    padding: 9px 11px;
    border: 1px solid var(--line-strong);
    border-radius: 7px;
    font: inherit;
}

.measurement-field input:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
    outline: none;
}

.spinner {
    width: 36px;
    height: 36px;
    margin: 0 auto 14px;
    border: 3px solid #e5e7eb;
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

#loadingModels {
    padding: 38px 18px;
    color: var(--muted);
    text-align: center;
}

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background: var(--bg);
}

.login-card {
    width: 100%;
    max-width: 400px;
    padding: 28px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.login-card h2 {
    margin-bottom: 18px;
    color: var(--text);
    text-align: center;
}

.error {
    padding: 10px 12px;
    margin-bottom: 12px;
    background: #fee2e2;
    border: 1px solid #fecaca;
    border-radius: 7px;
    color: #991b1b;
    font-size: 13px;
}

.alert {
    margin-bottom: 16px;
    padding: 11px 12px;
    border-radius: 7px;
    font-size: 13px;
}

.alert-success {
    background: #dcfce7;
    border: 1px solid #bbf7d0;
    color: #166534;
}

.alert-error {
    background: #fee2e2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

@media (max-width: 1000px) {
    .layout-grid,
    .stat-grid {
        grid-template-columns: 1fr;
    }

    .measurement-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .job-item {
        grid-template-columns: 1fr;
    }

    .measurement-input-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .top-bar {
        min-height: 56px;
        padding: 0 16px;
    }

    .top-bar small {
        display: none;
    }

    .sidebar {
        position: static;
        display: flex;
        width: 100%;
        height: auto;
        gap: 8px;
        padding: 10px;
        overflow-x: auto;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .sidebar a {
        flex: 0 0 auto;
        margin-bottom: 0;
    }

    .content {
        width: 100%;
        margin-left: 0;
        padding: 20px 14px 34px;
    }

    .page-header,
    .hero-panel {
        display: block;
    }

    .page-header .btn,
    .hero-panel .btn {
        margin-top: 14px;
    }

    .search-bar {
        display: block;
    }

    .search-bar .btn {
        width: 100%;
        margin-top: 8px;
    }

    .form-row {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .customer-card,
    .customer-summary {
        align-items: flex-start;
    }

    .stepper {
        overflow-x: auto;
    }

    .stepper-line {
        min-width: 30px;
    }

    .measurement-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .measurement-field {
        grid-template-columns: 1fr;
        gap: 6px;
    }
}
