/* پنل کاربری، کیف پول و شجره‌نامه — نسخه ۲ */
.aup-container, .aup-public, .aup-modal, .aup-tree-app, #aup-toast { --aup-line: #6b7280; --aup-primary: #2563eb; }

/* ===================== چیدمان کلی پنل ===================== */
.aup-container { display: flex; gap: 25px; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 12px; padding: 20px; font-family: inherit; max-width: 1280px; margin: 20px auto; box-sizing: border-box; }
.aup-container *, .aup-modal *, .aup-public * { box-sizing: border-box; }
.aup-sidebar { width: 240px; background: #fff; border-radius: 10px; padding: 20px; box-shadow: 0 2px 10px rgba(0,0,0,.04); flex-shrink: 0; align-self: flex-start; }
.aup-user-info { text-align: center; border-bottom: 1px solid #f1f5f9; padding-bottom: 15px; margin-bottom: 15px; }
.aup-avatar img { border-radius: 50%; border: 3px solid #3b82f6; }
.aup-wallet-badge { display: inline-block; background: #dcfce7; color: #166534; padding: 4px 12px; border-radius: 20px; font-size: 13px; font-weight: bold; margin-top: 8px; }
.aup-tabs { list-style: none; padding: 0; margin: 0; }
.aup-tabs li { padding: 12px 15px; border-radius: 8px; cursor: pointer; margin-bottom: 6px; transition: all .2s; font-weight: 500; }
.aup-tabs li.active, .aup-tabs li:hover { background: #eff6ff; color: #1d4ed8; }
.aup-logout { color: #dc2626; text-decoration: none; display: block; }
.aup-content { flex: 1 1 0; min-width: 0; background: #fff; border-radius: 10px; padding: 25px; box-shadow: 0 2px 10px rgba(0,0,0,.04); }
.aup-tab-content { display: none; }
.aup-tab-content.active { display: block; }
.aup-alert { background: #fef3c7; border: 1px solid #fcd34d; color: #92400e; padding: 14px 18px; border-radius: 8px; }

/* ===================== فرم‌ها و دکمه‌ها ===================== */
.aup-form-row { display: flex; gap: 15px; margin-bottom: 15px; }
.aup-form-group { flex: 1; margin-bottom: 12px; min-width: 0; }
.aup-form-group label, .aup-field > label { display: block; margin-bottom: 6px; font-size: 13px; color: #475569; }
.aup-form-group label small { color: #94a3b8; font-weight: normal; }
.aup-form-group input, .aup-form-group textarea, .aup-form-group select,
.aup-modal select, .aup-modal input[type=text], .aup-modal input[type=email] { width: 100%; padding: 10px; border: 1px solid #cbd5e1; border-radius: 6px; background: #fff; }
.aup-btn { padding: 10px 18px; border: none; border-radius: 6px; cursor: pointer; font-weight: bold; font-size: 14px; }
.aup-btn:disabled { opacity: .6; cursor: wait; }
.aup-btn-primary { background: #2563eb; color: #fff; }
.aup-btn-success { background: #16a344; color: #fff; }
.aup-btn-secondary { background: #475569; color: #fff; }
.aup-btn-danger { background: #dc2626; color: #fff; }
.aup-btn-ghost { background: #fff; color: #334155; border: 1px solid #cbd5e1; }
.aup-quick-amounts { display: flex; gap: 10px; margin: 10px 0; }
.aup-amt-btn { background: #f1f5f9; border: 1px solid #cbd5e1; padding: 8px 16px; border-radius: 6px; cursor: pointer; }
.aup-muted { color: #94a3b8; }

/* ===================== نوار ابزار و آمار ===================== */
.aup-tree-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; border-bottom: 1px solid #eee; padding-bottom: 12px; }
.aup-tree-hint { font-size: 13px; color: #475569; margin: 5px 0 0; line-height: 1.8; }
.aup-toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 10px; }
.aup-tb-group { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.aup-search { display: flex; align-items: center; gap: 4px; background: #fff; border: 1px solid #cbd5e1; border-radius: 8px; padding: 2px 6px; flex: 1 1 260px; max-width: 420px; }
.aup-search-input { border: 0 !important; outline: 0; flex: 1; min-width: 80px; padding: 8px 6px !important; background: transparent !important; box-shadow: none !important; }
.aup-search-count { font-size: 12px; color: #64748b; white-space: nowrap; }
.aup-tb { border: 1px solid #cbd5e1; background: #fff; color: #1e293b; border-radius: 6px; padding: 7px 12px; font-size: 13px; cursor: pointer; line-height: 1.2; font-family: inherit; }
.aup-tb:hover { background: #f1f5f9; }
.aup-tb.green { background: #4caf50; border-color: #4caf50; color: #fff; }
.aup-tb.red { background: #ef4444; border-color: #ef4444; color: #fff; }
.aup-tb.blue { background: #29a3d9; border-color: #29a3d9; color: #fff; }
.aup-tb.dark { background: #475569; border-color: #475569; color: #fff; }
.aup-tb.green:hover, .aup-tb.red:hover, .aup-tb.blue:hover, .aup-tb.dark:hover { filter: brightness(.92); }
.aup-zoom-level { min-width: 56px; }
.aup-stats { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.aup-stat { background: #f1f5f9; border-radius: 8px; padding: 6px 14px; text-align: center; min-width: 72px; }
.aup-stat b { display: block; font-size: 17px; color: #0f172a; }
.aup-stat span { font-size: 11px; color: #64748b; }

/* ===================== بوم شجره‌نامه ===================== */
.aup-tree-wrapper { position: relative; border-radius: 16px; border: 1px dashed #cbd5e1; background-color: #fcfdfd; overflow: hidden;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 800 600' width='100%25' height='100%25' opacity='0.08'%3E%3Cpath d='M400 580 Q400 350 400 200 M400 380 Q280 300 180 260 M400 340 Q520 260 620 220 M400 260 Q310 170 240 120 M400 240 Q490 150 560 100' stroke='%235c4033' stroke-width='24' fill='none' stroke-linecap='round'/%3E%3Ccircle cx='180' cy='250' r='45' fill='%2365a30d'/%3E%3Ccircle cx='620' cy='210' r='50' fill='%2365a30d'/%3E%3Ccircle cx='240' cy='110' r='55' fill='%2384cc16'/%3E%3Ccircle cx='560' cy='90' r='55' fill='%2384cc16'/%3E%3Ccircle cx='400' cy='130' r='70' fill='%234d7c0f'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: center; background-size: contain; }
.aup-tree-viewport { overflow: auto; max-height: 78vh; min-height: 440px; direction: ltr; text-align: center; display: flex; justify-content: flex-start; justify-content: safe center; cursor: grab; -webkit-overflow-scrolling: touch; }
.aup-tree-viewport.dragging { cursor: grabbing; user-select: none; }
.aup-tree-canvas { flex: 0 0 auto; padding: 46px 40px 260px; }
.aup-empty-tree { padding: 80px 20px; text-align: center; direction: rtl; color: #475569; }
.only-print { display: none; }

.aup-tree { display: inline-block; }
.aup-tree ul { padding: 34px 0 0; position: relative; display: flex; justify-content: center; margin: 0; list-style: none; }
.aup-tree > ul { padding-top: 0; }
.aup-tree li { list-style: none; text-align: center; position: relative; padding: 34px 10px 0; }
.aup-tree li::before, .aup-tree li::after { content: ''; position: absolute; top: 0; right: 50%; border-top: 3px solid var(--aup-line); width: 50%; height: 34px; }
.aup-tree li::after { right: auto; left: 50%; border-left: 3px solid var(--aup-line); }
.aup-tree li:only-child::after, .aup-tree li:only-child::before { display: none; }
.aup-tree li:only-child { padding-top: 0; }
.aup-tree > ul > li:only-child { padding-top: 0; }
.aup-tree li:first-child::before, .aup-tree li:last-child::after { border: 0 none; }
.aup-tree li:last-child::before { border-right: 3px solid var(--aup-line); border-radius: 0 14px 0 0; }
.aup-tree li:first-child::after { border-radius: 14px 0 0 0; }
.aup-tree ul ul::before { content: ''; position: absolute; top: 0; left: 50%; margin-left: -1.5px; border-left: 3px solid var(--aup-line); width: 0; height: 34px; }
.aup-tree li.collapsed > ul { display: none; }

/* واحد = فرد اصلی + همسران */
.aup-unit { display: inline-flex; direction: rtl; gap: 20px; align-items: flex-start; position: relative; padding: 18px 0 6px; }

/* ===================== کارت هر فرد ===================== */
.aup-card { position: relative; direction: rtl; width: 132px; background: #fff; border: 1px solid #e5e7eb; border-radius: 12px; padding: 30px 8px 10px; box-shadow: 0 3px 10px rgba(15,23,42,.22); cursor: pointer; text-align: center; transition: transform .15s, box-shadow .15s; }
.aup-card:hover { transform: translateY(-2px); box-shadow: 0 8px 18px rgba(15,23,42,.26); }
.aup-card.menu-open { z-index: 70; }
.aup-card.is-spouse { background: var(--ring); background: color-mix(in srgb, var(--ring) 72%, #fff); border: 1px dashed #1f2937; color: #fff; }
.aup-card.is-spouse .aup-card-name { border-top-color: rgba(255,255,255,.7); color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.35); }
.aup-card.is-spouse .aup-card-meta, .aup-card.is-spouse .aup-card-dates { color: #fff; opacity: .92; }
.aup-card.deceased:not(.is-spouse) { border-color: #1f2937; }
.aup-card.is-private { opacity: .85; }

.aup-avatar-ring { width: 76px; height: 76px; margin: 6px auto 6px; border-radius: 50%; border: 3px solid var(--ring); box-shadow: 0 0 0 3px #fff inset, 0 0 0 2px rgba(255,255,255,.9); background: #f8fafc; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.aup-avatar-ring img { width: 100%; height: 100%; object-fit: cover; display: block; }
.aup-card.deceased .aup-avatar-ring { filter: grayscale(.75); }
.aup-ico { width: 1em; height: 1em; display: inline-block; vertical-align: middle; flex-shrink: 0; }
.aup-avatar-ring .aup-ico { width: 46px; height: 46px; }
.aup-ico.g-male { color: #2f80d0; }
.aup-ico.g-female { color: #d946b8; }
.aup-ico.g-unknown { color: #94a3b8; }

.aup-badge-top { position: absolute; top: -17px; left: 50%; transform: translateX(-50%); width: 32px; height: 32px; z-index: 2; filter: drop-shadow(0 2px 2px rgba(0,0,0,.35)); }
.aup-badge-top .aup-ico { width: 32px; height: 32px; }
.aup-badge-top.leaf { color: #16a34a; }
.aup-badge-top.cross { color: #fff; background: #111827; border-radius: 50%; padding: 6px; }
.aup-badge-top.heart.married, .aup-badge-top.heart.widowed { color: #ef2b2b; }
.aup-badge-top.heart.widowed { color: #111827; }
.aup-badge-top.heart.divorced { color: #6b7280; background: #fff; border-radius: 50%; padding: 5px; }
.aup-badge-info { position: absolute; top: 18px; left: 50%; transform: translateX(-50%); width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff; background: #15803d; color: #fff; padding: 2px; cursor: pointer; z-index: 3; line-height: 1; display: flex; align-items: center; justify-content: center; }
.aup-badge-info .aup-ico { width: 18px; height: 18px; }
.aup-badge-info:hover { background: #166534; transform: translateX(-50%) scale(1.12); }

.aup-card-name { font-weight: 800; font-size: 13px; line-height: 1.5; border-top: 1px solid #e5e7eb; margin-top: 4px; padding-top: 6px; word-break: break-word; color: #0f172a; }
.aup-card-meta { font-size: 11px; color: #475569; margin-top: 2px; }
.aup-card-dates { font-size: 11px; color: #64748b; margin-top: 2px; direction: ltr; unicode-bidi: plaintext; }
.aup-card.hit { outline: 3px solid #f59e0b; outline-offset: 2px; }
.aup-card.current-hit { outline-color: #ef4444; }
.aup-card.pulse { animation: aupPulse 1s ease 2; }
@keyframes aupPulse { 0%,100% { box-shadow: 0 0 0 0 rgba(34,197,94,.7); } 50% { box-shadow: 0 0 0 16px rgba(34,197,94,0); } }

/* دکمه بستن/باز کردن شاخه */
.aup-toggle { position: absolute; bottom: -12px; left: 50%; transform: translateX(-50%); height: 24px; min-width: 24px; padding: 0 6px; border-radius: 12px; border: 2px solid #fff; background: #166534; color: #fff; cursor: pointer; font-size: 17px; line-height: 18px; z-index: 5; display: inline-flex; align-items: center; justify-content: center; gap: 3px; box-shadow: 0 1px 4px rgba(0,0,0,.4); font-family: inherit; }
.aup-toggle .aup-t-plus, .aup-toggle .aup-t-count { display: none; }
.aup-toggle .aup-t-count { font-style: normal; font-size: 11px; font-weight: bold; }
li.collapsed > .aup-unit > .aup-toggle { background: #b45309; }
li.collapsed > .aup-unit > .aup-toggle .aup-t-minus { display: none; }
li.collapsed > .aup-unit > .aup-toggle .aup-t-plus, li.collapsed > .aup-unit > .aup-toggle .aup-t-count { display: inline; }

/* منوی عملیات کارت */
.aup-menu { display: none; position: absolute; top: calc(100% - 6px); left: 50%; transform: translateX(-50%); z-index: 80; width: 172px; background: #fff; color: #1e293b; border-radius: 10px; padding: 6px; box-shadow: 0 10px 28px rgba(0,0,0,.32); text-align: right; cursor: default; }
.aup-card.menu-open .aup-menu { display: block; animation: aupFade .15s ease; }
@keyframes aupFade { from { opacity: 0; margin-top: -6px; } to { opacity: 1; margin-top: 0; } }
.aup-menu-id { font-size: 12px; font-weight: bold; text-align: center; color: #0f172a; border-bottom: 1px solid #e5e7eb; padding: 2px 0 6px; margin-bottom: 4px; }
.aup-menu-btn { display: flex; align-items: center; gap: 8px; width: 100%; background: none; border: 0; padding: 7px 8px; border-radius: 6px; cursor: pointer; font-size: 13px; color: #1e293b; text-align: right; font-family: inherit; }
.aup-menu-btn .aup-ico { width: 18px; height: 18px; color: #16a34a; }
.aup-menu-btn:hover { background: #f1f5f9; }
.aup-menu-btn.danger { color: #dc2626; }
.aup-menu-btn.danger .aup-ico { color: #dc2626; }

/* ===================== مودال‌ها ===================== */
.aup-modal { position: fixed; z-index: 99999; left: 0; top: 0; width: 100%; height: 100%; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; padding: 14px; }
.aup-modal-content { background: #fff; padding: 22px; border-radius: 10px; width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto; position: relative; direction: rtl; text-align: right; }
.aup-modal-wide { max-width: 640px; padding: 0; }
.aup-modal-head { display: flex; justify-content: space-between; align-items: center; background: #3b82a6; color: #fff; padding: 12px 18px; position: sticky; top: 0; z-index: 3; }
.aup-modal-head h4 { margin: 0; color: #fff; font-size: 16px; }
.aup-modal-head .aup-close-modal { position: static; font-size: 26px; line-height: 1; color: #fff; }
.aup-close-modal { position: absolute; left: 18px; top: 12px; font-size: 24px; cursor: pointer; }
.aup-modal-content h4 { margin: 0 0 12px; }
#aup-member-form { padding: 6px 18px 0; }
.aup-req-note { margin: 12px 18px 0; font-size: 13px; border-bottom: 2px solid #eab308; display: inline-block; padding-bottom: 2px; }
.aup-rel-banner { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; padding: 10px 14px; border-radius: 8px; margin: 12px 18px 0; font-size: 13px; text-align: center; }
.aup-mtabs { display: flex; border-bottom: 1px solid #e2e8f0; margin: 14px 0; gap: 2px; overflow-x: auto; }
.aup-mtabs button { background: #f8fafc; border: 1px solid #e2e8f0; border-bottom: 0; padding: 9px 16px; cursor: pointer; border-radius: 6px 6px 0 0; font-size: 13px; color: #1d4ed8; font-family: inherit; white-space: nowrap; }
.aup-mtabs button.active { background: #fff; color: #0f172a; font-weight: bold; }
.aup-mpane { display: none; }
.aup-mpane.active { display: block; }
.aup-field { margin-bottom: 14px; }
.aup-readonly { background: #f1f5f9; padding: 10px; border-radius: 6px; color: #475569; font-size: 13px; }
.aup-box { padding: 10px 12px; margin: 10px 0; }
.aup-box.purple { background: #c9bfe3; }
.aup-box .aup-form-row { margin-bottom: 0; }
.aup-box .aup-form-group { margin-bottom: 4px; }
.aup-box-title { display: block; font-weight: bold; margin-bottom: 6px; font-size: 13px; }
.aup-box.req, .aup-form-group.req input { border-bottom: 3px solid #eab308; }
.aup-radio { margin-left: 18px; font-size: 14px; cursor: pointer; }
.aup-check { display: flex; gap: 8px; align-items: flex-start; margin: 12px 0; font-size: 13px; cursor: pointer; }
.aup-date-row { display: flex; gap: 8px; }
.aup-date-row select, .aup-date-row input { flex: 1; min-width: 0; }
.aup-date-row.disabled { opacity: .45; }
.aup-kb { font-size: 11px; margin-top: 4px; border-radius: 4px; padding: 2px 6px; display: inline-block; }
.aup-kb:empty { display: none; }
.aup-kb.ok { background: #dcfce7; color: #166534; }
.aup-kb.warn { background: #fee2e2; color: #991b1b; }
.aup-photo-row { display: flex; gap: 10px; align-items: center; }
#aup-photo-preview { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; border: 2px solid #cbd5e1; }
.aup-color-row { display: flex; gap: 10px; align-items: center; }
.aup-color-row input[type=color] { width: 46px; height: 36px; padding: 2px; border: 1px solid #cbd5e1; border-radius: 6px; background: #fff; }
.aup-modal-foot { display: flex; justify-content: flex-start; gap: 10px; border-top: 1px solid #e2e8f0; margin: 18px -18px 0; padding: 14px 18px; position: sticky; bottom: 0; background: #fff; }
.aup-rel-group { margin-bottom: 14px; }
.aup-rel-group b { display: block; margin-bottom: 6px; color: #334155; }
.aup-rel-link { display: inline-block; margin: 0 0 6px 6px; background: #eff6ff; border: 1px solid #bfdbfe; color: #1d4ed8; border-radius: 16px; padding: 5px 12px; cursor: pointer; font-size: 13px; font-family: inherit; }
.aup-rel-link:hover { background: #dbeafe; }

.aup-info-photo { display: block; width: 96px; height: 96px; border-radius: 50%; object-fit: cover; margin: 0 auto 12px; border: 3px solid #cbd5e1; }
.aup-info-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.aup-info-table th { text-align: right; color: #64748b; font-weight: normal; padding: 7px 4px; width: 32%; border-bottom: 1px solid #f1f5f9; vertical-align: top; }
.aup-info-table td { padding: 7px 4px; border-bottom: 1px solid #f1f5f9; word-break: break-word; white-space: pre-wrap; }

.aup-legend { list-style: none; margin: 0; padding: 0; }
.aup-legend li { display: flex; align-items: center; gap: 12px; padding: 7px 0; border-bottom: 1px solid #f1f5f9; font-size: 14px; }
.lg-ico { width: 30px; height: 30px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: #f1f5f9; flex-shrink: 0; font-weight: bold; }
.lg-ico .aup-ico { width: 20px; height: 20px; }
.lg-ico.blue { color: #2f80d0; } .lg-ico.pink { color: #d946b8; } .lg-ico.green { color: #16a34a; } .lg-ico.red { color: #ef2b2b; } .lg-ico.gray { color: #6b7280; }
.lg-ico.dark { background: #111827; color: #fff; } .lg-ico.toggle { background: #166534; color: #fff; }
.lg-ring { width: 30px; height: 30px; border-radius: 50%; border: 4px solid #16a34a; flex-shrink: 0; }
.aup-legend-note { font-size: 12px; color: #64748b; margin-top: 12px; line-height: 1.9; }

#aup-share-url { direction: ltr; text-align: left; margin: 12px 0; }
.aup-share-btns { display: flex; flex-wrap: wrap; gap: 8px; }

/* دیالوگ تایید تیره */
.aup-confirm { z-index: 100000; }
.aup-confirm-box { background: #1f1f23; color: #f1f1f4; border-radius: 14px; padding: 22px 24px 18px; width: 100%; max-width: 420px; text-align: right; box-shadow: 0 20px 50px rgba(0,0,0,.5); }
.aup-confirm-title { font-weight: bold; font-size: 16px; margin-bottom: 8px; }
.aup-confirm-msg { font-size: 14px; line-height: 2; color: #d4d4d8; }
.aup-confirm-btns { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-start; margin-top: 18px; }
.aup-cbtn { border: 1px solid #52525b; background: transparent; color: #f4f4f5; border-radius: 22px; padding: 9px 22px; cursor: pointer; font-size: 14px; font-family: inherit; }
.aup-cbtn.primary { background: #c4b5fd; border-color: #c4b5fd; color: #1e1b3a; font-weight: bold; }
.aup-cbtn.danger { background: #f87171; border-color: #f87171; color: #2b0a0a; font-weight: bold; }
.aup-cbtn:hover { filter: brightness(1.1); }

.aup-toast { position: fixed; bottom: 26px; left: 50%; transform: translate(-50%, 30px); background: #1f2937; color: #fff; padding: 11px 22px; border-radius: 10px; z-index: 100001; opacity: 0; pointer-events: none; transition: all .25s; font-size: 14px; max-width: 90vw; direction: rtl; }
.aup-toast.show { opacity: 1; transform: translate(-50%, 0); }
.aup-toast.err { background: #b91c1c; }

.aup-public { max-width: 1280px; margin: 20px auto; }
.aup-public-title { text-align: center; margin-bottom: 16px; }
.aup-admin-wrap { background: #fff; border: 1px solid #ccd0d4; padding: 15px; margin-top: 15px; }

@media (max-width: 782px) {
    .aup-container { flex-direction: column; padding: 10px; }
    .aup-sidebar { width: 100%; }
    .aup-form-row { flex-direction: column; gap: 0; }
    .aup-content { padding: 14px; }
    .aup-tree-viewport { max-height: 70vh; }
}

/* ===================== پرینت ===================== */
@media print {
    @page { size: A4 landscape; margin: 8mm; }
    body * { visibility: hidden; }
    .no-print { display: none !important; }
    #aup-printable-tree, #aup-printable-tree * { visibility: visible; }
    #aup-printable-tree { position: absolute; left: 0; top: 0; width: 100%; border: 0; background: none; overflow: visible !important; }
    .aup-tree-viewport { overflow: visible !important; max-height: none !important; }
    .aup-menu, .aup-toggle, .aup-badge-info { display: none !important; }
    .aup-tree li.collapsed > ul { display: flex !important; }
    .only-print { display: block; text-align: center; margin-bottom: 14px; direction: rtl; }
    .aup-container, .aup-tree-canvas, .aup-tree-app * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
