/* === CSS Custom Properties (Material 3 inspired) === */
:root {
    --primary: #1565C0;
    --primary-light: #BBDEFB;
    --primary-container: #E3F2FD;
    --on-primary: #FFFFFF;
    --on-primary-container: #0D47A1;
    --surface: #FAFAFA;
    --surface-container: #FFFFFF;
    --surface-variant: #F0F0F0;
    --on-surface: #1C1B1F;
    --on-surface-variant: #6B6B6B;
    --secondary-container: #E8DEF8;
    --on-secondary-container: #1D192B;
    --error: #F44336;
    --outline: #B0B0B0;
    --green: #4CAF50;
    --yellow: #FFC107;
    --red: #F44336;
    --blue: #2196F3;
    --orange: #FF9800;
    --shadow: 0 2px 8px rgba(0,0,0,0.12);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.15);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    --transition: 0.2s ease;
}

/* === Dark Theme === */
[data-theme="dark"] {
    --primary: #90CAF9;
    --primary-light: #1A3A5C;
    --primary-container: #0D2137;
    --on-primary: #003258;
    --on-primary-container: #D1E4FF;
    --surface: #121212;
    --surface-container: #1E1E1E;
    --surface-variant: #2C2C2C;
    --on-surface: #E0E0E0;
    --on-surface-variant: #A0A0A0;
    --secondary-container: #332D41;
    --on-secondary-container: #E8DEF8;
    --error: #EF9A9A;
    --outline: #555;
    --shadow: 0 2px 8px rgba(0,0,0,0.4);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.5);
}
[data-theme="dark"] .app-header {
    background: #1A1A2E;
}
[data-theme="dark"] .modal {
    background: #1E1E1E;
}
[data-theme="dark"] .modal-overlay {
    background: rgba(0,0,0,0.7);
}
[data-theme="dark"] input,
[data-theme="dark"] textarea,
[data-theme="dark"] select {
    background: #2C2C2C;
    color: #E0E0E0;
    border-color: #444;
}
[data-theme="dark"] .folder-card {
    background: #1E1E1E;
}
[data-theme="dark"] .task-item {
    background: #1E1E1E;
}
[data-theme="dark"] .task-item:hover {
    background: #252525;
}
[data-theme="dark"] .filter-btn {
    background: #2C2C2C;
    color: #A0A0A0;
}
[data-theme="dark"] .filter-btn.active {
    background: var(--primary-container);
    color: var(--on-primary-container);
}
[data-theme="dark"] .btn-text-header {
    color: rgba(255,255,255,0.8);
}
[data-theme="dark"] .auth-container {
    background: #1E1E1E;
}
[data-theme="dark"] .priority-badge { opacity: 0.9; }

/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-tap-highlight-color: transparent; }
body {
    font-family: 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--surface);
    color: var(--on-surface);
    min-height: 100dvh;
    overflow-x: hidden;
}
input, textarea, select, button { font-family: inherit; font-size: inherit; }
a { color: var(--primary); }

/* === Utility === */
.hidden { display: none !important; }
.text-danger { color: var(--error); }

/* === Screens === */
.screen { min-height: 100dvh; display: flex; flex-direction: column; }

/* === Auth Screen === */
.auth-container {
    max-width: 380px;
    width: 100%;
    margin: auto;
    padding: 32px 24px;
}
.auth-logo {
    text-align: center;
    margin-bottom: 8px;
}
.auth-logo h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
    margin-top: 8px;
}
#auth-title {
    text-align: center;
    font-size: 16px;
    color: var(--on-surface-variant);
    margin-bottom: 24px;
    font-weight: 400;
}
#auth-form { display: flex; flex-direction: column; gap: 12px; }
#auth-toggle {
    margin-top: 8px;
    align-self: center;
}

/* === Form Fields === */
.form-field { display: flex; flex-direction: column; gap: 4px; }
.form-field label {
    font-size: 13px;
    font-weight: 500;
    color: var(--on-surface-variant);
}
.form-field input,
.form-field textarea,
.form-field select {
    padding: 12px 14px;
    border: 1.5px solid var(--outline);
    border-radius: var(--radius-sm);
    background: var(--surface-container);
    color: var(--on-surface);
    transition: border-color var(--transition);
    outline: none;
}
.form-field input:focus,
.form-field textarea:focus,
.form-field select:focus {
    border-color: var(--primary);
}
.form-field textarea { resize: vertical; }
.password-row { display: flex; gap: 6px; align-items: center; }
.password-row input { flex: 1; }
.password-row .btn-icon {
    width: 44px; height: 44px; flex-shrink: 0;
    border: 1.5px solid var(--outline); border-radius: var(--radius-sm);
    background: var(--surface-container); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: var(--on-surface-variant); transition: border-color var(--transition);
}
.password-row .btn-icon:hover { border-color: var(--primary); }

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 500;
    font-size: 14px;
    transition: all var(--transition);
    white-space: nowrap;
}
.btn-primary {
    background: var(--primary);
    color: var(--on-primary);
}
.btn-primary:hover { opacity: 0.9; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-danger {
    background: transparent;
    color: var(--error);
    font-weight: 500;
}
.btn-danger:hover { background: rgba(244,67,54,0.08); }
.btn-bold { font-weight: 700; }
.btn-text {
    background: transparent;
    color: var(--primary);
    padding: 8px 12px;
}
.btn-text:hover { background: rgba(21,101,192,0.08); }
.btn-text-header {
    background: transparent;
    color: var(--on-primary-container);
    padding: 6px 12px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 500;
    font-size: 14px;
}
.btn-text-header:hover { background: rgba(0,0,0,0.08); }
.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1.5px solid var(--outline);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn-outline:hover { background: var(--primary-container); }
.btn-full { width: 100%; }
.btn-icon {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    color: inherit;
}
.btn-icon:hover { background: rgba(0,0,0,0.08); }
.btn-loader {
    width: 18px;
    height: 18px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Error Message === */
.error-message {
    color: var(--error);
    font-size: 14px;
    padding: 8px;
    text-align: center;
}

/* === App Header === */
.app-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--primary-container);
    position: sticky;
    top: 0;
    z-index: 10;
}
.app-header .header-info { flex: 1; min-width: 0; }
.app-header h1 {
    font-size: 20px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.header-subtitle {
    font-size: 12px;
    color: var(--on-primary-container);
    opacity: 0.7;
}

/* === Main Content === */
.main-content {
    flex: 1;
    padding: 16px;
    padding-bottom: 80px;
}

/* === Empty State === */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 64px 16px;
    text-align: center;
    color: var(--on-surface-variant);
}
.empty-state p { font-size: 16px; font-weight: 500; margin-top: 12px; }
.empty-state .hint { font-size: 14px; font-weight: 400; opacity: 0.7; margin-top: 4px; }

/* === FAB === */
.fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: var(--primary);
    color: var(--on-primary);
    border: none;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--transition), box-shadow var(--transition);
    z-index: 5;
}
.fab:hover { transform: scale(1.05); box-shadow: 0 6px 20px rgba(0,0,0,0.2); }
.fab .material-symbols-outlined { font-size: 28px; }

/* === Folders Grid === */
.folders-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
}
.folder-card {
    background: var(--surface-container);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: box-shadow var(--transition);
}
.folder-card:hover { box-shadow: var(--shadow-lg); }
.folder-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 12px 8px 0 16px;
}
.folder-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 700;
    flex-shrink: 0;
}
.folder-actions { display: flex; gap: 0; }
.folder-actions .btn-icon { padding: 4px; }
.folder-actions .material-symbols-outlined { font-size: 18px; color: var(--on-surface-variant); }
.folder-card-body {
    padding: 8px 16px 16px;
    cursor: pointer;
}
.folder-card-body:hover { background: rgba(0,0,0,0.02); }
.folder-name {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.folder-count {
    font-size: 12px;
    color: var(--on-surface-variant);
    margin-bottom: 6px;
}
.progress-bar {
    height: 4px;
    background: var(--surface-variant);
    border-radius: 2px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.3s ease;
}

/* === Search Bar === */
.search-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: var(--surface-container);
    border: 1.5px solid var(--outline);
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
}
.search-bar .material-symbols-outlined { color: var(--on-surface-variant); font-size: 22px; }
.search-bar input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 15px;
    color: var(--on-surface);
}

/* === Stats Card === */
.stats-card {
    display: flex;
    justify-content: space-evenly;
    padding: 14px;
    background: var(--secondary-container);
    border-radius: var(--radius);
    margin-bottom: 12px;
}
.stat-item { text-align: center; }
.stat-value { display: block; font-size: 20px; font-weight: 700; }
.stat-value.primary { color: var(--primary); }
.stat-value.green { color: var(--green); }
.stat-value.blue { color: var(--blue); }
.stat-value.yellow { color: var(--yellow); }
.stat-label { font-size: 12px; color: var(--on-secondary-container); }

/* === Filter Bar === */
.filter-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.sort-select {
    padding: 6px 12px;
    border: 1px solid var(--outline);
    border-radius: var(--radius-sm);
    background: var(--surface-container);
    color: var(--on-surface);
    font-size: 13px;
    cursor: pointer;
    margin-left: auto;
}
.filter-btn {
    padding: 6px 16px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--on-surface);
    cursor: pointer;
    font-size: 14px;
    font-weight: 400;
    transition: all var(--transition);
}
.filter-btn.active {
    background: var(--primary-container);
    color: var(--on-primary-container);
    font-weight: 700;
}

/* === Task Card === */
.tasks-list { display: flex; flex-direction: column; gap: 8px; }
.task-card {
    background: var(--surface-container);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px;
    display: flex;
    gap: 10px;
    align-items: flex-start;
    cursor: pointer;
    transition: box-shadow var(--transition);
}
.task-card:hover { box-shadow: var(--shadow-lg); }
.task-card.completed {
    background: var(--surface-variant);
    opacity: 0.75;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.priority-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 6px;
}
.priority-dot.LOW { background: var(--green); }
.priority-dot.MEDIUM { background: var(--yellow); }
.priority-dot.HIGH { background: var(--red); }
.task-checkbox {
    width: 20px;
    height: 20px;
    accent-color: var(--primary);
    cursor: pointer;
    flex-shrink: 0;
    margin-top: 3px;
}
.task-body { flex: 1; min-width: 0; }
.task-file-badge {
    font-size: 11px;
    color: var(--primary);
    margin-bottom: 2px;
}
.task-title {
    font-size: 15px;
    font-weight: 500;
    word-break: break-word;
}
.task-card.completed .task-title { text-decoration: line-through; color: var(--on-surface-variant); }
.task-desc {
    font-size: 13px;
    color: var(--on-surface-variant);
    margin-top: 2px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.task-meta {
    font-size: 12px;
    color: var(--on-surface-variant);
    margin-top: 3px;
}
.task-meta .assignee { color: var(--primary); font-weight: 500; }
.task-due { font-weight: 500; }
.task-due.overdue { color: var(--red); }
.task-due.today { color: var(--orange); }
.task-due.soon { color: var(--yellow); }
.task-due.ok { color: var(--green); }
.task-actions {
    display: flex;
    flex-direction: column;
    gap: 0;
    flex-shrink: 0;
}
.task-actions .btn-icon { padding: 4px; }
.task-actions .material-symbols-outlined { font-size: 20px; }
.star-active { color: var(--yellow) !important; }
.star-inactive { color: var(--outline); }

/* === Modal === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 16px;
}
.modal {
    background: var(--surface-container);
    border-radius: var(--radius-lg);
    padding: 24px;
    width: 100%;
    max-width: 420px;
    max-height: 90dvh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    animation: modalIn 0.2s ease;
}
@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}
.modal-large { max-width: 500px; }
.modal h3 { font-size: 20px; font-weight: 600; margin-bottom: 16px; }
.modal p { font-size: 14px; color: var(--on-surface-variant); line-height: 1.5; margin-bottom: 12px; }
.modal-scroll { overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 12px; }
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--surface-variant);
}

/* === Notification Settings === */
.notif-settings-list { display: block; }
.notif-setting-item {
    display: flex !important;
    width: 100%;
    box-sizing: border-box;
    align-items: center;
    gap: 14px;
    padding: 14px 12px;
    cursor: pointer;
    font-size: 15px;
    border-bottom: 1px solid var(--surface-variant);
}
.notif-setting-item:last-child { border-bottom: none; }
.notif-setting-item input[type="checkbox"] {
    width: 22px;
    height: 22px;
    min-width: 22px;
    accent-color: var(--primary);
    cursor: pointer;
    flex-shrink: 0;
}
.notif-setting-item span { flex: 1; }
.btn-danger-text { color: var(--error) !important; }

/* === Files List (in task modal) === */
.files-list { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.file-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: var(--surface-variant);
    border-radius: 4px;
    font-size: 13px;
}
.file-item .file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-item .btn-icon { padding: 2px; }
.file-item .material-symbols-outlined { font-size: 16px; color: var(--error); }

/* === View Task === */
#view-task-content h3 {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 18px;
    margin-bottom: 12px;
}
.view-field {
    font-size: 13px;
    margin-bottom: 4px;
    color: var(--on-surface-variant);
}
.view-field strong { font-weight: 500; }
.view-files { margin-top: 8px; }
.view-files h4 { font-size: 14px; font-weight: 500; margin-bottom: 6px; }
.view-file-link {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 0;
    font-size: 13px;
    color: var(--primary);
    text-decoration: none;
    cursor: pointer;
}
.view-file-link:hover { text-decoration: underline; }

/* === Responsive === */
@media (max-width: 480px) {
    .folders-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .main-content { padding: 12px; padding-bottom: 80px; }
    .modal { padding: 20px; margin: 8px; }
    .app-header { padding: 10px 12px; }
    .app-header h1 { font-size: 18px; }
    .task-card { padding: 12px 10px; }
}
/* Comments */
.comments-section { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--outline); }
.comments-section h3 { font-size: 14px; color: var(--on-surface-variant); margin-bottom: 8px; }
#comments-list { max-height: 200px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.comment-item {
    padding: 8px 12px; border-radius: var(--radius-sm);
    background: var(--surface-variant); font-size: 13px;
}
.comment-author { font-weight: 600; color: var(--primary); font-size: 12px; }
.comment-time { font-size: 11px; color: var(--on-surface-variant); margin-left: 8px; }
.comment-text { margin-top: 4px; }
.comment-input-row {
    display: flex; gap: 8px; margin-top: 8px; align-items: center;
}
.comment-input-row input {
    flex: 1; padding: 8px 12px; border: 1px solid var(--outline);
    border-radius: var(--radius-sm); background: var(--surface-container);
    color: var(--on-surface);
}

/* History */
.history-section { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--outline); }
.history-toggle {
    font-size: 14px; color: var(--on-surface-variant); cursor: pointer;
    list-style: none; display: flex; align-items: center; gap: 4px;
}
.history-toggle::before { content: '\25B6'; font-size: 10px; transition: transform 0.2s; }
.history-section[open] .history-toggle::before { transform: rotate(90deg); }
#history-list { max-height: 200px; overflow-y: auto; margin-top: 8px; }
.history-item {
    padding: 6px 0; font-size: 12px; color: var(--on-surface-variant);
    border-bottom: 1px solid var(--surface-variant);
}
.history-item:last-child { border-bottom: none; }
.history-action { font-weight: 600; }
.history-time { font-size: 11px; opacity: 0.7; }

/* Pull-to-refresh */
.pull-indicator {
    position: fixed; top: 0; left: 0; right: 0; z-index: 9998;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    padding: 12px; background: var(--primary); color: var(--on-primary);
    font-size: 14px;
    animation: pull-slide 0.3s ease;
}
.pull-indicator.hidden { display: none; }
.pull-indicator .material-symbols-outlined { animation: spin 1s linear infinite; }
@keyframes pull-slide { from { transform: translateY(-100%); } to { transform: translateY(0); } }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* Toast notifications */
#toast-container {
    position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
    z-index: 9999; display: flex; flex-direction: column; gap: 8px; align-items: center;
    pointer-events: none;
}
.toast {
    padding: 12px 24px; border-radius: 12px; color: #fff; font-size: 14px;
    box-shadow: var(--elevation-2); pointer-events: auto;
    animation: toast-in 0.3s ease, toast-out 0.3s ease 2.7s forwards;
    max-width: 90vw; text-align: center;
}
.toast.success { background: #2e7d32; }
.toast.error { background: #c62828; }
.toast.info { background: var(--md-primary); }
@keyframes toast-in { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { from { opacity: 1; } to { opacity: 0; transform: translateY(-20px); } }

@media (min-width: 768px) {
    .folders-grid { grid-template-columns: repeat(3, 1fr); }
    .auth-container { padding: 48px 32px; }
}
@media (min-width: 1024px) {
    .folders-grid { grid-template-columns: repeat(4, 1fr); }
    .main-content { max-width: 900px; margin: 0 auto; }
}
