:root {
    --bg: #f9fafb;
    --surface: #ffffff;
    --surface-subtle: #f1f5f9;
    --border: rgba(15, 23, 42, 0.09);
    --border-strong: rgba(15, 23, 42, 0.16);
    --text: #0f172a;
    --text-muted: #475569;
    --text-soft: #64748b;
    --accent: #0f766e;
    --accent-hover: #115e59;
    --accent-soft: rgba(15, 118, 110, 0.09);
    --accent-ink: #ffffff;
    --danger: #b91c1c;
    --danger-soft: rgba(185, 28, 28, 0.08);
    --shadow-card: 0 16px 36px -18px rgba(15, 23, 42, 0.08);
    --shadow-float: 0 24px 48px -16px rgba(15, 23, 42, 0.16);
    --radius-xl: 1.5rem;
    --radius-lg: 1rem;
    --radius-md: 0.75rem;
    --radius-pill: 9999px;
    --font-sans: "Vazirmatn", system-ui, -apple-system, sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
}

[data-theme="dark"] {
    color-scheme: dark;
    --bg: #09090b;
    --surface: #131316;
    --surface-subtle: #1c1c21;
    --border: rgba(255, 255, 255, 0.09);
    --border-strong: rgba(255, 255, 255, 0.16);
    --text: #f4f4f5;
    --text-muted: #a1a1aa;
    --text-soft: #71717a;
    --accent: #14b8a6;
    --accent-hover: #2dd4bf;
    --accent-soft: rgba(20, 184, 166, 0.13);
    --accent-ink: #042f2e;
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, 0.12);
    --shadow-card: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 18px 36px -18px rgba(0, 0, 0, 0.6);
    --shadow-float: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 28px 56px -14px rgba(0, 0, 0, 0.75);
}

*,
*::before,
*::after {
    box-sizing: border-box;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

html {
    color-scheme: light;
    font-family: var(--font-sans);
    background-color: var(--bg);
    color: var(--text);
    scrollbar-gutter: stable;
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100svh;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.65;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: none;
    transition: background-color 0.25s ease, color 0.25s ease;
}

body.modal-open {
    overflow: hidden;
    touch-action: none;
}

img {
    max-width: 100%;
    display: block;
}

button,
input,
textarea,
select {
    font: inherit;
    color: inherit;
}

a {
    color: inherit;
    text-decoration: none;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Container & Navigation */
.page-container {
    width: 100%;
    max-width: 1320px;
    margin: 0 auto;
    padding-top: 0;
    padding-bottom: calc(4rem + env(safe-area-inset-bottom, 0px));
    padding-left: max(1.25rem, env(safe-area-inset-left, 0px));
    padding-right: max(1.25rem, env(safe-area-inset-right, 0px));
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    padding-top: env(safe-area-inset-top, 0px);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    background: rgba(249, 250, 251, 0.88);
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    border-bottom: 1px solid var(--border);
}

[data-theme="dark"] .topbar {
    background: rgba(9, 9, 11, 0.88);
    background: color-mix(in srgb, var(--bg) 82%, transparent);
}

.topbar-inner {
    max-width: 1320px;
    margin: 0 auto;
    padding: 0.9rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: -0.01em;
}

.brand-mark {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 0.7rem;
    background: var(--accent);
    color: var(--accent-ink);
    display: grid;
    place-items: center;
    flex-shrink: 0;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Buttons */
.btn,
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    transition: transform 0.14s cubic-bezier(0.22, 1, 0.36, 1),
        background-color 0.18s ease,
        border-color 0.18s ease,
        color 0.18s ease;
}

.btn:active,
.icon-btn:active {
    transform: scale(0.98);
}

.btn {
    padding: 0.65rem 1.05rem;
    min-height: 2.6rem;
}

.icon-btn {
    width: 2.5rem;
    height: 2.5rem;
    background: var(--surface);
    border-color: var(--border);
    color: var(--text);
}

.icon-btn:hover {
    border-color: var(--border-strong);
    background: var(--surface-subtle);
}

.btn-primary {
    background: var(--accent);
    color: var(--accent-ink);
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text);
}

.btn-secondary:hover {
    border-color: var(--border-strong);
    background: var(--surface-subtle);
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-muted);
}

.btn-ghost:hover {
    background: var(--surface-subtle);
    color: var(--text);
}

.btn-danger {
    background: var(--danger-soft);
    color: var(--danger);
    border-color: rgba(185, 28, 28, 0.25);
    border-color: color-mix(in srgb, var(--danger) 24%, transparent);
}

.btn-danger:hover {
    background: rgba(185, 28, 28, 0.16);
    background: color-mix(in srgb, var(--danger) 16%, transparent);
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

/* Asymmetric Hero */
.hero-grid {
    display: grid;
    grid-template-columns: 1.4fr 0.6fr;
    gap: 1.5rem;
    padding: 2.75rem 0 2rem;
    align-items: stretch;
}

.hero-main {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 1.5rem;
}

.eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    width: fit-content;
    padding: 0.3rem 0.75rem;
    border-radius: var(--radius-pill);
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 0.8rem;
    font-weight: 700;
}

.hero-title {
    margin: 0.75rem 0 0.75rem;
    font-size: clamp(1.85rem, 3.2vw, 2.85rem);
    line-height: 1.2;
    letter-spacing: -0.025em;
    font-weight: 800;
}

.hero-subtitle {
    margin: 0;
    color: var(--text-muted);
    font-size: 1rem;
    max-width: 58ch;
}

.hero-side {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    box-shadow: var(--shadow-card);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 1.25rem;
}

.stat-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.stat-cell {
    background: var(--surface-subtle);
    border-radius: var(--radius-lg);
    padding: 1rem;
}

.stat-value {
    font-family: var(--font-mono);
    font-size: 1.65rem;
    font-weight: 600;
    line-height: 1.1;
    color: var(--text);
}

.stat-label {
    margin-top: 0.35rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.hero-note {
    font-size: 0.85rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    padding-top: 1rem;
    margin: 0;
}

/* Search & Category Filters */
.controls-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 0 1.75rem;
    border-top: 1px solid var(--border);
}

.search-wrap {
    position: relative;
    flex: 1 1 280px;
    max-width: 420px;
}

.search-wrap svg {
    position: absolute;
    right: 0.9rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-soft);
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 0.7rem 2.6rem 0.7rem 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 0.92rem;
    transition: border-color 0.18s ease;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent);
}

.filter-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.filter-pill {
    padding: 0.45rem 0.9rem;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.filter-pill:hover {
    border-color: var(--border-strong);
    color: var(--text);
}

.filter-pill.is-active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
}

/* Asymmetric Bento Grid */
.bento-grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 1.25rem;
}

.assoc-card {
    grid-column: span 6;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 1.35rem;
    box-shadow: var(--shadow-card);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 1.25rem;
    animation: fadeUp 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
    animation-delay: calc(var(--stagger, 0) * 55ms);
    transition: border-color 0.2s ease, transform 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}

.assoc-card:hover {
    border-color: var(--border-strong);
    transform: translateY(-2px);
}

.assoc-card.is-featured {
    grid-column: span 7;
}

.assoc-card.is-companion {
    grid-column: span 5;
}

.assoc-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}

.assoc-identity {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    min-width: 0;
    flex: 1;
}

.assoc-avatar {
    width: 4.5rem;
    height: 4.5rem;
    border-radius: 1rem;
    object-fit: cover;
    border: 1px solid var(--border);
    background: var(--surface-subtle);
    flex-shrink: 0;
}

.assoc-avatar-fallback {
    width: 4.5rem;
    height: 4.5rem;
    border-radius: 1rem;
    border: 1px solid var(--border);
    background: var(--accent-soft);
    color: var(--accent);
    display: grid;
    place-items: center;
    font-weight: 800;
    font-size: 1.35rem;
    flex-shrink: 0;
}

.assoc-meta {
    min-width: 0;
    flex: 1;
}

.badge-pill {
    display: inline-block;
    padding: 0.2rem 0.65rem;
    border-radius: var(--radius-pill);
    background: var(--surface-subtle);
    color: var(--text-muted);
    font-size: 0.76rem;
    font-weight: 600;
    margin-bottom: 0.4rem;
}

.assoc-title {
    margin: 0;
    font-size: 1.18rem;
    font-weight: 700;
    line-height: 1.35;
}

.assoc-desc {
    margin: 0.45rem 0 0;
    font-size: 0.9rem;
    color: var(--text-muted);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* QR Tile on Card (Guaranteed White Quiet Zone) */
.qr-trigger {
    flex-shrink: 0;
    border: 1px solid var(--border);
    background: #ffffff;
    padding: 0.45rem;
    border-radius: 0.95rem;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    transition: transform 0.16s ease, border-color 0.16s ease;
}

.qr-trigger:hover {
    transform: scale(1.03);
    border-color: var(--accent);
}

.qr-trigger svg {
    width: 82px;
    height: 82px;
    display: block;
}

.qr-trigger-hint {
    font-size: 0.68rem;
    font-weight: 700;
    color: #334155;
}

/* Card Footer Actions */
.assoc-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}

.mono-handle {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: var(--text-muted);
    direction: ltr;
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 210px;
}

.assoc-buttons {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

/* Skeleton Loader */
.skeleton-card {
    grid-column: span 6;
    height: 225px;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
    background: linear-gradient(90deg,
            var(--surface) 25%,
            var(--surface-subtle) 50%,
            var(--surface) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite linear;
}

/* Empty & Error States */
.state-panel {
    grid-column: 1 / -1;
    background: var(--surface);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-xl);
    padding: 3rem 1.5rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.state-panel h3 {
    margin: 0;
    font-size: 1.15rem;
}

.state-panel p {
    margin: 0;
    color: var(--text-muted);
    max-width: 44ch;
    font-size: 0.92rem;
}

/* QR Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 60;
    background: rgba(9, 9, 11, 0.68);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    display: grid;
    place-items: center;
    padding: 1.25rem;
}

.modal-backdrop[hidden] {
    display: none;
}

.modal-surface {
    width: 100%;
    max-width: 440px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    box-shadow: var(--shadow-float);
    animation: fadeUp 0.22s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.modal-title {
    margin: 0.2rem 0 0;
    font-size: 1.2rem;
    font-weight: 700;
}

.modal-qr-stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.85rem;
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    background: var(--surface-subtle);
    margin-bottom: 1.25rem;
}

.qr-box-large {
    background: #ffffff;
    padding: 1rem;
    border-radius: 1rem;
    border: 1px solid rgba(15, 23, 42, 0.08);
}

.qr-box-large svg {
    width: 230px;
    height: 230px;
    display: block;
}

.modal-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.55rem;
}

/* Admin Panel (/path) */
.auth-shell {
    min-height: calc(100svh - 70px);
    display: grid;
    place-items: center;
    padding: 2rem 1rem;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 2rem;
    box-shadow: var(--shadow-card);
}

.admin-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 2rem 0 1.5rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.75rem;
}

.admin-split {
    display: grid;
    grid-template-columns: 1.15fr 0.85fr;
    gap: 1.5rem;
    align-items: start;
    margin-bottom: 2.5rem;
}

.panel-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    box-shadow: var(--shadow-card);
}

.panel-heading {
    margin: 0 0 1.25rem;
    font-size: 1.1rem;
    font-weight: 700;
}

.form-grid {
    display: grid;
    gap: 1rem;
}

.form-row-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.field label {
    font-size: 0.86rem;
    font-weight: 600;
    color: var(--text);
}

.field input[type="text"],
.field input[type="password"],
.field input[type="number"],
.field textarea {
    width: 100%;
    padding: 0.7rem 0.9rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--bg);
    font-size: 0.92rem;
    transition: border-color 0.16s ease;
}

.field input:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.field-hint {
    font-size: 0.78rem;
    color: var(--text-soft);
}

.field-error {
    font-size: 0.82rem;
    color: var(--danger);
    font-weight: 600;
}

.ltr-input {
    direction: ltr;
    text-align: left;
    font-family: var(--font-mono);
}

/* Image Dropzone */
.dropzone {
    border: 1.5px dashed var(--border-strong);
    border-radius: var(--radius-lg);
    padding: 1.15rem;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    transition: border-color 0.18s ease, background-color 0.18s ease;
}

.dropzone.is-dragover {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.dropzone-preview {
    width: 3.75rem;
    height: 3.75rem;
    border-radius: 0.8rem;
    object-fit: cover;
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.checkbox-line {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
}

.checkbox-line input {
    width: 1.1rem;
    height: 1.1rem;
    accent-color: var(--accent);
}

/* Admin Items List */
.admin-list {
    display: grid;
    gap: 0.75rem;
}

.admin-row {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 0.95rem 1.1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.admin-row-main {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    min-width: 0;
    flex: 1;
}

.admin-thumb {
    width: 3rem;
    height: 3rem;
    border-radius: 0.7rem;
    object-fit: cover;
    border: 1px solid var(--border);
    background: var(--surface-subtle);
    flex-shrink: 0;
}

.status-dot {
    display: inline-block;
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 50%;
    background: var(--accent);
    margin-left: 0.4rem;
}

.status-dot.is-hidden {
    background: var(--text-soft);
}

/* Footer */
.site-footer {
    margin-top: 3.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    color: var(--text-soft);
    font-size: 0.84rem;
}

/* Toasts */
.toast-root {
    position: fixed;
    bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
    left: 1.25rem;
    z-index: 80;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    background: var(--text);
    color: var(--bg);
    padding: 0.7rem 1.05rem;
    border-radius: var(--radius-md);
    font-size: 0.88rem;
    font-weight: 600;
    box-shadow: var(--shadow-float);
    animation: fadeUp 0.2s ease both;
}

.toast.is-error {
    background: var(--danger);
    color: #ffffff;
}

/* Animations */
@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Strict Mobile Collapse (< 768px) & iOS Auto-Zoom Prevention */
@media (max-width: 768px) {

    .hero-grid,
    .admin-split,
    .form-row-2 {
        grid-template-columns: 1fr;
    }

    .assoc-card,
    .assoc-card.is-featured,
    .assoc-card.is-companion,
    .skeleton-card {
        grid-column: span 12;
    }

    .assoc-top {
        flex-direction: column;
    }

    .qr-trigger {
        align-self: flex-start;
        flex-direction: row;
        padding: 0.5rem 0.75rem;
        gap: 0.65rem;
    }

    .qr-trigger svg {
        width: 64px;
        height: 64px;
    }

    .search-input,
    .field input[type="text"],
    .field input[type="password"],
    .field input[type="number"],
    .field textarea {
        font-size: 16px;
    }

    .toast-root {
        right: 1rem;
        left: 1rem;
    }
}