/* ZAD Media Archive — glass / luxury gallery. Theme-aware via CSS variables (snow / pearl / obsidian / light). */
.ma-root {
    --ma-surface: var(--surface, var(--glass-bg, var(--card, #ffffff)));
    --ma-card: var(--card, var(--surface, #ffffff));
    --ma-text: var(--text, #0f172a);
    --ma-muted: var(--text-muted, #64748b);
    --ma-accent: var(--accent, #0078d4);
    --ma-border: var(--glass-border, rgba(127, 140, 160, .28));
    --ma-shadow: var(--glass-shadow, 0 12px 40px rgba(15, 23, 42, .12));
    --ma-input: var(--input-bg, rgba(255, 255, 255, .6));
    --ma-radius: 18px;
    --ma-a1: var(--ma-accent);
    --ma-a2: color-mix(in srgb, var(--ma-accent) 55%, #a855f7);
    --ma-a3: color-mix(in srgb, var(--ma-accent) 60%, #22d3ee);
    color: var(--ma-text);
    position: relative;
    padding-bottom: 2rem;
}

/* ── KPI strip ─────────────────────────────────────────────── */
.ma-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.ma-kpi {
    position: relative;
    overflow: hidden;
    padding: 18px 20px;
    border-radius: var(--ma-radius);
    background: linear-gradient(145deg, color-mix(in srgb, var(--ma-surface) 92%, transparent), color-mix(in srgb, var(--ma-surface) 70%, transparent));
    border: 1px solid var(--ma-border);
    box-shadow: var(--ma-shadow), inset 0 1px 0 rgba(255, 255, 255, .25);
    backdrop-filter: blur(16px) saturate(140%);
    -webkit-backdrop-filter: blur(16px) saturate(140%);
    animation: ma-rise .6s cubic-bezier(.2, .8, .2, 1) both;
    transition: transform .25s ease, box-shadow .25s ease;
}
.ma-kpi:nth-child(2) { animation-delay: .06s; }
.ma-kpi:nth-child(3) { animation-delay: .12s; }
.ma-kpi:nth-child(4) { animation-delay: .18s; }
.ma-kpi:hover { transform: translateY(-3px); }
.ma-kpi::before {
    content: "";
    position: absolute;
    inset-inline-end: -40px;
    top: -40px;
    width: 130px;
    height: 130px;
    border-radius: 50%;
    background: radial-gradient(circle, var(--ma-a2), transparent 70%);
    opacity: .28;
    animation: ma-pulse 4.2s ease-in-out infinite;
}
.ma-kpi:nth-child(2)::before { background: radial-gradient(circle, var(--ma-a3), transparent 70%); animation-delay: .6s; }
.ma-kpi:nth-child(3)::before { background: radial-gradient(circle, #f59e0b, transparent 70%); animation-delay: 1.2s; }
.ma-kpi:nth-child(4)::before { background: radial-gradient(circle, #10b981, transparent 70%); animation-delay: 1.8s; }
.ma-kpi-ico {
    width: 38px; height: 38px;
    display: grid; place-items: center;
    border-radius: 12px;
    font-size: 1.15rem;
    background: color-mix(in srgb, var(--ma-accent) 16%, transparent);
    margin-bottom: 10px;
}
.ma-kpi-val {
    font-size: 1.85rem;
    font-weight: 800;
    letter-spacing: -.02em;
    line-height: 1.1;
    background: linear-gradient(120deg, var(--ma-text), var(--ma-a2));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.ma-kpi-lab {
    margin-top: 4px;
    font-size: .8rem;
    font-weight: 600;
    color: var(--ma-muted);
    text-transform: uppercase;
    letter-spacing: .06em;
}

/* ── Charts ────────────────────────────────────────────────── */
.ma-charts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.ma-chart {
    padding: 16px 18px 18px;
    border-radius: var(--ma-radius);
    background: color-mix(in srgb, var(--ma-surface) 86%, transparent);
    border: 1px solid var(--ma-border);
    box-shadow: var(--ma-shadow);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}
.ma-chart h4 {
    margin: 0 0 12px;
    font-size: .9rem;
    font-weight: 700;
    color: var(--ma-text);
}
.ma-hbar { display: grid; gap: 9px; }
.ma-hrow { display: grid; grid-template-columns: minmax(70px, 34%) 1fr auto; align-items: center; gap: 10px; font-size: .78rem; }
.ma-hrow-lab { color: var(--ma-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ma-hrow-val { color: var(--ma-text); font-weight: 700; font-variant-numeric: tabular-nums; }
.ma-track { height: 10px; border-radius: 99px; background: color-mix(in srgb, var(--ma-muted) 16%, transparent); overflow: hidden; }
.ma-fill {
    height: 100%;
    width: var(--w, 0%);
    border-radius: 99px;
    background: linear-gradient(90deg, var(--ma-a1), var(--ma-a2));
    transform-origin: left center;
    animation: ma-grow-x .9s cubic-bezier(.2, .8, .2, 1) both;
    animation-delay: var(--d, 0s);
    box-shadow: 0 0 12px color-mix(in srgb, var(--ma-a2) 45%, transparent);
}
[dir="rtl"] .ma-fill, .ma-root.is-rtl .ma-fill { transform-origin: right center; }
.ma-fill.kind-1 { background: linear-gradient(90deg, #38bdf8, #6366f1); }
.ma-fill.kind-2 { background: linear-gradient(90deg, #f472b6, #a855f7); }
.ma-fill.kind-3 { background: linear-gradient(90deg, #fbbf24, #f97316); }
.ma-fill.kind-4 { background: linear-gradient(90deg, #94a3b8, #64748b); }

.ma-vbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; height: 130px; padding-top: 6px; }
.ma-vcol { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; min-width: 0; }
.ma-vcol-n { font-size: .7rem; font-weight: 700; color: var(--ma-text); font-variant-numeric: tabular-nums; }
.ma-vcol-bar {
    width: 100%;
    max-width: 34px;
    height: var(--h, 4%);
    min-height: 4px;
    border-radius: 9px 9px 4px 4px;
    background: linear-gradient(180deg, var(--ma-a3), var(--ma-a1));
    transform-origin: bottom center;
    animation: ma-grow-y .9s cubic-bezier(.2, .8, .2, 1) both;
    animation-delay: var(--d, 0s);
    box-shadow: 0 6px 16px color-mix(in srgb, var(--ma-a1) 35%, transparent);
}
.ma-vcol-bar.is-zero { opacity: .35; box-shadow: none; }
.ma-vcol-d { font-size: .66rem; color: var(--ma-muted); white-space: nowrap; }
.ma-chart-empty { color: var(--ma-muted); font-size: .8rem; padding: 14px 0; text-align: center; }

/* ── Toolbar ───────────────────────────────────────────────── */
.ma-toolbar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 10px;
    padding: 12px 14px;
    margin-bottom: 16px;
    border-radius: var(--ma-radius);
    background: color-mix(in srgb, var(--ma-surface) 88%, transparent);
    border: 1px solid var(--ma-border);
    box-shadow: var(--ma-shadow);
    backdrop-filter: blur(18px) saturate(150%);
    -webkit-backdrop-filter: blur(18px) saturate(150%);
}
.ma-field { display: grid; gap: 3px; min-width: 130px; }
.ma-field.grow { flex: 1 1 220px; }
.ma-field > span { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--ma-muted); }
.ma-field input, .ma-field select {
    height: 38px;
    padding: 0 12px;
    border-radius: 11px;
    border: 1px solid var(--input-border, var(--ma-border));
    background: var(--ma-input);
    color: var(--input-text, var(--ma-text));
    font: inherit;
    font-size: .88rem;
    outline: none;
    transition: border-color .2s, box-shadow .2s;
}
.ma-field input:focus, .ma-field select:focus {
    border-color: var(--ma-accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--ma-accent) 22%, transparent);
}
.ma-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-inline-start: auto; }
.ma-btn {
    height: 38px;
    padding: 0 16px;
    display: inline-flex; align-items: center; gap: 7px;
    border-radius: 11px;
    border: 1px solid var(--ma-border);
    background: color-mix(in srgb, var(--ma-surface) 80%, transparent);
    color: var(--ma-text);
    font: inherit; font-size: .85rem; font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}
.ma-btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(0, 0, 0, .14); }
.ma-btn:disabled { opacity: .55; cursor: progress; }
.ma-btn.primary { color: #fff; border-color: transparent; background: linear-gradient(135deg, var(--ma-a1), var(--ma-a2)); }
.ma-btn.danger { color: #fff; border-color: transparent; background: linear-gradient(135deg, #ef4444, #be123c); }
.ma-upload { position: relative; overflow: hidden; }
.ma-upload input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; font-size: 0; }

.ma-banner {
    margin-bottom: 14px; padding: 10px 14px; border-radius: 12px;
    background: color-mix(in srgb, var(--ma-accent) 14%, transparent);
    border: 1px solid color-mix(in srgb, var(--ma-accent) 35%, transparent);
    font-size: .85rem; display: flex; justify-content: space-between; align-items: center; gap: 10px;
    animation: ma-rise .35s ease both;
}
.ma-banner.err { background: rgba(239, 68, 68, .12); border-color: rgba(239, 68, 68, .4); }
.ma-banner button { background: none; border: 0; color: inherit; font-size: 1.1rem; cursor: pointer; }

.ma-count { font-size: .8rem; color: var(--ma-muted); margin: 0 4px 10px; }

/* ── Masonry grid ──────────────────────────────────────────── */
.ma-grid { column-width: 220px; column-gap: 14px; }
.ma-card {
    display: block;
    width: 100%;
    break-inside: avoid;
    margin: 0 0 14px;
    padding: 0;
    text-align: start;
    cursor: pointer;
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid var(--ma-border);
    background: color-mix(in srgb, var(--ma-surface) 90%, transparent);
    color: var(--ma-text);
    font: inherit;
    box-shadow: 0 6px 20px rgba(15, 23, 42, .08);
    transition: transform .28s cubic-bezier(.2, .8, .2, 1), box-shadow .28s ease, border-color .28s;
    animation: ma-rise .5s cubic-bezier(.2, .8, .2, 1) both;
    animation-delay: calc(var(--i, 0) * 25ms);
}
.ma-card:hover, .ma-card:focus-visible {
    transform: translateY(-6px) scale(1.012);
    border-color: color-mix(in srgb, var(--ma-accent) 55%, transparent);
    box-shadow: 0 22px 44px rgba(15, 23, 42, .22), 0 0 0 1px color-mix(in srgb, var(--ma-accent) 30%, transparent);
    outline: none;
}
.ma-thumb {
    position: relative;
    aspect-ratio: var(--ar, 4 / 3);
    background: linear-gradient(135deg, color-mix(in srgb, var(--ma-accent) 14%, transparent), color-mix(in srgb, var(--ma-a2) 12%, transparent));
    overflow: hidden;
    display: grid; place-items: center;
}
.ma-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .6s ease; }
.ma-card:hover .ma-thumb img { transform: scale(1.07); }
.ma-thumb img.is-doc { object-fit: contain; padding: 14px; }
.ma-thumb .ma-ico { font-size: 2.6rem; opacity: .8; }
.ma-kind {
    position: absolute; top: 9px; inset-inline-start: 9px;
    padding: 3px 9px; border-radius: 99px;
    font-size: .66rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase;
    color: #fff; background: rgba(15, 23, 42, .62);
    backdrop-filter: blur(8px);
}
.ma-kind.k1 { background: rgba(14, 116, 144, .72); }
.ma-kind.k2 { background: rgba(147, 51, 234, .72); }
.ma-kind.k3 { background: rgba(217, 119, 6, .78); }
.ma-play {
    position: absolute; inset: 0; display: grid; place-items: center;
    font-size: 2.2rem; color: #fff; text-shadow: 0 4px 18px rgba(0, 0, 0, .6);
}
.ma-meta { padding: 11px 13px 13px; display: grid; gap: 6px; }
.ma-name { font-size: .84rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ma-sub { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: .72rem; color: var(--ma-muted); }
.ma-chip {
    display: inline-block; max-width: 100%;
    padding: 2px 9px; border-radius: 99px;
    font-size: .68rem; font-weight: 700;
    color: var(--ma-accent);
    background: color-mix(in srgb, var(--ma-accent) 14%, transparent);
    border: 1px solid color-mix(in srgb, var(--ma-accent) 28%, transparent);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ── Empty / loading ───────────────────────────────────────── */
.ma-empty {
    text-align: center;
    padding: 56px 20px;
    border-radius: 24px;
    border: 1.5px dashed var(--ma-border);
    background: radial-gradient(circle at 50% 0%, color-mix(in srgb, var(--ma-accent) 12%, transparent), transparent 65%);
}
.ma-empty-ico { font-size: 3.4rem; display: inline-block; animation: ma-float 3.6s ease-in-out infinite; filter: drop-shadow(0 10px 18px rgba(0, 0, 0, .25)); }
.ma-empty h3 { margin: 12px 0 4px; font-size: 1.15rem; }
.ma-empty p { margin: 0 auto 16px; max-width: 420px; color: var(--ma-muted); font-size: .88rem; }
.ma-more { display: flex; justify-content: center; margin: 10px 0 4px; }
.ma-skel {
    height: 160px; border-radius: 16px; margin-bottom: 14px; break-inside: avoid;
    background: linear-gradient(100deg, color-mix(in srgb, var(--ma-muted) 10%, transparent) 30%, color-mix(in srgb, var(--ma-muted) 22%, transparent) 50%, color-mix(in srgb, var(--ma-muted) 10%, transparent) 70%);
    background-size: 220% 100%;
    animation: ma-shimmer 1.4s linear infinite;
}

/* ── Detail drawer ─────────────────────────────────────────── */
.ma-scrim {
    position: fixed; inset: 0; z-index: 1200;
    background: rgba(2, 6, 23, .55);
    backdrop-filter: blur(6px);
    animation: ma-fade .25s ease both;
}
.ma-drawer {
    position: fixed; top: 0; bottom: 0; inset-inline-end: 0;
    z-index: 1210;
    width: min(560px, 100vw);
    display: flex; flex-direction: column;
    background: color-mix(in srgb, var(--ma-card) 96%, transparent);
    color: var(--ma-text);
    border-inline-start: 1px solid var(--ma-border);
    box-shadow: -24px 0 70px rgba(0, 0, 0, .4);
    backdrop-filter: blur(22px);
    animation: ma-slide-in .38s cubic-bezier(.2, .8, .2, 1) both;
}
[dir="rtl"] .ma-drawer, .ma-root.is-rtl .ma-drawer { box-shadow: 24px 0 70px rgba(0, 0, 0, .4); animation-name: ma-slide-in-rtl; }
.ma-drawer-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--ma-border); }
.ma-drawer-head h3 { flex: 1; margin: 0; font-size: 1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ma-x { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--ma-border); background: transparent; color: inherit; font-size: 1.1rem; cursor: pointer; transition: transform .2s, background .2s; }
.ma-x:hover { transform: rotate(90deg); background: color-mix(in srgb, var(--ma-accent) 14%, transparent); }
.ma-drawer-body { flex: 1; overflow-y: auto; padding: 18px; display: grid; gap: 16px; align-content: start; }
.ma-preview {
    border-radius: 16px; overflow: hidden; min-height: 200px; max-height: 52vh;
    display: grid; place-items: center;
    background: repeating-conic-gradient(color-mix(in srgb, var(--ma-muted) 12%, transparent) 0 25%, transparent 0 50%) 50% / 20px 20px;
    border: 1px solid var(--ma-border);
}
.ma-preview img, .ma-preview video { max-width: 100%; max-height: 52vh; display: block; object-fit: contain; }
.ma-preview iframe, .ma-preview embed { width: 100%; height: 52vh; border: 0; background: #fff; }
.ma-preview .ma-nopreview { padding: 30px; text-align: center; color: var(--ma-muted); display: grid; gap: 10px; justify-items: center; }
.ma-preview .ma-nopreview img { width: 120px; height: 120px; }
.ma-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
.ma-table th { text-align: start; width: 38%; padding: 8px 10px; color: var(--ma-muted); font-weight: 600; vertical-align: top; }
.ma-table td { padding: 8px 10px; word-break: break-word; font-weight: 500; }
.ma-table tr + tr { border-top: 1px solid color-mix(in srgb, var(--ma-border) 70%, transparent); }
.ma-drawer-foot { display: flex; flex-wrap: wrap; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--ma-border); }

/* ── Motion ────────────────────────────────────────────────── */
@keyframes ma-rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes ma-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes ma-pulse { 0%, 100% { transform: scale(1); opacity: .22; } 50% { transform: scale(1.25); opacity: .38; } }
@keyframes ma-grow-x { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes ma-grow-y { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes ma-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-9px); } }
@keyframes ma-shimmer { from { background-position: 120% 0; } to { background-position: -120% 0; } }
@keyframes ma-slide-in { from { transform: translateX(100%); } to { transform: none; } }
@keyframes ma-slide-in-rtl { from { transform: translateX(-100%); } to { transform: none; } }

@media (max-width: 640px) {
    .ma-grid { column-width: 150px; column-gap: 10px; }
    .ma-toolbar { position: static; }
    .ma-actions { margin-inline-start: 0; width: 100%; }
    .ma-actions .ma-btn { flex: 1; justify-content: center; }
    .ma-kpi-val { font-size: 1.5rem; }
}
@media (prefers-reduced-motion: reduce) {
    .ma-root *, .ma-root *::before, .ma-scrim, .ma-drawer { animation: none !important; transition: none !important; }
}

/* ── Top bar button ────────────────────────────────────────── */
.media-archive-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px;
    border-radius: 10px;
    border: 1px solid var(--glass-border, rgba(127, 140, 160, .3));
    background: var(--glass-bg, transparent);
    color: var(--text, inherit);
    cursor: pointer; text-decoration: none; padding: 0;
    transition: transform .18s ease, color .18s ease, box-shadow .18s ease;
}
.media-archive-btn:hover, .media-archive-btn:focus-visible {
    transform: translateY(-1px);
    color: var(--accent, #0078d4);
    box-shadow: 0 6px 16px rgba(0, 0, 0, .18);
    outline: none;
}
.media-archive-btn svg { display: block; }
