/* === Fonts === */
@font-face {
    font-family: 'Yekan';
    src: url("/static/fonts/YekanNewFaceD2-Regular.ttf") format("truetype");
}

@font-face {
    font-family: 'Yekan-bold';
    src: url("/static/fonts/YekanNewFaceD2-Bold.ttf") format("truetype");
}

/* === Theme tokens === */
:root {
    --bg: #031014;
    --panel: #0a2d36;
    --border: rgba(255, 255, 255, .08);
    --txt: #daf2f8;
    --muted: #86a3ab;
    --accent: #0daa2b;
    --danger: #dd1d65;
    --brand: #2a33a8;
}

/* === Base === */
* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--txt);
    font-family: 'Yekan', Tahoma, sans-serif;
}

.page {
    min-height: 100dvh;
    display: grid;
    place-items: start center;
    padding: 24px;
}

.card {
    width: min(880px, 96%);
    background: linear-gradient(180deg, #0b2230 0%, #07161a 100%);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 18px 18px 22px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
}

h1 {
    margin: 0 0 14px;
    font-size: 20px;
    color: #bfe0e8;
}

/* === Forms === */
.form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.row {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.row.two {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

label {
    font-size: 13px;
    color: #9fb1b8;
}

input, select, textarea {
    background: #0b2b30;
    color: #d6f0f4;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
    line-height: 1.9;
    font-family: 'Yekan', Tahoma, sans-serif;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}

textarea {
    min-height: 120px;
    resize: vertical;
}

input::placeholder, textarea::placeholder {
    color: #9bb7bf;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(42, 51, 168, .25);
    background: #103744;
}

.searchbar input[type="search"] {
    width: 100%;
    border-radius: 12px;
}

.checkbox {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.help {
    color: #7aa0aa;
    font-size: 12px;
}

.fieldset {
    border: 1px dashed rgba(255, 255, 255, .14);
    border-radius: 12px;
    padding: 12px;
}

.fieldset > legend {
    padding: 0 8px;
    color: #9bd0d9;
    font-size: 13px;
}

/* === Buttons === */
.actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 8px;
}

.btn {
    appearance: none;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 14px;
    font-family: 'Yekan', Tahoma, sans-serif; /* ← اضافه کن */
    color: #e8fbff;
    background: #0f3a48;
    cursor: pointer;
    transition: .15s ease;
}


.btn:hover {
    transform: translateY(-1px);
}

.btn.primary {
    background: var(--accent);
    color: #032126;
    border-color: transparent;
}

.btn.warn {
    background: var(--danger);
    border-color: transparent;
}

.btn:disabled, .btn[disabled] {
    opacity: .55;
    cursor: not-allowed;
    filter: grayscale(.1);
}

/* === Notices & Table === */
.notice {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #0b2b30;
    color: #bfe0e8;
}

.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 8px;
}

.table th, .table td {
    padding: 10px 12px;
    background: #0b2b30;
    border: 1px solid var(--border);
}

.table th {
    color: #9bd0d9;
    font-weight: 700;
}

/* === Wizard & Lists (committee_assign & assign_inline) === */
.wizard {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.section {
    background: #09161a;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 1rem;
    padding: 1rem;
}

.searchbar {
    margin: .5rem 0 .8rem;
    display: flex;
    gap: .5rem;
}

.list {
    max-height: 340px;
    overflow: auto;
    border: 1px dashed rgba(255, 255, 255, .08);
    border-radius: .6rem;
}

.list a {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .55rem .7rem;
    border-bottom: 1px solid rgba(255, 255, 255, .06);
    position: relative;
}

.list a, .list a:link, .list a:visited {
    color: #cfe7ee;
    text-decoration: none;
}

.list a:hover {
    background: #0c1e24;
}

.list .meta {
    opacity: .7;
    font-size: .85rem;
}

.list img {
    width: 38px;
    height: 38px;
    border-radius: .4rem;
    object-fit: cover;
    background: #0c1e24;
}

/* انتخاب‌شده (یکسان برای .pick و .person-row) */
.list a.selected,
.person-row.selected {
    border: 2px solid #3b82f6 !important;
    background: #0c1e24;
    position: relative;
}

.list a.selected::after,
.person-row.selected::after {
    content: "✓ انتخاب شد";
    position: absolute;
    top: 6px;
    left: 8px;
    font-size: .78rem;
    padding: .15rem .4rem;
    border-radius: .4rem;
    background: #134e4a;
    color: #d1fae5;
}

/* انتخاب‌ها */
.sel {
    min-height: 140px;
    background: #0b2b30;
    border: 1px dashed rgba(255, 255, 255, .08);
    border-radius: .6rem;
    padding: .6rem;
}

.chips {
    display: flex;
    gap: .45rem;
    flex-wrap: wrap;
    margin: .25rem 0 .75rem;
}

.chip {
    display: inline-block;
    padding: .35rem .6rem;
    border: 1px solid rgba(255, 255, 255, .15);
    border-radius: .6rem;
    cursor: pointer;
    user-select: none;
    color: #cfe7ee;
    text-decoration: none;
    background: #0e2e39;
}

.chip:hover {
    background: #0c1e24;
}

.chip.removing {
    border-color: #ef4444;
    background: #3b0d0d;
}

.muted {
    opacity: .8;
    font-size: .85rem;
}

.notice-inline {
    margin: .5rem 0;
}

/* === Modal (shared) === */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

/* نمایش/عدم‌نمایش مودال با aria-hidden */
.modal-backdrop[aria-hidden="true"] {
    display: none;
}

.modal-backdrop[aria-hidden="false"] {
    display: flex;
}

.modal {
    background: #fff;
    color: #123;
    border-radius: 12px;
    padding: 18px;
    width: 92%;
    max-width: 600px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, .35);
}

.modal h2 {
    margin: 0 0 10px;
    font-size: 18px;
    color: #0f3a48;
}

.modal .summary {
    border: 1px solid #e6eef2;
    border-radius: 10px;
    padding: 10px;
    background: #fbfdff;
}

.summary h4 {
    margin: 8px 0 6px;
    font-size: 14px;
    color: #264957;
}

.modal .actions {
    margin-top: 14px;
    display: flex;
    gap: 10px;
    justify-content: center;
}

/* === Buttons palette (success/error + ghost state) === */
.btn-success {
    background: var(--accent);
    border-color: var(--accent);
    color: #032126;
}

.btn-success:hover {
    filter: brightness(.95);
}

.btn-error {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

.btn-error:hover {
    filter: brightness(.96);
}

/* حالت ghost یعنی رأیِ فعلی کاربر (outline) */
.btn.ghost {
    background: transparent;
}

.btn-success.ghost {
    background: transparent;
    border-color: rgba(13, 170, 43, .45);
    color: var(--accent);
}

.btn-success.ghost:hover {
    background: rgba(13, 170, 43, .10);
    border-color: rgba(13, 170, 43, .65);
}

.btn-error.ghost {
    background: transparent;
    border-color: rgba(221, 29, 101, .45);
    color: var(--danger);
}

.btn-error.ghost:hover {
    background: rgba(221, 29, 101, .10);
    border-color: #b5164f; /* var(--danger-600) */
    color: #b5164f;
}

.badge-count {
    margin-inline-start: .5rem;
    background: #0e2e39;
    border-color: rgba(255, 255, 255, .18);
    font-weight: 700;
    padding: .25rem .55rem;
}

/* === Messages === */
.messages {
    margin: 0 0 1rem;
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

.msg {
    position: relative;
    padding: .75rem 1rem .75rem 2.25rem;
    border-radius: .75rem;
    border: 1px solid;
    overflow: hidden;
}

.msg::before {
    content: "";
    position: absolute;
    left: .6rem;
    top: 50%;
    transform: translateY(-50%);
    width: 1rem;
    height: 1rem;
    border-radius: 50%;
}

.msg.success {
    background: #052a18;
    border-color: #166534;
    color: #d1fae5;
}

.msg.success::before {
    background: #22c55e;
}

.msg.error {
    background: #2a1113;
    border-color: #7f1d1d;
    color: #fee2e2;
}

.msg.error::before {
    background: #ef4444;
}

.msg.warning {
    background: #2a1f06;
    border-color: #92400e;
    color: #ffedd5;
}

.msg.warning::before {
    background: #f59e0b;
}

.msg.info {
    background: #0a2430;
    border-color: #075985;
    color: #e0f2fe;
}

.msg.info::before {
    background: #38bdf8;
}

.msg .close {
    position: absolute;
    right: .6rem;
    top: .3rem;
    cursor: pointer;
    opacity: .75;
}

/* === Mandates list (scoped) === */
.mandates-table .actions-col {
    width: 1%;
    white-space: nowrap;
}

.actions-cell {
    display: flex;
    gap: 6px;
    align-items: center;
    justify-content: flex-start;
    flex-wrap: wrap;
}

.btn.sm.ghost {
    background: transparent;
    border: 1px dashed var(--border, #2a2d35);
}

.actions-cell details {
    position: relative;
}

.actions-cell details summary {
    list-style: none;
    cursor: pointer;
    display: inline-block;
}

.actions-cell details summary::-webkit-details-marker {
    display: none;
}

.actions-cell details[open] summary {
    opacity: 0.9;
}

.actions-cell .menu {
    position: absolute;
    z-index: 40;
    right: 0;
    top: calc(100% + 6px);
    min-width: 180px;
    padding: 6px;
    border: 1px solid var(--border, #2a2d35);
    border-radius: 10px;
    background: var(--card, #121318);
    box-shadow: 0 10px 24px rgba(0, 0, 0, .25);
}

.actions-cell .menu a {
    display: block;
    padding: 8px 10px;
    border-radius: 8px;
    line-height: 1.35;
}

.actions-cell .menu a:hover {
    background: rgba(255, 255, 255, .06);
}

/* === Responsive === */
@media (max-width: 820px) {
    .mandates-table th, .mandates-table td {
        font-size: 0.92rem;
    }
}

@media (max-width: 640px) {
    .mandates-table thead th:nth-child(4),
    .mandates-table tbody td:nth-child(4) {
        white-space: normal;
    }
}

@media (max-width: 640px) {
    .wizard {
        grid-template-columns: 1fr;
    }
}

/* === Mandate A4 (print-only scoped) === */
.sheet {
    width: 210mm;
    margin: 0 auto 18mm;
    background: #fff;
    color: #123;
    border: 1px solid #e7eef2;
    box-shadow: 0 10px 40px rgba(0, 0, 0, .15);
}

.sheet .container {
    padding: 22mm 18mm 16mm;
}

.sheet .hdr {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 10px;
}

.sheet .hdr .org {
    font-weight: 700;
    font-size: 18px;
}

.sheet .hdr .meta {
    font-size: 12px;
    line-height: 1.6;
    text-align: left;
}

/* فقط درون برگه چاپ رنگ تیتر را تغییر می‌دهیم */
.sheet h1 {
    color: #0f3a48;
}

.sheet .subtitle {
    margin: 4px 0 12px;
    color: #456;
    font-size: 13px;
}

.sheet .grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 8px;
}

.sheet .box {
    border: 1px solid #e6eef2;
    border-radius: 10px;
    padding: 10px 12px;
    background: #fbfdff;
}

.sheet .box h3 {
    margin: 0 0 8px;
    color: #0f3a48;
    font-size: 14px;
}

/* اسکوپ‌دهی row مخصوص چاپ تا با .row عمومی تداخل نکند */
.sheet .row {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px dashed #e6eef2;
}

.sheet .row:last-child {
    border-bottom: none;
}

.sheet .row > span {
    color: #567;
    font-size: 13px;
}

.sheet .row > b {
    color: #123;
    font-size: 13.5px;
}

.sheet .h3 {
    margin: 14px 0 8px;
    font-size: 14px;
    color: #0f3a48;
}

.sheet .clause-text {
    white-space: pre-wrap;
    line-height: 1.85;
    font-size: 12.8px;
    color: #222;
}

.sheet .clause-text.subtle {
    color: #444;
}

.sheet .committee {
    margin: 0;
    padding: 0 1.2rem;
    line-height: 1.9;
    font-size: 13.2px;
}

.sheet .signatures {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin: 16px 0 8px;
}

.sheet .sign-box .line {
    height: 42px;
    border-bottom: 1px solid #c7d6df;
    margin: 8px 0;
}

.sheet .sign-box .who {
    color: #345;
    font-size: 12.8px;
}

.sheet .ftr {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8mm 18mm 14mm;
    color: #345;
    font-size: 12px;
    background: #f3f8fb;
    border-top: 1px solid #e7eef2;
}

/* Toolbar (screen only) */
.toolbar {
    display: flex;
    justify-content: flex-end;
    padding: 10px 0;
}

@media print {
    body {
        background: #fff !important;
    }

    .toolbar {
        display: none !important;
    }

    .sheet {
        box-shadow: none !important;
        border: none !important;
        margin: 0;
    }

    .sheet .container {
        padding: 18mm 14mm 10mm;
    }

    .sheet .ftr {
        border: 0;
        background: #fff;
        padding: 8mm 14mm 0;
    }
}

/* === People list (assign_inline) === */
.people-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.person-row {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .55rem .7rem;
    border-bottom: 1px solid rgba(255, 255, 255, .06);
    cursor: pointer;
    transition: background .15s ease, transform .06s ease;
}

.person-row:last-child {
    border-bottom: 0;
}

.person-row:hover {
    background: #0c1e24;
}

.person-row:active {
    transform: translateY(1px);
}

.person-row .avatar-wrap {
    flex: 0 0 auto;
}

.person-row .avatar-wrap .avatar {
    width: 42px;
    height: 42px;
    border-radius: .5rem;
    object-fit: cover;
    background: #0c1e24;
    border: 1px solid rgba(255, 255, 255, .06);
}

.person-row .meta {
    display: grid;
    gap: .15rem;
}

.person-row .meta .name {
    font-size: .98rem;
    color: #e6f6fb;
    font-family: 'Yekan-bold', Tahoma, sans-serif;
}

.person-row .meta .hint {
    font-size: .78rem;
    color: #8fb0b9;
}

/* === Scrollbars for members list === */
#members-list {
    scrollbar-width: thin;
    scrollbar-color: #214957 transparent;
}

#members-list::-webkit-scrollbar {
    height: 8px;
    width: 8px;
}

#members-list::-webkit-scrollbar-thumb {
    background: #214957;
    border-radius: 8px;
}

#members-list::-webkit-scrollbar-track {
    background: transparent;
}

/* === A4 Resignation — روشن و فشرده (Scoped to .sheet) === */

/* گرید فشرده برای باکس‌های بالایی و آمار رأی‌ها */
.sheet .grid.compact {
    gap: 8px;
    margin-top: 4px;
}

/* تیتر بخش‌ها جمع‌وجورتر */
.sheet .h3 {
    margin: 12px 0 6px;
    font-size: 14px;
    color: #0f3a48;
}

/* چیپ‌های خلاصه */
.sheet .summary.row-grid {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    gap: 6px;
    margin: 8px 10mm 8px;
    align-items: start;
    overflow: hidden;
}

.sheet .chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border: 1px solid #e6eef2;
    border-radius: 999px;
    background: #fff;
    font-size: 12px;
}

.sheet .chip .k {
    color: #64748b;
}

.sheet .chip .v {
    color: #0f172a;
    font-weight: 600;
}

/* کلید-مقدار کم‌جا */
.sheet .kv {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 4px 10px;
    align-items: baseline;
    margin: 4px 0;
}

.sheet .kv .k {
    color: #64748b;
}

.sheet .kv .v {
    color: #0f172a;
    font-weight: 600;
}

/* کارت‌های روشن */
.sheet .card {
    background: #ffffff;
    border: 1px solid #e6eef2;
    border-radius: 8px;
    padding: 8px 10px;
    margin: 8px 10mm;
}

.sheet .card.lite {
    background: #fbfdff;
}

/* جدول روشن و فشرده */
.sheet .table.simple {
    width: 100%;
    border-collapse: collapse;
    border-spacing: 0;
    font-size: 12px;
}

.sheet .table.simple thead th {
    background: #f3f8fb;
    color: #334155;
    border: 1px solid #e6eef2;
    padding: 6px 8px;
    text-align: right;
}

.sheet .table.simple td {
    background: #ffffff;
    color: #123;
    border: 1px solid #e6eef2;
    padding: 6px 8px;
}

/* نشان‌های رأی */
.sheet .badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    line-height: 1.4;
    border: 1px solid #dbe8f0;
}

.sheet .badge.ok {
    color: #065f46;
    background: #d1fae5;
    border-color: #a7f3d0;
}

.sheet .badge.no {
    color: #7f1d1d;
    background: #fee2e2;
    border-color: #fecaca;
}

.sheet .badge.ghost {
    color: #475569;
    background: #e2e8f0;
    border-color: #cbd5e1;
}

.sheet .muted {
    color: #64748b;
}

/* استایل بخش امضاها */
.sheet .signatures {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10mm;
    margin: 6mm 10mm 10mm;
}

.sheet .sign .label {
    color: #0f172a;
    margin-bottom: 6px;
}

.sheet .sign .line {
    height: 16mm;
    border-bottom: 1px dashed #94a3b8;
}

/* چاپ پاکیزه */
@media print {
    @page {
        size: A4;
        margin: 12mm;
    }

    .toolbar {
        display: none !important;
    }

    body {
        background: #fff !important;
    }

    .sheet {
        box-shadow: none !important;
        margin: 0 !important;
    }

    .sheet .card, .sheet .signatures, .sheet .grid, .sheet .row-grid, .sheet .table, .sheet .hdr, .sheet .ftr {
        page-break-inside: avoid;
    }
}

/* ========== Mandates: responsive helpers (v2025-09-30) ========== */

/* فاصلهٔ امن از فوتر ثابت (اگر footer.html موجود باشد) */
:root {
    --footer-height: 60px;
}

html:has(.footer-nav) body,
body:has(.footer-nav) {
    padding-bottom: calc(var(--footer-height) + env(safe-area-inset-bottom) + 12px);
}

/* ظرف استاندارد عریض ولی ریسپانسیو */
.w-max-1120 {
    width: min(1120px, 96%);
    margin-inline: auto;
}

/* جدول‌های عریض: قاب اسکرول افقی امن در موبایل */
.table-wrap {
    overflow-x: auto;
}

.table.simple, .mandates-table {
    min-width: 720px;
}

@media (max-width: 900px) {
    .table.simple, .mandates-table {
        min-width: 680px;
    }
}

/* دکمه‌ها مناسب لمس در موبایل */
.btn, .btn.primary, .btn.warn, .btn.sm {
    min-height: 44px;
}

/* کمکی‌ها (جایگزین استایل‌های inline) */
.mt-05 {
    margin-top: .25rem;
}

.mt-1 {
    margin-top: 1rem;
}

.mb-1 {
    margin-bottom: .75rem;
}

.pad-sm {
    padding: .6rem .8rem;
}

.prewrap {
    white-space: pre-wrap;
}

.col-actions {
    width: clamp(200px, 40vw, 320px);
}

/* ستون اقدامات ریسپانسیو */
/* --- Mandate detail: mobile polish --- */
.card .table td {
    word-break: break-word;
}

/* ستون عنوانِ سطرها؛ بدون inline-style */
.card .table tbody tr > th:first-child {
    width: clamp(120px, 40vw, 180px);
}

/* دکمه‌ها در موبایل نشکنند/زیر هم بروند */
@media (max-width: 720px) {
    .actions {
        flex-wrap: wrap;
        justify-content: flex-start;
    }
}

/* iOS Safari: prevent auto-zoom on input focus */
@media (max-width: 820px) {
    input, select, textarea {
        font-size: 16px;
    }
}

/* keep text sizing predictable on iOS */
html {
    -webkit-text-size-adjust: 100%;
}

@media (max-width: 560px) {
    .row.two {
        grid-template-columns: 1fr;
    }
}

.sign-caption {
    font-size: .9em;
    margin-top: .25rem;
}

.badge-yellow {
    background: #3d2f00;
    border: 1px solid rgba(255, 208, 0, .35);
    color: #ffd35c;
}

.badge-red {
    background: #3a0d12;
    border: 1px solid rgba(255, 89, 89, .35);
    color: #ff8a9a;
}
