/* =========================================
   ADMIN ORDERS PAGE
   Extends the shared Admin Products theme.
========================================= */

.order-finance-panel {
    margin-bottom: 22px;
    overflow: hidden;
    background: var(--admin-surface);
    border: 1px solid var(--admin-border);
    border-radius: var(--admin-radius-lg);
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.055);
}

.finance-panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 21px 24px 17px;
}

.finance-panel-heading h2 {
    margin: 0;
    color: #0f172a;
    font-size: 18px;
}

.due-now-badge,
.read-only-badge,
.credit-count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 34px;
    padding: 7px 11px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 800;
    white-space: nowrap;
}

.due-now-badge {
    color: #9a3412;
    background: #fff7ed;
    border: 1px solid #fed7aa;
}

.due-now-badge strong {
    color: #c2410c;
    font-size: 13px;
}

.finance-summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1px;
    background: var(--admin-border);
    border-top: 1px solid var(--admin-border);
}

.finance-summary-card {
    display: flex;
    min-width: 0;
    flex-direction: column;
    padding: 18px 24px;
    background: #ffffff;
}

.finance-summary-card span {
    color: #64748b;
    font-size: 10px;
    font-weight: 850;
    letter-spacing: 0.055em;
    text-transform: uppercase;
}

.finance-summary-card strong {
    margin-top: 7px;
    overflow: hidden;
    color: #172033;
    font-size: 17px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.finance-summary-card small {
    margin-top: 4px;
    overflow: hidden;
    color: #64748b;
    font-size: 11px;
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.finance-summary-card.success {
    box-shadow: inset 0 3px 0 #10b981;
}

.finance-summary-card.warning {
    box-shadow: inset 0 3px 0 #f59e0b;
}

.orders-panel {
    margin-top: 0;
}

.order-panel-heading {
    align-items: center;
}

.read-only-badge {
    color: #334155;
    background: #f1f5f9;
    border: 1px solid #dbe3ed;
}

/* =========================================
   FILTERS
========================================= */

.order-toolbar {
    display: grid;
    grid-template-columns:
        minmax(260px, 1.7fr)
        minmax(150px, 0.72fr)
        minmax(150px, 0.72fr)
        minmax(145px, 0.65fr)
        minmax(145px, 0.65fr)
        auto;
    gap: 10px;
    padding: 17px 26px;
    background: var(--admin-surface-soft);
    border-top: 1px solid #e7edf5;
    border-bottom: 1px solid #e7edf5;
}

.order-toolbar .search-control input,
.order-toolbar .filter-control,
.date-filter-control {
    height: 44px;
}

.date-filter-control {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    padding-left: 11px;
    background: #ffffff;
    border: 1px solid var(--admin-border);
    border-radius: 11px;
}

.date-filter-control > span {
    color: var(--admin-muted);
    font-size: 10px;
    font-weight: 850;
    text-transform: uppercase;
}

.date-filter-control input {
    min-width: 0;
    width: 100%;
    height: 100%;
    padding: 0 8px 0 0;
    color: var(--admin-text);
    background: transparent;
    border: 0;
    outline: none;
    font-size: 11px;
    font-weight: 650;
    cursor: pointer;
}

.date-filter-control:focus-within {
    border-color: #76a0f8;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.11);
}

.order-filter-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.order-filter-actions .primary-button,
.order-filter-actions .secondary-button {
    min-height: 44px;
    padding: 9px 13px;
    font-size: 11px;
}

.refresh-icon-button {
    flex: 0 0 44px;
    width: 44px;
    padding: 0 !important;
}

/* =========================================
   ORDER TABLE
========================================= */

.order-table {
    min-width: 1100px;
}

.order-table th,
.order-table td {
    padding-top: 17px;
    padding-bottom: 17px;
}

.order-identity,
.order-product {
    display: flex;
    min-width: 190px;
    align-items: center;
    gap: 11px;
}

.order-identity-icon,
.order-product-thumb {
    display: grid;
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    overflow: hidden;
    place-items: center;
    color: #2563eb;
    background: #e8f0ff;
    border: 1px solid #d8e4fb;
    border-radius: 11px;
}

.order-product-thumb {
    color: #7c3aed;
    background: #f3e8ff;
    border-color: #e9d5ff;
}

.order-product-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.order-identity-copy,
.order-product-copy,
.timeline-stack,
.purchase-stack {
    display: flex;
    min-width: 0;
    flex-direction: column;
}

.order-identity-copy strong,
.order-product-copy strong {
    max-width: 210px;
    overflow: hidden;
    color: #172033;
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.order-identity-copy code,
.order-product-copy code {
    max-width: 210px;
    margin-top: 4px;
    overflow: hidden;
    color: #64748b;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 9px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.order-identity-copy small,
.order-product-copy small {
    margin-top: 4px;
    color: #8a98ab;
    font-size: 9px;
    white-space: nowrap;
}

.purchase-stack {
    min-width: 118px;
}

.purchase-stack strong {
    color: #1e293b;
    font-size: 12px;
    white-space: nowrap;
}

.purchase-stack span {
    width: max-content;
    margin-top: 5px;
    padding: 3px 6px;
    color: #1d4ed8;
    background: #eff6ff;
    border-radius: 6px;
    font-size: 8px;
    font-weight: 850;
}

.purchase-stack small {
    margin-top: 5px;
    color: #64748b;
    font-size: 9px;
    white-space: nowrap;
}

.income-progress {
    min-width: 170px;
}

.income-progress-values {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 9px;
}

.income-progress-values strong {
    color: #1e293b;
    font-size: 11px;
    white-space: nowrap;
}

.income-progress-values span {
    color: #64748b;
    font-size: 9px;
    font-weight: 750;
}

.income-progress-track {
    height: 6px;
    margin-top: 8px;
    overflow: hidden;
    background: #e8eef6;
    border-radius: 999px;
}

.income-progress-track span {
    display: block;
    width: var(--income-progress, 0%);
    height: 100%;
    background: linear-gradient(90deg, #2563eb, #10b981);
    border-radius: inherit;
}

.income-progress > small {
    display: block;
    margin-top: 6px;
    color: #8492a6;
    font-size: 9px;
    white-space: nowrap;
}

.timeline-stack {
    min-width: 145px;
}

.timeline-stack strong {
    color: #334155;
    font-size: 10px;
    white-space: nowrap;
}

.timeline-stack small {
    margin-top: 5px;
    color: #64748b;
    font-size: 9px;
    white-space: nowrap;
}

.timeline-stack .due-label {
    color: #c2410c;
    font-weight: 800;
}

.status-pill.completed,
.credit-status.credited {
    color: #0369a1;
    background: #e0f2fe;
}

.status-pill.cancelled,
.credit-status.failed {
    color: #b91c1c;
    background: #fee2e2;
}

.status-pill.pending,
.credit-status.pending {
    color: #a16207;
    background: #fef3c7;
}

.order-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    min-height: 72px;
    padding: 14px 26px;
    background: #fbfcfe;
    border-top: 1px solid #e8edf4;
}

.order-pagination p {
    margin: 0;
    color: #64748b;
    font-size: 11px;
    font-weight: 650;
}

.order-pagination .secondary-button {
    min-height: 38px;
    font-size: 11px;
}

.order-safety-note {
    display: flex;
    align-items: flex-start;
    gap: 11px;
    margin-top: 18px;
    padding: 14px 17px;
    color: #52637a;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid var(--admin-border);
    border-radius: 13px;
    font-size: 11px;
    line-height: 1.55;
}

.order-safety-note i {
    margin-top: 2px;
    color: var(--admin-primary);
}

.order-safety-note p {
    margin: 0;
}

/* =========================================
   ORDER DETAIL MODAL
========================================= */

.order-detail-modal {
    width: min(1180px, 100%);
}

.order-detail-body {
    gap: 16px;
    max-height: min(74vh, 790px);
    background: #f8fafc;
}

.detail-loading-state {
    display: flex;
    min-height: 260px;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: #52637a;
    font-size: 13px;
    font-weight: 700;
}

.detail-loading-state i {
    color: var(--admin-primary);
    font-size: 18px;
}

#orderDetailContent {
    display: grid;
    gap: 16px;
}

.order-detail-hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 20px;
    color: #e2e8f0;
    background:
        radial-gradient(circle at 88% 10%, rgba(59, 130, 246, 0.36), transparent 16rem),
        #101a2f;
    border-radius: 16px;
}

.detail-hero-main {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 14px;
}

.detail-hero-icon {
    display: grid;
    flex: 0 0 48px;
    width: 48px;
    height: 48px;
    place-items: center;
    color: #ffffff;
    background: rgba(37, 99, 235, 0.82);
    border: 1px solid rgba(147, 197, 253, 0.35);
    border-radius: 14px;
    font-size: 17px;
}

.detail-hero-copy {
    min-width: 0;
}

.detail-hero-copy span {
    color: #94a3b8;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.detail-hero-copy h3 {
    margin: 5px 0 0;
    overflow-wrap: anywhere;
    color: #ffffff;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 17px;
}

.detail-hero-copy p {
    margin: 5px 0 0;
    color: #aebbd0;
    font-size: 10px;
}

.detail-hero-meta {
    display: flex;
    align-items: center;
    gap: 9px;
}

.detail-hero-version {
    padding: 6px 9px;
    color: #cbd5e1;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 8px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 9px;
    font-weight: 800;
}

.detail-section {
    min-width: 0;
    padding: 18px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 15px;
}

.detail-section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

.detail-section-heading h3 {
    margin: 0;
    color: #1e293b;
    font-size: 15px;
}

.detail-metric-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
}

.detail-metric {
    display: flex;
    min-width: 0;
    flex-direction: column;
    padding: 13px;
    background: #f8fafc;
    border: 1px solid #e4eaf2;
    border-radius: 11px;
}

.detail-metric span {
    color: #64748b;
    font-size: 8px;
    font-weight: 850;
    letter-spacing: 0.055em;
    text-transform: uppercase;
}

.detail-metric strong {
    margin-top: 6px;
    overflow: hidden;
    color: #172033;
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.detail-metric small {
    margin-top: 4px;
    color: #8492a6;
    font-size: 9px;
}

.detail-two-column-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.detail-list {
    margin: 0;
}

.detail-list > div {
    display: grid;
    grid-template-columns: minmax(110px, 0.45fr) minmax(0, 1fr);
    gap: 15px;
    padding: 10px 0;
    border-top: 1px solid #edf1f6;
}

.detail-list > div:first-child {
    padding-top: 0;
    border-top: 0;
}

.detail-list > div:last-child {
    padding-bottom: 0;
}

.detail-list dt {
    color: #64748b;
    font-size: 9px;
    font-weight: 800;
    text-transform: uppercase;
}

.detail-list dd {
    min-width: 0;
    margin: 0;
    overflow-wrap: anywhere;
    color: #27364b;
    font-size: 10px;
    font-weight: 680;
    text-align: right;
}

.detail-list dd code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 9px;
}

.detail-list .muted-value {
    color: #94a3b8;
    font-weight: 600;
}

.credits-heading {
    margin-bottom: 12px;
}

.credit-count-badge {
    min-height: 28px;
    color: #1d4ed8;
    background: #eff6ff;
    border: 1px solid #dbeafe;
}

.credit-table-wrap {
    overflow-x: auto;
    border: 1px solid #e6ebf2;
    border-radius: 11px;
}

.credit-table {
    width: 100%;
    min-width: 720px;
    border-collapse: collapse;
}

.credit-table th,
.credit-table td {
    padding: 11px 13px;
    text-align: left;
    border-bottom: 1px solid #e8edf4;
}

.credit-table th {
    color: #64748b;
    background: #f8fafc;
    font-size: 8px;
    font-weight: 850;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    white-space: nowrap;
}

.credit-table td {
    color: #334155;
    font-size: 9px;
}

.credit-table tr:last-child td {
    border-bottom: 0;
}

.credit-table code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 8px;
}

.credit-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 7px;
    border-radius: 999px;
    font-size: 8px;
    font-weight: 850;
    text-transform: capitalize;
    white-space: nowrap;
}

.credit-status::before {
    width: 5px;
    height: 5px;
    background: currentColor;
    border-radius: 50%;
    content: "";
}

.credits-empty-state {
    padding: 34px 20px;
    color: #64748b;
    text-align: center;
    background: #f8fafc;
    border: 1px dashed #cbd5e1;
    border-radius: 11px;
}

.credits-empty-state i {
    color: #94a3b8;
    font-size: 22px;
}

.credits-empty-state p {
    margin: 9px 0 0;
    font-size: 10px;
}

.order-detail-footer > span {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: #64748b;
    font-size: 10px;
    font-weight: 700;
}

.order-detail-footer > span i {
    color: #475569;
}

/* =========================================
   RESPONSIVE LAYOUT
========================================= */

@media (max-width: 1500px) {
    .order-toolbar {
        grid-template-columns: minmax(260px, 1fr) repeat(2, minmax(155px, 0.5fr));
    }

    .date-filter-control {
        grid-row: 2;
    }

    .order-filter-actions {
        grid-column: 3;
        grid-row: 2;
    }
}

@media (max-width: 1180px) {
    .finance-summary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .order-toolbar {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .order-search {
        grid-column: 1 / -1;
    }

    .date-filter-control,
    .order-filter-actions {
        grid-column: auto;
        grid-row: auto;
    }

    .order-filter-actions {
        justify-content: stretch;
    }

    .order-filter-actions > button:not(.refresh-icon-button) {
        flex: 1;
    }

    .detail-metric-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 720px) {
    .finance-panel-heading {
        align-items: flex-start;
        padding: 18px 20px 15px;
    }

    .finance-summary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .finance-summary-card {
        padding: 15px 17px;
    }

    .finance-summary-card strong {
        font-size: 14px;
    }

    .order-panel-heading {
        align-items: flex-start;
    }

    .order-toolbar {
        grid-template-columns: 1fr;
        padding: 14px 20px;
    }

    .order-search {
        grid-column: auto;
    }

    .order-filter-actions {
        flex-wrap: wrap;
    }

    .order-filter-actions .refresh-icon-button {
        flex-basis: 44px;
    }

    .order-table {
        min-width: 0;
    }

    .order-table td:nth-child(2) {
        grid-column: 1 / -1;
        padding-bottom: 12px;
        border-bottom: 1px solid #e8edf4;
    }

    .order-table td:nth-child(2)::before {
        display: none;
    }

    .order-table td:nth-child(5) {
        grid-column: 1 / -1;
    }

    .order-identity,
    .order-product {
        min-width: 0;
    }

    .income-progress,
    .timeline-stack,
    .purchase-stack {
        min-width: 0;
    }

    .order-pagination {
        flex-direction: column;
        align-items: stretch;
        padding: 16px 20px;
        text-align: center;
    }

    .order-pagination .secondary-button {
        width: 100%;
    }

    .order-detail-body {
        max-height: none;
        background: #f8fafc;
    }

    .order-detail-hero {
        align-items: flex-start;
        flex-direction: column;
    }

    .detail-hero-meta {
        width: 100%;
        justify-content: space-between;
    }

    .detail-metric-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .detail-two-column-grid {
        grid-template-columns: 1fr;
    }

    .credit-table-wrap {
        border: 0;
        overflow: visible;
    }

    .credit-table,
    .credit-table tbody,
    .credit-table tr,
    .credit-table td {
        display: block;
        width: 100%;
    }

    .credit-table {
        min-width: 0;
    }

    .credit-table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }

    .credit-table tbody {
        display: grid;
        gap: 10px;
    }

    .credit-table tr {
        padding: 12px;
        background: #f8fafc;
        border: 1px solid #e2e8f0;
        border-radius: 10px;
    }

    .credit-table td {
        display: grid;
        grid-template-columns: 100px minmax(0, 1fr);
        gap: 12px;
        padding: 7px 0;
        text-align: right;
        border-bottom: 1px solid #e8edf4;
    }

    .credit-table td::before {
        color: #94a3b8;
        content: attr(data-label);
        font-size: 8px;
        font-weight: 850;
        text-align: left;
        text-transform: uppercase;
    }

    .credit-table td:last-child {
        border-bottom: 0;
    }

    .order-detail-footer {
        flex-direction: row;
        align-items: center;
    }
}

@media (max-width: 440px) {
    .finance-panel-heading {
        flex-direction: column;
    }

    .finance-summary-grid {
        grid-template-columns: 1fr;
    }

    .read-only-badge {
        width: 100%;
    }

    .order-filter-actions .primary-button,
    .order-filter-actions .secondary-button {
        flex: 1 1 calc(50% - 8px);
    }

    .order-filter-actions .refresh-icon-button {
        flex-basis: 44px;
        max-width: 44px;
    }

    .detail-metric-grid {
        grid-template-columns: 1fr;
    }

    .detail-list > div {
        grid-template-columns: 1fr;
        gap: 4px;
    }

    .detail-list dd {
        text-align: left;
    }

    .order-detail-footer > span {
        display: none;
    }

    .order-detail-footer .secondary-button {
        width: 100%;
    }
}
