/* Reset and base styles */
:root {
    /* Base left padding for top-level titles */
    --title-pad: 12px;
    /* Per-level indent */
    --indent: 20px;
    /* Fixed visual width reserved for the subtask toggle button */
    --toggle-w: 80px;
    /* Wikipedia-like palette */
    --bg-offwhite: #f6f4ef;
    --bg-panel: #fbfaf6;
    --accent-blue: #6b7f9e;
    --accent-blue-dark: #5a6f8d;
    --accent-blue-light: #d9e1ea;
    --text-main: #2a2f36;
    --text-muted: #5b6670;
    --border-soft: #e2ded6;
}
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: Georgia, 'Times New Roman', serif;
    line-height: 1.6;
    color: var(--text-main);
    background-color: var(--bg-offwhite);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Header styles */
header {
    background: var(--accent-blue);
    color: white;
    padding: 2rem 0;
    text-align: center;
    margin-bottom: 2rem;
    border-radius: 10px;
    position: relative;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.user-info {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-info span {
    font-weight: 500;
}

.user-info .btn {
    padding: 8px 16px;
    font-size: 0.9rem;
    min-width: 80px;
}

/* Main content styles */
main {
    background: var(--bg-panel);
    padding: 2rem;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    border: 1px solid var(--border-soft);
}

.hero h2 {
    color: var(--text-main);
    font-size: 2rem;
    margin-bottom: 1rem;
    text-align: center;
}

.hero p {
    font-size: 1.1rem;
    margin-bottom: 2rem;
    text-align: center;
    color: var(--text-muted);
}

.features {
    margin: 2rem 0;
}

.features h3 {
    color: var(--text-main);
    margin-bottom: 1rem;
    font-size: 1.5rem;
}

.features ul {
    list-style: none;
    margin-left: 1rem;
}

.features li {
    margin-bottom: 0.8rem;
    font-size: 1.1rem;
    color: var(--text-muted);
}

.cta-section {
    text-align: center;
    margin-top: 3rem;
    padding: 2rem;
    background: #f3f1ec;
    border-radius: 8px;
    border: 1px solid var(--border-soft);
}

.cta-text {
    font-size: 1.2rem;
    margin-bottom: 2rem;
    color: var(--text-main);
    font-weight: 500;
}

.auth-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* Button styles */
.btn {
    display: inline-block;
    padding: 12px 24px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    text-decoration: none;
    text-align: center;
    transition: all 0.3s ease;
    min-width: 120px;
}

.btn-primary {
    background: var(--accent-blue);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-blue-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(90, 111, 141, 0.25);
}

.btn-secondary {
    background: #7a8692;
    color: white;
}

.btn-secondary:hover {
    background: #697580;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(105, 117, 128, 0.25);
}

.btn-add {       background: #5f8a72; color: #fff; }
.btn-add:hover { background: #547c66; transform: translateY(-2px); box-shadow: 0 4px 12px rgba(84, 124, 102, 0.25); }

.btn-sleep {       background: #6a7a8b; color: #fff; }
.btn-sleep:hover { background: #5f6f80; transform: translateY(-2px); box-shadow: 0 4px 12px rgba(90, 111, 141, 0.2); }

.btn-home {       background: #7a8fae; color: #fff; }
.btn-home:hover { background: #6c82a3; transform: translateY(-2px); box-shadow: 0 4px 12px rgba(90, 111, 141, 0.2); }

.btn-logout {        background: #9a6b6b; color: white; }
.btn-logout:hover {  background: #875b5b; transform: translateY(-2px); box-shadow: 0 4px 12px rgba(154, 107, 107, 0.25); }

/* Dashboard styles */
.dashboard {
    text-align: center;
}

.dashboard h2 {
    color: var(--text-main);
    margin-bottom: 1rem;
}

.dashboard p {
    font-size: 1.1rem;
    margin-bottom: 2rem;
    color: var(--text-muted);
}

.dashboard-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* Modal styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background-color: white;
    margin: 5% auto;
    padding: 2rem;
    border-radius: 10px;
    width: 90%;
    max-width: 500px;
    position: relative;
    animation: slideIn 0.3s ease;
}

.close {
    color: #6c757d;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    position: absolute;
    top: 1rem;
    right: 1.5rem;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    transition: all 0.2s ease;
    line-height: 0;
    font-family: Arial, sans-serif;
}

.close:hover {
    color: #495057;
    background-color: #e9ecef;
    border-color: #adb5bd;
    transform: scale(1.05);
}

/* Form styles */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-main);
}

.form-group input {
    width: 100%;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 5px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(107, 127, 158, 0.12);
}

/* Ensure selects and textareas match input styling */
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 5px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
    background-color: #fff;
}

.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(107, 127, 158, 0.12);
}

/* Comfortable textarea height by default (overridden in modal-large when needed) */
.form-group textarea { min-height: 100px; }

.error-message {
    color: #e74c3c;
    font-size: 0.9rem;
    margin-top: 0.5rem;
    display: block;
}

.help-text {
    color: #666;
    font-size: 0.9rem;
    margin-top: 0.5rem;
    display: block;
}

.message {
    margin-top: 1rem;
    padding: 1rem;
    border-radius: 5px;
    text-align: center;
    font-weight: 500;
}

.message.success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.message.error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-50px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive design */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    .user-info {
        position: static;
        margin-top: 1rem;
        justify-content: center;
    }
    
    main {
        padding: 1.5rem;
    }
    
    .auth-buttons {
        flex-direction: column;
        align-items: center;
    }
    
    /* Make most buttons full-width on narrow screens, but keep certain core buttons sized as desktop
       (do not expand btn-home, btn-logout, btn-primary or subtask-toggle) */
    .btn:not(.btn-home):not(.btn-logout):not(.btn-primary):not(.subtask-toggle) {
        width: 100%;
        max-width: 200px;
    }
    
    .modal-content {
        margin: 10% auto;
        width: 95%;
        padding: 1.5rem;
    }
}

/* Expandable section styles */
.expandable-section {
    margin: 1.5rem 0;
}

.expandable-toggle {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 1rem;
    width: 100%;
    text-align: left;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
    font-weight: 500;
    color: #495057;
    transition: all 0.3s ease;
}

.expandable-toggle:hover {
    background: #e9ecef;
    border-color: #adb5bd;
}

.expandable-toggle .toggle-icon {
    transition: transform 0.3s ease;
    font-size: 0.9rem;
    color: #6c757d;
}

.expandable-content {
    border: 1px solid #dee2e6;
    border-top: none;
    border-radius: 0 0 8px 8px;
    padding: 1.5rem;
    background: #fff;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        max-height: 0;
        padding-top: 0;
        padding-bottom: 0;
    }
    to {
        opacity: 1;
        max-height: 1000px;
        padding-top: 1.5rem;
        padding-bottom: 1.5rem;
    }
}

.expandable-content .form-group {
    margin-bottom: 1.5rem;
}

.expandable-content .form-row {
    margin-bottom: 1.5rem;
}

/* Task-specific styles */

.task-form-section {
    background: var(--bg-panel);
    padding: 2rem;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    border: 1px solid var(--border-soft);
    margin-bottom: 2rem;
}

.parent-task-info {
    background: #eef2f7;
    border: 1px solid #d7e0ea;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 2rem;
}

.parent-task-info h3 {
    margin: 0 0 0.5rem 0;
    color: #3b4a5a;
}

.parent-task {
    font-size: 1.1rem;
}

.task-group {
    color: #6c757d;
    font-style: italic;
    margin-left: 0.5rem;
}

/* Form layout helpers for task pages */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

.reset-options {
    border-top: 2px solid #e9ecef;
    padding-top: 1.5rem;
    margin-top: 1.5rem;
}

.reset-options h3 { color: #2c3e50; margin-bottom: 1rem; }
.reset-days-group { margin-bottom: 1rem; }
.reset-days-group label { font-weight: 500; margin-bottom: 0.5rem; }

.checkbox-group { display: flex; flex-wrap: wrap; gap: 1rem; }
.checkbox-group label { display: flex; align-items: center; font-weight: normal; margin-bottom: 0; cursor: pointer; }
.checkbox-group input[type="checkbox"] { width: auto; margin-right: 0.5rem; }

.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 0.5rem; }
.checkbox-grid label { display: flex; align-items: center; font-weight: normal; margin-bottom: 0; cursor: pointer; font-size: 0.9rem; }
.checkbox-grid input[type="checkbox"] { width: auto; margin-right: 0.3rem; }

.form-actions { margin-top: 2rem; display: flex; gap: 1rem; justify-content: flex-start; }

/* Compact tasks table */
.tasks-table { padding: 0; }

.compact-tasks { width: 100%; border-collapse: collapse; background: white; table-layout: fixed; }

.compact-tasks th:nth-child(1),
.compact-tasks td:nth-child(1) { width: 50%; min-width: 120px; text-align: left; }
.compact-tasks th:nth-child(2),
.compact-tasks td:nth-child(2) { width: 15%; min-width: 80px; }
.compact-tasks th:nth-child(3),
.compact-tasks td:nth-child(3) { width: 10%; min-width: 60px; }
.compact-tasks th:nth-child(4),
.compact-tasks td:nth-child(4) { width: 25%; min-width: 180px; }

.compact-tasks th { background: #f8f9fa; padding: 0.75rem; text-align: center; font-weight: 600; border-bottom: 2px solid #dee2e6; color: #495057; }
.compact-tasks td { padding: 0.5rem 0.75rem; border-bottom: 1px solid #dee2e6; vertical-align: middle; text-align: center; }

.task-row { 
    cursor: pointer; 
    transition: background-color 0.2s ease; 
    display: none; 
}
.task-row.filtered-visible { display: table-row; }
.task-row:hover { background-color: #f8f9fa; }
.task-row.overdue { background-color: #f8d7da; border-left: 4px solid #dc3545; }
.task-row.overdue:hover { background-color: #f5c6cb; }

.subtask-row { background-color: #f8f9fb; }
.subtask-row:hover { background-color: #e9ecf5; }
.subtask-row.overdue { background-color: #f3d5d7; }

.task-title-cell { font-weight: 500; word-wrap: break-word; }
.task-title-cell { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-title-cell[class*="depth-"] { position: relative; }
/* Depth indentation helpers (simple per-level indent; no toggle offset) */
.task-title-cell.depth-0 { padding-left: var(--title-pad) !important; }
.task-title-cell.depth-1 { padding-left: calc(var(--title-pad) + var(--indent) * 1) !important; }
.task-title-cell.depth-2 { padding-left: calc(var(--title-pad) + var(--indent) * 2) !important; }
.task-title-cell.depth-3 { padding-left: calc(var(--title-pad) + var(--indent) * 3) !important; }
.task-title-cell.depth-4 { padding-left: calc(var(--title-pad) + var(--indent) * 4) !important; }
.task-title-cell.depth-5 { padding-left: calc(var(--title-pad) + var(--indent) * 5) !important; }
/* Visual guide for nested rows */
tr.task-row.subtask-row .task-title-cell { border-left: 2px solid rgba(107, 127, 158, 0.3); }
tr.task-row.subtask-row.depth-3 .task-title-cell,
tr.task-row.subtask-row.depth-4 .task-title-cell,
tr.task-row.subtask-row.depth-5 .task-title-cell { border-left-color: rgba(107, 127, 158, 0.45); }
/* Prevent layout shift with long titles at deep levels */
.compact-tasks td .task-title-cell { overflow-wrap: anywhere; }
.task-type { font-size: 0.75rem; background: #6c757d; color: white; padding: 0.125rem 0.375rem; border-radius: 10px; margin-left: 0.5rem; font-weight: normal; }

.due-date-cell { font-size: 0.9rem; color: #6c757d; min-width: 100px; }
.no-due-date { color: #adb5bd; }
.overdue-indicator { color: #dc3545; font-weight: bold; margin-left: 0.25rem; }

.actions-cell { white-space: normal; text-align: center; padding: 0.5rem 0.25rem !important; }
.actions-cell .btn-sm { margin-bottom: 0.2rem; }
/* Keep action buttons compact so all can fit */
.actions-cell .btn { width: auto; max-width: none; }
.actions-cell .btn-sm { padding: 0; width: 32px; height: 32px; font-size: 1rem; margin-right: 0.3rem; min-width: 32px; display: inline-flex; align-items: center; justify-content: center; border-radius: 4px; }

.btn-sm { padding: 0.5rem 1rem; font-size: 0.75rem; border-radius: 3px; margin-right: 0.3rem; border: none; cursor: pointer; transition: all 0.2s ease; min-width: 24px; display: inline-block; text-decoration: none; text-align: center; vertical-align: middle; line-height: 1; }
.btn-sm-single { background: #6f7f95; color: #fff; }
.btn-success { padding: 0.5rem 1rem; font-weight: bold; font-size: 0.75rem; border-radius: 3px; border: none; cursor: pointer; transition: all 0.2s ease; min-width: 24px; display: inline-block; text-decoration: none; text-align: center; vertical-align: middle; line-height: 1; background: #5f8a72; color: white; }
.btn-success:hover { background: #547c66; transform: translateY(-2px); box-shadow: 0 4px 12px rgba(84, 124, 102, 0.25); }

/* Complete button (blue) */
.btn-complete { background: var(--accent-blue); color: #fff;}
.btn-complete:hover { background: var(--accent-blue-dark); transform: translateY(-2px); box-shadow: 0 4px 12px rgba(90, 111, 141, 0.25); }

/* Close button (stone) */
.btn-close { background: #7c8694; color: #fff;}
.btn-close:hover { background: #6c7683; transform: translateY(-2px); box-shadow: 0 4px 12px rgba(124, 134, 148, 0.25); }

/* Edit button (muted amber) */
.btn-edit { background: #b7854a; color: #fff;}
.btn-edit:hover { background: #a4763f; transform: translateY(-2px); box-shadow: 0 4px 12px rgba(183, 133, 74, 0.25); }
.emoji-edit { line-height: 1; display: inline-block; font-size: 1.1rem; }

.subtask-indicator { color: var(--accent-blue); font-weight: bold; margin-right: 0.5rem; }

.modal-large { width: 90%; max-width: 800px; max-height: 90vh; overflow-y: auto; margin: 2% auto; }
.modal-large .form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.modal-large .form-group textarea { min-height: 100px; }

.task-details-view { padding: 1rem 0; }
.task-details-table { width: 100%; border-collapse: collapse; margin-bottom: 2rem; }
.task-details-table tbody { width: 100%; display: table-row-group; }
.task-details-table tr { display: table-row; border-bottom: 1px solid #dee2e6; }
.task-details-table tr:last-child { border-bottom: none; }
.detail-label { font-weight: 600; color: var(--text-main); padding: 0.75rem; width: 25%; vertical-align: top; background: #f2f1ed; border-right: 1px solid var(--border-soft); }
.detail-content { padding: 0.75rem; color: var(--text-muted); vertical-align: top; }
.detail-content.description-text { white-space: pre-wrap; max-width: 500px; word-wrap: break-word; }
.detail-content a { color: #2f5c8f; text-decoration: none; }
.detail-content a:hover { text-decoration: underline; }
.modal-actions { border-top: 2px solid #e9ecef; padding-top: 1.5rem; display: flex; gap: 1rem; justify-content: flex-end; }

/* Ensure sleep control inside the view modal stays compact and on a single right-aligned row */
#modalSleepActions .form-group { display: flex; align-items: center; gap: 8px; }
#modalSleepActions .form-group select { width: auto; min-width: 120px; }
#modalSleepActions .form-group button { white-space: nowrap; }

/* Ensure the sleep actions container spans full width and the control is pushed to the right */
#modalSleepActions { width: 100%; }
#modalSleepActions #sleepControlContainer { margin-left: auto; }

/* Paired Accounts modal styles */
#pairs-modal { display: none; }
#pairs-modal .modal-content { max-width: 700px; }
#pairs-modal .modal-close { position: absolute; right: 1rem; top: .5rem; font-size: 1rem; cursor: pointer; }
#pending-table td, #pending-table th { border: 1px solid #eee; padding: .3rem; }
#paired-table td, #paired-table th { border: 1px solid #eee; padding: .3rem; }
#paired-table td:last-child { text-align: center; }
#paired-list { list-style: none; padding-left: 0; }
#paired-list li { padding: .35rem 0; }

.subtasks-container { max-height: 300px; overflow-y: auto; border: 1px solid #e9ecef; border-radius: 6px; background: #f8f9fa; }
.subtask-item { padding: 12px; border-bottom: 1px solid #e9ecef; cursor: pointer; transition: background-color 0.2s ease; }
.subtask-item:last-child { border-bottom: none; }
.subtask-item:hover { background-color: #e9ecef; }
.subtask-item.overdue-subtask { border-left: 4px solid #dc3545; background-color: #f8d7da; }
.subtask-item.overdue-subtask:hover { background-color: #f5c6cb; }
.subtask-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.subtask-title { font-weight: 500; color: #333; }
.subtask-details { display: flex; gap: 12px; font-size: 12px; color: #666; }
.subtask-priority { font-weight: 500; }
.subtask-due { color: #856404; }
.subtask-type { color: #0056b3; font-style: italic; }

/* Subtask toggle button */
.subtask-toggle { background: #f2f1ed; border: 1px solid var(--border-soft); color: #5b6670; font-size: 12px; cursor: pointer; display: inline-flex; align-items: center; justify-content: flex-start; gap: 2px; vertical-align: middle; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-radius: 4px; transition: all 0.2s ease; line-height: 1.5; }
.subtask-toggle:hover { background: #e9ecef; border-color: #adb5bd; color: #495057; }
.subtask-toggle:active { background: #dee2e6; transform: translateY(1px); }
.subtask-toggle.btn { min-width: auto; padding: 4px 8px 4px 12px; font-size: 12px; }
.subtask-toggle:hover { color: #333; }
.subtask-toggle .toggle-icon { font-size: 12px; margin-left: 2px; }
.subtask-toggle { font-size: 10px; color: #666; margin-left: 6px; }
.subtask-count { font-size: 12px; color: #666; margin-left: 6px; }

/* Filter controls for compact view overrides */
.filter-controls { margin-bottom: 1rem; }
.filter-controls select, .filter-controls input { padding: 0.375rem; font-size: 0.9rem; }

.group-section { background: var(--bg-panel); border-radius: 10px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08); margin-bottom: 2rem; overflow-x: auto; overflow-y: hidden; border: 1px solid var(--border-soft); }

/* External-owner groups (tasks assigned to others) should be hidden by default; JS toggles visibility */
.external-owner-group { display: none !important; opacity: 0; transition: opacity 180ms ease, max-height 220ms ease; }
.external-owner-group.show { display: block !important; opacity: 1; }
.group-header { background: var(--accent-blue); color: white; padding: 1rem 1.5rem; display: flex; justify-content: space-between; align-items: center; }
.group-title-section { display: flex; align-items: center; gap: 0.5rem; }
.group-toggle { background: none; border: none; color: white; cursor: pointer; padding: 0.25rem; border-radius: 3px; display: flex; align-items: center; justify-content: center; transition: background-color 0.2s ease; }
.group-toggle:hover { background-color: rgba(255, 255, 255, 0.1); }
.group-toggle-icon { font-size: 14px; transition: transform 0.2s ease; }
.group-header h2 { margin: 0; font-size: 1.5rem; }
.group-actions { display: flex; gap: 0.5rem; }

.task-item { border-bottom: 1px solid #e9ecef; padding: 1rem 1.5rem; transition: background-color 0.2s ease; }
.task-item:last-child { border-bottom: none; }
.task-item:hover { background-color: #f8f9fa; }
.task-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 0.5rem; }
.task-title { font-size: 1.2rem; font-weight: 600; color: #2c3e50; margin: 0; }
.task-priority { background: #7a8692; color: white; padding: 0.25rem 0.5rem; border-radius: 12px; font-size: 0.8rem; font-weight: 600; }
.task-priority.priority-high { background: #dc3545; }
.task-priority.priority-medium { background: #ffc107; color: #212529; }
.task-priority.priority-low { background: #28a745; }
.task-priority { cursor: pointer; display: inline-block; transition: transform 0.15s ease, box-shadow 0.15s ease; will-change: transform; }
.task-priority:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,0.35); }
.task-meta { display: flex; gap: 1rem; font-size: 0.9rem; color: #6c757d; margin-bottom: 0.5rem; }
.task-description { color: #555; margin-bottom: 0.5rem; }
.task-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.task-actions .btn { padding: 0.5rem 1rem; font-size: 0.9rem; }

.status-badge { padding: 0.25rem 0.75rem; border-radius: 12px; font-size: 0.8rem; font-weight: 600; text-transform: uppercase; }
.status-open { background: #d4edda; color: #155724; }
.status-pending { background: #fff3cd; color: #856404; }
.status-completed { background: #cce5ff; color: #004085; }
.status-closed { background: #f8d7da; color: #721c24; }

/* Status-colored select */
.select-status { border-radius: 6px; padding: 8px 12px; border: 1px solid #ced4da; background-color: #fff; transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease; }
.select-status.open { background: #d4edda; color: #155724; border-color: #c3e6cb; }
.select-status.pending { background: #fff3cd; color: #856404; border-color: #ffeeba; }
.select-status.completed { background: #cce5ff; color: #004085; border-color: #b8daff; }
.select-status.closed { background: #f8d7da; color: #721c24; border-color: #f5c6cb; }
select.select-status option { color: #212529; background: #fff; }

.overdue { background: #f8d7da !important; border-left: 4px solid #dc3545; }

.subtask { margin-left: 2rem; border-left: 3px solid var(--accent-blue); background: #f6f6f2; }
.add-subtask-btn { background: #28a745; color: white; border: none; padding: 0.5rem; border-radius: 50%; width: 32px; height: 32px; cursor: pointer; font-size: 1.2rem; line-height: 1; display: flex; align-items: center; justify-content: center; }
.add-subtask-btn:hover { background: #218838; }

.no-tasks { text-align: center; padding: 3rem; color: #6c757d; }

/* Priority popover refinements */
.priority-popover { border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,0.15); }
.priority-popover .priority-number-input {
    width: 70px;
    padding: 6px 8px;
    border: 2px solid #dee2e6;
    border-radius: 6px;
    font-weight: 600;
    text-align: center;
    background: #fff;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.priority-popover .priority-number-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}
/* Remove native spinners where possible */
.priority-popover .priority-number-input::-webkit-outer-spin-button,
.priority-popover .priority-number-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.priority-popover .priority-number-input { -moz-appearance: textfield; appearance: textfield; }

.priority-popover .priority-actions { display: flex; justify-content: center; gap: 8px; margin-top: 10px; }

/* Mobile adjustments for compact table */
@media (max-width: 768px) {
    /* Use fixed table layout so widths are honored and title truncates */
    .compact-tasks { table-layout: fixed; }
    /* Shrink title column and keep actions roomy */
    .compact-tasks th:nth-child(1), .compact-tasks td:nth-child(1) { width: 40%; min-width: 80px; }
    .compact-tasks th:nth-child(2), .compact-tasks td:nth-child(2) { width: 18%; min-width: 60px; }
    .compact-tasks th:nth-child(3), .compact-tasks td:nth-child(3) { width: 12%; min-width: 50px; }
    .compact-tasks th:nth-child(4), .compact-tasks td:nth-child(4) { width: 30%; min-width: 120px; }
    .compact-tasks th, .compact-tasks td { padding: 0.45rem 0.35rem; }
    .compact-tasks th { font-size: 0.85rem; white-space: normal; }
    /* Allow wrapping in actions so all buttons remain visible */
    .actions-cell { white-space: normal; }
    /* Ensure action buttons don't become full-width on mobile */
    .actions-cell .btn { width: auto !important; max-width: none !important; }
    /* Keep square buttons when wrapped */
    .actions-cell .btn-sm { padding: 0; width: 32px; height: 32px; font-size: 0.9rem; margin-right: 0.1rem; margin-bottom: 0.2rem; min-width: 32px; display: inline-flex; align-items: center; justify-content: center; }

    /* Mobile: collapse status and priority columns to give title more room.
       We animate width/padding/opacity for a smoother transition when viewport changes. */
    .compact-tasks th:nth-child(2), .compact-tasks td:nth-child(2),
    .compact-tasks th:nth-child(3), .compact-tasks td:nth-child(3) {
        width: 0 !important;
        max-width: 0 !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
        opacity: 0 !important;
        visibility: hidden !important;
        overflow: hidden !important;
        transition: width 220ms ease, max-width 220ms ease, padding 220ms ease, opacity 180ms ease;
    }
    /* Make title column take available width */
    .compact-tasks th:nth-child(1), .compact-tasks td:nth-child(1) { width: 100%; min-width: 120px; }

    /* Hide add-subtask and edit buttons that live inside the actions column on mobile
       (this preserves group-level Add Task buttons which are outside .actions-cell) */
    .actions-cell .btn-add, .actions-cell .btn-edit, .actions-cell .add-subtask-btn {
        display: none !important;
    }

    /* Allow title to wrap instead of truncating on narrow screens */
    .task-title-cell {
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: clip !important;
    }

    /* Reduce font size of group titles and group-level Add Task button on mobile */
    .group-header { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
    .group-header h2 { font-size: 1.15rem; }
    .group-actions { width: 100%; }
    .group-actions .btn-add { padding: 8px 12px; font-size: 0.9rem; min-width: 96px; width: 100%; }

    /* Prevent horizontal scroll on mobile for task groups */
    .group-section { overflow-x: hidden; }

    /* Stack task detail rows as cards */
    .task-details-table { display: block; }
    .task-details-table tbody { display: block; width: 100%; }
    .task-details-table tr { display: block; margin-bottom: 0.75rem; border: 1px solid var(--border-soft); border-radius: 6px; overflow: hidden; width: 100%; box-sizing: border-box; }
    .task-details-table tr:last-child { border-bottom: 1px solid var(--border-soft); margin-bottom: 0.75rem; }
    .task-details-table td { display: block; width: 100%; border-right: none; box-sizing: border-box; }
    .detail-label { background: #e9e7e1; font-weight: 700; padding: 0.6rem 0.75rem; }
    .detail-content { padding: 0.5rem 0.75rem 0.75rem; }

    /* Stack modal action buttons */
    .modal-actions { flex-direction: column; align-items: stretch; }
    .modal-actions .btn { width: 100% !important; max-width: none !important; }

    /* Sleep control: button then select */
    #modalSleepActions { justify-content: flex-start; }
    #modalSleepActions .form-group { flex-direction: column; align-items: stretch; gap: 6px; }
    #modalSleepActions .form-group button { order: 1; width: 100%; }
    #modalSleepActions .form-group select { order: 2; width: 100%; min-width: 0; }

    /* Add task: stack date fields and actions */
    .form-row { grid-template-columns: 1fr; }
    .form-actions { flex-direction: column; align-items: stretch; }
    .form-actions .btn, .form-actions a { width: 100%; }

    /* Paired accounts: keep Add Task/Remove aligned with spacing */
    #paired-table td:last-child { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
    #paired-table td:last-child .btn { width: 100%; margin: 0; }
}

/* Image styling */
img { max-width: 100%; height: auto; border-radius: 8px; display: inline-block; }

/* Fun animated gradient border (apply class 'fun-border' to any <img>) */
img.fun-border {
    position: relative;
    border: 4px solid transparent;
    border-radius: 16px;
    background:
        linear-gradient(#fff, #fff) padding-box,
        linear-gradient(135deg, #667eea, #764ba2, #28a745, #ffc107, #dc3545, #667eea) border-box;
    background-size: 300% 300%, 100% 100%;
    animation: funBorderShift 8s linear infinite;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

img.fun-border:hover {
    transform: translateY(-4px) rotate(-1deg);
    box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}

@keyframes funBorderShift {
    0% { background-position: 0% 50%, 0 0; }
    50% { background-position: 100% 50%, 0 0; }
    100% { background-position: 0% 50%, 0 0; }
}

/* Subtle pulse variant (optional: add class 'fun-border pulse') */
img.fun-border.pulse { animation: funBorderShift 8s linear infinite, funPulse 3s ease-in-out infinite; }
@keyframes funPulse { 0%,100% { filter: brightness(1); } 50% { filter: brightness(1.12); } }

/* Promotion drop zone for dragging subtasks to top-level */
tr.promotion-drop-zone td {
    background: #f8f9fb;
    font-style: italic;
    color: #888;
    transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}
tr.promotion-drop-zone td { border: 2px dashed transparent; }
tr.promotion-drop-zone td.drag-over, tr.promotion-drop-zone td:hover { background: #eef4fb; color: #555; }

.draggable {
  touch-action: none;          /* or: pan-y / pan-x if you only drag one way */
  -webkit-user-select: none;   /* iOS: avoid text selection */
  user-select: none;
}

/* Drag bubble showing moved item count */
.drag-bubble {
    min-width: 34px;
    min-height: 34px;
    padding: 6px 10px;
    border-radius: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    letter-spacing: 0.4px;
    background: #222;
    color: #fff;
    box-shadow: 0 8px 20px rgba(0,0,0,0.35);
}

/* Visual highlight when dragging over a group area */
.group-section.drag-over-group {
    outline: 3px dashed rgba(102,126,234,0.8);
    box-shadow: 0 6px 30px rgba(102,126,234,0.12);
}
.tasks-table.drag-over-group {
    background-color: rgba(102,126,234,0.03);
}

/* Highlight the specific row that will become the parent while dragging */
tr.task-row.drag-over {
    background: linear-gradient(90deg, rgba(74,144,226,0.06), rgba(74,144,226,0.02));
    border-left: 4px solid #4a90e2;
    box-shadow: 0 6px 18px rgba(74,144,226,0.08);
    transition: background 120ms ease, box-shadow 160ms ease, transform 160ms ease;
    transform: translateZ(0);
}
/* Slightly lift on hover as a complementary affordance */
tr.task-row.drag-over:hover {
    transform: translateY(-2px);
}