/* 1. CORE THEME VARIABLES & RESET */
:root {
    --bg-light: #f8f9fa;
    --bg-dark: #0b0f19;
    --text-light: #212529;
    --text-dark: #ffffff;
    --surface-light: #ffffff;
    --surface-dark: #1e2336;
    --border-light: #dee2e6;
    --border-dark: #2d344a;
}

body {
    background-color: var(--bg-light);
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    color: var(--text-light);
    transition: background-color 0.3s ease, color 0.3s ease;
}

h1, h2, h4, h5 { font-weight: 700; }

/* 2. SHARED COMPONENTS & FORMS */
.modern-input {
    border: 1px solid var(--border-light);
    border-radius: 6px;
    height: 38px;
    background-color: var(--surface-light);
    color: var(--text-light);
    transition: border-color 0.3s, background-color 0.3s, color 0.3s;
}
.modern-input:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
    outline: none;
}

.user-badge { transition: transform 0.2s ease; }
.user-badge:hover { transform: translateY(-2px); }

.main-task-card, .sub-task {
    background-color: var(--surface-light);
    border: 1px solid var(--border-light);
    border-radius: 8px !important;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.3s, border-color 0.3s;
}

.sub-task { margin-left: 20px; }
.sub-task:hover {
    transform: translateX(3px);
    box-shadow: 0 4px 10px rgba(0,0,0,0.04) !important;
}

.action-btn {
    background-color: var(--surface-light);
    color: #495057;
    border: 1px solid var(--border-light);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    transition: all 0.2s ease;
    padding: 0;
}
.action-btn:hover { background-color: #f1f3f5; color: #212529; border-color: #ced4da; }
.action-btn.delete-btn:hover { color: #dc3545; border-color: #dc3545; background-color: #fff5f5; }
.action-btn.success-btn:hover { color: #28a745; border-color: #28a745; background-color: #f4fdf5; }

.toggle-btn {
    width: 28px; height: 28px; padding: 0; display: flex;
    align-items: center; justify-content: center; border-radius: 6px;
    transition: all 0.2s ease; background-color: var(--surface-light); border: 1px solid var(--border-light); color: #495057;
}
.toggle-btn[aria-expanded="true"] .icon-closed { display: none; }
.toggle-btn[aria-expanded="false"] .icon-open { display: none; }
.toggle-btn:focus { outline: none !important; box-shadow: none !important; }

.drag-handle { cursor: grab; opacity: 0.3; transition: opacity 0.2s ease; }
.drag-handle:hover { opacity: 0.8; }
.drag-handle:active { cursor: grabbing; }
.main-drag-handle, .sub-drag-handle { user-select: none; cursor: grab; }
.main-drag-handle:active, .sub-drag-handle:active { cursor: grabbing; }

.completed-text { color: #adb5bd !important; opacity: 0.85 !important; text-decoration: none !important; transition: color 0.3s ease; }

/* MULTI-ACTION TOOLBAR & KEYWORD EDIT MODE */
.kw-edit-mode .keyword-badge {
    border: 1px dashed #adb5bd !important;
    opacity: 0.9;
}
.multi-action-toolbar {
    display: none;
    background-color: #f8f9fa;
    border-radius: 6px;
    padding: 4px 8px;
    border: 1px solid #dee2e6;
}
.kw-edit-mode .multi-action-toolbar {
    display: flex !important;
}
.kw-edit-mode .default-actions {
    display: none !important;
}

/* --- MULTILINE TEXT HELPERS FOR TASKS AND SUBCATEGORIES --- */
.task-title-text {
    white-space: normal;
    word-break: break-word;
    line-height: 1.3;
    flex: 1; 
    text-align: left;
    margin-right: 10px;
}

.subtask-text {
    white-space: normal !important;
    word-break: break-word !important;
    text-align: left;
    max-width: 100%;
    line-height: 1.4;
    display: inline-block;
}

/* --- THE FIX: ENFORCING STRICT WRAPPING FOR LONG DESCRIPTIONS --- */
.keyword-list {
    min-width: 0;
    width: 100%;
}

.keyword-chip-wrap {
    max-width: 100%;
    display: inline-flex;
    min-width: 0;
    box-sizing: border-box;
}

.keyword-chip-wrap form {
    max-width: 100%;
    display: inline-flex;
    min-width: 0;
    box-sizing: border-box;
    margin: 0;
}

.keyword-badge {
    display: inline-flex;
    align-items: flex-start;
    background-color: var(--surface-light);
    color: #495057;
    border: 2px solid #ced4da;
    border-radius: 12px;
    padding: 6px 14px;
    margin-right: 6px; margin-bottom: 6px; margin-top: 4px;
    font-size: 0.85rem; font-weight: 600; letter-spacing: 0.3px;
    cursor: grab; user-select: none; transition: all 0.2s ease;

    /* STRICTEST WRAPPING RULES */
    max-width: 100%;
    min-width: 0;
    width: fit-content;
    box-sizing: border-box;
    white-space: normal !important;
    word-break: break-word !important;
    overflow-wrap: break-word !important;
    text-align: left;
    line-height: 1.4;
    height: auto;
    flex-shrink: 1;
}

.kw-text {
    white-space: normal !important;
    word-break: break-word !important;
    overflow-wrap: break-word !important;
    max-width: 100%;
    display: inline-block;
    min-width: 0;
}

.keyword-badge:active { cursor: grabbing; }
.keyword-badge:hover { background-color: #f8f9fa; border-color: #adb5bd; transform: translateY(-1px); }

/* CUSTOM COMPLETED KEYWORD & SUBCATEGORY STYLING */
.kw-completed, .sub-completed { 
    background-color: #ffffff !important; 
    border: 2px solid #28a745 !important; 
    color: #212529 !important; 
    font-weight: bold;
}

.add-keyword-badge { border: 2px dashed #ced4da !important; color: #6c757d !important; cursor: pointer !important; background-color: transparent !important; }
.add-keyword-badge:hover { border-color: #28a745 !important; color: #28a745 !important; background-color: #f4fdf5 !important; transform: translateY(-1px); }

.sortable-ghost { opacity: 0.4 !important; }
.sortable-drag { cursor: grabbing !important; }

/* --- RIGHT CLICK MENU (FIXED) --- */
#keywordContextMenu {
    display: none;
    position: absolute;
    z-index: 1000;
    background-color: var(--surface-light);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 4px 0;
    min-width: 140px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}
.context-item { padding: 8px 15px; cursor: pointer; font-size: 0.9rem; font-weight: 600; transition: background-color 0.2s; color: var(--text-light); }
.context-item:hover { background-color: var(--bg-light); }

.profile-avatar { width: 72px; height: 72px; border-radius: 50%; background-color: #f8f9fa; color: #343a40; display: flex; align-items: center; justify-content: center; font-size: 2.2rem; font-weight: 700; border: 3px solid #343a40; }

/* 3. GRID VIEW COMPONENTS & MODALS */
.app-grid-container { display: flex; flex-wrap: wrap; justify-content: flex-start; gap: 2%; padding: 20px 0; }
.grid-task-wrapper { width: 15%; margin-bottom: 2%; cursor: grab; }
.grid-task-wrapper:active { cursor: grabbing; }


.app-box, .modal-content {
    border: 1px solid #ced4da !important;
}

.app-box {
    width: 100%; aspect-ratio: 4 / 3; background-color: #ffffff;
    border-radius: 20px; display: flex; flex-direction: column; justify-content: center; align-items: center;
    transition: transform 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
    position: relative; pointer-events: none; box-shadow: 0 .125rem .25rem rgba(0,0,0,.075);
    padding: 10px;
}
.grid-task-wrapper:not(.sortable-drag) .app-box { pointer-events: auto; cursor: pointer; }
.app-box:hover { transform: translateY(-6px); background-color: #f1f3f5; box-shadow: 0 .5rem 1rem rgba(0,0,0,.15) !important; }

.grid-reminder-indicator {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #28a745;
    font-size: 1.45rem;
    line-height: 1;
    z-index: 2;
    pointer-events: none;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.22));
}

.app-icon { font-size: 32px; font-weight: 800; color: #212529; margin-bottom: 10px; }

/* APP TITLE: MULTI-LINE CLAMP UP TO 2 LINES */
.app-title { 
    font-size: 14px; 
    font-weight: 600; 
    color: #212529; 
    text-align: center; 
    width: 100%; 
    word-break: break-word; 
    white-space: normal; 
    display: -webkit-box; 
    -webkit-line-clamp: 2; 
    -webkit-box-orient: vertical; 
    overflow: hidden; 
    line-height: 1.3; 
}

@media (max-width: 992px) { .grid-task-wrapper { width: 23.5%; } }
@media (max-width: 768px) { .grid-task-wrapper { width: 32%; } .sub-task { margin-left: 5px !important; } .keyword-badge { font-size: 0.75rem; padding: 3px 10px; } }
@media (max-width: 576px) { .grid-task-wrapper { width: 48%; } }

.custom-progress { background-color: #e9ecef; border-radius: 4px; overflow: hidden; box-shadow: inset 0 1px 2px rgba(0,0,0,0.05); }

/* 4. DARK THEME OVERRIDES */
body[data-theme="dark"] { background-color: var(--bg-dark); color: var(--text-dark); }

body[data-theme="dark"] .bg-white, body[data-theme="dark"] .card, body[data-theme="dark"] .main-task-card,
body[data-theme="dark"] .sub-task, body[data-theme="dark"] .modal-content, body[data-theme="dark"] .alert-info,
body[data-theme="dark"] .main-header-card, body[data-theme="dark"] .header-card {
    background-color: var(--surface-dark) !important; border-color: var(--border-dark) !important; color: var(--text-dark) !important;
}

body[data-theme="dark"] .text-dark, body[data-theme="dark"] .chart-text { color: #ffffff !important; }
body[data-theme="dark"] .text-secondary { color: #adb5bd !important; }
body[data-theme="dark"] .bg-light, body[data-theme="dark"] .modal-body.bg-light { background-color: var(--bg-dark) !important; }

body[data-theme="dark"] .action-btn, body[data-theme="dark"] .toggle-btn { background-color: #252a40; border-color: #4a4e6d; color: #e2e8f0; }
body[data-theme="dark"] .action-btn:hover, body[data-theme="dark"] .toggle-btn:hover { background-color: #3c3f58; color: #fff; }

body[data-theme="dark"] .keyword-badge, body[data-theme="dark"] .sub-badge {
    background-color: #252a40; border-color: rgba(108, 117, 125, 0.5) !important; color: #e2e8f0; border-width: 1px; border-style: solid;
}
body[data-theme="dark"] .keyword-badge:hover, body[data-theme="dark"] .sub-badge:hover { background-color: #3c3f58; }

body[data-theme="dark"] .kw-completed, body[data-theme="dark"] .sub-completed {
    background-color: transparent !important; color: var(--text-dark) !important; border: 2px solid #28a745 !important;
}

body[data-theme="dark"] .modern-input { background-color: var(--surface-dark); border-color: #4a4e6d; color: #fff; }
body[data-theme="dark"] .modern-input:focus { border-color: #ffffff; background-color: #252a40; box-shadow: none; }

body[data-theme="dark"] .badge-light { background-color: #252a40; color: #e2e8f0; border-color: rgba(108, 117, 125, 0.5) !important; border-width: 1px; border-style: solid; }
body[data-theme="dark"] .profile-avatar { background-color: #252a40; color: #fff; border-color: #4a4e6d; }

body[data-theme="dark"] .dynamic-btn { background-color: #e2e8f0; color: #0b0f19; border-color: #e2e8f0; transition: all 0.3s; }
body[data-theme="dark"] .dynamic-btn-outline { color: #e2e8f0; border-color: #e2e8f0; background-color: transparent; transition: all 0.3s; }
body[data-theme="dark"] .dynamic-btn-outline:hover { background-color: #e2e8f0; color: #0b0f19; }

body[data-theme="dark"] .multi-action-toolbar { background-color: #252a40; border: 1px solid #4a4e6d; }

body[data-theme="dark"] .app-box, body[data-theme="dark"] .modal-content { border: 1px solid #6c757d !important; }
body[data-theme="dark"] .app-box { background-color: #3c3f58; box-shadow: none !important; }
body[data-theme="dark"] .app-box:hover { background-color: #4a4e6d; box-shadow: 0 10px 20px rgba(0,0,0,0.4) !important; }
body[data-theme="dark"] .app-icon { color: #ffffff; }
body[data-theme="dark"] .app-title { color: #e2e8f0; }

body[data-theme="dark"] #keywordContextMenu { background-color: var(--surface-dark); border-color: var(--border-dark); }
body[data-theme="dark"] .context-item { color: var(--text-dark); }
body[data-theme="dark"] .context-item:hover { background-color: #252a40; }
body[data-theme="dark"] .context-item.text-danger { color: #dc3545 !important; }

/* 5. CUSTOM MODAL WIDTH FOR DESKTOP */
.task-modal-dialog {
    max-width: 95%;
    margin: 1.75rem auto;
}

@media (min-width: 992px) {
    .task-modal-dialog {
        max-width: 50%;
    }
}

/* 6. COMPLETED IMAGE STAMP */
.completed-stamp {
    height: 32px; /* Perfect match for the 32px action buttons to prevent row stretching */
    width: auto;
    transform: rotate(-15deg) translateY(-2px);
    opacity: 0.95;
    pointer-events: none;
    user-select: none;
    margin-left: 12px !important;
    filter: drop-shadow(0px 2px 4px rgba(0,0,0,0.15));
}

/* 7. TASK REMINDERS */
.action-btn.reminder-btn:hover {
    color: #17a2b8;
    border-color: #17a2b8;
    background-color: #f1fcfe;
}

.action-btn.reminder-btn.reminder-active {
    color: #28a745;
    border-color: #28a745;
    background-color: #f4fdf5;
}

.reminder-modal-dialog {
    max-width: 430px;
}

.reminder-modal-content {
    border-radius: 14px;
    overflow: hidden;
}

.reminder-help-text {
    line-height: 1.45;
}

.reminder-toast-container {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 2000;
    width: min(480px, calc(100vw - 48px));
    pointer-events: none;
}

.reminder-toast {
    position: relative;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    min-height: 132px;
    margin-top: 12px;
    padding: 22px 24px;
    border: 1px solid var(--border-light);
    border-left: 6px solid #28a745;
    border-radius: 12px;
    background-color: var(--surface-light);
    color: var(--text-light);
    pointer-events: auto;
    animation: reminder-toast-in 0.2s ease-out;
}

.reminder-toast-content {
    min-width: 0;
    width: 100%;
    padding-right: 34px;
}

.reminder-toast-title {
    margin-bottom: 7px;
    font-size: 1.18rem;
}

.reminder-toast-message {
    margin-bottom: 8px;
    font-size: 1.08rem;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.reminder-reset-message {
    margin-top: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    color: #28a745;
}

.reminder-toast-help {
    margin-top: 10px;
    font-size: 0.88rem;
    line-height: 1.4;
    color: #6c757d;
}

.reminder-toast-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 9px;
    margin-top: 18px;
}

.reminder-toast-actions .btn {
    min-width: 106px;
    min-height: 38px;
}

.reminder-action-status {
    margin-top: 10px;
    font-size: 0.88rem;
    font-weight: 600;
    color: #dc3545;
}

.reminder-toast-close {
    position: absolute;
    top: 14px;
    right: 16px;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #6c757d;
    font-size: 1.65rem;
    line-height: 1;
    padding: 0 0 3px;
    cursor: pointer;
}

.reminder-toast-close:hover,
.reminder-toast-close:focus {
    background-color: rgba(108, 117, 125, 0.12);
    color: #343a40;
    outline: none;
}

@keyframes reminder-toast-in {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

body[data-theme="dark"] .action-btn.reminder-btn:hover {
    color: #6edff6;
    border-color: #17a2b8;
    background-color: #233844;
}

body[data-theme="dark"] .action-btn.reminder-btn.reminder-active {
    color: #57d879;
    border-color: #28a745;
    background-color: #203a2a;
}

body[data-theme="dark"] .reminder-toast {
    background-color: var(--surface-dark);
    border-color: var(--border-dark);
    border-left-color: #28a745;
    color: var(--text-dark);
}

body[data-theme="dark"] .reminder-toast-close {
    color: #adb5bd;
}

body[data-theme="dark"] .reminder-toast-close:hover,
body[data-theme="dark"] .reminder-toast-close:focus {
    background-color: rgba(173, 181, 189, 0.14);
    color: #ffffff;
}

body[data-theme="dark"] .reminder-toast-help {
    color: #adb5bd;
}

@media (max-width: 576px) {
    .reminder-toast-container {
        right: 10px;
        bottom: 10px;
        width: calc(100vw - 20px);
    }

    .reminder-toast {
        min-height: 112px;
        padding: 18px;
    }

    .reminder-toast-actions .btn {
        flex: 1 1 120px;
    }
}

/* 8. THREE-DOT ACTION MENUS */
.action-menu {
    position: relative;
    flex-shrink: 0;
}

.action-menu-toggle.dropdown-toggle::after {
    display: none;
}

.action-menu-toggle {
    font-size: 0.95rem;
}

.action-menu-toggle.has-active-reminder {
    color: #28a745;
    border-color: #28a745;
}

.action-menu-dropdown {
    min-width: 178px;
    padding: 6px;
    border: 1px solid var(--border-light);
    border-radius: 9px;
    background-color: var(--surface-light);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
    z-index: 1085;
}

.action-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 10px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text-light);
    font-size: 0.92rem;
    font-weight: 600;
    line-height: 1.2;
    text-align: left;
}

.action-menu-item i {
    width: 16px;
    text-align: center;
}

.action-menu-item:hover,
.action-menu-item:focus {
    background-color: var(--bg-light);
    color: var(--text-light);
    outline: none;
}

.action-menu-item.reminder-menu-active {
    color: #28a745;
}

.action-menu-delete {
    color: #dc3545;
}

.action-menu-delete:hover,
.action-menu-delete:focus {
    background-color: #fff2f3;
    color: #c82333;
}

.action-menu-dropdown .dropdown-divider {
    margin: 5px 0;
    border-top-color: var(--border-light);
}

.selection-mode-label {
    padding: 0 4px;
    color: #6c757d;
    font-size: 0.78rem;
    font-weight: 700;
    white-space: nowrap;
}

.selection-apply-btn.selection-edit-action {
    color: #007bff;
    border-color: #007bff;
}

.selection-apply-btn.selection-delete-action {
    color: #dc3545;
    border-color: #dc3545;
}

body[data-theme="dark"] .action-menu-dropdown {
    background-color: var(--surface-dark);
    border-color: #4a4e6d;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
}

body[data-theme="dark"] .action-menu-item {
    color: #e2e8f0;
}

body[data-theme="dark"] .action-menu-item:hover,
body[data-theme="dark"] .action-menu-item:focus {
    background-color: #343a52;
    color: #ffffff;
}

body[data-theme="dark"] .action-menu-item.reminder-menu-active {
    color: #57d879;
}

body[data-theme="dark"] .action-menu-delete {
    color: #ff7b86;
}

body[data-theme="dark"] .action-menu-delete:hover,
body[data-theme="dark"] .action-menu-delete:focus {
    background-color: #4a2930;
    color: #ff9aa3;
}

body[data-theme="dark"] .action-menu-dropdown .dropdown-divider {
    border-top-color: #4a4e6d;
}

body[data-theme="dark"] .selection-mode-label {
    color: #adb5bd;
}

@media (max-width: 576px) {
    .action-menu-dropdown {
        min-width: 164px;
    }

    .selection-mode-label {
        display: none;
    }
}

/* Keep an open three-dot menu above later task cards on iPhone/WebKit. */
.task-container.action-menu-layer,
.subtask-container.action-menu-layer,
.main-task-card.action-menu-layer,
.modal-dialog.action-menu-layer {
    position: relative !important;
    z-index: 2200 !important;
}

.modal-content.action-menu-layer {
    overflow: visible !important;
    position: relative !important;
    z-index: 2201 !important;
}

.action-menu.action-menu-open {
    position: relative;
    z-index: 2202 !important;
}

.action-menu.action-menu-open .action-menu-dropdown,
.action-menu-dropdown.show {
    z-index: 2203 !important;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

/* Bootstrap/Popper may add GPU transforms on WebKit. Keep the menu clickable. */
.action-menu-dropdown {
    pointer-events: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: manipulation;
}
