/* ==========================================================================
   Side cart drawer (.dcd) + personalisation popup (.dpm)
   functions/functionCartDrawer.php, assets/footer/js/global/della-drawer.js
   Tokens and .dc-btn come from 0_della-ui.css.
   ========================================================================== */

html.dcd-lock,
html.dcd-lock body {
    overflow: hidden !important;
}

/* ---------- Drawer ---------- */

.dcd {
    position: fixed;
    inset: 0;
    z-index: 100050;
    font-family: var(--dc-font);
    color: var(--dc-ink);
    -webkit-font-smoothing: antialiased;
}

.dcd[hidden] {
    display: none;
}

.dcd *,
.dcd *::before,
.dcd *::after,
.dpm *,
.dpm *::before,
.dpm *::after {
    box-sizing: border-box;
}

.dcd :where(h2, h3, p, ul, dl, dd),
.dpm :where(h2, p) {
    margin: 0;
}

.dcd :where(ul) {
    padding: 0;
    list-style: none;
}

.dcd__overlay {
    position: absolute;
    inset: 0;
    background: rgba(23, 23, 23, .45);
    opacity: 0;
    transition: opacity .25s ease;
}

.dcd__panel {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(440px, 100vw);
    display: flex;
    flex-direction: column;
    background: var(--dc-surface);
    box-shadow: var(--dc-shadow-lg);
    transform: translateX(100%);
    transition: transform .26s cubic-bezier(.2, .8, .2, 1);
    outline: none;
}

.dcd.is-open .dcd__overlay { opacity: 1; }
.dcd.is-open .dcd__panel { transform: none; }

.dcd__body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.dcd__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 12px 14px 20px;
    border-bottom: 1px solid var(--dc-line);
}

.dcd__title {
    font-family: var(--dc-font-display);
    font-size: 22px;
    font-weight: 500;
    line-height: 1.2;
    color: var(--dc-ink);
}

.dcd__count {
    font-family: var(--dc-font);
    font-size: 15px;
    font-weight: 400;
    color: var(--dc-muted);
}

.dcd__scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 4px 20px 20px;
}

.dcd__loading {
    flex: 1;
    display: grid;
    place-items: center;
}

.dcd__spinner {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid var(--dc-line);
    border-top-color: var(--dc-gold-btn);
    animation: dc-spin .7s linear infinite;
}

.dcd__error {
    margin: 12px 20px 0 !important;
    padding: 10px 12px;
    border-radius: var(--dc-radius-sm);
    background: var(--dc-error-soft);
    color: var(--dc-error);
    font-size: 14px;
}

.dcd__body[aria-busy="true"] .dcd-items {
    opacity: .6;
    pointer-events: none;
}

/* Items */
.dcd-items > li + li {
    border-top: 1px solid var(--dc-line);
}

.dcd-item {
    display: grid;
    grid-template-columns: 84px minmax(0, 1fr);
    gap: 14px;
    padding: 16px 0;
    transition: opacity .2s ease;
}

.dcd-item.is-updating { opacity: .55; }
.dcd-item.is-leaving { opacity: .3; }

.dcd-item__media {
    display: block;
    width: 84px;
    height: 84px;
    border-radius: var(--dc-radius-sm);
    background: #f4f2ed;
    overflow: hidden;
}

.dcd-item__media img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    mix-blend-mode: multiply;
}

.dcd-item__body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.dcd-item__top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}

.dcd-item__name {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.35;
    padding-top: 2px;
}

.dcd-item__name a {
    color: var(--dc-ink);
    text-decoration: none;
}

.dcd-item__name a:hover { text-decoration: underline; }

.dcd-item__remove {
    width: 32px;
    height: 32px;
    margin: -4px -6px 0 0;
    color: var(--dc-muted);
}

.dcd-item__remove:hover { color: var(--dc-error); }
.dcd-item__remove .dc-icon { width: 17px; height: 17px; }

.dcd-item__meta {
    font-size: 13px;
    line-height: 1.45;
    color: var(--dc-muted);
}

.dcd-item__pers {
    font-size: 13px;
    color: var(--dc-ink-2);
}

.dcd-item__problem {
    display: flex;
    gap: 6px;
    align-items: flex-start;
    font-size: 13px;
    color: var(--dc-error);
}

.dcd-item__bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 6px;
}

.dcd-item__bottom .dc-qty { height: 36px; }
.dcd-item__bottom .dc-qty__btn { width: 34px; }
.dcd-item__bottom .dc-qty__value { line-height: 34px; width: 36px; }

.dcd-item__set {
    font-size: 13px;
    color: var(--dc-muted);
}

.dcd-item__price {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-size: 15px;
    white-space: nowrap;
}

.dcd-item__price s {
    font-size: 13px;
    color: var(--dc-muted);
}

/* Suggestions inside the drawer */
.dcd .dw-rail {
    margin-top: 8px;
    padding-top: 18px;
    border-top: 1px solid var(--dc-line);
}

.dcd .dw-rail__title { font-size: 17px; }

/* Empty */
.dcd-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 48px 8px 32px;
    text-align: center;
}

.dcd-empty__icon {
    display: inline-grid;
    place-items: center;
    width: 64px;
    height: 64px;
    margin-bottom: 8px;
    border-radius: 50%;
    background: var(--dc-gold-soft);
    color: var(--dc-gold-ink);
}

.dcd-empty__icon .dc-icon { width: 28px; height: 28px; }
.dcd-empty__title { font-family: var(--dc-font-display); font-size: 22px; }
.dcd-empty__text { color: var(--dc-muted); font-size: 15px; margin-bottom: 12px !important; }

/* Footer */
.dcd__foot {
    display: grid;
    gap: 10px;
    padding: 16px 20px calc(16px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--dc-line);
    background: var(--dc-surface);
    box-shadow: 0 -6px 18px rgba(23, 23, 23, .04);
}

.dcd-totals {
    display: grid;
    gap: 4px;
}

.dcd-totals__row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: 14px;
    color: var(--dc-ink-2);
}

.dcd-totals__row dd { margin: 0; }
.dcd-totals__row.is-saving dd { color: var(--dc-success); }

.dcd-totals__row--total {
    margin-top: 4px;
    font-size: 17px;
    font-weight: 700;
    color: var(--dc-ink);
}

.dcd-foot__note {
    font-size: 12px;
    color: var(--dc-muted);
}

@media (max-width: 479px) {
    .dcd__scroll { padding: 4px 16px 16px; }
    .dcd__foot { padding-left: 16px; padding-right: 16px; }
    .dcd-item { grid-template-columns: 72px minmax(0, 1fr); gap: 12px; }
    .dcd-item__media { width: 72px; height: 72px; }
}

/* ---------- Personalisation popup ---------- */

.dpm {
    position: fixed;
    inset: 0;
    z-index: 100060;
    display: grid;
    place-items: center;
    padding: 16px;
    font-family: var(--dc-font);
    color: var(--dc-ink);
}

.dpm[hidden] { display: none; }

.dpm__overlay {
    position: absolute;
    inset: 0;
    background: rgba(23, 23, 23, .5);
    opacity: 0;
    transition: opacity .2s ease;
}

.dpm__dialog {
    position: relative;
    width: min(480px, 100%);
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    padding: 20px 24px 24px;
    border-radius: var(--dc-radius);
    background: var(--dc-surface);
    box-shadow: var(--dc-shadow-lg);
    transform: translateY(12px);
    opacity: 0;
    transition: transform .2s ease, opacity .2s ease;
}

.dpm.is-open .dpm__overlay { opacity: 1; }
.dpm.is-open .dpm__dialog { transform: none; opacity: 1; }

.dpm__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 0 -10px 12px 0;
}

.dpm__title {
    font-family: var(--dc-font-display);
    font-size: 22px;
    font-weight: 500;
}

.dpm__product {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px;
    border: 1px solid var(--dc-line);
    border-radius: var(--dc-radius-sm);
    background: var(--dc-bg);
}

.dpm__product img {
    width: 72px;
    height: 72px;
    object-fit: contain;
    border-radius: 6px;
    background: #fff;
}

.dpm__name { font-weight: 600; font-size: 15px; line-height: 1.35; }
.dpm__price { font-size: 14px; color: var(--dc-ink-2); margin-top: 2px !important; }

.dpm__lead {
    margin: 14px 0 4px !important;
    font-size: 13px;
    line-height: 1.5;
    color: var(--dc-muted);
}

.dpm__fields {
    display: grid;
    gap: 14px;
    margin-top: 12px;
}

.dpm-field { position: relative; }

.dpm-label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 600;
    color: var(--dc-ink);
}

.dpm-req { color: var(--dc-error); }
.dpm-opt { font-weight: 400; color: var(--dc-muted); }

.dpm-input {
    width: 100%;
    min-height: 48px;
    padding: 12px 14px;
    border: 1px solid var(--dc-line-strong);
    border-radius: var(--dc-radius-sm);
    background: #fff;
    font: 400 16px/1.3 var(--dc-font);
    color: var(--dc-ink);
}

.dpm-input:focus {
    outline: none;
    border-color: var(--dc-ink);
    box-shadow: var(--dc-focus);
}

.dpm-field.has-error .dpm-input,
.dpm-field.has-error .dpm-drop { border-color: var(--dc-error); }

.dpm-count {
    position: absolute;
    top: 2px;
    right: 0;
    font-size: 12px;
    color: var(--dc-muted);
}

.dpm-drop {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 56px;
    padding: 12px 14px;
    border: 1px dashed var(--dc-line-strong);
    border-radius: var(--dc-radius-sm);
    background: var(--dc-bg);
    font-size: 14px;
    cursor: pointer;
}

.dpm-drop:hover { border-color: var(--dc-ink); }
.dpm-drop small { margin-left: auto; color: var(--dc-muted); }
.dpm-drop span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dpm-field.is-uploading .dpm-drop { opacity: .7; }
.dpm-field.is-done .dpm-drop { border-style: solid; border-color: var(--dc-success); }
.dpm-file:focus-visible + .dpm-error,
.dpm-field:focus-within .dpm-drop { box-shadow: var(--dc-focus); }

.dpm-error,
.dpm__form-error {
    margin-top: 6px !important;
    font-size: 13px;
    color: var(--dc-error);
}

.dpm__actions {
    display: grid;
    justify-items: center;
    gap: 10px;
    margin-top: 20px;
}

@media (max-width: 479px) {
    .dpm { padding: 0; place-items: end center; }
    .dpm__dialog {
        width: 100%;
        max-height: 92vh;
        border-radius: var(--dc-radius) var(--dc-radius) 0 0;
        padding: 16px 16px calc(20px + env(safe-area-inset-bottom, 0px));
        transform: translateY(40px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .dcd__panel, .dcd__overlay, .dpm__dialog, .dpm__overlay { transition: none; }
}

@media print {
    .dcd, .dpm { display: none !important; }
}
