/* Admin modal + toast panel */
.portal-modal-open {
    overflow: hidden;
}

#portal-create-modal.kt-modal,
#portal-filter-modal.kt-modal,
#portal-delete-modal.kt-modal {
    z-index: 10050;
}

/* Flex centering — overrides Metronic fixed+translate dialog (breaks with display:block) */
#portal-create-modal.open,
#portal-filter-modal.open,
#portal-delete-modal.open {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    overflow-y: auto;
}

#portal-create-modal.open .kt-modal-backdrop,
#portal-filter-modal.open .kt-modal-backdrop,
#portal-delete-modal.open .kt-modal-backdrop {
    display: block;
    z-index: 0;
}

#portal-create-modal.open .kt-modal-dialog,
#portal-filter-modal.open .kt-modal-dialog,
#portal-delete-modal.open .kt-modal-dialog {
    position: relative;
    inset: auto;
    top: auto;
    inset-inline-start: auto;
    inset-inline-end: auto;
    transform: none;
    translate: none;
    display: block;
    z-index: 1;
    flex-shrink: 0;
    width: min(100%, 36rem);
    max-width: calc(100vw - 2rem);
    padding: 0;
    margin: 0;
    overflow: visible;
}

#portal-create-modal.portal-modal-lg.open .kt-modal-dialog {
    width: min(100%, 48rem);
}

#portal-create-modal.portal-modal-xl.open .kt-modal-dialog {
    width: min(100%, 56rem);
}

#portal-create-modal .portal-product-form .kt-input,
#portal-create-modal .portal-product-form .kt-select,
#portal-create-modal .portal-product-form textarea.kt-input {
    width: 100%;
}

#portal-create-modal .portal-product-form .kt-form-label {
    margin-bottom: 0;
}

#portal-create-modal .portal-product-form .kt-label {
    align-items: flex-start;
}

#portal-create-modal .kt-modal-content,
#portal-filter-modal .kt-modal-content,
#portal-delete-modal .kt-modal-content {
    position: relative;
    top: auto;
    transform: none;
    translate: none;
    width: 100%;
    max-height: min(88vh, 720px);
    animation: portal-modal-in 0.22s ease-out;
}

#portal-create-modal .kt-modal-body,
#portal-filter-modal .kt-modal-body {
    max-height: calc(min(88vh, 720px) - 8rem);
    overflow-y: auto;
}

#portal-delete-modal.open .kt-modal-dialog {
    width: min(100%, 28rem);
}

#portal-delete-modal .kt-modal-body {
    overflow: visible;
}

@keyframes portal-modal-in {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.portal-modal-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    min-height: 8rem;
    color: var(--secondary-foreground, #6b7280);
    font-size: 0.875rem;
}

.portal-modal-loading::before {
    content: '';
    width: 2rem;
    height: 2rem;
    border: 2px solid var(--border, #e5e7eb);
    border-top-color: var(--primary, #3b82f6);
    border-radius: 50%;
    animation: portal-spin 0.7s linear infinite;
}

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

#portal-toast-host {
    position: fixed;
    inset-inline-end: 1rem;
    top: 5.5rem;
    z-index: 10060;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
    max-width: min(24rem, calc(100vw - 2rem));
}

.portal-toast {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
    padding: 0.875rem 1rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border, #e5e7eb);
    background: var(--popover, #fff);
    color: var(--foreground, #111);
    box-shadow: 0 10px 25px -12px rgb(0 0 0 / 0.25);
    animation: portal-toast-in 0.25s ease-out;
    font-size: 0.875rem;
    line-height: 1.45;
}

.portal-toast-success {
    border-color: #86efac;
    background: #f0fdf4;
    color: #166534;
}

.portal-toast-error {
    border-color: #fca5a5;
    background: #fef2f2;
    color: #991b1b;
}

@keyframes portal-toast-in {
    from {
        opacity: 0;
        transform: translateX(12px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Order detail modal */
.portal-order-detail {
    font-size: 0.875rem;
}

.portal-order-detail-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 0.375rem;
    background: color-mix(in srgb, var(--primary, #3b82f6) 12%, transparent);
    color: var(--primary, #3b82f6);
    font-size: 1rem;
    flex-shrink: 0;
}

.portal-order-detail-icon-sm {
    width: 1.5rem;
    height: 1.5rem;
    font-size: 0.875rem;
}

.portal-order-detail-dl {
    display: grid;
    gap: 0.5rem;
    margin: 0;
}

.portal-order-detail-dl > div {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
}

.portal-order-detail-dl dt {
    margin: 0;
    font-size: 0.75rem;
    color: var(--secondary-foreground, #6b7280);
    flex-shrink: 0;
}

.portal-order-detail-dl dd {
    margin: 0;
    font-size: 0.8125rem;
    text-align: end;
    word-break: break-word;
}

.portal-order-detail-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.625rem;
    border-radius: 9999px;
    border: 1px solid var(--border, #e5e7eb);
    background: var(--background, #fff);
    font-size: 0.75rem;
}

.portal-order-detail-chip code {
    font-size: 0.75rem;
    font-weight: 600;
}

.portal-order-detail-section {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
}

.portal-order-detail-section-head {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.portal-order-detail-table thead th {
    font-size: 0.75rem;
    font-weight: 600;
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}

.portal-order-detail-table tbody td {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
    vertical-align: middle;
}

.portal-product-versions-card .kt-table-wrapper {
    overflow-x: auto;
}

.portal-product-versions-table {
    min-width: 100%;
    table-layout: fixed;
}

.portal-product-versions-table thead th {
    font-size: 0.75rem;
    font-weight: 600;
    padding-top: 0.625rem;
    padding-bottom: 0.625rem;
    white-space: nowrap;
}

.portal-product-versions-table tbody td {
    padding-top: 0.625rem;
    padding-bottom: 0.625rem;
    vertical-align: middle;
}

.portal-order-detail-payment {
    background: color-mix(in srgb, var(--muted, #f3f4f6) 35%, transparent);
}

.portal-sales-chart-column {
    transition: height 0.2s ease;
}

/* Sales report */
.portal-sales-report-hero {
    border-color: color-mix(in srgb, var(--primary, #3b82f6) 18%, var(--border, #e5e7eb));
}

.portal-sales-kpi {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 0.875rem 1rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border, #e5e7eb);
    background: var(--background, #fff);
    min-height: 5.5rem;
}

.portal-sales-kpi-primary {
    border-color: color-mix(in srgb, var(--primary, #3b82f6) 28%, var(--border, #e5e7eb));
    background: color-mix(in srgb, var(--primary, #3b82f6) 6%, var(--background, #fff));
}

.portal-sales-kpi-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--secondary-foreground, #6b7280);
}

.portal-sales-kpi-value {
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1.2;
    color: var(--foreground, #111);
}

.portal-sales-kpi-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.7rem;
    margin-top: auto;
}

.portal-sales-trend {
    display: inline-flex;
    align-items: center;
    padding: 0.1rem 0.4rem;
    border-radius: 9999px;
    font-weight: 600;
    font-size: 0.7rem;
    line-height: 1.2;
}

.portal-sales-trend-up {
    color: #166534;
    background: #dcfce7;
}

.portal-sales-trend-down {
    color: #991b1b;
    background: #fee2e2;
}

.portal-sales-trend-neutral {
    color: var(--secondary-foreground, #6b7280);
    background: var(--muted, #f3f4f6);
}

.portal-sales-status-card {
    background: color-mix(in srgb, var(--muted, #f3f4f6) 40%, transparent);
}

.portal-sales-breakdown-row:last-child {
    border-bottom: none;
}

.portal-sales-progress {
    height: 0.375rem;
    border-radius: 9999px;
    background: var(--muted, #f3f4f6);
    overflow: hidden;
}

.portal-sales-progress-bar {
    height: 100%;
    border-radius: 9999px;
    min-width: 2px;
    transition: width 0.25s ease;
    background: var(--primary, #3b82f6);
}

.portal-sales-progress-bar-success {
    background: #16a34a;
}

.portal-sales-chart-bar {
    position: relative;
}

.portal-sales-chart-tooltip {
    position: absolute;
    bottom: calc(100% + 0.35rem);
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
    font-size: 0.65rem;
    padding: 0.2rem 0.45rem;
    border-radius: 0.25rem;
    background: var(--popover, #fff);
    border: 1px solid var(--border, #e5e7eb);
    box-shadow: 0 4px 12px rgb(0 0 0 / 0.08);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    z-index: 2;
}

.portal-sales-chart-bar:hover .portal-sales-chart-tooltip,
.portal-sales-chart-bar:focus-within .portal-sales-chart-tooltip {
    opacity: 1;
}

.portal-table-actions {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.25rem;
}

.portal-action-btn {
    flex-shrink: 0;
}

.portal-action-btn:hover {
    background: color-mix(in srgb, var(--primary, #3b82f6) 8%, transparent);
}

.portal-action-btn.text-destructive:hover {
    background: color-mix(in srgb, var(--destructive, #ef4444) 10%, transparent);
}

[data-portal-settings-tabs] .kt-card-header {
    scrollbar-width: thin;
}

[data-portal-settings-tabs] .kt-tabs.kt-tabs-line {
    border-bottom: none;
}

.portal-settings-tab-panel.hidden {
    display: none;
}

/* kt-input sets a fixed single-line height — do not use it on textarea */
textarea.kt-input {
    height: auto;
    min-height: calc(var(--spacing, 0.25rem) * 20);
    padding-block: calc(var(--spacing, 0.25rem) * 3);
    resize: vertical;
    line-height: 1.5;
    field-sizing: content;
}

.portal-textarea-code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
    font-size: 0.8125rem;
    line-height: 1.5;
    text-align: left;
    direction: ltr;
    unicode-bidi: plaintext;
}

.portal-toolbar-filter-active::after {
    content: '';
    display: inline-block;
    width: 0.4rem;
    height: 0.4rem;
    margin-inline-start: 0.35rem;
    border-radius: 50%;
    background: var(--primary, #3b82f6);
    vertical-align: middle;
}

[data-portal-list-panel].portal-list-busy {
    opacity: 0.55;
    pointer-events: none;
    transition: opacity 0.15s ease;
}
