/*
 * کیت رابط دلوین — «یک صفحه، دو پوسته» (۱۹ سپتامبر ۲۰۲۶)
 * هر قطعه یک بار نوشته می‌شود و در index.html (دسکتاپ) و mobile.html (گوشی) یکسان کار می‌کند.
 * همه‌ی کلاس‌ها با پیشوند dk- تا با style.css و mobile-app.css تداخل نکنند.
 * رنگ‌ها از متغیرهای مشترک دو پوسته خوانده می‌شوند؛ حالت شب با [data-theme="dark"].
 * مرز گوشی/دسکتاپ: 768px (همان DK.isMobile).
 */

:root {
    --dk-accent: var(--brand, var(--primary-color, #3b82f6));
    --dk-accent-rgb: var(--brand-rgb, 59, 130, 246);
    --dk-surface: var(--bg-primary, #ffffff);
    --dk-ground: var(--bg-secondary, #f8fafc);
    --dk-sunken: var(--bg-tertiary, #f1f5f9);
    --dk-line: var(--border-color, #e5e7eb);
    --dk-text: var(--text-primary, #1f2937);
    --dk-muted: var(--text-secondary, #6b7280);
    --dk-faint: var(--text-tertiary, #9ca3af);
    --dk-radius: 14px;
    --dk-radius-sm: 10px;
    --dk-shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 14px rgba(15, 23, 42, .04);
    --dk-shadow-lift: 0 18px 50px rgba(15, 23, 42, .22);

    /* رنگ‌های معنایی: زمینه‌ی کم‌رنگ + متن پررنگ، ملایم (قاعده‌ی پیشخوان: رنگ تند نه) */
    --dk-neutral-bg: rgba(100, 116, 139, .12);  --dk-neutral-fg: #475569;
    --dk-info-bg: rgba(59, 130, 246, .12);      --dk-info-fg: #1d4ed8;
    --dk-success-bg: rgba(16, 185, 129, .13);   --dk-success-fg: #047857;
    --dk-warning-bg: rgba(245, 158, 11, .16);   --dk-warning-fg: #b45309;
    --dk-danger-bg: rgba(239, 68, 68, .12);     --dk-danger-fg: #b91c1c;
    --dk-violet-bg: rgba(139, 92, 246, .13);    --dk-violet-fg: #6d28d9;
}

[data-theme="dark"] {
    --dk-shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .18);
    --dk-shadow-lift: 0 18px 50px rgba(0, 0, 0, .55);
    --dk-neutral-bg: rgba(148, 163, 184, .16); --dk-neutral-fg: #cbd5e1;
    --dk-info-bg: rgba(96, 165, 250, .16);     --dk-info-fg: #93c5fd;
    --dk-success-bg: rgba(52, 211, 153, .15);  --dk-success-fg: #6ee7b7;
    --dk-warning-bg: rgba(251, 191, 36, .15);  --dk-warning-fg: #fcd34d;
    --dk-danger-bg: rgba(248, 113, 113, .15);  --dk-danger-fg: #fca5a5;
    --dk-violet-bg: rgba(167, 139, 250, .16);  --dk-violet-fg: #c4b5fd;
}

/* ───────── ریشه‌ی صفحه ───────── */
.dk-page {
    direction: rtl;
    color: var(--dk-text);
    font-family: inherit;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-bottom: 8px;
    min-width: 0;
}
.dk-page *, .dk-layer * { box-sizing: border-box; }
.dk-page [hidden], .dk-layer [hidden] { display: none !important; }
.dk-page svg, .dk-layer svg { flex-shrink: 0; }

/* ───────── سربرگ ───────── */
.dk-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.dk-head h2 {
    margin: 0;
    font-size: 1.3rem;
    font-weight: 800;
    line-height: 1.4;
    text-wrap: balance;
}
.dk-head p { margin: 2px 0 0; color: var(--dk-muted); font-size: .86rem; }
.dk-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ───────── دکمه ───────── */
.dk-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 40px;
    padding: 0 16px;
    border-radius: var(--dk-radius-sm);
    border: 1px solid var(--dk-line);
    background: var(--dk-surface);
    color: var(--dk-text);
    font: inherit;
    font-size: .88rem;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s, border-color .15s, opacity .15s;
    -webkit-tap-highlight-color: transparent;
}
.dk-btn:hover { background: var(--dk-sunken); }
.dk-btn:focus-visible, .dk-input:focus-visible, .dk-tab:focus-visible, .dk-x:focus-visible {
    outline: 2px solid var(--dk-accent);
    outline-offset: 2px;
}
.dk-btn svg { width: 16px; height: 16px; }
.dk-btn--primary { background: var(--dk-accent); border-color: var(--dk-accent); color: #fff; }
.dk-btn--primary:hover { background: var(--dk-accent); opacity: .9; }
.dk-btn--danger { color: var(--dk-danger-fg); border-color: var(--dk-danger-bg); background: var(--dk-danger-bg); }
.dk-btn--ghost { border-color: transparent; background: transparent; }
.dk-btn--sm { min-height: 32px; padding: 0 10px; font-size: .8rem; }
.dk-btn--icon { width: 36px; min-height: 36px; padding: 0; }
.dk-btn[disabled], .dk-btn.is-busy { opacity: .6; cursor: default; pointer-events: none; }
.dk-btn.is-busy::before {
    content: '';
    width: 14px; height: 14px;
    border-radius: 50%;
    border: 2px solid currentColor;
    border-top-color: transparent;
    animation: dk-spin .7s linear infinite;
}

/* ───────── سطح (کارت/پنل) ───────── */
.dk-panel {
    background: var(--dk-surface);
    border: 1px solid var(--dk-line);
    border-radius: var(--dk-radius);
    box-shadow: var(--dk-shadow);
    padding: 18px;
    min-width: 0;
}
.dk-panel-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    margin: 0 0 14px;
}
.dk-panel-title h3 { margin: 0; font-size: 1rem; font-weight: 800; }

/* ───────── کارت آمار ───────── */
.dk-stats {
    display: grid;
    grid-template-columns: repeat(var(--dk-cols, 4), minmax(0, 1fr));
    gap: 12px;
}
.dk-stat {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--dk-surface);
    border: 1px solid var(--dk-line);
    border-radius: var(--dk-radius);
    box-shadow: var(--dk-shadow);
    padding: 14px 16px;
    min-width: 0;
    text-align: right;
    font: inherit;
    color: inherit;
}
button.dk-stat { cursor: pointer; }
.dk-stat-icon {
    width: 40px; height: 40px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.dk-stat-icon svg { width: 20px; height: 20px; }
.dk-stat-val {
    font-size: 1.45rem;
    font-weight: 800;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}
.dk-stat-lbl { font-size: .76rem; color: var(--dk-muted); margin-top: 2px; }

/* ───────── برچسب وضعیت ───────── */
.dk-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: .74rem;
    font-weight: 700;
    white-space: nowrap;
    line-height: 1.5;
    background: var(--dk-neutral-bg);
    color: var(--dk-neutral-fg);
}
.dk-tone-info    { background: var(--dk-info-bg);    color: var(--dk-info-fg); }
.dk-tone-success { background: var(--dk-success-bg); color: var(--dk-success-fg); }
.dk-tone-warning { background: var(--dk-warning-bg); color: var(--dk-warning-fg); }
.dk-tone-danger  { background: var(--dk-danger-bg);  color: var(--dk-danger-fg); }
.dk-tone-violet  { background: var(--dk-violet-bg);  color: var(--dk-violet-fg); }
.dk-tone-neutral { background: var(--dk-neutral-bg); color: var(--dk-neutral-fg); }

/* ───────── نوار پیشرفت ───────── */
.dk-progress { display: flex; align-items: center; gap: 8px; min-width: 90px; }
.dk-progress-track {
    flex: 1;
    height: 7px;
    border-radius: 999px;
    background: var(--dk-sunken);
    overflow: hidden;
}
.dk-progress-fill {
    height: 100%;
    border-radius: inherit;
    background: var(--dk-accent);
    transition: width .4s ease;
}
.dk-progress-val {
    font-size: .74rem;
    font-weight: 700;
    color: var(--dk-muted);
    min-width: 34px;
    font-variant-numeric: tabular-nums;
}

/* ───────── فیلترها ───────── */
.dk-filters { display: flex; flex-direction: column; gap: 10px; }
.dk-filters-toggle { display: none; }
.dk-filters-body {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 10px;
    align-items: end;
}

/* ───────── فرم ───────── */
.dk-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.dk-form--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.dk-span-all { grid-column: 1 / -1; }
.dk-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.dk-field > label { font-size: .8rem; font-weight: 700; color: var(--dk-muted); }
.dk-field > label .dk-req { color: var(--dk-danger-fg); }
.dk-hint { font-size: .72rem; color: var(--dk-faint); }
.dk-input {
    width: 100%;
    min-height: 42px;
    padding: 8px 12px;
    border: 1px solid var(--dk-line);
    border-radius: var(--dk-radius-sm);
    background: var(--dk-surface);
    color: var(--dk-text);
    font: inherit;
    font-size: .9rem;
}
textarea.dk-input { min-height: 84px; resize: vertical; line-height: 1.7; }
select.dk-input { cursor: pointer; }
.dk-input:disabled { background: var(--dk-sunken); color: var(--dk-faint); cursor: not-allowed; }
.dk-fieldset {
    grid-column: 1 / -1;
    border: 1px solid var(--dk-line);
    border-radius: var(--dk-radius);
    background: var(--dk-ground);
    padding: 14px;
    margin: 0;
    min-width: 0;
}
.dk-fieldset > legend {
    padding: 0 6px;
    font-size: .82rem;
    font-weight: 800;
    color: var(--dk-text);
}

/* ───────── جدول ↔ کارت ───────── */
.dk-table-wrap { overflow-x: auto; margin: 0 -4px; }
.dk-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .86rem;
}
.dk-table th {
    text-align: right;
    font-size: .76rem;
    font-weight: 700;
    color: var(--dk-muted);
    padding: 10px 12px;
    border-bottom: 1px solid var(--dk-line);
    white-space: nowrap;
}
.dk-table td {
    padding: 12px;
    border-bottom: 1px solid var(--dk-line);
    vertical-align: middle;
}
.dk-table tbody tr:last-child td { border-bottom: 0; }
.dk-table tbody tr:hover td { background: var(--dk-ground); }
.dk-num { font-variant-numeric: tabular-nums; }
.dk-strong { font-weight: 700; }
.dk-muted { color: var(--dk-muted); }
.dk-row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.dk-cards { display: flex; flex-direction: column; gap: 10px; }
.dk-card {
    background: var(--dk-surface);
    border: 1px solid var(--dk-line);
    border-radius: var(--dk-radius);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.dk-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.dk-card-title { font-weight: 800; font-size: .95rem; line-height: 1.5; }
.dk-card-sub { font-size: .78rem; color: var(--dk-muted); margin-top: 2px; }
.dk-card-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; }
.dk-kv { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.dk-kv-k { font-size: .7rem; color: var(--dk-faint); }
.dk-kv-v { font-size: .85rem; min-width: 0; overflow-wrap: anywhere; }
.dk-card-actions { display: flex; gap: 8px; border-top: 1px solid var(--dk-line); padding-top: 10px; }
.dk-card-actions .dk-btn { flex: 1; }

/* ───────── تب‌ها ───────── */
.dk-tabs {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
    border-bottom: 1px solid var(--dk-line);
    padding-bottom: 10px;
}
.dk-tabs::-webkit-scrollbar { display: none; }
.dk-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 999px;
    border: 1px solid var(--dk-line);
    background: transparent;
    color: var(--dk-muted);
    font: inherit;
    font-size: .82rem;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}
.dk-tab svg { width: 14px; height: 14px; }
.dk-tab[aria-selected="true"] { background: var(--dk-accent); border-color: var(--dk-accent); color: #fff; }
.dk-tab-count {
    background: var(--dk-danger-fg);
    color: #fff;
    border-radius: 999px;
    padding: 0 7px;
    font-size: .7rem;
}

/* ───────── ردیف فهرست (رتبه، پایش) ───────── */
.dk-rows { display: flex; flex-direction: column; gap: 8px; }
.dk-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 10px 12px;
    border: 1px solid var(--dk-line);
    border-radius: var(--dk-radius-sm);
    background: var(--dk-surface);
    font-size: .85rem;
}
.dk-row.is-flagged { border-color: var(--dk-danger-bg); background: var(--dk-danger-bg); }
.dk-row-main { flex: 1; min-width: 120px; font-weight: 700; }
.dk-row-tags { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.dk-row-note {
    width: 100%;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: .82rem;
    line-height: 1.7;
    border-right: 3px solid currentColor;
}
.dk-rank {
    width: 30px; height: 30px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800;
    font-size: .85rem;
    flex-shrink: 0;
    background: var(--dk-sunken);
    color: var(--dk-muted);
    font-variant-numeric: tabular-nums;
}
.dk-rank--1 { background: #f5c451; color: #5b3a00; }
.dk-rank--2 { background: #cbd5e1; color: #1e293b; }
.dk-rank--3 { background: #d6a27a; color: #3b1d06; }

/* ───────── بخش تاشو ───────── */
.dk-fold { border: 1px solid var(--dk-line); border-radius: var(--dk-radius); overflow: hidden; background: var(--dk-surface); }
.dk-fold > summary {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: var(--dk-ground);
    cursor: pointer;
}
.dk-fold > summary::-webkit-details-marker { display: none; }
.dk-fold > summary .dk-chevron { margin-right: auto; transition: transform .2s; color: var(--dk-faint); }
.dk-fold[open] > summary .dk-chevron { transform: rotate(180deg); }
.dk-fold-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.dk-group-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 10px 14px;
    background: var(--dk-ground);
    border-bottom: 1px solid var(--dk-line);
    font-weight: 800;
}

/* ───────── وضعیت خالی و بارگذاری ───────── */
.dk-empty {
    text-align: center;
    padding: 36px 16px;
    color: var(--dk-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}
.dk-empty svg { width: 40px; height: 40px; opacity: .35; }
.dk-empty h4 { margin: 0; font-size: .95rem; color: var(--dk-text); }
.dk-empty p { margin: 0; font-size: .84rem; max-width: 42ch; }
.dk-skeleton { display: flex; flex-direction: column; gap: 10px; }
.dk-skeleton span {
    display: block;
    height: 44px;
    border-radius: var(--dk-radius-sm);
    background: linear-gradient(90deg, var(--dk-sunken), var(--dk-ground), var(--dk-sunken));
    background-size: 200% 100%;
    animation: dk-shimmer 1.2s ease-in-out infinite;
}
.dk-error { color: var(--dk-danger-fg); text-align: center; padding: 20px; font-size: .88rem; }

/* ───────── پنجره: دسکتاپ وسط صفحه، گوشی برگه‌ی پایین ───────── */
.dk-layer {
    position: fixed;
    inset: 0;
    z-index: 9000;              /* زیر پیام‌ها (toast ۹۹۹۹۹۹) و تقویم؛ روی نوار بالا و پایین */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    direction: rtl;
}
.dk-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, .45);
    animation: dk-fade .18s ease-out;
}
.dk-sheet {
    position: relative;
    width: 100%;
    max-width: var(--dk-sheet-w, 640px);
    max-height: calc(100vh - 48px);
    display: flex;
    flex-direction: column;
    background: var(--dk-surface);
    color: var(--dk-text);
    border-radius: 18px;
    box-shadow: var(--dk-shadow-lift);
    animation: dk-pop .2s ease-out;
    overflow: hidden;
}
.dk-sheet--sm { --dk-sheet-w: 440px; }
.dk-sheet--lg { --dk-sheet-w: 900px; }
.dk-sheet--xl { --dk-sheet-w: 1100px; }
.dk-sheet-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--dk-line);
    flex-shrink: 0;
}
.dk-sheet-head h3 { margin: 0; flex: 1; font-size: 1rem; font-weight: 800; min-width: 0; }
.dk-grip { display: none; }
.dk-x {
    width: 34px; height: 34px;
    border-radius: 50%;
    border: 0;
    background: var(--dk-sunken);
    color: var(--dk-muted);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
}
.dk-x svg { width: 18px; height: 18px; }
.dk-sheet-body { padding: 18px; overflow-y: auto; overscroll-behavior: contain; flex: 1; min-height: 0; }
.dk-sheet-foot {
    display: flex;
    gap: 8px;
    justify-content: flex-start;
    padding: 12px 18px;
    border-top: 1px solid var(--dk-line);
    background: var(--dk-surface);
    flex-shrink: 0;
}
.dk-sheet-foot:empty { display: none; }
body.dk-lock { overflow: hidden; }

@keyframes dk-spin { to { transform: rotate(360deg); } }
@keyframes dk-shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
@keyframes dk-fade { from { opacity: 0; } }
@keyframes dk-pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes dk-rise { from { transform: translateY(100%); } }

/* ═════════ گوشی ═════════ */
@media (max-width: 767.98px) {
    .dk-page { gap: 12px; }
    .dk-head h2 { font-size: 1.1rem; }
    .dk-head-actions { width: 100%; }
    .dk-head-actions .dk-btn { flex: 1; }
    .dk-panel { padding: 14px; border-radius: 16px; }
    .dk-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .dk-stat { padding: 12px; gap: 10px; }
    .dk-stat-icon { width: 36px; height: 36px; }
    .dk-stat-val { font-size: 1.2rem; }

    .dk-filters-toggle { display: inline-flex; align-self: flex-start; }
    .dk-filters:not(.is-open) .dk-filters-body { display: none; }
    .dk-filters-body { grid-template-columns: 1fr; }

    .dk-form, .dk-form--3 { grid-template-columns: 1fr; }
    .dk-input { min-height: 46px; font-size: 16px; }   /* ۱۶px: آیفون روی فیلد زوم نکند */

    .dk-layer { align-items: flex-end; padding: 0; }
    .dk-sheet {
        max-width: none;
        max-height: 92vh;
        border-radius: 20px 20px 0 0;
        animation: dk-rise .24s ease-out;
    }
    .dk-grip {
        display: block;
        position: absolute;
        top: 6px;
        left: 50%;
        width: 38px;
        height: 4px;
        margin-left: -19px;
        border-radius: 99px;
        background: var(--dk-line);
    }
    .dk-sheet-head { padding: 16px 16px 12px; }
    .dk-sheet-body { padding: 14px 16px; }
    .dk-sheet-foot { padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px)); }
    .dk-sheet-foot .dk-btn { flex: 1; min-height: 46px; }
}

@media (prefers-reduced-motion: reduce) {
    .dk-sheet, .dk-backdrop, .dk-skeleton span, .dk-progress-fill { animation: none; transition: none; }
}
