:root {
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --accent-color: #6366f1;
    --accent-hover: #4f46e5;
    --danger-color: #ef4444;
    --border-color: #e2e8f0;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.05), 0 2px 4px -2px rgb(0 0 0 / 0.05);
    --modal-overlay: rgba(15, 23, 42, 0.4);
}

[data-theme="dark"] {
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --accent-color: #818cf8;
    --accent-hover: #a5b4fc;
    --border-color: #334155;
    --modal-overlay: rgba(0, 0, 0, 0.6);
    --shadow: 0 10px 15px -3px rgb(0 0 0 / 0.3), 0 4px 6px -4px rgb(0 0 0 / 0.3);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Outfit', 'Inter', -apple-system, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.5;
    transition: background-color 0.3s ease;
}

.container {
    max-width: 500px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
    min-height: 100vh;
}

.group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.group-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.group-title-area {
    display: flex;
    align-items: center;
    gap: 1rem;
    cursor: pointer;
    user-select: none;
}

.group-bulk-checkbox {
    flex-shrink: 0;
}

.group-title {
    font-size: 1.125rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}

.group-title-area.completed .group-title {
    text-decoration: line-through;
    color: var(--text-secondary);
    opacity: 0.7;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem;
}

.header-actions,
.header-actions-group {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.icon-btn {
    background: transparent;
    border: none;
    padding: 0.625rem;
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: var(--border-color);
    color: var(--text-primary);
    transform: scale(1.1);
}

#theme-toggle .sun-icon { display: block; }
#theme-toggle .moon-icon { display: none; }

[data-theme="dark"] #theme-toggle .sun-icon { display: none; }
[data-theme="dark"] #theme-toggle .moon-icon { display: block; }

#settings-toggle {
    display: none; /* JS will show it when logged in */
}

h1 {
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.025em;
    background: linear-gradient(135deg, var(--accent-color), #a855f7);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.card {
    background: var(--card-bg);
    border-radius: 1.5rem;
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
}

/* Auth Section */
#auth-section {
    text-align: center;
    margin-top: 15vh;
}

#auth-intro .subtitle {
    font-size: 1.125rem;
    font-weight: 700;
    line-height: 1.6;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    margin-bottom: 2.5rem;
    background: linear-gradient(135deg, var(--text-primary), var(--accent-color));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.auth-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.help-text {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px dashed var(--border-color);
}

.help-text p {
    font-size: 0.75rem;
    color: var(--text-secondary);
    opacity: 0.7;
    margin: 0.35rem 0;
    line-height: 1.4;
}

.primary-btn, .secondary-btn, .danger-btn, .text-btn {
    padding: 0.875rem 1.5rem;
    border-radius: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
    font-size: 1rem;
}

.primary-btn {
    background-color: var(--accent-color);
    color: white;
}

.primary-btn:hover {
    background-color: var(--accent-hover);
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(99, 102, 241, 0.3);
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.secondary-btn {
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.secondary-btn:hover {
    background-color: var(--border-color);
}

.text-btn {
    background: transparent;
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
}

.text-btn:hover {
    color: var(--text-primary);
    background: var(--border-color);
}

/* Routine View */
.view-container {
    animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.section-header h2 {
    flex-grow: 1;
}

.section-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
}

.list-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: 1fr;
    margin-bottom: 2rem;
}

.category-item {
    padding: 0.875rem 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-decoration: none;
    cursor: pointer;
}

.category-item strong {
    font-size: 1.125rem;
}

.category-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Edit Mode Control */
.category-actions .icon-button.danger,
.group-actions .icon-button.danger,
.task-actions .icon-button.danger,
.category-actions .edit-icon-svg,
.group-actions .edit-icon-svg,
.task-actions .edit-icon-svg {
    display: none;
}

body.edit-mode .category-actions .icon-button.danger,
body.edit-mode .group-actions .icon-button.danger,
body.edit-mode .task-actions .icon-button.danger {
    display: flex;
}

body.edit-mode .category-item,
body.edit-mode .task-item {
    position: relative;
    padding-left: 2.5rem !important;
    transition: transform 0.2s, box-shadow 0.2s;
}

body.edit-mode .task-group-card {
    position: relative;
    transition: transform 0.2s, box-shadow 0.2s;
}

body.edit-mode .category-item:active,
body.edit-mode .task-item:active,
body.edit-mode .task-group-card:active {
    cursor: grabbing;
    transform: scale(1.02);
    z-index: 10;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

/* Drag Handle Element */
.drag-handle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 100%;
    position: absolute;
    left: 0;
    top: 0;
    font-size: 1.4rem;
    color: var(--text-secondary);
    opacity: 0.4;
    cursor: grab;
    transition: all 0.2s;
    user-select: none;
}

body.edit-mode .drag-handle {
    display: flex;
}

.drag-handle:hover {
    opacity: 1 !important;
    color: var(--accent-color) !important;
}

body.edit-mode .group-header {
    padding-left: 2.5rem;
    position: relative;
}

/* Inline Edit Signals (Pencil Icon) */
body.edit-mode .category-name,
body.edit-mode .group-title,
body.edit-mode .task-name {
    cursor: text;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0.5rem;
    margin: -0.25rem;
    border-radius: 0.5rem;
    transition: all 0.2s;
}

body.edit-mode .category-name:hover,
body.edit-mode .group-title:hover,
body.edit-mode .task-name:hover {
    background-color: rgba(99, 102, 241, 0.08); /* Sophisticated highlight */
    color: var(--accent-color);
}

body.edit-mode .category-name::after,
body.edit-mode .group-title::after,
body.edit-mode .task-name::after {
    content: "✎";
    font-size: 0.9em;
    opacity: 0.3; /* Always slightly visible to signal editability */
    transition: all 0.2s;
}

body.edit-mode .category-name:hover::after,
body.edit-mode .group-title:hover::after,
body.edit-mode .task-name:hover::after {
    opacity: 1;
    transform: scale(1.2);
}


.list-stack {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 2rem;
}

/* Task Item Card */
.task-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    background: var(--card-bg);
    border-radius: 1rem;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    transition: all 0.2s;
    cursor: pointer;
    user-select: none;
}

.task-item.completed {
    opacity: 0.7;
    background: var(--bg-color);
}

.task-item.completed .task-name {
    text-decoration: line-through;
    color: var(--text-secondary);
}

.task-actions {
    display: flex;
    gap: 0.5rem;
}

/* Prevent interaction with checkbox in edit mode to allow dragging/editing */
body.edit-mode .custom-checkbox {
    pointer-events: none;
    opacity: 0.4;
    cursor: not-allowed;
}

body.edit-mode .checkmark {
    border-style: dashed;
    background-color: transparent !important;
}

.task-edit-input, .inline-edit-input {
    width: 100%;
    background: var(--bg-color);
    border: 1px solid var(--accent-color);
    border-radius: 0.5rem;
    padding: 0.25rem 0.5rem;
    font-family: inherit;
    font-size: inherit;
    font-weight: inherit;
    color: var(--text-primary);
    outline: none;
}

/* Custom Checkbox */
.custom-checkbox {
    position: relative;
    width: 1.5rem;
    height: 1.5rem;
    cursor: pointer;
}

.custom-checkbox input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
}

.checkmark {
    position: absolute;
    top: 0;
    left: 0;
    height: 1.5rem;
    width: 1.5rem;
    background-color: var(--bg-color);
    border: 2px solid var(--border-color);
    border-radius: 0.5rem;
    transition: all 0.2s;
}

.custom-checkbox:hover input ~ .checkmark {
    border-color: var(--accent-color);
}

.custom-checkbox input:checked ~ .checkmark {
    background-color: var(--accent-color);
    border-color: var(--accent-color);
}

.checkmark:after {
    content: "";
    position: absolute;
    display: none;
    left: 0.45rem;
    top: 0.15rem;
    width: 0.35rem;
    height: 0.7rem;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.custom-checkbox input:checked ~ .checkmark:after {
    display: block;
}

.task-name {
    flex: 1;
    font-weight: 500;
    font-size: 1rem;
}

/* Add Form */
.add-form {
    display: none;
    gap: 0.75rem;
    background: var(--card-bg);
    padding: 0.5rem;
    border-radius: 1.25rem;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
}

.add-form input {
    flex: 1;
    background: transparent;
    border: none;
    padding: 0.5rem 0.75rem;
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
}

.add-form input:focus {
    outline: none;
}

.fab-btn {
    width: 3rem;
    height: 3rem;
    border-radius: 1rem;
    background: var(--accent-color);
    color: white;
    border: none;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.fab-btn:hover {
    background: var(--accent-hover);
    transform: rotate(90deg);
}

/* Icon Button */
.icon-button {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 0.75rem;
    transition: 0.2s;
    display: flex;
    align-items: center;
}

.icon-button:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.icon-button.danger:hover {
    color: var(--danger-color);
    background: #fef2f2;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--modal-overlay);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.3s;
}

.modal-content {
    width: 90%;
    max-width: 400px;
    transform: scale(0.9);
    animation: popIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes popIn {
    to { transform: scale(1); }
}

.settings-group {
    margin: 1.5rem 0;
}

.settings-group label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.uuid-display {
    display: block;
    background: var(--bg-color);
    padding: 1rem;
    border-radius: 0.75rem;
    font-family: monospace;
    font-size: 0.875rem;
    word-break: break-all;
}

.settings-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
}

.modal-actions button {
    flex: 1;
}

.danger-btn {
    background: #fef2f2;
    color: var(--danger-color);
}

.danger-btn:hover {
    background: #fee2e2;
}

[data-theme="dark"] .danger-btn {
    background: rgba(239, 68, 68, 0.1);
}

[data-theme="dark"] .danger-btn:hover {
    background: rgba(239, 68, 68, 0.2);
}

/* Group Layout */
.group-stack {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    margin-bottom: 2rem;
}

.task-group-card {
    background: var(--card-bg);
    border-radius: 1.5rem;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.group-header {
    padding: 0.875rem 1.25rem;
    background: var(--bg-color);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.group-title {
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 0.5rem;
    transition: background 0.2s;
}

.group-title:hover {
    background: var(--border-color);
}

.group-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

input[type="text"], .theme-select {
    flex: 1;
    padding: 0.875rem 1.25rem;
    border-radius: 1rem;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    transition: all 0.2s;
}

input[type="text"]:focus, .theme-select:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.theme-select {
    width: 100%;
    cursor: pointer;
}

.bulk-check-btn {
    font-size: 0.75rem;
    padding: 0.4rem 0.8rem;
    border-radius: 2rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.bulk-check-btn.all-completed {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.group-content {
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.group-footer {
    padding: 1rem;
    border-top: 1px dashed var(--border-color);
    background: rgba(0,0,0,0.02);
}

.group-footer .add-form {
    box-shadow: none;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
}

.group-add-form {
    margin-top: 3rem;
    border-style: dashed;
}

.inline-edit-input {
    background: var(--bg-color);
    border: 1px solid var(--accent-color);
    padding: 0.25rem 0.5rem;
    border-radius: 0.5rem;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    width: auto;
    margin-left: -0.5rem;
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    color: white;
    padding: 0.875rem 1.75rem;
    border-radius: 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2);
    z-index: 2000;
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: none;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast.info { background: rgba(59, 130, 246, 0.9); }
.toast.warn { background: rgba(245, 158, 11, 0.9); }
.toast.error { background: rgba(239, 68, 68, 0.9); }

[data-theme="dark"] .toast {
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

/* Sort Mode */
.sortable-item {
    cursor: grab;
    user-select: none;
    touch-action: none;
}

.sortable-item:active {
    cursor: grabbing;
}

.sortable-ghost {
    opacity: 0.4;
    background: var(--accent-color) !important;
}

[data-theme="dark"] .sortable-ghost {
    opacity: 0.2;
}

/* Visibility Control for Edit Mode */
body.edit-mode .add-form {
    display: flex !important; /* Ensure it shows up even if nested */
}

/* Toggle Switch Styles */
.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.switch {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 26px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border-color);
    transition: .3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

input:checked + .slider {
    background-color: var(--accent-color);
}

input:checked + .slider:before {
    transform: translateX(20px);
}

/* Skeleton Loading */
.loading-skeleton {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding: 0.5rem;
}

.skeleton-item {
    height: 120px;
    background: linear-gradient(90deg, var(--card-bg) 25%, var(--border-color) 50%, var(--card-bg) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 1.5rem;
    opacity: 0.6;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Visibility Control for Edit Mode */
body.edit-mode .add-form {
    display: flex !important;
    margin-top: 1rem;
    animation: fadeIn 0.3s ease;
}

/* Update Snackbar */
.snackbar {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(150%);
    z-index: 2000;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 0.75rem 1.25rem;
    min-width: 300px;
    justify-content: space-between;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    background: var(--card-bg);
    border: 1px solid var(--accent-color);
}

.snackbar.show {
    transform: translateX(-50%) translateY(0);
}

.snackbar span {
    font-size: 0.9rem;
    font-weight: 500;
}

.snackbar button {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
}
