/* CSS Variables for Premium Theming */
:root {
    --primary-color: #3b82f6;
    /* Bright Blue */
    --primary-hover: #2563eb;
    --background-color: #f3f4f6;
    /* Light Gray */
    --surface-color: #ffffff;
    --text-primary: #111827;
    /* Near Black */
    --text-secondary: #6b7280;
    /* Gray */
    --border-color: #e5e7eb;

    /* Status Colors */
    --status-pending-bg: #fff7ed;
    --status-pending-text: #c2410c;
    --status-progress-bg: #eff6ff;
    --status-progress-text: #1d4ed8;
    --status-done-bg: #ecfdf5;
    --status-done-text: #047857;

    /* Dimensions */
    --radius-md: 0.5rem;
    --radius-lg: 1rem;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

/* Reset & Base */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background-color: var(--background-color);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

h1,
h2,
h3 {
    line-height: 1.2;
    color: var(--text-primary);
}

/* App Layout */
.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
    /* Mobile first: reduced padding */
}

/* Responsive Padding for larger screens */
@media (min-width: 768px) {
    .app-container {
        padding: 2rem;
    }
}

.app-header {
    text-align: center;
    margin-bottom: 2rem;
    padding: 1.5rem 0;
    background: linear-gradient(to right, #3b82f6, #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.app-header h1 {
    font-size: 2rem;
    /* Mobile first: smaller font */
    font-weight: 800;
    letter-spacing: -0.025em;
    margin-bottom: 0.5rem;
    background: inherit;
    /* Fallback */
}

@media (min-width: 768px) {
    .app-header h1 {
        font-size: 3rem;
    }
}

.app-header p {
    color: var(--text-secondary);
    font-size: 1rem;
    -webkit-text-fill-color: var(--text-secondary);
    /* Reset text fill */
}

/* Main Grid Layout */
main {
    display: grid;
    gap: 1.5rem;
    grid-template-columns: 1fr;
    /* Mobile first */
}

@media (min-width: 900px) {
    main {
        grid-template-columns: 350px 1fr;
        align-items: start;
        gap: 2rem;
    }

    /* Guest View Overrides: Single Column Centered */
    .guest-mode main {
        grid-template-columns: 1fr;
        max-width: 800px;
        margin: 0 auto;
    }
}

/* Card Common Styles */
.task-form-section,
.task-list-section {
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
    /* Mobile: reduced padding */
    /* Ensure consistent padding for both sections */
}

@media (min-width: 768px) {

    .task-form-section,
    .task-list-section {
        padding: 2rem;
    }
}

/* Mobile Toggle Logic */
.mobile-only-btn {
    display: block;
    width: 100%;
}

.mobile-hidden {
    display: none;
}

.task-form-section.visible {
    display: block;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (min-width: 900px) {
    .mobile-only-btn {
        display: none !important;
    }

    .mobile-hidden {
        display: block;
        /* Always show on desktop, but allow JS override */
    }
}

/* Form Styles */
.task-form-section {
    position: relative;
    /* Changed from sticky for mobile generally, but keep for desktop */
    border: 1px solid var(--border-color);
}

@media (min-width: 900px) {
    .task-form-section {
        position: sticky;
        top: 2rem;
    }
}

.task-form-section h2 {
    font-size: 1.25rem;
    margin-bottom: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    border-bottom: 2px solid var(--background-color);
    padding-bottom: 0.75rem;
}

.task-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
    /* Ensure group takes full width */
}

.form-row {
    display: grid;
    grid-template-columns: 1fr;
    /* Mobile first: stack */
    gap: 1.25rem;
    width: 100%;
}

@media (min-width: 768px) {
    .form-row {
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
    }
}

label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
}

/* INPUT FIXES */
input[type="text"],
input[type="url"],
input[type="email"],
input[type="password"],
textarea,
select {
    width: 100%;
    /* CRITICAL FIX: Ensure inputs don't overflow */
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 16px;
    /* Prevent zoom on iOS inputs */
    font-family: inherit;
    transition: all 0.2s ease;
    background-color: #f9fafb;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--primary-color);
    background-color: var(--surface-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

textarea {
    resize: vertical;
    min-height: 80px;
}

/* Attachment Styles */
.attachments-input-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.attachment-row {
    display: grid;
    grid-template-columns: 1fr;
    /* Mobile: stack */
    gap: 0.5rem;
    align-items: stretch;
    /* Stretch items to fill width */
    padding: 0.5rem;
    background-color: #f8fafc;
    border-radius: var(--radius-md);
}

@media (min-width: 768px) {
    .attachment-row {
        grid-template-columns: 1fr 1fr auto;
        align-items: center;
        background-color: transparent;
        padding: 0;
    }
}

.remove-attachment {
    background-color: #fee2e2;
    color: #ef4444;
    border: none;
    border-radius: var(--radius-md);
    width: 100%;
    /* Mobile: full width button */
    padding: 0.5rem;
    cursor: pointer;
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

@media (min-width: 768px) {
    .remove-attachment {
        width: 36px;
        height: 36px;
        background-color: transparent;
        color: var(--text-secondary);
        font-size: 1.5rem;
    }

    .remove-attachment:hover {
        background-color: #fee2e2;
        color: #ef4444;
    }
}

/* Buttons */
.btn-primary {
    background-color: var(--primary-color);
    color: white;
    font-weight: 600;
    padding: 0.875rem 1.5rem;
    /* Larger touch target */
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    width: 100%;
    transition: transform 0.1s, background-color 0.2s;
    font-size: 1rem;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: transparent;
    border: 1px dashed var(--border-color);
    color: var(--text-secondary);
    padding: 0.75rem;
    /* Larger touch target */
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.9rem;
    width: 100%;
    transition: all 0.2s;
}

.btn-secondary:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background-color: #eff6ff;
}

/* Task List */
.list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.task-list {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Task Cards */
.task-card {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
    overflow: hidden;
}

@media (min-width: 768px) {
    .task-card {
        padding: 2rem;
    }
}

.task-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background-color: var(--primary-color);
    opacity: 0.5;
}

.task-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    border-color: #cbd5e1;
}

.task-header {
    display: flex;
    flex-direction: column;
    /* Mobile first: stack */
    gap: 0.5rem;
    margin-bottom: 1rem;
}

@media (min-width: 500px) {
    .task-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: flex-start;
    }
}

.task-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    word-break: break-word;
    /* Ensure long words wrap */
}

.task-status {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 0.35rem 0.85rem;
    border-radius: 9999px;
    letter-spacing: 0.05em;
    align-self: flex-start;
    /* Don't stretch on mobile */
}

.status-pending {
    background-color: var(--status-pending-bg);
    color: var(--status-pending-text);
}

.status-in_progress {
    background-color: var(--status-progress-bg);
    color: var(--status-progress-text);
}

.status-done {
    background-color: var(--status-done-bg);
    color: var(--status-done-text);
}

.task-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.task-description {
    color: var(--text-primary);
    opacity: 0.8;
    margin-bottom: 1.5rem;
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-word;
}

.task-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.attachment-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.8rem;
    background-color: #f1f5f9;
    color: var(--primary-color);
    text-decoration: none;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    transition: background-color 0.2s;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attachment-link:hover {
    background-color: #e2e8f0;
}

.task-footer {
    display: flex;
    flex-direction: column;
    /* Mobile first: stack buttons if needed or wrap */
    gap: 1rem;
    border-top: 1px solid #f3f4f6;
    padding-top: 1.5rem;
}

@media (min-width: 500px) {
    .task-footer {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
}

.task-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    width: 100%;
}

@media (min-width: 500px) {
    .task-actions {
        width: auto;
    }
}

.action-btn {
    width: 100%;
    /* Mobile: full width actions */
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    display: flex;
    justify-content: center;
    align-items: center;
}

@media (min-width: 500px) {
    .action-btn {
        width: auto;
    }
}

/* --- Header User Controls --- */

.app-header {
    /* Override existing centering if needed, but let's make it flex */
    text-align: left;
    /* Reset default center */
}

.header-content {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: center;
    justify-content: center;
    text-align: center;
}

@media (min-width: 600px) {
    .header-content {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        text-align: left;
    }
}

.user-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: rgba(255, 255, 255, 0.5);
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.user-info {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
}

.btn-logout {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.4rem;
    border-radius: 50%;
    transition: all 0.2s;
}

/* --- Advanced Features Styles --- */

.task-title-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.task-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    font-size: 0.75rem;
}

.badge {
    padding: 0.2rem 0.5rem;
    border-radius: 0.25rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.badge-public {
    background-color: #dcfce7;
    color: #166534;
}

.badge-private {
    background-color: #f1f5f9;
    color: #475569;
}

.badge-shared {
    background-color: #e0f2fe;
    color: #0369a1;
}

.badge-owner {
    background-color: #f3e8ff;
    color: #7e22ce;
}

.task-history-footer {
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px dashed var(--border-color);
    color: var(--text-secondary);
    font-size: 0.8rem;
}

/* --- Modal Styles --- */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    backdrop-filter: blur(4px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    padding: 2rem;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
    animation: scaleUp 0.2s ease-out;
    max-height: 90vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* Custom Scrollbar for Modal */
.modal-content::-webkit-scrollbar {
    width: 6px;
}

.modal-content::-webkit-scrollbar-track {
    background: transparent;
}

.modal-content::-webkit-scrollbar-thumb {
    background-color: #cbd5e1;
    border-radius: 20px;
}

.modal-content::-webkit-scrollbar-thumb:hover {
    background-color: #94a3b8;
}



@media (max-width: 600px) {
    .modal-content {
        width: 100%;
        height: 100%;
        max-height: 100vh;
        max-width: none;
        border-radius: 0;
        padding: 1rem;
    }

    .modal-header {
        margin-bottom: 1rem;
    }
}

@keyframes scaleUp {
    from {
        transform: scale(0.95);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-header h3 {
    margin: 0;
}

.share-form {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.shared-users-list {
    list-style: none;
    margin-top: 1rem;
    padding: 0;
}

.shared-user-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem;
    background: #f8fafc;
    border-radius: var(--radius-md);
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.visibility-controls {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1rem;
    padding: 0.5rem;
    background: #f1f5f9;
    border-radius: var(--radius-md);
}

.visibility-controls label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-weight: normal;
}

/* --- Search & Filters --- */
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    margin-top: 1rem;
    width: 100%;
}

.search-input {
    flex: 1;
    min-width: 200px;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    background: var(--bg-card);
    color: var(--text-primary);
}

.filter-group {
    display: flex;
    gap: 0.5rem;
}

.btn-filter {
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.btn-filter:hover {
    background: var(--bg-main);
}

.btn-filter.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* --- Edit Modal Attachments --- */
.current-attachments-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.edit-attachment-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0.8rem;
    background: #f8fafc;
    /* Using a safe hex color instead of variable not defined */
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
}

.edit-attachment-item span {
    word-break: break-all;
    margin-right: 0.5rem;
    overflow-wrap: anywhere;
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    padding: 0.5rem;
    border-radius: 50%;
    transition: background-color 0.2s, color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
}

.btn-icon:hover {
    background-color: #f3f4f6;
    color: var(--text-primary);
}

.btn-icon-small {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0 0.3rem;
}

@media (max-width: 600px) {
    .filters {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-group {
        overflow-x: auto;
        padding-bottom: 0.5rem;
    }

    .btn-filter {
        white-space: nowrap;
    }
}