@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-subtle: #f1f5f9;
    --border: #e2e8f0;
    --border-hover: #cbd5e1;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --accent: #2563eb;
    --accent-light: #eff6ff;
    --accent-border: #bfdbfe;
    --success: #059669;
    --success-light: #ecfdf5;
    --success-border: #a7f3d0;
    --kpi-bg: #f0fdf4;
    --kpi-text: #166534;
    --kpi-border: #bbf7d0;
    --sidebar-w: 300px;
    --header-h: 60px;
    --radius-sm: 6px;
    --radius-md: 10px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Vazirmatn', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg);
    color: var(--text-main);
    line-height: 1.65;
    font-size: 15px;
    direction: rtl;
}

/* Header */
.app-header {
    height: var(--header-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.85rem;
}

.menu-toggle-btn {
    display: none;
    background: var(--surface-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.4rem 0.65rem;
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--text-main);
}

.brand-title {
    font-weight: 800;
    font-size: 1.05rem;
    display: flex;
    align-items: center;
    gap: 8px;
    letter-spacing: -0.3px;
}

.brand-badge {
    background: var(--accent-light);
    color: var(--accent);
    font-size: 0.72rem;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 600;
    border: 1px solid var(--accent-border);
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-item {
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.88rem;
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius-sm);
    transition: all 0.15s ease;
}

.nav-item:hover {
    color: var(--text-main);
    background: var(--surface-subtle);
}

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

/* Two-Column App Layout */
.app-layout {
    display: flex;
    max-width: 1440px;
    margin: 0 auto;
    position: relative;
}

/* Sticky Sidebar (Right in RTL) */
.sidebar {
    width: var(--sidebar-w);
    height: calc(100vh - var(--header-h));
    position: sticky;
    top: var(--header-h);
    overflow-y: auto;
    border-left: 1px solid var(--border);
    background: var(--surface);
    padding: 1.25rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    flex-shrink: 0;
}

.sidebar-overlay {
    display: none;
}

/* Progress Box */
.progress-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.9rem 1rem;
}

.progress-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.progress-bar-track {
    width: 100%;
    height: 7px;
    background: #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--success);
    transition: width 0.3s ease;
}

.progress-stats {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

/* Sidebar Navigation Tree */
.sidebar-menu-title {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
}

.nav-tree {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.nav-phase-item {
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.nav-phase-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.65rem;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-main);
    text-decoration: none;
    border-radius: var(--radius-sm);
    transition: all 0.15s ease;
}

.nav-phase-link:hover, .nav-phase-link.active {
    background: var(--accent-light);
    color: var(--accent);
}

.nav-phase-link .badge {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 400;
}

.nav-sub-tree {
    list-style: none;
    padding-right: 0.85rem;
    margin-top: 0.2rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    border-right: 1px solid var(--border);
}

.nav-sub-link {
    display: block;
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: all 0.12s;
}

.nav-sub-link:hover, .nav-sub-link.active {
    color: var(--text-main);
    background: var(--bg);
    font-weight: 500;
}

/* Main Content Area */
.main-content {
    flex: 1;
    min-width: 0;
    padding: 1.5rem 2rem 5rem;
}

/* Sticky Quick Navigation Filter Bar */
.sticky-filter-wrapper {
    position: sticky;
    top: var(--header-h);
    z-index: 90;
    background: var(--bg);
    padding: 0.75rem 0;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.search-input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    font-size: 16px;
    font-family: inherit;
    outline: none;
    margin-bottom: 0.75rem;
    transition: border-color 0.15s;
}

.search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.quick-nav-pills {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: none;
}
.quick-nav-pills::-webkit-scrollbar { display: none; }

.filter-pill {
    padding: 0.35rem 0.8rem;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 20px;
    font-size: 0.82rem;
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
    font-weight: 500;
    font-family: inherit;
    transition: all 0.15s ease;
}

.filter-pill:hover {
    color: var(--text-main);
    border-color: var(--border-hover);
}

.filter-pill.active {
    background: var(--text-main);
    color: #ffffff;
    border-color: var(--text-main);
}

/* Phase Section Cards */
.phase-section {
    scroll-margin-top: calc(var(--header-h) + 120px);
    margin-bottom: 3.5rem;
}

.phase-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--text-main);
    padding-bottom: 0.6rem;
    margin-bottom: 1.5rem;
}

.phase-title {
    font-size: 1.25rem;
    font-weight: 800;
}

.sub-section {
    scroll-margin-top: calc(var(--header-h) + 120px);
    margin-bottom: 2rem;
}

.sub-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.85rem;
    cursor: pointer;
    user-select: none;
}

.sub-title {
    font-size: 1.02rem;
    font-weight: 700;
    color: #1e293b;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sub-title::before {
    content: "";
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: 50%;
}

.sub-toggle-icon {
    font-size: 0.8rem;
    color: var(--text-muted);
    transition: transform 0.2s;
}

.sub-section.collapsed .task-list {
    display: none;
}
.sub-section.collapsed .sub-toggle-icon {
    transform: rotate(180deg);
}

/* Task Cards */
.task-list {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.task-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.15rem 1.35rem;
    transition: border-color 0.15s, opacity 0.15s;
}

.task-card:hover {
    border-color: var(--border-hover);
}

.task-card.checked {
    background: #fafafa;
    border-color: #f1f5f9;
}

.task-card.checked .task-title-text {
    text-decoration: line-through;
    color: var(--text-muted);
}

.task-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 0.85rem;
}

.task-title {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    font-weight: 600;
    font-size: 1rem;
    line-height: 1.5;
}

.custom-check {
    appearance: none;
    width: 1.25rem;
    height: 1.25rem;
    border: 1.5px solid #cbd5e1;
    border-radius: 5px;
    cursor: pointer;
    margin-top: 2px;
    flex-shrink: 0;
    position: relative;
    background: #ffffff;
    transition: all 0.15s;
}

.custom-check:checked {
    background: var(--success);
    border-color: var(--success);
}

.custom-check:checked::after {
    content: '';
    position: absolute;
    left: 6px;
    top: 2px;
    width: 4px;
    height: 8px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.task-id {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 0.2rem 0.55rem;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

/* Task Meta Details */
.task-details {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    font-size: 0.91rem;
    color: #334155;
}

.detail-row {
    line-height: 1.7;
}

.detail-label {
    font-weight: 600;
    color: var(--text-main);
    display: inline-block;
    margin-left: 6px;
}

/* Interactive Code Pill */
.code-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: #f1f5f9;
    color: #0f172a;
    border: 1px solid #cbd5e1;
    border-radius: 5px;
    padding: 2px 7px;
    margin: 2px 3px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85em;
    direction: ltr !important;
    unicode-bidi: isolate;
    cursor: pointer;
    user-select: all;
    transition: all 0.15s ease;
    vertical-align: middle;
}

.code-pill:hover {
    background: #e2e8f0;
    border-color: #94a3b8;
}

.code-pill.copied {
    background: var(--success-light) !important;
    border-color: var(--success-border) !important;
    color: var(--success) !important;
}

/* KPI Box */
.task-kpi {
    background: var(--kpi-bg);
    color: var(--kpi-text);
    border: 1px solid var(--kpi-border);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.85rem;
    font-size: 0.86rem;
    margin-top: 0.85rem;
    line-height: 1.6;
}

.task-kpi strong {
    color: #14532d;
    font-weight: 600;
}

/* Actions Footer */
.task-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

.status-select {
    padding: 0.35rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-main);
    font-family: inherit;
    font-size: 13px;
    outline: none;
    cursor: pointer;
}

.btn-note {
    padding: 0.35rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-muted);
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-note:hover {
    background: var(--bg);
    color: var(--text-main);
}

.note-area {
    width: 100%;
    min-height: 75px;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-top: 0.85rem;
    font-family: inherit;
    font-size: 14px;
    outline: none;
    resize: vertical;
    display: none;
    background: #fafafa;
}

.note-area.active {
    display: block;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #0f172a;
    color: #ffffff;
    padding: 0.6rem 1.25rem;
    border-radius: 30px;
    font-size: 0.88rem;
    font-weight: 500;
    opacity: 0;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 9999;
    pointer-events: none;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* Back to Top Floating Button */
.back-to-top {
    position: fixed;
    bottom: 1.5rem;
    left: 1.5rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    transition: all 0.2s;
    opacity: 0;
    visibility: hidden;
    z-index: 80;
}
.back-to-top.show {
    opacity: 1;
    visibility: visible;
}
.back-to-top:hover {
    background: var(--text-main);
    color: #fff;
}

/* Kanban Board */
.kanban-board {
    display: flex;
    gap: 1.25rem;
    overflow-x: auto;
    padding-bottom: 1.5rem;
}

.kanban-col {
    flex: 1;
    min-width: 320px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.1rem;
}

.kanban-col-header {
    font-weight: 700;
    font-size: 0.95rem;
    margin-bottom: 1rem;
    padding-bottom: 0.6rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
}

.kanban-items {
    min-height: 60vh;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.kanban-card {
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 0.9rem;
    border-radius: var(--radius-sm);
    cursor: grab;
    font-size: 0.9rem;
}

.kanban-card:active {
    cursor: grabbing;
}

/* Floating Highlighter */
#highlight-btn {
    position: fixed;
    display: none;
    background: #0f172a;
    color: #ffffff;
    padding: 0.4rem 0.85rem;
    border: none;
    border-radius: 6px;
    font-size: 0.82rem;
    font-family: inherit;
    cursor: pointer;
    z-index: 999;
}

/* Highlights Page */
.highlight-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-right: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    padding: 1rem 1.2rem;
    margin-bottom: 1rem;
}

.highlight-date {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}

/* Responsive & Mobile Drawer */
@media (max-width: 1024px) {
    .menu-toggle-btn {
        display: block;
    }
    .sidebar {
        position: fixed;
        right: -320px;
        top: 0;
        height: 100vh;
        z-index: 200;
        transition: right 0.25s ease;
        box-shadow: -4px 0 20px rgba(0,0,0,0.1);
    }
    .sidebar.open {
        right: 0;
    }
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.3);
        z-index: 199;
        display: none;
    }
    .sidebar-overlay.open {
        display: block;
    }
    .main-content {
        padding: 1rem 1rem 4rem;
    }
}
