:root {
    --bg: #f5f7fb;
    --panel: #ffffff;
    --ink: #172033;
    --muted: #6b7280;
    --line: #e5e7eb;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #0f766e;
    --danger: #b91c1c;
    --warning: #a16207;
    --warning-soft: #fef3c7;
    --soft-blue: #eff6ff;
    --soft-green: #ecfdf5;
    --soft-red: #fef2f2;
    --soft-gray: #f3f4f6;
    --radius: 8px;
    --shadow: 0 12px 28px rgba(15, 23, 42, 0.05);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background: var(--bg);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
}

a {
    color: inherit;
    text-decoration: none;
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 260px;
    padding: 28px 18px;
    background: #111827;
    color: #f9fafb;
}

.brand {
    margin-bottom: 32px;
    padding: 4px 8px;
    font-size: 32px;
    line-height: 1.2;
    font-weight: 700;
}

.nav {
    display: grid;
    gap: 10px;
}

.nav a,
.logout-form button {
    width: 100%;
    display: block;
    min-height: 58px;
    padding: 14px 16px;
    border: 0;
    border-radius: var(--radius);
    color: #d1d5db;
    background: transparent;
    text-align: left;
    font: inherit;
    font-size: 24px;
    font-weight: 650;
    line-height: 1.25;
    cursor: pointer;
}

.nav a:hover,
.nav a.active,
.logout-form button:hover {
    color: #ffffff;
    background: #1f2937;
}

.nav a.active {
    background: #2563eb;
}

.logout-form {
    margin-top: 28px;
}

.main {
    margin-left: 260px;
    padding: 28px;
}

.auth-main {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 22px;
}

.topbar h1,
.login-card h1,
.detail-title h2 {
    margin: 4px 0 0;
    font-size: 30px;
    line-height: 1.2;
    letter-spacing: 0;
}

.page-kicker {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
}

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

.panel {
    padding: 20px;
    margin-bottom: 20px;
}

.login-card {
    width: min(420px, 100%);
    padding: 28px;
}

.form-stack,
.filter-grid,
.form-grid fieldset,
.stats-grid,
.detail-header {
    display: grid;
    gap: 16px;
}

.filter-grid {
    grid-template-columns: repeat(4, minmax(170px, 1fr));
    align-items: end;
}

label {
    display: grid;
    gap: 8px;
    color: #374151;
    font-size: 16px;
    font-weight: 600;
}

input,
select,
textarea {
    width: 100%;
    min-height: 48px;
    padding: 12px 14px;
    border: 1px solid #d1d5db;
    border-radius: var(--radius);
    background: #ffffff;
    color: var(--ink);
    font: inherit;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
    outline: 2px solid rgba(37, 99, 235, 0.18);
    border-color: var(--primary);
}

.check-line {
    min-height: 50px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
}

.check-line input {
    width: auto;
    min-height: auto;
}

.filter-actions,
.form-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.btn {
    min-height: 46px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 11px 18px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #ffffff;
    color: var(--ink);
    font: inherit;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    line-height: 1.2;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.btn:hover {
    border-color: #cbd5e1;
    background: #f8fafc;
}

.btn.primary {
    border-color: var(--primary);
    background: var(--primary);
    color: #ffffff;
}

.btn.primary:hover {
    border-color: var(--primary-dark);
    background: var(--primary-dark);
}

.btn.subtle {
    background: #f9fafb;
    color: #374151;
}

.btn.subtle:hover {
    background: #f3f4f6;
}

.btn.tiny {
    min-height: 36px;
    padding: 8px 12px;
    font-size: 15px;
}

.btn.status-action {
    border-color: #bfdbfe;
    background: var(--soft-blue);
    color: #1d4ed8;
}

.btn.status-action:hover {
    border-color: #93c5fd;
    background: #dbeafe;
}

.btn.danger {
    border-color: #fecaca;
    background: #fef2f2;
    color: var(--danger);
}

.btn.danger:hover {
    border-color: #fca5a5;
    background: #fee2e2;
}

.table-panel {
    overflow-x: auto;
    padding: 0;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.pagination {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin: 4px 0 18px;
}

.page-link,
.page-ellipsis,
.page-total {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    border-radius: var(--radius);
    font-weight: 600;
}

.page-link {
    border: 1px solid var(--line);
    background: #ffffff;
    color: var(--ink);
}

.page-link:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.page-link.active {
    border-color: var(--primary);
    background: var(--primary);
    color: #ffffff;
}

.page-link.disabled {
    background: #f9fafb;
    color: var(--muted);
    cursor: not-allowed;
}

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

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 1480px;
    font-size: 17px;
}

th,
td {
    padding: 16px 16px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
    white-space: nowrap;
}

td:nth-child(n+3):not(.actions),
.fb-ads-table td,
.price-layout td {
    font-variant-numeric: tabular-nums;
}

tbody tr:hover td {
    background: #fbfdff;
}

tbody td {
    font-weight: 400;
}

th {
    background: #f8fafc;
    color: #374151;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0;
}

.sort-link {
    color: #1f2937;
    font-weight: 700;
}

.product-image {
    width: 108px;
    height: 108px;
    display: grid;
    place-items: center;
    border-radius: var(--radius);
    object-fit: cover;
    background: #eef2f7;
    color: var(--muted);
    font-size: 15px;
    overflow: hidden;
}

.sku-text,
.mobile-product-card strong {
    font-size: 22px;
    font-weight: 500;
}

.desktop-products td:nth-child(3) {
    font-size: 24px;
    font-weight: 400;
}

.actions {
    min-width: 240px;
    vertical-align: middle;
    padding-right: 18px;
}

.action-group {
    min-height: 108px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    flex-wrap: nowrap;
}

.action-group form {
    display: flex;
    align-items: center;
    margin: 0;
}

.desktop-products .btn.tiny {
    min-height: 42px;
    padding: 9px 15px;
    font-size: 17px;
}

.desktop-products .action-group .btn.tiny {
    height: 42px;
    min-width: 58px;
    line-height: 1;
}

.remove-row {
    border-color: #e5e7eb;
    background: #ffffff;
}

.remove-row:hover {
    border-color: #fecaca;
    background: var(--soft-red);
    color: var(--danger);
}

.flash-wrap {
    display: grid;
    gap: 10px;
    margin-bottom: 16px;
}

.flash {
    padding: 12px 14px;
    border-radius: var(--radius);
    background: #eff6ff;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

.flash.success {
    background: #ecfdf5;
    color: var(--success);
    border-color: #99f6e4;
}

.flash.danger {
    background: #fef2f2;
    color: var(--danger);
    border-color: #fecaca;
}

.flash.warning {
    background: #fffbeb;
    color: var(--warning);
    border-color: #fde68a;
}

.form-grid fieldset {
    margin: 0 0 18px;
    padding: 0;
    border: 0;
    grid-template-columns: repeat(3, minmax(220px, 1fr));
}

legend {
    grid-column: 1 / -1;
    margin-bottom: 4px;
    font-size: 22px;
    font-weight: 700;
}

.wide {
    grid-column: span 2;
}

.detail-header {
    grid-template-columns: 2fr repeat(3, 1fr);
    margin-bottom: 18px;
}

.detail-title {
    display: flex;
    align-items: center;
    gap: 18px;
    margin: 0;
}

.detail-title .product-image {
    width: 132px;
    height: 132px;
}

.metric-card {
    padding: 22px;
    min-height: 126px;
}

.metric-card span,
.stats-grid span,
.clerk-detail span {
    display: block;
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 16px;
}

.metric-card strong {
    font-size: 30px;
    line-height: 1.15;
}

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

.stats-grid > div,
.clerk-detail > div {
    padding: 18px;
    border-radius: var(--radius);
    background: #f9fafb;
}

.metric-card p strong,
.metric-card strong,
.shipment-summary strong,
.order-info strong,
.mobile-stock {
    font-variant-numeric: tabular-nums;
}

.clerk-detail {
    display: grid;
    grid-template-columns: repeat(3, 1fr) auto;
    gap: 12px;
    align-items: end;
}

.empty,
.empty-state {
    text-align: center;
    color: var(--muted);
}

.empty-state {
    padding: 42px;
}

.mobile-products {
    display: none;
}

.mobile-product-filters {
    display: none;
}

.mobile-order-filters,
.mobile-orders {
    display: none;
}

.shipments-table table {
    min-width: 1080px;
}

.status-pill,
.status-done {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    padding: 6px 11px;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 700;
    line-height: 1.1;
}

.status-pill.in_transit,
.order-status-reserved,
.product-status-active {
    background: var(--soft-blue);
    color: #1d4ed8;
}

.status-pill.arrived,
.status-done,
.order-status-signed,
.user-status-active {
    background: var(--soft-green);
    color: var(--success);
}

.product-status-inactive,
.user-status-inactive {
    background: var(--soft-gray);
    color: #4b5563;
}

.order-status-pending_shipment {
    background: var(--warning-soft);
    color: #92400e;
}

.order-status-pending_rejected {
    background: #fef3c7;
    color: #9a3412;
}

.order-status-pending_shipping_conflict {
    background: #ede9fe;
    color: #6d28d9;
}

.order-status-shipped {
    background: #e0f2fe;
    color: #0369a1;
}

.order-status-rejected {
    background: var(--soft-red);
    color: var(--danger);
}

.inline-status-form {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}

.status-select {
    min-height: 38px;
    max-width: 180px;
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 700;
}

.action-group.compact {
    min-height: 42px;
}

.shipment-form fieldset {
    margin: 0 0 20px;
    padding: 0;
    border: 0;
}

.shipment-basic {
    display: grid;
    grid-template-columns: repeat(3, minmax(220px, 1fr));
    gap: 14px;
}

.shipment-items-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.shipment-items-head h2 {
    margin: 0;
    font-size: 22px;
}

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

.shipment-row {
    display: grid;
    grid-template-columns: minmax(220px, 1.2fr) 96px minmax(120px, 0.6fr) auto;
    gap: 12px;
    align-items: end;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #f9fafb;
}

.shipment-row .sku-message {
    grid-column: 1 / -1;
    min-height: 20px;
    color: var(--muted);
    font-size: 14px;
}

.sku-message {
    min-height: 20px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 500;
}

.shipment-row .sku-message.error,
.sku-message.error {
    color: var(--danger);
}

.shipment-image {
    width: 92px;
    height: 92px;
    display: grid;
    place-items: center;
    border-radius: var(--radius);
    background: #eef2f7;
    color: var(--muted);
    overflow: hidden;
}

.shipment-image img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

.shipment-summary {
    display: flex;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
}

.shipment-summary > div:not(.form-actions) {
    min-width: 160px;
    padding: 14px;
    border-radius: var(--radius);
    background: #f9fafb;
}

.shipment-summary span {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 15px;
}

.shipment-summary strong {
    font-size: 24px;
}

.shipment-detail-header .metric-card strong {
    font-size: 22px;
}

.orders-table table {
    min-width: 1200px;
}

.reserved-soon td {
    background: #1e3a8a;
    color: #ffffff;
    border-bottom-color: #1e40af;
}

.orders-table tbody tr.reserved-soon:hover td {
    background: #1e40af;
    color: #ffffff;
    border-bottom-color: #1d4ed8;
}

.orders-table tbody tr.reserved-soon:hover .sku-text {
    color: #ffffff;
}

.reserved-soon .status-pill,
.reserved-soon .btn,
.reserved-soon .status-select {
    color: var(--ink);
}

.order-status-reserved {
    background: var(--soft-blue);
    color: #1d4ed8;
}

.order-form fieldset {
    margin: 0 0 20px;
    padding: 0;
    border: 0;
}

.order-basic {
    display: grid;
    grid-template-columns: repeat(3, minmax(220px, 1fr));
    gap: 14px;
}

.profit-note {
    display: flex;
    align-items: center;
    min-height: 48px;
    padding: 12px 14px;
    border-radius: var(--radius);
    background: #f9fafb;
    color: var(--muted);
    font-weight: 600;
}

.order-info {
    display: grid;
    grid-template-columns: repeat(4, minmax(160px, 1fr));
    gap: 14px;
}

.order-info > div {
    padding: 14px;
    border-radius: var(--radius);
    background: #f9fafb;
}

.order-info span {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 14px;
}

.order-info strong {
    font-weight: 600;
}

.status-form {
    grid-column: 1 / -1;
    display: flex;
    gap: 12px;
    align-items: end;
    flex-wrap: wrap;
}

.status-form label {
    min-width: 240px;
}

.order-detail-header .metric-card strong {
    font-size: 22px;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.dashboard-grid.three {
    grid-template-columns: repeat(3, minmax(220px, 1fr));
    margin-bottom: 0;
}

.metric-card p,
.stat-box p {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 16px;
}

.stat-box {
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #f9fafb;
}

.stat-box h3,
.price-scope h3,
.panel h2 {
    margin: 0 0 14px;
}

.chart-card {
    margin-top: 20px;
}

.chart-wrap {
    position: relative;
    height: 320px;
    min-width: 620px;
}

.price-scope {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.price-layout {
    display: block;
    overflow-x: auto;
}

.price-layout table {
    width: 100%;
    border-collapse: collapse;
    min-width: 680px;
    font-size: 16px;
}

.fb-ads-table table,
.users-table table {
    min-width: 1100px;
}

.fb-ads-table th,
.fb-ads-table td {
    text-align: right;
}

.fb-ads-table th:first-child,
.fb-ads-table td:first-child {
    text-align: left;
}

.order-actions {
    gap: 14px;
    min-height: 52px;
}

.orders-table .order-action-btn {
    min-height: 42px;
    min-width: 72px;
    padding: 10px 18px;
    font-size: 17px;
}

.order-items-detail-row td {
    padding: 14px 18px;
    background: #f8fafc;
}

.order-items-strip {
    display: flex;
    gap: 14px;
    align-items: stretch;
    flex-wrap: wrap;
    max-width: 100%;
    overflow: visible;
}

.order-item-chip,
.mobile-order-item {
    display: flex;
    align-items: center;
    gap: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
}

.order-item-chip {
    flex: 0 1 210px;
    min-width: 170px;
    max-width: 100%;
    padding: 10px 12px;
}

.order-item-image {
    width: 64px;
    height: 64px;
    flex: 0 0 64px;
    overflow: hidden;
    border-radius: 10px;
    background: #eef2f7;
    color: var(--muted);
    display: grid;
    place-items: center;
    font-size: 14px;
    font-weight: 700;
}

.order-item-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.order-item-chip strong,
.mobile-order-item strong {
    display: block;
    margin-bottom: 4px;
    font-size: 17px;
    color: var(--ink);
    overflow-wrap: anywhere;
    word-break: break-word;
}

.order-item-chip span,
.mobile-order-item span {
    color: var(--muted);
    font-weight: 700;
}

.order-items-empty {
    padding: 12px 14px;
    border: 1px dashed var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    color: var(--muted);
    font-weight: 700;
}

.order-coordinates-line {
    margin-top: 14px;
    padding: 10px 12px;
    border-radius: var(--radius);
    background: #eef2f7;
    color: var(--ink);
    font-size: 16px;
    font-weight: 700;
    overflow-wrap: anywhere;
    word-break: break-word;
    user-select: text;
}

.detail-actions {
    margin-top: 14px;
}

.detail-actions form,
.action-group form {
    margin: 0;
}

@media (max-width: 900px) {
    .sidebar {
        position: static;
        width: auto;
        padding: 14px;
    }

    .brand {
        margin-bottom: 14px;
        padding: 0;
        font-size: 18px;
    }

    .nav {
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
    }

    .nav a,
    .logout-form button {
        min-height: 44px;
        padding: 10px 12px;
        font-size: 16px;
        font-weight: 600;
    }

    .logout-form {
        margin-top: 12px;
    }

    .main {
        margin-left: 0;
        padding: 16px 16px calc(140px + env(safe-area-inset-bottom));
    }

    .filter-grid,
    .form-grid fieldset,
    .detail-header,
    .stats-grid,
    .clerk-detail {
        grid-template-columns: 1fr;
    }

    .pagination {
        gap: 6px;
        margin-bottom: calc(120px + env(safe-area-inset-bottom));
    }

    .page-link,
    .page-ellipsis,
    .page-total {
        min-height: 42px;
        padding: 9px 11px;
    }

    .wide {
        grid-column: auto;
    }

    .desktop-products {
        display: none;
    }

    .desktop-product-filters {
        display: none;
    }

    .mobile-product-filters {
        display: block;
    }

    .mobile-filter-row {
        display: grid;
        gap: 14px;
    }

    .mobile-products {
        display: block;
        padding: 0;
        margin-bottom: 120px;
    }

    .mobile-product-table {
        min-width: 0;
        font-size: 17px;
    }

    .mobile-product-table th,
    .mobile-product-table td {
        padding: 12px 10px;
    }

    .mobile-product-table .product-image {
        width: 76px;
        height: 76px;
        font-size: 13px;
    }

    .mobile-sku-link {
        display: inline-flex;
        min-height: 44px;
        align-items: center;
        color: var(--primary);
    }

    .mobile-stock {
        font-size: 22px;
        font-weight: 600;
    }

    .desktop-order-filters,
    .desktop-orders {
        display: none;
    }

    .mobile-order-filters {
        display: block;
    }

    .mobile-order-search {
        display: grid;
        gap: 14px;
    }

    .mobile-order-actions-top {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .mobile-order-actions-top .btn {
        min-height: 50px;
        font-size: 17px;
    }

    .mobile-orders {
        display: grid;
        gap: 14px;
        margin-bottom: 120px;
    }

    .mobile-order-card {
        border: 1px solid var(--line);
        border-radius: var(--radius);
        background: var(--panel);
        box-shadow: var(--shadow);
        padding: 16px;
    }

    .reserved-soon-card {
        border-color: #1e40af;
        background: #1e3a8a;
        color: #ffffff;
    }

    .mobile-order-head {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 12px;
        margin-bottom: 14px;
    }

    .mobile-order-head strong {
        display: block;
        margin-top: 4px;
        font-size: 20px;
    }

    .mobile-order-label,
    .mobile-order-grid span {
        color: var(--muted);
        font-size: 14px;
    }

    .reserved-soon-card .mobile-order-label,
    .reserved-soon-card .mobile-order-grid span {
        color: #dbeafe;
    }

    .reserved-soon-card .status-pill {
        color: var(--ink);
    }

    .mobile-status-form {
        flex: 0 0 auto;
        flex-wrap: wrap;
        justify-content: flex-end;
        max-width: 190px;
    }

    .mobile-status-form .status-select {
        max-width: 190px;
        min-height: 42px;
    }

    .mobile-status-form .btn {
        min-height: 38px;
    }

    .mobile-order-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }

    .mobile-order-grid strong {
        display: block;
        margin-top: 4px;
        font-size: 17px;
        word-break: break-word;
    }

    .mobile-order-wide {
        grid-column: 1 / -1;
    }

    .mobile-order-items-detail {
        margin-top: 14px;
    }

    .mobile-order-items-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        gap: 10px;
    }

    .mobile-order-item {
        padding: 10px;
        min-width: 0;
    }

    .mobile-order-item .order-item-image {
        width: 58px;
        height: 58px;
        flex-basis: 58px;
    }

    .mobile-order-buttons {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        margin-top: 16px;
    }

    .mobile-order-buttons form {
        margin: 0;
    }

    .mobile-order-btn {
        width: 100%;
        min-height: 50px;
        font-size: 17px;
    }

    .shipment-basic,
    .order-basic,
    .order-info,
    .dashboard-grid,
    .dashboard-grid.three,
    .price-layout,
    .shipment-row {
        grid-template-columns: 1fr;
    }

    .price-layout {
        overflow-x: visible;
    }

    .shipment-items-head,
    .shipment-summary {
        align-items: stretch;
        flex-direction: column;
    }

    .status-form {
        display: grid;
        grid-template-columns: 1fr;
    }

    .status-form label {
        min-width: 0;
    }
}
