/*------------------------------------------------------------
    1. Import Fonts
------------------------------------------------------------*/
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500&display=swap');

/*------------------------------------------------------------
    2. Root Variables (Dark Mode Colors)
------------------------------------------------------------*/
:root {
    --background-color: #121212;
    --text-color: #e0e0e0;
    --header-background: #1f1f1f;
    --card-background: #1e1e1e;
    --card-border: #2c2c2c;
    --button-background: #007bff;
    --button-hover-background: #0056b3;
    --button-text-color: #ffffff;
    --input-background: #2c2c2c;
    --input-border: #444444;
}

/*------------------------------------------------------------
    3. Global Styles
------------------------------------------------------------*/
body {
    margin: 0;
    font-family: 'Roboto', sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
}

a {
    text-decoration: none;
    color: inherit;
}

a:visited,
a:hover {
    color: inherit;
}

/* Reset margins and padding for all elements */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/*------------------------------------------------------------
    4. Header Styles
------------------------------------------------------------*/
header {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--header-background);
    padding: 15px;
    position: sticky;
    top: 0;
    z-index: 5;
    /* Ensure header is below back-button */
}

header h1 {
    font-size: 28px;
    margin: 0;
}

.back-button {
    position: absolute;
    left: 15px;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-color);
}

/*------------------------------------------------------------
    5. Forms (Add List and Add Task)
------------------------------------------------------------*/
.add-list-form,
.add-task-form {
    display: flex;
    padding: 15px;
    gap: 10px;
}

.add-list-form input,
.add-task-form input {
    flex: 1;
    padding: 12px;
    font-size: 18px;
    background-color: var(--input-background);
    border: 1px solid var(--input-border);
    border-radius: 5px;
    color: var(--text-color);
}

.add-list-form button,
.add-task-form button {
    padding: 12px 24px;
    font-size: 18px;
    background-color: var(--button-background);
    color: var(--button-text-color);
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

/*------------------------------------------------------------
    6. Lists and Tasks Containers
------------------------------------------------------------*/
.lists-container,
.tasks-container {
    display: flex;
    flex-direction: column;
    padding: 15px;
    gap: 15px;
    /* This creates space between task cards */
}

#active-objectives {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Completed objectives section */
#completed-objectives {
    margin-top: 20px;
    border-top: 1px solid var(--card-border);
    padding-top: 20px;
}

/*------------------------------------------------------------
    7. List Card Styles
------------------------------------------------------------*/
.list-card {
    background-color: var(--card-background);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 20px;
    display: flex;
    align-items: center;
    cursor: pointer;
}

.list-card:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.list-header {
    display: flex;
    align-items: center;
    gap: 10px;
}

.list-name {
    font-size: 24px;
    font-weight: 500;
}

/*------------------------------------------------------------
    8. Task Card Styles
------------------------------------------------------------*/
.task-card {
    background-color: var(--card-background);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 20px;
    display: flex;
    align-items: center;
}

.task-card:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.task-content {
    display: flex;
    align-items: center;
    gap: 15px;
    cursor: pointer;
    flex-grow: 1;
    pointer-events: auto;
    /* Ensure touch events are allowed */
}

.task-buttons {
    display: flex;
    align-items: center;
}

.checkbox {
    font-size: 24px;
}

.task-title {
    font-size: 22px;
    flex: 1;
}

.completed .task-title {
    text-decoration: line-through;
    color: #6c757d;
}

/* Ensure consistent spacing on mobile */
@media (max-width: 600px) {

    .lists-container,
    .tasks-container,
    #active-objectives,
    #completed-objectives {
        gap: 10px;
        /* Slightly reduced gap for mobile, but still maintaining space */
    }

    .task-card {
        padding: 15px;
        /* Slightly reduced padding for mobile */
    }

    #completed-objectives {
        margin-top: 15px;
        padding-top: 15px;
    }

    #completed-objectives::before {
        font-size: 16px;
        margin-bottom: 10px;
    }
}

/*------------------------------------------------------------
    9. Buttons (Edit and Delete)
------------------------------------------------------------*/
.edit-list-button,
.edit-task-button,
.delete-list-button,
.delete-task-button {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    pointer-events: auto;
    /* Ensure touch events are allowed */
}

.edit-list-button,
.edit-task-button {
    color: #ffc107;
    margin-right: 1.5em;
}

.delete-list-button,
.delete-task-button {
    color: #dc3545;
}

/*------------------------------------------------------------
    10. Drag Handle Styles
------------------------------------------------------------*/
/* Style for the drag handle */
.drag-handle {
    cursor: grab;
    /* Indicates draggable area */
    padding: 8px;
    margin-right: 8px;
    font-size: 24px;
    color: #888;
    user-select: none;
    /* Prevents text selection */
}

.drag-handle:active {
    cursor: grabbing;
    /* Changes cursor when active */
}

/* Ensure the card displays flexibly with aligned items */
.list-card,
.task-card {
    display: flex;
    align-items: center;
}

/* Optional: Add spacing between drag handle and content */
.list-card .list-header,
.task-card .task-content {
    display: flex;
    align-items: center;
}

/*------------------------------------------------------------
    11. Mobile Responsiveness
------------------------------------------------------------*/
@media (max-width: 600px) {
    header h1 {
        font-size: 24px;
    }

    .list-name,
    .task-title {
        font-size: 20px;
    }

    .add-list-form input,
    .add-task-form input,
    .add-list-form button,
    .add-task-form button {
        font-size: 16px;
    }

    /* Adjust drag handle size for smaller screens */
    .drag-handle {
        font-size: 20px;
        padding: 6px;
        margin-right: 6px;
    }

    /* Adjust button sizes */
    .edit-list-button,
    .edit-task-button,
    .delete-list-button,
    .delete-task-button {
        font-size: 20px;
        padding: 6px;
    }
}

/*------------------------------------------------------------
    12. Modal Styles
------------------------------------------------------------*/
/* Modal container */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.6);
    align-items: center;
    justify-content: center;
    pointer-events: none;
    /* Prevent blocking interactions when hidden */
}

/* Modal Content */
.modal-content {
    background-color: var(--card-background);
    margin: auto;
    padding: 20px;
    border: 1px solid var(--card-border);
    border-radius: 10px;
    width: 90%;
    max-width: 400px;
    position: relative;
    animation: fadeIn 0.3s;
    pointer-events: auto;
    /* Allow interactions inside modal */
}

/* Modal Heading */
#modal-title {
    margin-top: 0;
    margin-bottom: 4vh;
    font-size: 24px;
    text-align: center;
}

/* Modal Form */
#edit-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

#edit-form input {
    padding: 12px;
    font-size: 18px;
    background-color: var(--input-background);
    border: 1px solid var(--input-border);
    border-radius: 5px;
    color: var(--text-color);
}

#edit-form button {
    padding: 12px;
    font-size: 18px;
    background-color: var(--button-background);
    color: var(--button-text-color);
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

/* Animation */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive Modal */
@media (max-width: 600px) {
    .modal-content {
        width: 95%;
        padding-bottom: 20vh;
    }

    #modal-title {
        margin-bottom: 2vh;
    }
}

/*------------------------------------------------------------
    13. Login Page Styles
------------------------------------------------------------*/
.login-container {
    max-width: 400px;
    margin: 50px auto;
    background-color: var(--card-background);
    padding: 30px;
    border: 1px solid var(--card-border);
    border-radius: 10px;
    text-align: center;
}

.login-container h2 {
    margin-bottom: 20px;
    font-size: 28px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.login-form input {
    padding: 12px;
    font-size: 18px;
    background-color: var(--input-background);
    border: 1px solid var(--input-border);
    border-radius: 5px;
    color: var(--text-color);
}

.login-form button {
    padding: 12px;
    font-size: 18px;
    background-color: var(--button-background);
    color: var(--button-text-color);
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

.flashes {
    list-style-type: none;
    padding: 0;
    margin-bottom: 15px;
}

.flashes li {
    padding: 10px;
    border-radius: 5px;
    margin-bottom: 10px;
}

.flashes .success {
    background-color: #28a745;
    color: white;
}

.flashes .danger {
    background-color: #dc3545;
    color: white;
}

.flashes .info {
    background-color: #17a2b8;
    color: white;
}

/*------------------------------------------------------------
14. Sorting Buttons and Group Toggle
------------------------------------------------------------*/
/* Container for sorting buttons and group toggle */
.sort-and-group-controls {
    margin: 20px 40px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

/* Styling for sorting buttons and group toggle */
.sort-and-group-controls button,
.group-toggle {
    padding: 10px 20px;
    background-color: #2c2c2c;
    color: #ffffff;
    border: 1px solid #444444;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    transition: background-color 0.3s, border-color 0.3s, transform 0.2s;
    white-space: nowrap;
}

/* Hover effect for buttons and group toggle */
.sort-and-group-controls button:hover,
.group-toggle:hover {
    background-color: #3a3a3a;
    border-color: #555555;
    transform: translateY(-2px);
}

/* Active state for buttons */
.sort-and-group-controls button.active {
    background-color: #4a90e2;
    border-color: #4a90e2;
    color: #ffffff;
    cursor: default;
    transform: none;
}

/* Sort icon styling */
.sort-and-group-controls button .sort-icon {
    margin-left: 8px;
    font-size: 12px;
    transition: transform 0.3s;
}

/* Rotate sort icon for descending order */
.sort-and-group-controls button.desc .sort-icon {
    transform: rotate(180deg);
}

/* Group toggle specific styling */
.group-toggle {
    margin-left: auto;
    gap: 10px;
}

.group-toggle label {
    cursor: pointer;
}

.group-toggle input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 40px;
    height: 20px;
    background-color: #1a1a1a;
    border-radius: 10px;
    position: relative;
    cursor: pointer;
    transition: background-color 0.3s;
}

.group-toggle input[type="checkbox"]::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    background-color: #ffffff;
    transition: transform 0.3s;
}

.group-toggle input[type="checkbox"]:checked {
    background-color: #4a90e2;
}

.group-toggle input[type="checkbox"]:checked::before {
    transform: translateX(20px);
}

/* Responsive adjustments */
@media (max-width: 600px) {
    .sort-and-group-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .sort-and-group-controls button,
    .group-toggle {
        width: 100%;
        justify-content: center;
        margin-left: 0;
    }

    .group-toggle {
        margin-top: 10px;
    }
}