/*
 * Khat Sara UI contract
 * Final shared visual layer for public pages and the customer panel.
 * Keep this file loaded after site.css so legacy page rules converge here.
 */

:root {
    --ks-content-width: 1440px;
    --ks-reading-width: 1120px;
    --ks-section-gap: 20px;
    --ks-card-radius: 18px;
    --ks-hero-radius: 24px;
    --ks-card-border: var(--color-border);
    --ks-card-shadow: 0 14px 34px rgba(15, 34, 61, .07);
    --ks-card-shadow-hover: 0 18px 42px rgba(15, 34, 61, .11);
    --ks-focus-ring: 0 0 0 4px rgba(14, 165, 233, .15);
}

@supports (color: color-mix(in srgb, #000 50%, #fff)) {
    :root {
        --ks-card-border: color-mix(in srgb, var(--color-border) 88%, var(--color-primary) 12%);
    }
}

html {
    scroll-behavior: smooth;
}

body {
    background-image:
        radial-gradient(circle at 8% 16%, rgba(14, 165, 233, .045), transparent 24rem),
        radial-gradient(circle at 92% 38%, rgba(20, 184, 166, .035), transparent 28rem);
    background-attachment: fixed;
}

main {
    min-height: 58vh;
}

.container,
.site-shell,
.panel-page,
.customer-page {
    width: min(calc(100% - 32px), var(--ks-content-width));
    margin-inline: auto;
}

.site-page,
.panel-main,
.customer-main {
    display: grid;
    align-content: start;
    gap: var(--ks-section-gap);
}

/* Shared hero contract */
.site-page-hero,
.panel-hero,
.customer-page-hero,
.profile-hero,
.panel-page > .hero,
.panel-main > .hero {
    position: relative;
    isolation: isolate;
    min-height: 164px;
    padding: 28px 32px;
    border: 1px solid rgba(125, 211, 252, .24);
    border-radius: var(--ks-hero-radius);
    overflow: hidden;
    box-shadow: 0 20px 44px rgba(2, 23, 51, .14);
}

.site-page-hero h1,
.panel-hero h1,
.customer-page-hero h1,
.profile-hero h1,
.site-page-hero h2,
.panel-hero h2,
.customer-page-hero h2,
.profile-hero h2 {
    margin: 0 0 9px;
    line-height: 1.35;
    letter-spacing: -.025em;
}

.site-page-hero p,
.panel-hero p,
.customer-page-hero p,
.profile-hero p {
    max-width: 760px;
    margin: 0;
    line-height: 1.9;
    color: rgba(255, 255, 255, .76);
}

/* Consistent surfaces across public pages and customer panel */
:where(.site-page, .panel-main, .customer-main) :where(
    .card,
    .panel-card,
    .dashboard-card,
    .content-card,
    .profile-card,
    .summary-card,
    .filter-card,
    .table-wrap,
    .empty-state
) {
    border: 1px solid var(--ks-card-border);
    border-radius: var(--ks-card-radius);
    box-shadow: var(--ks-card-shadow);
}

:where(.site-page, .panel-main, .customer-main) :where(.card, .panel-card, .dashboard-card, .profile-card) {
    transition: border-color .2s ease, box-shadow .2s ease, transform .2s ease;
}

@media (hover: hover) {
    :where(.site-page, .panel-main, .customer-main) :where(.card, .panel-card, .dashboard-card, .profile-card):hover {
        border-color: rgba(14, 165, 233, .22);
        box-shadow: var(--ks-card-shadow-hover);
    }
}

/* Customer panel structure */
.panel-page,
.customer-page {
    gap: 20px;
}

.panel-sidebar,
.customer-sidebar {
    border: 1px solid var(--ks-card-border);
    border-radius: 20px;
    box-shadow: var(--ks-card-shadow);
}

.panel-sidebar nav,
.customer-sidebar nav {
    display: grid;
    gap: 5px;
}

.panel-sidebar nav a,
.customer-sidebar nav a {
    min-height: 44px;
    border-radius: 12px;
}

/* Profile: balanced desktop composition and predictable history width */
.profile-content-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.16fr);
    align-items: start;
    gap: 18px;
}

.profile-history-section {
    grid-column: 1 / -1;
}

.profile-password-card form {
    display: grid;
    gap: 13px;
}

.profile-otp-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: end;
}

/* Forms, controls and keyboard accessibility */
:where(.site-page, .panel-main, .customer-main, .modal-box) :where(input, select, textarea) {
    min-height: 44px;
    border-radius: 12px;
    border-color: var(--ks-card-border);
    background-clip: padding-box;
    transition: border-color .18s ease, box-shadow .18s ease, background-color .18s ease;
}

:where(.site-page, .panel-main, .customer-main, .modal-box) textarea {
    min-height: 112px;
}

:where(.site-page, .panel-main, .customer-main, .modal-box) :where(input, select, textarea):focus {
    border-color: var(--color-primary);
    box-shadow: var(--ks-focus-ring);
    outline: 0;
}

:where(.site-page, .panel-main, .customer-main, .modal-box) :where(button, .btn, [role="button"]) {
    min-height: 42px;
    border-radius: 12px;
}

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 3px;
}

/* One modal language for purchases, inquiries, auth and customer actions */
.modal-box {
    width: min(94vw, 620px);
    max-height: min(88vh, 900px);
    border: 1px solid rgba(125, 211, 252, .25);
    border-radius: 20px;
    box-shadow: 0 28px 80px rgba(2, 12, 31, .28);
}

.modal-box.modal-wide,
.modal-box.is-wide {
    width: min(94vw, 860px);
}

.modal-box > :where(.modal-header, header):first-child {
    border-start-start-radius: inherit;
    border-start-end-radius: inherit;
}

.modal-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

/* Tables and empty states should not look like unfinished pages */
.table-wrap {
    overflow: auto;
    background: var(--color-surface);
}

table {
    border-collapse: separate;
    border-spacing: 0;
}

thead th {
    white-space: nowrap;
}

.empty-state {
    min-height: 150px;
    display: grid;
    place-items: center;
    padding: 28px;
    text-align: center;
    background: linear-gradient(145deg, rgba(255, 255, 255, .8), rgba(239, 248, 255, .72));
}

[data-theme="dark"] body {
    background-image:
        radial-gradient(circle at 8% 16%, rgba(14, 165, 233, .07), transparent 25rem),
        radial-gradient(circle at 92% 38%, rgba(20, 184, 166, .055), transparent 30rem);
}

[data-theme="dark"] .empty-state {
    background: linear-gradient(145deg, rgba(15, 34, 61, .92), rgba(10, 26, 49, .88));
}

@media (max-width: 991.98px) {
    .container,
    .site-shell,
    .panel-page,
    .customer-page {
        width: min(calc(100% - 24px), var(--ks-content-width));
    }

    .profile-content-grid {
        grid-template-columns: 1fr;
    }

    .profile-history-section {
        grid-column: auto;
    }
}

@media (max-width: 700px) {
    :root {
        --ks-section-gap: 14px;
        --ks-card-radius: 15px;
        --ks-hero-radius: 19px;
    }

    .container,
    .site-shell,
    .panel-page,
    .customer-page {
        width: min(calc(100% - 20px), var(--ks-content-width));
    }

    .site-page-hero,
    .panel-hero,
    .customer-page-hero,
    .profile-hero,
    .panel-page > .hero,
    .panel-main > .hero {
        min-height: 142px;
        padding: 22px 20px;
    }

    .profile-otp-row,
    .modal-actions {
        grid-template-columns: 1fr;
    }

    .modal-actions > * {
        flex: 1 1 100%;
    }
}

/* Final dark-mode contract for public pages and the customer workspace.
 * This intentionally lives at the end of the shared layer so new cards,
 * dialogs and Bootstrap fragments inherit an accessible dark surface. */
[data-theme="dark"] {
    --ks-card-shadow: 0 14px 36px rgba(0, 0, 0, .28);
    --ks-card-shadow-hover: 0 20px 46px rgba(0, 0, 0, .38);
}

[data-theme="dark"] :where(.site-page, .panel-main, .customer-main) :where(
    .card, .panel-card, .dashboard-card, .content-card, .profile-card,
    .summary-card, .filter-card, .table-wrap, .empty-state, .panel-block,
    .panel-modern-block, .panel-dashboard-block, .panel-stat-card
) {
    color: var(--color-text);
    background-color: var(--color-surface);
    border-color: var(--color-border);
    box-shadow: var(--ks-card-shadow);
}

[data-theme="dark"] :where(.site-page, .panel-main, .customer-main) :where(
    .card-header, .card-footer, .panel-header, .panel-footer, .summary-row,
    .detail-row, .meta-row, .timeline-item, .upload-box, .preview-box,
    .receipt-box, .bank-account-info, .form-note
) {
    color: var(--color-text);
    background-color: var(--color-surface-alt);
    border-color: var(--color-border);
}

[data-theme="dark"] :where(.modal, .modal-overlay) {
    background-color: rgba(0, 5, 16, .8);
}

[data-theme="dark"] :where(.modal-box, .modal-content, .dialog-box, [role="dialog"]) {
    color: var(--color-text);
    border-color: var(--color-border);
}

[data-theme="dark"] :where(.modal-box, .modal-content, .dialog-box) :where(
    .modal-header, .modal-body, .modal-footer, .card, .panel-profile-row,
    .detail-card, .summary-card, .table-responsive
) {
    color: var(--color-text);
    background-color: var(--color-surface);
    border-color: var(--color-border);
}

[data-theme="dark"] :where(input, select, textarea):not([type="checkbox"]):not([type="radio"]):not([type="range"]) {
    color: var(--color-text);
    background-color: var(--color-surface-alt);
    border-color: var(--border-interactive);
}

[data-theme="dark"] :where(input, textarea)::placeholder {
    color: #8fa3b8;
    opacity: 1;
}

[data-theme="dark"] :where(input, select, textarea):disabled,
[data-theme="dark"] :where(input, textarea)[readonly] {
    color: #8295a9;
    background-color: #0d1825;
    border-color: #22364a;
    opacity: 1;
}

[data-theme="dark"] input:-webkit-autofill,
[data-theme="dark"] input:-webkit-autofill:hover,
[data-theme="dark"] input:-webkit-autofill:focus {
    -webkit-text-fill-color: var(--color-text);
    -webkit-box-shadow: 0 0 0 1000px var(--color-surface-alt) inset;
    caret-color: var(--color-text);
}

[data-theme="dark"] :where(table, .table) {
    --bs-table-color: var(--color-text);
    --bs-table-bg: transparent;
    --bs-table-border-color: var(--color-border);
    --bs-table-hover-color: var(--color-text);
    --bs-table-hover-bg: #12283d;
    color: var(--color-text);
    border-color: var(--color-border);
}

[data-theme="dark"] :where(table, .table) :where(th, td) {
    color: inherit;
    border-color: var(--color-border);
}

[data-theme="dark"] :where(table, .table) thead th {
    color: #bfd0df;
    background-color: #13283c;
}

[data-theme="dark"] :where(.alert, .toast, .dropdown-menu, .list-group-item, .accordion-item, .accordion-button) {
    color: var(--color-text);
    background-color: var(--color-surface);
    border-color: var(--color-border);
}

[data-theme="dark"] .accordion-button:not(.collapsed),
[data-theme="dark"] :where(.dropdown-item, .list-group-item):hover {
    color: var(--color-text);
    background-color: var(--color-surface-alt);
}

[data-theme="dark"] :where(.text-body, .text-dark) { color: var(--color-text) !important; }
[data-theme="dark"] :where(.text-muted, .text-secondary, small, .form-text) { color: var(--color-text-muted) !important; }
[data-theme="dark"] :where(hr, .divider) { border-color: var(--color-border); opacity: 1; }
[data-theme="dark"] ::-webkit-scrollbar-track { background: #0b1521; }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: #36516b; border-color: #0b1521; }

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}

/* استاندارد تصویری ویدیوی احراز هویت در ثبت نام */
.kyc-intro {
    margin-bottom: 12px;
    padding: 11px 13px;
    border: 1px solid color-mix(in srgb, var(--color-primary) 18%, var(--color-border));
    border-radius: 12px;
    background: color-mix(in srgb, var(--color-primary-light) 72%, var(--color-surface));
}

.kyc-recording-standard {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin: 10px 0;
}

.kyc-standard-item {
    display: grid;
    grid-template-columns: 32px 1fr;
    align-items: center;
    column-gap: 8px;
    padding: 10px;
    border: 1px solid var(--color-border);
    border-radius: 12px;
    background: var(--color-surface);
}

.kyc-standard-item > span {
    grid-row: 1 / 3;
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: var(--color-primary-light);
    font-size: 17px;
}

.kyc-standard-item b { font-size: 11px; }
.kyc-standard-item small { color: var(--color-text-muted); font-size: 9px; line-height: 1.6; }

.kyc-speech-script {
    margin: 10px 0 12px;
    padding: 11px 13px;
    border-right: 3px solid var(--color-primary);
    border-radius: 10px;
    background: var(--color-bg);
}

.kyc-speech-script > span { color: var(--color-primary); font-size: 10px; font-weight: 900; }
.kyc-speech-script p { margin: 5px 0 0; color: var(--color-text); font-size: 11px; font-weight: 700; line-height: 1.9; }

.kyc-camera-stage {
    position: relative;
    min-height: 220px;
    overflow: hidden;
    border: 1px solid var(--color-border);
    border-radius: 13px;
    background: #030712;
}

.kyc-webcam-box .kyc-camera-stage video {
    display: block;
    min-height: 220px;
    border-radius: 0;
}

video.is-mirrored-live {
    transform: scaleX(-1);
}

.kyc-camera-guide {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.kyc-camera-guide[hidden], .kyc-recording-badge[hidden] { display: none !important; }
.kyc-face-frame, .kyc-card-frame { position: absolute; border: 2px dashed rgba(255,255,255,.72); }
.kyc-face-frame { top: 13%; right: 15%; width: 34%; height: 67%; border-radius: 45% 45% 38% 38%; }
.kyc-card-frame { left: 9%; bottom: 18%; width: 33%; aspect-ratio: 1.58; border-radius: 9px; }
.kyc-face-frame i, .kyc-card-frame i {
    position: absolute;
    right: 50%;
    bottom: -24px;
    translate: 50% 0;
    padding: 2px 7px;
    border-radius: 6px;
    color: #fff;
    background: rgba(2, 6, 23, .72);
    font: 700 9px inherit;
    white-space: nowrap;
}

.kyc-camera-guide > small {
    position: absolute;
    right: 50%;
    bottom: 8px;
    translate: 50% 0;
    width: max-content;
    max-width: 90%;
    padding: 4px 10px;
    border-radius: 8px;
    color: #fff;
    background: rgba(2, 6, 23, .72);
    font-size: 9px;
}

.kyc-recording-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 9px;
    border-radius: 999px;
    color: #fff;
    background: rgba(153, 27, 27, .88);
    font-size: 9px;
    font-weight: 800;
}

.kyc-recording-badge i { width: 7px; height: 7px; border-radius: 50%; background: #fff; animation: kyc-recording-pulse 1s infinite; }
@keyframes kyc-recording-pulse { 50% { opacity: .3; } }
.kyc-file-box p { margin: 0 0 10px; color: var(--color-text-muted); font-size: 10px; line-height: 1.8; }

@media (max-width: 600px) {
    .kyc-recording-standard { grid-template-columns: 1fr; }
    .kyc-standard-item { min-height: 58px; }
}
