/* CSS Variables / Theme */
:root {
    /* Light Mode */
    --primary: #4F46E5;
    --primary-hover: #4338CA;
    --secondary: #F3F4F6;
    --secondary-hover: #E5E7EB;
    
    --bg-app: #f4f6f8;
    --bg-surface: #FFFFFF;
    
    --text-main: #111827;
    --text-secondary: #4B5563;
    --text-muted: #9CA3AF;
    
    --border-color: #E5E7EB;
    
    --danger: #EF4444;
    --danger-hover: #DC2626;
    
    --status-todo: #E5E7EB;
    --status-progress: #FDE047;
    --status-done: #86EFAC;
    
    --priority-high: #FEE2E2;
    --priority-high-text: #991B1B;
    --priority-medium: #FEF9C3;
    --priority-medium-text: #854D0E;
    --priority-low: #F3F4F6;
    --priority-low-text: #374151;
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    
    --radius-md: 8px;
    --radius-lg: 12px;
    --transition-speed: 0.3s;
}

/* Dark Mode Theme */
[data-theme="dark"] {
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --secondary: #374151;
    --secondary-hover: #4b5563;
    
    --bg-app: #111827;
    --bg-surface: #1f2937;
    
    --text-main: #f9fafb;
    --text-secondary: #d1d5db;
    --text-muted: #9ca3af;
    
    --border-color: #374151;
    
    --danger: #f87171;
    --danger-hover: #ef4444;
    
    --status-todo: #374151;
    --status-progress: #854d0e;
    --status-done: #166534;
    
    --priority-high: #7f1d1d;
    --priority-high-text: #fca5a5;
    --priority-medium: #713f12;
    --priority-medium-text: #fde047;
    --priority-low: #374151;
    --priority-low-text: #d1d5db;
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.6), 0 2px 4px -1px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.6), 0 4px 6px -2px rgba(0, 0, 0, 0.5);
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Inter', sans-serif; }
body { background-color: var(--bg-app); color: var(--text-main); overflow-x: hidden; transition: background-color var(--transition-speed), color var(--transition-speed); }

/* Theme Toggle */
.theme-toggle {
    background: var(--secondary);
    color: var(--text-main);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.25rem;
    transition: all var(--transition-speed);
}
.theme-toggle:hover { background: var(--secondary-hover); }

/* Base Components */
.app-container { display: flex; height: 100vh; overflow: hidden; }

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 10;
    transition: background-color var(--transition-speed), border-color var(--transition-speed);
}

.sidebar-header { padding: 1.5rem; display: flex; align-items: center; gap: 0.75rem; border-bottom: 1px solid var(--border-color); }
.logo-icon { font-size: 2rem; color: var(--primary); }
.sidebar-header h2 { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.025em; }

.sidebar-nav { padding: 1.5rem 1rem; display: flex; flex-direction: column; gap: 0.5rem; }
.nav-item { display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem 1rem; color: var(--text-secondary); text-decoration: none; border-radius: var(--radius-md); font-weight: 500; transition: all 0.2s; }
.nav-item i { font-size: 1.25rem; }
.nav-item:hover { background-color: var(--secondary); color: var(--text-main); }
.nav-item.active { background-color: var(--primary); color: white; }

/* Main Content Area */
.main-content { flex: 1; display: flex; flex-direction: column; overflow-y: auto; background-color: var(--bg-app); transition: background-color var(--transition-speed); }
.top-header { padding: 2rem; display: flex; justify-content: space-between; align-items: flex-end; }
.page-title { font-size: 1.875rem; font-weight: 700; color: var(--text-main); letter-spacing: -0.025em; }
.page-subtitle { color: var(--text-secondary); margin-top: 0.25rem; }
.header-actions { display: flex; align-items: center; gap: 1rem; }

/* Buttons */
.btn { padding: 0.625rem 1.25rem; border-radius: var(--radius-md); font-weight: 500; font-size: 0.875rem; cursor: pointer; display: inline-flex; align-items: center; gap: 0.5rem; border: none; transition: all 0.2s; }
.btn-primary { background-color: var(--primary); color: white; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background-color: var(--primary-hover); }
.btn-secondary { background-color: var(--secondary); color: var(--text-main); }
.btn-secondary:hover { background-color: var(--secondary-hover); }
.btn-danger { background-color: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover { background-color: var(--danger); color: white; }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.8rem; }

/* Dashboard Matrix */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.5rem; padding: 0 2rem; margin-bottom: 2rem; }
.stat-card {
    background: var(--bg-surface); padding: 1.5rem; border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color); display: flex; align-items: center; gap: 1rem; transition: transform 0.2s, background-color var(--transition-speed);
}
.stat-card:hover { align-items: center; transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-icon { width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1.5rem; }
.stat-icon.primary { background-color: rgba(79, 70, 229, 0.1); color: var(--primary); }
.stat-icon.success { background-color: rgba(34, 197, 94, 0.1); color: #22c55e; }
.stat-icon.warning { background-color: rgba(234, 179, 8, 0.1); color: #eab308; }
.stat-icon.admin { background-color: rgba(236, 72, 153, 0.1); color: #ec4899; }
.stat-info h3 { margin: 0; font-size: 1.75rem; color: var(--text-main); font-weight: 700; }
.stat-info p { margin: 0; padding-top: 0.2rem; color: var(--text-secondary); font-size: 0.875rem; font-weight: 500;}

/* Project/Data Cards */
.projects-overview-section, .list-container { padding: 0 2rem 2rem; }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.section-header h3 { font-size: 1.25rem; font-weight: 600; }
.project-cards-container { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1.5rem; }
.project-card {
    background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-lg);
    padding: 1.5rem; box-shadow: var(--shadow-sm); transition: box-shadow 0.2s, transform 0.2s, background-color var(--transition-speed);
    text-decoration: none; color: inherit; display: flex; flex-direction: column;
}
.project-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--primary); }
.project-card-title { font-size: 1.125rem; font-weight: 600; margin-bottom: 0.5rem; color: var(--text-main); }
.project-card-desc { color: var(--text-secondary); font-size: 0.875rem; margin-bottom: 1.5rem; flex:1; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.project-metrics { display: flex; justify-content: space-between; font-size: 0.875rem; font-weight: 500; color: var(--text-secondary); }
.progress-bar { width: 100%; height: 6px; background-color: var(--secondary); border-radius: 999px; margin-top: 0.5rem; overflow: hidden; }
.progress-fill { height: 100%; background-color: var(--primary); border-radius: 999px; }

/* Table specific (for admin users page) */
.table-container { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-lg); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 1rem 1.5rem; text-align: left; border-bottom: 1px solid var(--border-color); }
th { background-color: var(--secondary); font-weight: 600; font-size: 0.875rem; color: var(--text-main); text-transform: uppercase; letter-spacing: 0.05em; }
td { color: var(--text-secondary); font-size: 0.875rem; }
tr:last-child td { border-bottom: none; }
tr:hover { background-color: var(--secondary); }

/* Kanban Board Layout */
/*
 * PHP hosting fix: min-height:0 on both .has-board and .kanban-board is
 * the critical flex fix. Without it, flex children refuse to shrink below
 * their content size and the board overflows the viewport vertically
 * instead of scrolling horizontally.
 * align-items:stretch (removed flex-start) makes all columns the same
 * height so col-body overflow-y:auto works correctly inside each column.
 */
.main-content.has-board {
    display: flex;
    flex-direction: column;
    min-height: 0;       /* allow flex shrink on PHP-hosted environments */
    overflow: hidden;    /* prevent double vertical scrollbars on the board page */
}
.board-header { padding-bottom: 1rem; align-items: center; }
.breadcrumb { font-size: 0.875rem; color: var(--text-secondary); margin-bottom: 0.5rem; display: flex; align-items: center; gap: 0.25rem; }
.breadcrumb a { color: var(--primary); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
.kanban-board { display: flex; gap: 1.5rem; padding: 0 2rem 2rem; overflow-x: auto; flex: 1; min-height: 0; align-items: flex-start; scrollbar-width: thin; }
.kanban-board::-webkit-scrollbar { height: 8px; }
.kanban-board::-webkit-scrollbar-track { background: transparent; }
.kanban-board::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }

.kanban-col {
    background-color: var(--secondary); border-radius: var(--radius-lg); width: 320px; min-width: 320px;
    display: flex; flex-direction: column; border: 1px solid var(--border-color); box-shadow: var(--shadow-sm);
    overflow: hidden; max-height: 100%;
}
.col-header { padding: 1.25rem 1.25rem 0.75rem; display:flex; justify-content:space-between; align-items:center; }
.col-header h3 { font-size: 0.875rem; font-weight: 600; color: var(--text-main); display: flex; align-items: center; gap: 0.5rem; text-transform: uppercase; letter-spacing: 0.05em; }
.task-count { background-color: rgba(79, 70, 229, 0.1); color: var(--primary); padding: 0.1rem 0.5rem; border-radius: 999px; font-size: 0.75rem; margin-left: 0.5rem; }
.col-body { padding: 0 1.25rem 1.25rem; flex: 1; overflow-y: auto; min-height: 150px; display: flex; flex-direction: column; gap: 0.75rem; scrollbar-width: none; }
.col-body::-webkit-scrollbar { display: none; }

/* Kanban Cards */
.task-card { background-color: var(--bg-surface); padding: 1rem; border-radius: var(--radius-md); box-shadow: var(--shadow-sm); border: 1px solid var(--border-color); cursor: grab; transition: transform 0.2s, box-shadow 0.2s, background-color var(--transition-speed); display:flex; flex-direction:column; }
.task-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: var(--primary); }
.task-card:active { cursor: grabbing; transform: scale(0.98); box-shadow: var(--shadow-sm); }
.task-card.dragging { opacity: 0.5; box-shadow: var(--shadow-lg); transform: scale(1.02); }
.task-labels { margin-bottom: 0.75rem; display: flex; align-items: center; justify-content: space-between; }
.priority-label { font-size: 0.7rem; font-weight: 600; padding: 0.15rem 0.5rem; border-radius: 4px; text-transform: uppercase; }
.priority-high { background-color: var(--priority-high); color: var(--priority-high-text); }
.priority-medium { background-color: var(--priority-medium); color: var(--priority-medium-text); }
.priority-low { background-color: var(--priority-low); color: var(--priority-low-text); }
.task-card h4 { font-size: 0.95rem; font-weight: 500; margin-bottom: 0.5rem; color: var(--text-main); line-height: 1.4; }
.task-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 1rem; border-top: 1px solid var(--border-color); padding-top: 0.75rem; font-size: 0.75rem; color: var(--text-secondary); }
.task-card:hover { border-color: var(--primary); box-shadow: var(--shadow-md); }
.assignee-badge { background-color: var(--primary); color: white; width: 24px; height: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.6rem; font-weight: bold; }

/* Modals — backdrop-filter removed for performance (expensive GPU compositing) */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(0, 0, 0, 0.45);
    display: flex; align-items: center; justify-content: center;
    z-index: 100; opacity: 0; visibility: hidden;
    transition: opacity 0.15s ease, visibility 0.15s ease; /* specific props only */
}
.modal-overlay.active { opacity: 1; visibility: visible; }
.modal-content {
    background-color: var(--bg-surface); border-radius: var(--radius-lg); width: 100%; max-width: 500px;
    box-shadow: var(--shadow-lg); transform: translateY(16px);
    transition: transform 0.15s ease; /* faster, GPU-cheap */
    color: var(--text-main); border: 1px solid var(--border-color);
}
.modal-overlay.active .modal-content { transform: translateY(0); }
.modal-header { padding: 1.5rem; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { font-size: 1.125rem; font-weight: 600; }
.close-btn { background: none; border: none; font-size: 1.5rem; color: var(--text-secondary); cursor: pointer; }
.close-btn:hover { color: var(--text-main); }

#project-form, #task-form, .modal-body { padding: 1.5rem; }
.form-group { margin-bottom: 1.25rem; }
.form-row { display: flex; gap: 1rem; }
.form-row .col { flex: 1; }
.form-group label { display: block; font-size: 0.875rem; font-weight: 500; margin-bottom: 0.5rem; color: var(--text-main); }
.form-group input, .form-group textarea, .form-group select { width: 100%; padding: 0.625rem; border: 1px solid var(--border-color); border-radius: var(--radius-md); font-size: 0.875rem; outline: none; transition: border 0.2s, background-color var(--transition-speed); background: var(--bg-app); color: var(--text-main); }
.form-group input:focus, .form-group textarea:focus, .form-group select:focus { border-color: var(--primary); }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.75rem; margin-top: 2rem; }
.modal-actions.space-between { justify-content: space-between; }
.hidden { display: none !important; }

/* ===== Sprint Section Card (settings.html inline panel, NOT a modal) ===== */
/* user-modal-styled caps at 560px which is fine in a modal, but as a full-
   width settings card it must span the entire list-container width.        */
.sprint-section-card {
    max-width: 100% !important;
    width: 100%;
}

/* Tabs */
.tab-btn { color: var(--text-secondary); border-bottom: 2px solid transparent !important; }
.tab-btn.active { color: var(--primary) !important; border-bottom: 2px solid var(--primary) !important; }

/* Required field asterisk */
.required-asterisk { color: #EF4444; font-weight: 700; margin-right: 2px; }

/* Date input wrapper - click-anywhere-to-open */
.date-input-wrapper {
    position: relative; cursor: pointer; display: flex; align-items: center;
    border: 1px solid var(--border-color); border-radius: var(--radius-md);
    background: var(--bg-app); overflow: hidden; transition: border 0.2s;
}
.date-input-wrapper:hover, .date-input-wrapper:focus-within { border-color: var(--primary); }
.date-input-icon {
    padding: 0 0.625rem; font-size: 1.1rem; color: var(--primary);
    pointer-events: none; flex-shrink: 0;
}
.date-input-wrapper input[type="date"] {
    border: none !important; border-radius: 0 !important; background: transparent !important;
    padding: 0.625rem 0.625rem 0.625rem 0; flex: 1; cursor: pointer;
    color: var(--text-main);
}
.date-input-wrapper input[type="date"]:focus { outline: none; }

/* Project task badge on project cards (Projects tab) */
.project-task-badge {
    display: inline-flex; align-items: center; gap: 0.4rem; margin-top: 0.75rem;
    font-size: 0.8rem; font-weight: 600; color: var(--primary);
    background: rgba(79, 70, 229, 0.08); padding: 0.3rem 0.65rem;
    border-radius: 999px; width: fit-content;
}

/* ===== Redesigned User Registration Modal ===== */
.user-modal-styled { max-width: 560px !important; padding: 0 !important; overflow: hidden; }

.user-modal-header {
    display: flex; align-items: center; gap: 1rem; padding: 1.5rem;
    background: linear-gradient(135deg, var(--primary) 0%, #7C3AED 100%);
    color: white;
}
.user-modal-header-icon {
    width: 44px; height: 44px; background: rgba(255,255,255,0.2); border-radius: 50%;
    display: flex; align-items: center; justify-content: center; font-size: 1.4rem; flex-shrink: 0;
}
.user-modal-header h3 { font-size: 1.1rem; font-weight: 700; color: white; margin: 0; }
.user-modal-subtitle { font-size: 0.8rem; color: rgba(255,255,255,0.75); margin-top: 2px; }
.user-modal-header .close-btn { margin-left: auto; color: rgba(255,255,255,0.8); font-size: 1.5rem; }
.user-modal-header .close-btn:hover { color: white; }

.user-form-section {
    padding: 1.25rem 1.5rem 0.5rem;
    border-bottom: 1px solid var(--border-color);
}
.user-form-section:last-of-type { border-bottom: none; }

.user-form-section-title {
    font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em;
    color: var(--primary); margin-bottom: 1rem; display: flex; align-items: center; gap: 0.4rem;
}
.user-form-section-title i { font-size: 1rem; }

/* Input with icon prefix */
.input-icon-wrap {
    display: flex; align-items: center;
    border: 1px solid var(--border-color); border-radius: var(--radius-md);
    background: var(--bg-app); overflow: hidden; transition: border 0.2s;
}
.input-icon-wrap:focus-within { border-color: var(--primary); }
.input-icon-wrap > i {
    padding: 0 0.625rem; font-size: 1rem; color: var(--text-muted); flex-shrink: 0;
}
.input-icon-wrap input {
    border: none !important; border-radius: 0 !important; background: transparent !important;
    flex: 1; padding: 0.625rem 0.625rem 0.625rem 0;
    color: var(--text-main); font-size: 0.875rem;
}
.input-icon-wrap input:focus { outline: none; }
.input-icon-wrap input::placeholder { color: var(--text-muted); }

.user-modal-actions {
    display: flex; justify-content: space-between; align-items: center;
    padding: 1rem 1.5rem 1.25rem; background: var(--secondary);
    border-top: 1px solid var(--border-color);
}
.required-note { font-size: 0.78rem; color: var(--text-muted); }


/* ===== Stage Progress Bar — improved ===== */
.stage-progress-track {
    height: 6px; background: var(--border-color);
    overflow: hidden; flex-shrink: 0; margin: 0;
}
.stage-progress-fill {
    height: 100%; border-radius: 0;
    transition: width 0.6s cubic-bezier(0.4,0,0.2,1);
}

/* Stage percent badge in col-header */
.stage-percent-badge {
    font-size: 0.7rem; font-weight: 700; color: var(--text-muted);
    background: var(--secondary); padding: 0.1rem 0.45rem;
    border-radius: 999px; letter-spacing: 0.02em; flex-shrink: 0;
}

/* Project-level completion bar (board header) */
.project-completion-bar {
    padding: 0.6rem 2rem; background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex; align-items: center; gap: 1rem;
}
.project-completion-bar:empty { display: none; }
.completion-label { font-size: 0.8rem; font-weight: 600; color: var(--text-secondary); white-space: nowrap; }
.completion-track { flex: 1; height: 8px; background: var(--secondary); border-radius: 999px; overflow: hidden; }
.completion-fill {
    height: 100%; background: linear-gradient(90deg, #4F46E5, #22c55e);
    border-radius: 999px; transition: width 0.6s ease;
}
.completion-percent { font-size: 0.8rem; font-weight: 700; color: var(--primary); min-width: 42px; text-align: right; }


/* ===== Updated Col-Header Layout ===== */
.col-header { padding: 0.85rem 1rem 0.6rem; display:flex; justify-content:space-between; align-items:center; }
.col-header-left { display:flex; align-items:center; gap:0.5rem; }
.col-header-left h3 { font-size: 0.875rem; font-weight: 600; color: var(--text-main); display: flex; align-items: center; gap: 0.5rem; text-transform: uppercase; letter-spacing: 0.05em; }

/* "+" add task button before stage title */
.stage-add-btn {
    width: 24px; height: 24px; border: none; border-radius: 6px;
    background: rgba(79, 70, 229, 0.12); color: var(--primary);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    font-size: 1rem; flex-shrink: 0; transition: background 0.2s, transform 0.15s;
}
.stage-add-btn:hover { background: var(--primary); color: white; transform: scale(1.1); }

/* Stage delete button */
.stage-delete-btn {
    width: 24px; height: 24px; border: none; border-radius: 6px;
    background: transparent; color: var(--text-muted);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    font-size: 0.9rem; flex-shrink: 0; transition: background 0.2s, color 0.2s;
}
.stage-delete-btn:hover { background: var(--danger); color: white; }

/* ===== Board Filter Bar ===== */
.board-filter-bar {
    display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
    padding: 0.65rem 2rem; background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    border-top: 1px solid var(--border-color);
    min-height: 52px;
}
.board-filter-bar:empty { display: none; }
.filter-label {
    font-size: 0.8rem; font-weight: 600; color: var(--text-secondary);
    display: flex; align-items: center; gap: 0.3rem; white-space: nowrap;
}
.filter-label i { font-size: 1rem; color: var(--primary); }
.board-filter-bar select {
    padding: 0.4rem 0.65rem; border: 1px solid var(--border-color); border-radius: 8px;
    background: var(--bg-app); color: var(--text-main); font-size: 0.8rem;
    cursor: pointer; outline: none; transition: border 0.2s;
    font-family: 'Inter', sans-serif;
}
.board-filter-bar select:focus { border-color: var(--primary); }
.filter-clear-btn { flex-shrink: 0; }

/* ===== Task Modal Improvements ===== */
.task-modal-content { max-width: 780px !important; }
.task-modal-header { background: var(--secondary); border-bottom: 1px solid var(--border-color); }
.task-modal-header h3 { font-size: 1.05rem; }

/* Task form left panel wider, assignee select full width */
.task-form-panel { flex: 1.4; overflow-y: auto; border-right: 1px solid var(--border-color); display: flex; flex-direction: column; }
.task-form-panel #task-form { flex: 1; display: flex; flex-direction: column; padding-bottom: 0; }
.task-form-panel .form-group select { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/*
 * Sticky action bar — the Save/Create Task button is ALWAYS visible even
 * when the form content overflows the 580-px fixed modal height.
 * Without this, the button scrolls out of view on live hosts where
 * computed form heights differ slightly from local.
 */
.task-form-panel .modal-actions {
    position: sticky;
    bottom: 0;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    padding: 0.85rem 1.5rem;
    margin-top: auto;
    z-index: 2;
}

/* ===== Task Attachment Styles ===== */
.attachment-upload-area {
    border: 2px dashed var(--border-color); border-radius: var(--radius-md);
    padding: 1rem; text-align: center; cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    display: flex; flex-direction: column; align-items: center; gap: 0.3rem;
}
.attachment-upload-area:hover { border-color: var(--primary); background: rgba(79,70,229,0.04); }
.attachment-upload-area i { font-size: 1.6rem; color: var(--text-muted); }
.attachment-upload-area p { margin: 0; font-size: 0.8rem; color: var(--text-secondary); }
.attachment-upload-area small { font-size: 0.72rem; color: var(--text-muted); }

.attachments-preview-grid { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.75rem; }
.attachment-item {
    border: 1px solid var(--border-color); border-radius: 8px;
    overflow: hidden; background: var(--secondary);
    display: flex; flex-direction: column; width: 88px; position: relative;
}
.attachment-thumb {
    width: 88px; height: 68px; object-fit: cover; display: block;
    background: var(--border-color);
}
.attachment-file-box {
    width: 88px; height: 68px; display:flex; align-items:center; justify-content:center;
    background: var(--secondary); font-size: 2rem; color: var(--primary);
}
.attachment-footer {
    padding: 0.25rem 0.35rem; display: flex; align-items: center; justify-content: space-between; gap: 0.25rem;
}
.attachment-view {
    background: transparent;
    border: none;
    color: var(--primary);
    cursor: pointer;
    font-size: 0.68rem;
    padding: 0;
}
.attachment-view:hover { text-decoration: underline; }
.attachment-name {
    font-size: 0.68rem; color: var(--text-secondary); white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis; flex: 1;
    text-decoration: none;
}
.attachment-remove {
    background: none; border: none; color: var(--danger); cursor: pointer;
    font-size: 0.9rem; padding: 0; line-height: 1; flex-shrink: 0;
}
.attachment-remove:hover { color: var(--danger-hover); }

.task-assignee-name {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.15rem;
}

.image-viewer-content {
    max-width: 900px !important;
    width: min(92vw, 900px);
}

.image-viewer-body {
    padding: 1rem;
    background: var(--secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    max-height: 80vh;
}

.image-viewer-body img {
    max-width: 100%;
    max-height: 72vh;
    object-fit: contain;
    border-radius: 12px;
}

/* Performance: specific compositing hints only where truly needed */
.task-card { will-change: transform; }
.modal-overlay { will-change: opacity; }

/* =====================================================
   MOBILE RESPONSIVENESS — Mobile-first Breakpoints
   xs  : < 480px
   sm  : 480px – 768px
   md  : 768px – 1024px
   lg  : > 1024px (desktop default — handled above)
   ===================================================== */

/* ── Hamburger / Sidebar Overlay Toggle ─────────────── */
.sidebar-toggle-btn {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 200;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    font-size: 1.4rem;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: background 0.2s;
}
.sidebar-toggle-btn:hover { background: var(--primary-hover); }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 149;
    transition: opacity 0.25s;
}
.sidebar-overlay.active { display: block; }

/* ── Responsive Sidebar Drawer ──────────────────────── */
@media (max-width: 1024px) {
    .sidebar-toggle-btn { display: flex; }

    .sidebar {
        position: fixed;
        top: 0;
        left: -280px;
        height: 100vh;
        width: 260px;
        z-index: 150;
        transition: left 0.28s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: var(--shadow-lg);
    }

    .sidebar.open { left: 0; }

    .main-content {
        width: 100%;
        flex: 1;
    }

    .app-container {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
        overflow: visible;
    }

    .main-content {
        overflow-y: auto;
        height: 100vh;
    }
}

/* ── Top Header ─────────────────────────────────────── */
@media (max-width: 1024px) {
    .top-header {
        padding: 1rem 1rem 0.75rem 68px; /* leave room for hamburger */
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    .board-header {
        padding-bottom: 0.5rem;
    }

    .project-completion-bar {
        padding: 0.6rem 1rem;
        flex-wrap: wrap; /* allow wrapping on narrow screens */
        gap: 0.5rem;
    }

    .page-title { font-size: 1.4rem; }
}

@media (max-width: 480px) {
    .top-header {
        padding: 0.75rem 0.75rem 0.5rem 60px;
        align-items: flex-start;
        flex-direction: column; /* stack breadcrumb/title and actions */
    }

    .page-title { font-size: 1.2rem; }

    .header-actions {
        width: 100%; /* take full width to distribute buttons */
        justify-content: flex-start;
        gap: 0.5rem;
        flex-wrap: wrap;
    }
    
    .header-actions .btn {
        flex: 1; /* let buttons stretching equally */
        justify-content: center;
        font-size: 0.75rem;
        padding: 0.4rem 0.6rem;
    }

    .project-completion-bar {
        flex-direction: column;
        align-items: stretch;
    }
    .completion-track {
        order: -1; /* visually place the progress bar at top if it wraps */
    }
    .completion-label-wrapper { align-self: flex-start; }

    .header-actions .btn { font-size: 0.78rem; padding: 0.45rem 0.75rem; }
}

/* ── Stats Grid ─────────────────────────────────────── */
@media (max-width: 1024px) {
    .stats-grid {
        padding: 0 1rem;
        grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
        gap: 1rem;
        margin-bottom: 1.5rem;
    }
}

@media (max-width: 600px) {
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
        padding: 0 0.75rem;
    }

    .stat-card { padding: 1rem; }
    .stat-info h3 { font-size: 1.4rem; }
    .stat-icon { width: 40px; height: 40px; font-size: 1.2rem; }
}

@media (max-width: 360px) {
    .stats-grid { grid-template-columns: 1fr; }
}

/* ── Dashboard Sections ─────────────────────────────── */
@media (max-width: 1024px) {
    .projects-overview-section,
    .stage-overview-section,
    .list-container { padding: 0 1rem 1.5rem; }

    .project-cards-container {
        grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
        gap: 1rem;
    }

    .section-header { margin-bottom: 1rem; }
}

@media (max-width: 600px) {
    .project-cards-container { grid-template-columns: 1fr; }
    .section-header { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
    .section-header h3 { font-size: 1.05rem; }
}

/* ── Project filter wrap on dashboard ──────────────── */
@media (max-width: 600px) {
    #project-filter-select {
        width: 100%;
        padding: 0.55rem 0.75rem;
        font-size: 0.85rem;
    }
}

/* ── Tables: responsive card layout on mobile ───────── */
@media (max-width: 768px) {
    .table-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    table { min-width: 500px; }
    th, td { padding: 0.75rem 1rem; }
}

@media (max-width: 540px) {
    /* Stack table into cards on very small screens */
    .table-container { overflow: visible; border: none; background: transparent; }
    table, thead, tbody, th, td, tr { display: block; }
    thead { display: none; }
    tr {
        background: var(--bg-surface);
        border: 1px solid var(--border-color);
        border-radius: var(--radius-lg);
        margin-bottom: 1rem;
        padding: 0.75rem 1rem;
        box-shadow: var(--shadow-sm);
    }
    td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.45rem 0;
        border-bottom: 1px solid var(--border-color);
        font-size: 0.85rem;
    }
    td:last-child { border-bottom: none; }
    td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-main);
        font-size: 0.78rem;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        margin-right: 0.5rem;
        flex-shrink: 0;
    }
}

/* ── Forms ──────────────────────────────────────────── */
@media (max-width: 768px) {
    .form-row {
        flex-direction: column;
        gap: 0;
    }
    .form-row .col { flex: unset; }

    .form-group input,
    .form-group textarea,
    .form-group select {
        padding: 0.75rem;
        font-size: 0.9rem;
    }
}

/* ── Modals ─────────────────────────────────────────── */
@media (max-width: 768px) {
    .modal-overlay {
        align-items: flex-end;
        padding: 0;
    }

    .modal-content {
        max-width: 100% !important;
        width: 100%;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        transform: translateY(100%);
        max-height: 92vh;
        overflow-y: auto;
    }

    .modal-overlay.active .modal-content { transform: translateY(0); }

    /* Task Modal override — full height drawer on mobile */
    .task-modal-content {
        max-width: 100% !important;
        width: 100%;
        height: 92vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    }

    .task-modal-content > div[style] {
        flex-direction: column !important;
        height: auto !important;
        overflow: visible !important;
    }

    .task-form-panel {
        border-right: none !important;
        border-bottom: 1px solid var(--border-color);
        overflow-y: visible;
    }

    #task-tabs {
        flex: unset !important;
        height: 340px;
    }

    /* User Modal on mobile */
    .user-modal-styled { max-width: 100% !important; }
}

@media (max-width: 480px) {
    .modal-content { max-height: 96vh; }
    .modal-header { padding: 1rem; }
    .modal-header h3 { font-size: 1rem; }
    #project-form, #task-form, .modal-body { padding: 1rem; }
    .modal-actions { gap: 0.5rem; flex-wrap: wrap; }
    .modal-actions .btn { flex: 1; justify-content: center; }

    .user-modal-header { padding: 1rem; }
    .user-modal-header h3 { font-size: 1rem; }
    .user-form-section { padding: 1rem 1rem 0.5rem; }
    .user-modal-actions { padding: 0.75rem 1rem 1rem; flex-direction: column; gap: 0.5rem; }
    .user-modal-actions > div[style] { width: 100% !important; }
    .user-modal-actions .btn { flex: 1; justify-content: center; }

    /* Stage Customize modal */
    #stage-customize-list { grid-template-columns: 1fr !important; }
}

/* ── Kanban / Board ─────────────────────────────────── */
@media (max-width: 1024px) {
    .kanban-board { padding: 0 1rem 1.5rem; gap: 1rem; }
    .project-completion-bar { padding: 0.6rem 1rem; }
    .board-filter-bar { padding: 0.5rem 1rem; gap: 0.5rem; }
}

@media (max-width: 768px) {
    .kanban-board {
        flex-direction: row; /* keep horizontal scroll on mobile */
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
        padding: 0 0.75rem 1.5rem;
        gap: 0.75rem;
    }

    .kanban-col {
        width: 280px;
        min-width: 280px;
        scroll-snap-align: start;
    }
}

@media (max-width: 480px) {
    .kanban-col { width: 260px; min-width: 260px; }
}

/* ── Auth page ──────────────────────────────────────── */
@media (max-width: 540px) {
    .auth-card { margin: 1rem; padding: 1.5rem 1rem; width: auto; }
    .auth-logo { font-size: 1.1rem; }
}

/* ── Buttons: touch-friendly ────────────────────────── */
@media (max-width: 768px) {
    .btn { min-height: 42px; }
    .btn-sm { min-height: 36px; }
}

/* ── Utility: no horizontal overflow ────────────────── */
@media (max-width: 1024px) {
    html, body { overflow-x: hidden; }
}

/* =============================================================================
   TAG STYLES
   ============================================================================= */

/* Base chip — settings table + task modal picker */
.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.22rem 0.6rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    border: 1px solid transparent;
    white-space: nowrap;
    line-height: 1.4;
    cursor: default;
}
.tag-chip button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 0;
    color: inherit;
    opacity: 0.65;
    transition: opacity 0.15s;
    margin-left: 0.1rem;
}
.tag-chip button:hover { opacity: 1; }

/* Smaller chip used on kanban cards */
.tag-chip-sm {
    display: inline-flex;
    align-items: center;
    padding: 0.13rem 0.42rem;
    border-radius: 999px;
    font-size: 0.67rem;
    font-weight: 600;
    border: 1px solid transparent;
    white-space: nowrap;
    line-height: 1.4;
}

/* Tag chip strip on kanban task cards */
.card-tag-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.28rem;
    margin: 0.4rem 0 0.2rem;
}

/* Tag picker inside the task form */
.tag-picker {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-app);
    padding: 0.45rem 0.6rem;
    transition: border-color 0.2s;
}
.tag-picker:focus-within { border-color: var(--primary); }

.tag-picker select {
    width: 100%;
    border: none !important;
    background: transparent !important;
    padding: 0.25rem 0 !important;
    font-size: 0.85rem;
    cursor: pointer;
    color: var(--text-secondary);
    outline: none;
    box-shadow: none !important;
}

.tag-picker-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.5rem;
}
.tag-picker-chips:empty { display: none; }

/* Tag colour palette — settings modal */
.tag-color-palette {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.4rem;
}
.color-swatch {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    padding: 0;
    outline: none;
    transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.color-swatch:hover  { transform: scale(1.2); }
.color-swatch.selected {
    border-color: var(--text-main);
    transform: scale(1.18);
    box-shadow: 0 0 0 3px var(--bg-surface);
}

/* =============================================================================
   ENHANCED MOBILE RESPONSIVENESS
   ============================================================================= */

/* On mobile the board page body scrolls vertically; restore overflow */
@media (max-width: 1024px) {
    .main-content.has-board {
        overflow: visible;
        min-height: unset;
    }
    .kanban-board {
        min-height: unset;
        /* re-enable natural column height (no stretch) on mobile where
           columns vary in length and viewport height isn't fixed */
        align-items: flex-start;
    }
}

/* Board filter bar — horizontal scroll instead of wrapping on mobile */
@media (max-width: 768px) {
    .board-filter-bar {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding: 0.5rem 0.75rem;
        gap: 0.4rem;
    }
    .board-filter-bar::-webkit-scrollbar { display: none; }
    .board-filter-bar select {
        flex-shrink: 0;
        min-width: 110px;
        max-width: 140px;
        font-size: 0.75rem;
    }
    .filter-label, .filter-clear-btn { flex-shrink: 0; }
}

/* Settings/admin sections on small mobile */
@media (max-width: 600px) {
    /* Sprint & Tag section cards: stack header buttons full-width */
    .sprint-section-card .user-modal-header {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    .sprint-section-card .user-modal-header .btn {
        margin-left: 0 !important;
        width: 100%;
        justify-content: center;
    }
}

/* Tag chips on very small screens */
@media (max-width: 480px) {
    .card-tag-chips { gap: 0.2rem; }
    .tag-chip-sm    { font-size: 0.62rem; padding: 0.1rem 0.35rem; }
    .tag-picker-chips { gap: 0.3rem; }
    .tag-color-palette { gap: 0.4rem; }
    .color-swatch  { width: 24px; height: 24px; }
}

/* Board breadcrumb/title on mobile */
@media (max-width: 480px) {
    .breadcrumb  { font-size: 0.78rem; }
    .page-title  { font-size: 1.1rem; }
    .board-header .header-actions { gap: 0.4rem; }
}

/* Task modal: iOS touch scroll */
@media (max-width: 768px) {
    .task-form-panel { -webkit-overflow-scrolling: touch; }
}

/* User modal on very small phones */
@media (max-width: 400px) {
    .user-modal-header { flex-wrap: wrap; gap: 0.5rem; }
    .user-modal-header .close-btn { margin-left: auto; }
    .user-form-section { padding: 0.75rem; }
}

/* Tables: ensure action cells flex on mobile card layout */
@media (max-width: 600px) {
    td[data-label="Actions"] {
        display: flex !important;
        gap: 0.4rem;
        flex-wrap: wrap;
    }
}
