:root {
    --primary: #4361ee;
    --secondary: #3f37c9;
    --dark: #1f2933;
    --muted: #64748b;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --border: #e2e8f0;
    --sidebar-width: 250px;
}

body {
    background: #f5f7fa;
    color: var(--dark);
    min-height: 100vh;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body.modal-open {
    overflow: hidden;
}

.main-content {
    flex-grow: 1;
    margin-left: var(--sidebar-width);
    padding: 30px;
    width: calc(100% - var(--sidebar-width));
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.page-title {
    margin: 0;
    font-size: 2rem;
    color: var(--primary);
}

.page-subtitle {
    margin: 6px 0 0;
    color: var(--muted);
}

.page-header .date-filter {
    background: var(--surface);
    padding: 6px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    display: flex;
    gap: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
}

.page-header .date-filter .btn {
    padding: 10px 16px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--muted);
    font-weight: 600;
    cursor: pointer;
}

.page-header .date-filter .btn:hover {
    background: #eff6ff;
    color: #3b82f6;
}

.page-header .date-filter .btn.active {
    background: #3b82f6;
    color: #fff;
}

.summary-cards {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 22px;
}

.card {
    background: var(--surface);
    border-radius: 14px;
    padding: 18px;
    display: flex;
    gap: 14px;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
}

.card-icon {
    width: 46px;
    height: 46px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 22px;
}

.bg-blue { background: #4361ee; }
.bg-purple { background: #9b59b6; }
.bg-green { background: #28a745; }
.bg-orange { background: #e67e22; }

.card-info h3 {
    margin: 0 0 4px;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.card-info span {
    font-size: 22px;
    font-weight: 700;
    color: #1a202c;
}

.orders-section {
    background: var(--surface);
    border-radius: 14px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
}

.orders-header {
    margin-bottom: 14px;
}

.orders-header h2 {
    margin: 0;
    font-size: 1.35rem;
}

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

.orders-placeholder {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px 20px;
    color: var(--muted);
}

.orders-placeholder i {
    display: block;
    font-size: 32px;
    color: #3b82f6;
    margin-bottom: 8px;
}

.orders-placeholder h3 {
    margin: 0 0 6px;
    color: var(--dark);
}

.order-card {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 14px;
    align-items: center;
    min-height: 94px;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    background: var(--surface);
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.order-card:hover,
.order-card:focus-visible {
    border-color: #3b82f6;
    box-shadow: 0 8px 18px rgba(59, 130, 246, 0.16);
    transform: translateY(-1px);
    outline: none;
}

.order-card__media {
    display: flex;
    align-items: center;
    justify-content: center;
}

.company-logo {
    width: 62px;
    height: 62px;
    border-radius: 10px;
    border: 1px solid #dbe3f0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}

.company-logo .company-initials {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 0.7px;
}

.company-logo img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: none;
}

.order-card__content {
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 5px;
}

.order-card .company-name {
    margin: 0;
    font-size: 0.98rem;
    font-weight: 700;
    color: #1e293b;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.order-card .order-number {
    margin: 0;
    color: #6b7280;
    font-size: 0.84rem;
}

.order-inline-total {
    margin: 0;
    color: #1d4ed8;
    font-size: 0.92rem;
    font-weight: 700;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    font-size: 0.73rem;
    font-weight: 700;
    text-transform: capitalize;
    padding: 4px 10px;
}

.status-pending { background: #fff3cd; color: #856404; }
.status-accepted { background: #e0e7ff; color: #4f46e5; }
.status-shop_accepted { background: #e0e7ff; color: #4f46e5; }
.status-waiting_driver_pickup { background: #e0f2fe; color: #075985; }
.status-waiting-driver-pickup { background: #e0f2fe; color: #075985; }
.status-sent { background: #dbeafe; color: #2563eb; }
.status-delivered { background: #dcfce7; color: #16a34a; }
.status-driver_delivered { background: #dcfce7; color: #16a34a; }
.status-customer_received { background: #bbf7d0; color: #166534; }
.status-shop_settled { background: #99f6e4; color: #115e59; }
.status-cancelled { background: #fee2e2; color: #dc2626; }
.status-rejected { background: #ffe4e6; color: #b91c1c; }
.status-customer_cancelled { background: #fee2e2; color: #dc2626; }
.status-shop_rejected { background: #ffe4e6; color: #b91c1c; }

.order-card__total {
    align-self: end;
    font-size: 0.9rem;
    font-weight: 600;
    color: #334155;
    text-align: right;
    white-space: nowrap;
}

.grid-sentinel {
    height: 1px;
}

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.42);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #e5e7eb;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

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

.action-modal {
    position: fixed;
    inset: 0;
    display: none;
    z-index: 2200;
}

.action-modal.is-open {
    display: block;
}

.action-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.58);
    backdrop-filter: blur(3px);
}

.action-modal__dialog {
    position: absolute;
    top: 50%;
    left: calc(var(--sidebar-width) + ((100vw - var(--sidebar-width)) / 2));
    transform: translate(-50%, -50%);
    width: min(940px, calc(100vw - var(--sidebar-width) - 32px));
    max-height: calc(100vh - 40px);
    background: #fff;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    overflow: auto;
    box-shadow: 0 20px 55px rgba(15, 23, 42, 0.35);
}

.action-modal__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
}

.action-modal__header h3 {
    margin: 0;
    font-size: 1.2rem;
}

.action-modal__close {
    border: 0;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: #f1f5f9;
    color: #334155;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.action-modal__body {
    padding: 20px;
    display: grid;
    grid-template-columns: 1fr;
    gap: 18px;
}

.action-modal__timeline-wrap {
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 14px;
    background: #f8fafc;
}

.action-modal__timeline-title {
    margin: 0 0 12px;
    color: #334155;
    font-size: 0.98rem;
    font-weight: 700;
}

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

.timeline-grid.single-column {
    grid-template-columns: 1fr;
}

.timeline-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.timeline-step {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.timeline-step__rail {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.timeline-step__circle {
    width: 26px;
    height: 26px;
    border-radius: 999px;
    border: 2px solid #cbd5e1;
    color: #64748b;
    background: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
}

.timeline-step__circle.is-reached {
    border-color: #3b82f6;
    background: #dbeafe;
    color: #1d4ed8;
}

.timeline-step__circle.is-current {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.timeline-step__circle.is-failed {
    border-color: #dc2626;
    background: #fee2e2;
    color: #b91c1c;
}

.timeline-step__connector {
    width: 2px;
    min-height: 20px;
    background: #cbd5e1;
    margin-top: 4px;
}

.timeline-step__connector.is-reached {
    background: #3b82f6;
}

.timeline-step__connector.is-failed {
    background: #dc2626;
}

.timeline-step__badge {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 0.76rem;
    font-weight: 700;
    background: #e2e8f0;
    color: #334155;
}

.timeline-step__badge.is-reached {
    background: #dbeafe;
    color: #1d4ed8;
}

.timeline-step__badge.is-current {
    background: #bfdbfe;
}

.timeline-step__badge.is-failed {
    background: #fee2e2;
    color: #b91c1c;
}

.action-modal__actions {
    display: grid;
    gap: 10px;
}

.action-stack-btn {
    width: 100%;
    border: 0;
    border-radius: 12px;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.92rem;
    font-weight: 700;
    cursor: pointer;
}

.action-stack-btn i {
    font-size: 1.1rem;
}

.action-stack-btn.primary {
    background: #dbeafe;
    color: #1d4ed8;
}

.action-stack-btn.neutral {
    background: #ecfeff;
    color: #0e7490;
}

.action-stack-btn.danger {
    background: #fee2e2;
    color: #b91c1c;
}

@media (max-width: 1024px) {
    .main-content {
        margin-left: 0;
        width: 100%;
        padding: 60px 20px 100px;
    }

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

    .action-modal__dialog {
        left: 50%;
        width: min(940px, calc(100vw - 24px));
    }
}

@media (max-width: 760px) {
    .orders-grid {
        grid-template-columns: 1fr;
    }

    .order-card {
        grid-template-columns: auto 1fr;
        grid-template-areas:
            'media content'
            'media total';
        row-gap: 8px;
    }

    .order-card__media { grid-area: media; }
    .order-card__content { grid-area: content; }
    .order-card__total {
        grid-area: total;
        justify-self: end;
    }

    .timeline-grid {
        grid-template-columns: 1fr;
    }

    .action-modal__dialog {
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        max-height: calc(100vh - 32px);
        width: calc(100vw - 20px);
    }
}

html[data-theme='dark'] body {
    background: #0b1220;
    color: #e2e8f0;
}

html[data-theme='dark'] .page-title {
    color: #93c5fd;
}

html[data-theme='dark'] .page-subtitle,
html[data-theme='dark'] .orders-placeholder,
html[data-theme='dark'] .order-card .order-number,
html[data-theme='dark'] .order-card__total,
html[data-theme='dark'] .card-info h3 {
    color: #94a3b8;
}

html[data-theme='dark'] .page-header .date-filter,
html[data-theme='dark'] .card,
html[data-theme='dark'] .orders-section,
html[data-theme='dark'] .order-card,
html[data-theme='dark'] .action-modal__dialog {
    background: #111827;
    border-color: #334155;
    box-shadow: 0 14px 34px rgba(2, 6, 23, 0.5);
}

html[data-theme='dark'] .page-header .date-filter .btn {
    color: #cbd5e1;
}

html[data-theme='dark'] .page-header .date-filter .btn:hover {
    background: rgba(59, 130, 246, 0.24);
    color: #dbeafe;
}

html[data-theme='dark'] .page-header .date-filter .btn.active {
    background: #2563eb;
    color: #ffffff;
}

html[data-theme='dark'] .card-info span,
html[data-theme='dark'] .orders-header h2,
html[data-theme='dark'] .orders-placeholder h3,
html[data-theme='dark'] .order-card .company-name,
html[data-theme='dark'] .order-inline-total,
html[data-theme='dark'] .action-modal__header h3,
html[data-theme='dark'] .action-modal__timeline-title,
html[data-theme='dark'] .timeline-step__content,
html[data-theme='dark'] .timeline-step__title {
    color: #f8fafc;
}

html[data-theme='dark'] .company-logo {
    border-color: #334155;
}

html[data-theme='dark'] .status-pending {
    background: rgba(180, 83, 9, 0.35);
    color: #fdba74;
}

html[data-theme='dark'] .status-accepted {
    background: rgba(79, 70, 229, 0.35);
    color: #c4b5fd;
}

html[data-theme='dark'] .status-shop_accepted {
    background: rgba(79, 70, 229, 0.35);
    color: #c4b5fd;
}

html[data-theme='dark'] .status-waiting_driver_pickup {
    background: rgba(3, 105, 161, 0.35);
    color: #7dd3fc;
}

html[data-theme='dark'] .status-sent {
    background: rgba(30, 64, 175, 0.38);
    color: #93c5fd;
}

html[data-theme='dark'] .status-delivered {
    background: rgba(22, 101, 52, 0.38);
    color: #86efac;
}

html[data-theme='dark'] .status-driver_delivered,
html[data-theme='dark'] .status-customer_received {
    background: rgba(22, 101, 52, 0.38);
    color: #86efac;
}

html[data-theme='dark'] .status-shop_settled {
    background: rgba(19, 78, 74, 0.42);
    color: #99f6e4;
}

html[data-theme='dark'] .status-cancelled,
html[data-theme='dark'] .status-rejected {
    background: rgba(127, 29, 29, 0.4);
    color: #fca5a5;
}

html[data-theme='dark'] .status-customer_cancelled,
html[data-theme='dark'] .status-shop_rejected {
    background: rgba(127, 29, 29, 0.4);
    color: #fca5a5;
}

html[data-theme='dark'] .loading-overlay {
    background: rgba(2, 6, 23, 0.72);
}

html[data-theme='dark'] .spinner {
    border-color: #334155;
    border-top-color: #60a5fa;
}

html[data-theme='dark'] .action-modal__backdrop {
    background: rgba(2, 6, 23, 0.74);
}

html[data-theme='dark'] .action-modal__header {
    border-bottom-color: #334155;
}

html[data-theme='dark'] .action-modal__close {
    background: #1e293b;
    color: #cbd5e1;
}

html[data-theme='dark'] .action-modal__timeline-wrap {
    border-color: #334155;
    background: #0f172a;
}

html[data-theme='dark'] .timeline-step__circle {
    border-color: #475569;
    background: #0f172a;
    color: #94a3b8;
}

html[data-theme='dark'] .timeline-step__circle.is-reached {
    border-color: #60a5fa;
    background: rgba(37, 99, 235, 0.24);
    color: #bfdbfe;
}

html[data-theme='dark'] .timeline-step__circle.is-current {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

html[data-theme='dark'] .timeline-step__circle.is-failed {
    border-color: #ef4444;
    background: rgba(127, 29, 29, 0.38);
    color: #fca5a5;
}

html[data-theme='dark'] .timeline-step__connector {
    background: #475569;
}

html[data-theme='dark'] .timeline-step__connector.is-reached {
    background: #60a5fa;
}

html[data-theme='dark'] .timeline-step__connector.is-failed {
    background: #ef4444;
}

html[data-theme='dark'] .timeline-step__badge {
    background: #1e293b;
    color: #cbd5e1;
}

html[data-theme='dark'] .timeline-step__badge.is-reached,
html[data-theme='dark'] .timeline-step__badge.is-current {
    background: rgba(37, 99, 235, 0.3);
    color: #bfdbfe;
}

html[data-theme='dark'] .timeline-step__badge.is-failed {
    background: rgba(127, 29, 29, 0.38);
    color: #fca5a5;
}

html[data-theme='dark'] .action-stack-btn.primary {
    background: rgba(37, 99, 235, 0.3);
    color: #bfdbfe;
}

html[data-theme='dark'] .action-stack-btn.neutral {
    background: rgba(8, 145, 178, 0.28);
    color: #a5f3fc;
}

html[data-theme='dark'] .action-stack-btn.danger {
    background: rgba(127, 29, 29, 0.4);
    color: #fca5a5;
}
