/* ==========================================================================
   ۱. متغیرهای سیستم طراحی (Design Tokens)
   ========================================================================== */
:root {
    --bg-main: #F7F6F2;
    --bg-surface: #FFFFFF;
    --bg-muted: #EFECE6;
    --bg-hover: #E6E2D8;
    
    --text-primary: #2B2D2A;
    --text-secondary: #5C605A;
    --text-muted: #8C9189;

    --border-color: #E2DEC9;
    --shadow-sm: 0 2px 8px rgba(43, 45, 42, 0.04);
    --shadow-md: 0 8px 24px rgba(43, 45, 42, 0.08);

    --accent-primary: #4A6B5D;
    --accent-hover: #3B564B;
    --accent-light: #E8F0EC;

    --color-warning: #D97742;
    --color-warning-bg: #FDF3ED;
    --color-success: #3E7B52;
    --color-success-bg: #EBF5EE;
    --color-danger: #C94A4A;
    --color-danger-bg: #FDECEC;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --font-family: 'Vazirmatn', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

/* حالت تاریک */
[data-theme="dark"] {
    --bg-main: #161816;
    --bg-surface: #202421;
    --bg-muted: #2A2F2B;
    --bg-hover: #343A35;

    --text-primary: #ECEAE4;
    --text-secondary: #B0B5AE;
    --text-muted: #787E76;

    --border-color: #323833;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);

    --accent-light: rgba(74, 107, 93, 0.22);
    --color-warning-bg: rgba(217, 119, 66, 0.15);
    --color-success-bg: rgba(62, 123, 82, 0.15);
    --color-danger-bg: rgba(201, 74, 74, 0.15);
}

[data-accent="terracotta"] {
    --accent-primary: #C86D51;
    --accent-hover: #AD583E;
    --accent-light: #F9ECE8;
}
[data-accent="ocean"] {
    --accent-primary: #3D6B7E;
    --accent-hover: #2E5464;
    --accent-light: #E8F1F5;
}

/* ==========================================================================
   ۲. تنظیمات پایه و قفل کردن اسکرول افقی در موبایل
   ========================================================================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    font-family: var(--font-family);
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.6;
    font-size: 15px;
    transition: background-color 0.25s ease, color 0.25s ease;
}

button, input, select, textarea {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    max-width: 100%;
}

button {
    cursor: pointer;
    border: none;
    background: none;
}

button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* ==========================================================================
   ۳. ساختار لایه‌بندی (Layout)
   ========================================================================== */
.app-layout {
    display: flex;
    min-height: 100vh;
    min-height: 100dvh;
    width: 100%;
    position: relative;
}

.sidebar {
    width: 260px;
    flex-shrink: 0;
    background-color: var(--bg-surface);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100dvh;
    z-index: 100;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.3s;
}

.sidebar-header {
    padding: 20px 18px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-logo {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
    background-color: var(--accent-primary);
    color: #fff;
    font-weight: 800;
    font-size: 19px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.brand-text h1 {
    font-size: 17px;
    font-weight: 700;
    line-height: 1.2;
}

.brand-text p {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.sidebar-nav {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-weight: 500;
    text-align: right;
    width: 100%;
    transition: var(--transition);
}

.nav-item:hover {
    background-color: var(--bg-muted);
    color: var(--text-primary);
}

.nav-item.active {
    background-color: var(--accent-light);
    color: var(--accent-primary);
    font-weight: 700;
}

.nav-icon {
    font-size: 18px;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 14px 16px;
    border-top: 1px solid var(--border-color);
}

.storage-notice {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--color-success);
    flex-shrink: 0;
}

.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    width: 100%;
}

/* هدر بالایی */
.top-header {
    min-height: 64px;
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    padding: 8px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 90;
    width: 100%;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.search-box {
    position: relative;
    width: 100%;
    max-width: 320px;
    min-width: 0;
}

.search-box input {
    width: 100%;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background-color: var(--bg-main);
    font-size: 13px;
}

.search-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    left: 0;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    max-height: 300px;
    overflow-y: auto;
    z-index: 250;
    padding: 8px;
}

.search-result-item {
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.search-result-item:hover {
    background-color: var(--bg-muted);
}

.datetime-display {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    background-color: var(--bg-muted);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    white-space: nowrap;
}

.clock-badge {
    font-weight: 700;
    color: var(--accent-primary);
    padding-right: 8px;
    border-right: 1px solid var(--border-color);
}

.main-content {
    padding: 24px;
    max-width: 1320px;
    width: 100%;
    margin: 0 auto;
    flex: 1;
}

/* ==========================================================================
   ۴. کامپوننت‌های مشترک (کارت‌ها، دکمه‌ها، فرم‌ها، نوار پیشرفت)
   ========================================================================== */
.view-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 14px;
}

.view-title {
    min-width: 0;
    flex: 1 1 240px;
}

.view-title h2 {
    font-size: 22px;
    font-weight: 700;
    word-break: break-word;
}

.view-title p {
    color: var(--text-secondary);
    font-size: 13.5px;
    margin-top: 4px;
}

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

.card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 18px;
    box-shadow: var(--shadow-sm);
    min-width: 0;
    overflow: hidden;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.card-title {
    font-size: 15.5px;
    font-weight: 700;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    transition: var(--transition);
}

.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-primary { background-color: var(--accent-primary); color: #fff; }
.btn-primary:hover { background-color: var(--accent-hover); }
.btn-secondary { background-color: var(--bg-muted); color: var(--text-primary); }
.btn-secondary:hover { background-color: var(--bg-hover); }
.btn-danger { background-color: var(--color-danger-bg); color: var(--color-danger); }
.btn-danger:hover { background-color: var(--color-danger); color: #fff; }

.icon-btn {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    background-color: var(--bg-muted);
    transition: var(--transition);
    font-size: 16px;
}
.icon-btn:hover { background-color: var(--bg-hover); color: var(--text-primary); }

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 9px;
    border-radius: 99px;
    font-size: 11.5px;
    font-weight: 600;
    background-color: var(--bg-muted);
    color: var(--text-secondary);
    white-space: nowrap;
}
.badge-high { background-color: var(--color-danger-bg); color: var(--color-danger); }
.badge-medium { background-color: var(--color-warning-bg); color: var(--color-warning); }
.badge-low { background-color: var(--color-success-bg); color: var(--color-success); }
.badge-accent { background-color: var(--accent-light); color: var(--accent-primary); }

.progress-track {
    width: 100%;
    height: 9px;
    background-color: var(--bg-muted);
    border-radius: 99px;
    overflow: hidden;
    margin: 8px 0;
}

.progress-fill {
    height: 100%;
    background-color: var(--accent-primary);
    border-radius: 99px;
    transition: width 0.4s ease;
}

/* فرم‌ها */
.form-group { margin-bottom: 14px; min-width: 0; }
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-secondary);
}
.form-control {
    width: 100%;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background-color: var(--bg-main);
}
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* آیتم وظیفه */
.task-list { display: flex; flex-direction: column; gap: 10px; }
.task-item {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    padding: 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background-color: var(--bg-main);
    transition: var(--transition);
}
.task-item.completed { opacity: 0.65; }
.task-item.completed .task-title {
    text-decoration: line-through;
    color: var(--text-muted);
}
.task-right {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    flex: 1;
    min-width: 0;
}
.task-checkbox {
    width: 20px;
    height: 20px;
    margin-top: 3px;
    flex-shrink: 0;
    accent-color: var(--accent-primary);
    cursor: pointer;
}
.task-title {
    word-break: break-word;
    line-height: 1.45;
}
.task-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
    font-size: 11.5px;
    color: var(--text-muted);
}
.task-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
    flex-wrap: wrap;
}

/* تقویم ماهانه */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 6px;
}
.cal-day-header {
    text-align: center;
    font-weight: 600;
    font-size: 12px;
    color: var(--text-secondary);
    padding: 6px 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cal-cell {
    min-height: 82px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 6px;
    background-color: var(--bg-main);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: var(--transition);
    min-width: 0;
    overflow: hidden;
}
.cal-cell:hover { border-color: var(--accent-primary); }
.cal-cell.today {
    border: 2px solid var(--accent-primary);
    background-color: var(--accent-light);
}
.cal-cell.selected {
    box-shadow: 0 0 0 2px var(--color-warning);
}
.cal-cell.empty {
    background-color: transparent;
    border-color: transparent;
    cursor: default;
}
.cal-date-num { font-weight: 700; font-size: 13px; }

/* کانبان پروژه‌ها */
.kanban-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}
.kanban-col {
    background-color: var(--bg-muted);
    border-radius: var(--radius-md);
    padding: 14px;
    min-width: 0;
}
.kanban-col h4 {
    margin-bottom: 12px;
    font-size: 14px;
    display: flex;
    justify-content: space-between;
}

/* تایمر تمرکز */
.timer-circle {
    width: 210px;
    height: 210px;
    border-radius: 50%;
    border: 8px solid var(--accent-light);
    margin: 18px auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.timer-digits {
    font-size: 42px;
    font-weight: 800;
    color: var(--accent-primary);
    direction: ltr;
}

/* مودال و Toast */
.modal-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px;
    z-index: 1200;
}
.modal-card {
    background-color: var(--bg-surface);
    border-radius: var(--radius-lg);
    max-width: 520px;
    width: 100%;
    max-height: 90dvh;
    overflow-y: auto;
    padding: 20px;
    box-shadow: var(--shadow-md);
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}
.toast-container {
    position: fixed;
    bottom: 84px;
    left: 16px;
    right: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    z-index: 1300;
    pointer-events: none;
}
.toast {
    background-color: var(--text-primary);
    color: var(--bg-surface);
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    box-shadow: var(--shadow-md);
    max-width: 100%;
    text-align: center;
}
.empty-state {
    text-align: center;
    padding: 28px 14px;
    color: var(--text-muted);
    font-size: 13.5px;
}

.hidden { display: none !important; }
.mobile-only { display: none; }

/* ==========================================================================
   ۵. بهینه‌سازی اختصاصی و کامل موبایل و تبلت (Responsive Mobile-First)
   ========================================================================== */
@media (max-width: 992px) {
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .grid-3 { grid-template-columns: 1fr; }
    .grid-2 { grid-template-columns: 1fr; }
    .kanban-board { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .mobile-only { display: inline-flex; }

    /* ۱. اصلاح کامل منوی کشویی موبایل بدون ایجاد اسکرول افقی */
    .sidebar {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: min(82vw, 300px);
        height: 100dvh;
        z-index: 1100;
        transform: translateX(105%);
        visibility: hidden;
        box-shadow: none;
        border-left: 1px solid var(--border-color);
    }

    .sidebar.open {
        transform: translateX(0);
        visibility: visible;
        /* ایجاد لایه تاریک روی کل صفحه پشت منو بدون نیاز به تغییر HTML */
        box-shadow: -100vw 0 0 100vw rgba(0, 0, 0, 0.55), -8px 0 24px rgba(0, 0, 0, 0.3);
    }

    /* ۲. اصلاح هدر بالا در موبایل تا دکمه‌ها بیرون نزنند */
    .top-header {
        padding: 8px 12px;
        gap: 8px;
        min-height: 58px;
    }

    .header-right {
        gap: 8px;
        flex: 1;
    }

    .search-box {
        max-width: none;
        flex: 1;
    }

    .search-box input {
        padding: 7px 10px;
        font-size: 12.5px;
    }

    .datetime-display {
        display: none; /* در موبایل تاریخ در تیتر داشبورد هست تا هدر شلوغ نشود */
    }

    #quickAddTaskBtn {
        padding: 7px 10px;
        font-size: 12px;
    }

    /* ۳. تنظیم فاصله محتوای اصلی برای جلوگیری از رفتن زیر منوی پایین */
    .main-content {
        padding: 14px 12px calc(82px + env(safe-area-inset-bottom, 0px));
    }

    .view-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        margin-bottom: 16px;
    }

    .view-title {
        flex: none;
    }

    .view-title h2 {
        font-size: 19px;
    }

    /* دکمه‌های بالای داشبورد در موبایل به صورت منظم کنار هم قرار بگیرند */
    .view-header > div:last-child {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        width: 100%;
    }

    .view-header > div:last-child .btn {
        flex: 1 1 auto;
        font-size: 13px;
        padding: 8px 10px;
    }

    /* کارت‌های آماری در موبایل تک‌ستونه یا ۲ ستونه خوانا شوند */
    .grid-4 {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .card {
        padding: 14px;
        border-radius: var(--radius-md);
    }

    .form-row {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    /* آیتم‌های وظیفه در موبایل */
    .task-item {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .task-actions {
        justify-content: flex-end;
        border-top: 1px dashed var(--border-color);
        padding-top: 8px;
        width: 100%;
    }

    /* تقویم ماهانه در موبایل */
    .calendar-grid {
        gap: 4px;
    }
    .cal-day-header {
        font-size: 10.5px;
    }
    .cal-cell {
        min-height: 62px;
        padding: 4px;
    }
    .cal-cell .badge {
        font-size: 9.5px;
        padding: 1px 5px;
    }

    /* ۴. طراحی استاندارد و تراز نوار ناوبری پایین موبایل (Bottom Bar) */
    .mobile-bottom-nav {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: calc(64px + env(safe-area-inset-bottom, 0px));
        padding-bottom: env(safe-area-inset-bottom, 0px);
        background-color: var(--bg-surface);
        border-top: 1px solid var(--border-color);
        box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
        display: grid;
        grid-template-columns: repeat(5, 1fr);
        align-items: center;
        z-index: 950;
    }

    .mob-nav-btn {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        height: 100%;
        width: 100%;
        color: var(--text-muted);
        gap: 3px;
        padding: 6px 2px;
        border-radius: 0;
        transition: var(--transition);
    }

    .mob-nav-btn span {
        font-size: 19px;
        line-height: 1;
    }

    .mob-nav-btn small {
        font-size: 11px;
        font-weight: 500;
        white-space: nowrap;
    }

    .mob-nav-btn.active {
        color: var(--accent-primary);
        background-color: var(--accent-light);
    }

    .mob-nav-btn.active small {
        font-weight: 700;
    }
}

/* برای گوشی‌های بسیار باریک */
@media (max-width: 380px) {
    .grid-4 {
        grid-template-columns: 1fr;
    }
}
