/* ===================================== */
/* == Global Variables & Basic Styles == */
/* ===================================== */

/* Dark Mode Variables (Default) */
:root {
    /* --bg-color and --text-color are now in HTML */
    --surface-color: #1e1e1e;
    --primary-color: #2ecc71;
    --primary-hover: #27ae60;
    --primary-light: rgba(46, 204, 113, 0.15);
    --danger-color: #e74c3c;
    --text-secondary: #a0a0a0;
    --border-color: #333;
}

/* Light Mode Variables */
[data-theme="light"] {
    --surface-color: #ffffff; 
    --primary-color: #2ecc71; 
    --primary-hover: #27ae60; 
    --primary-light: rgba(46, 204, 113, 0.1);
    --danger-color: #e74c3c;
    --text-secondary: #6c757d;
    --border-color: #dee2e6;
}

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

.app-container {
    max-width: 800px;
    margin: auto;
}

/* ============================ */
/* == Screen & Layout System == */
/* ============================ */

.screen {
    display: none;
    animation: fadeIn 0.3s ease;
}

.screen.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ================== */
/* == Header & Nav == */
/* ================== */

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 5px;
    margin-bottom: 20px;
}

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

.header-btn {
    background: none;
    border: none;
    color: var(--primary-color);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    width: 45px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease;
}

.header-btn:hover {
    background-color: var(--primary-light);
}

.theme-toggle {
    background: none;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    width: 45px;
    height: 45px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    color: var(--text-color);
}

.theme-toggle:hover {
    border-color: var(--primary-color);
    background-color: var(--primary-light);
}

.theme-toggle svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform 0.3s ease-in-out;
}

/* Theme icon visibility */
.theme-toggle .sun-icon { display: none; }
.theme-toggle .moon-icon { display: block; }
[data-theme="light"] .theme-toggle .sun-icon { display: block; }
[data-theme="light"] .theme-toggle .moon-icon { display: none; }

[data-theme="dark"] .theme-toggle:hover .moon-icon { transform: rotate(15deg); }
[data-theme="light"] .theme-toggle:hover .sun-icon { transform: rotate(15deg); }

/* ================= */
/* == Goal Cards  == */
/* ================= */

#goalsListContainer,
#archivedGoalsContainer {
    display: grid;
    gap: 15px;
}

.goal-card {
    background-color: var(--surface-color);
    border-radius: 12px;
    border-right: 5px solid var(--primary-color);
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    padding: 15px;
    gap: 15px;
}

.goal-card:hover {
    background-color: var(--primary-light);
}

.goal-card-content {
    flex-grow: 1;
    cursor: pointer;
}

.goal-card h3 {
    margin: 0 0 10px 0;
    font-size: 18px;
}

.goal-card .details {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text-secondary);
    font-size: 14px;
}

.goal-card .progress-bar {
    width: 100%;
    height: 6px;
    background-color: var(--border-color);
    border-radius: 3px;
    margin-top: 15px;
    overflow: hidden;
}

.goal-card .progress-bar-fill {
    height: 100%;
    background-color: var(--primary-color);
    width: 0%;
    transition: width 0.5s ease;
}

.goal-card .actions-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.goal-card .icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.goal-card .icon-btn svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.goal-card .delete-btn svg {
    stroke-width: 2.3;
}
.goal-card .unarchive-btn svg {
    stroke-width: 2.5;
}

.goal-card .edit-btn:hover,
.goal-card .unarchive-btn:hover {
    color: var(--primary-color);
    background-color: var(--primary-light);
}

.goal-card .delete-btn:hover {
    color: var(--danger-color);
    background-color: rgba(231, 76, 60, 0.1);
}

/* ====================== */
/* == Empty State Msgs == */
/* ====================== */

.loader {
    text-align: center;
    padding: 50px;
    font-size: 18px;
    color: var(--text-secondary);
}

.loader::after {
    content: ' ...';
}

#noGoalsMessage,
#noArchivedGoalsMessage {
    text-align: center;
    color: var(--text-secondary);
    padding: 50px 20px;
    border: 2px dashed var(--border-color);
    border-radius: 12px;
}

#noGoalsMessage svg,
#noArchivedGoalsMessage svg {
    width: 80px;
    height: 80px;
    margin-bottom: 20px;
    stroke: var(--text-secondary);
    opacity: 0.6;
}

/* ================= */
/* == Form Styles == */
/* ================= */

.form-group {
    margin-bottom: 20px;
}

.form-group label,
.form-group .form-group-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 12px;
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-color);
    font-family: 'Tajawal', sans-serif;
    font-size: 16px;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(46, 204, 113, 0.3);
}

.compound-input {
    display: flex;
    gap: 10px;
}

.compound-input input { flex: 1; }
.compound-input select { flex: 2; }

#submitGoal {
    width: 100%;
    padding: 15px;
    background-color: var(--primary-color);
    color: var(--bg-color);
    border: none;
    border-radius: 8px;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    transition: background-color 0.3s ease;
    margin-top: 10px;
}

#submitGoal:hover {
    background-color: var(--primary-hover);
}

/* Fix for date input's native color scheme in different themes */
input[type="date"] { color-scheme: dark; }
[data-theme="light"] input[type="date"] { color-scheme: light; }

/* Custom styling for input[type="date"] for a consistent look */
.date-input-overlay-wrapper {
    position: relative;
    display: block;
    width: 100%;
}

.date-input-overlay-wrapper input[type="date"] {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    z-index: 10;
    cursor: pointer;
}

.date-overlay {
    position: relative;
    z-index: 1;
    padding: 12px;
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    user-select: none;
    pointer-events: none; /* Crucial: lets clicks pass through to the real input */
    min-height: 20px;
}

.date-input-overlay-wrapper:hover .date-overlay,
.date-input-overlay-wrapper input[type="date"]:focus + .date-overlay {
    border-color: var(--primary-color);
}
.date-input-overlay-wrapper input[type="date"]:focus + .date-overlay {
    box-shadow: 0 0 0 2px rgba(46, 204, 113, 0.3);
}
.date-input-overlay-wrapper:hover .date-overlay svg {
    color: var(--primary-color);
}

.date-overlay span {
    color: var(--text-color);
    font-size: 16px;
    flex: 1;
}

.date-overlay svg {
    color: var(--text-secondary);
    transition: color 0.2s ease;
    flex-shrink: 0;
}

/* ======================== */
/* == Goal Detail Screen == */
/* ======================== */

#goalDetailHeader {
    text-align: center;
    padding: 15px;
    background-color: var(--surface-color);
    border-radius: 12px;
    margin-bottom: 20px;
}

#goalDetailHeader h2 { margin: 0 0 5px 0; }
#goalDetailHeader p { margin: 0; color: var(--text-secondary); }

#planDetailContainer {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.plan-item {
    display: flex;
    align-items: center;
    background-color: var(--surface-color);
    border-radius: 10px;
    padding: 15px;
    transition: background-color 0.3s;
}

.plan-item.completed {
    background-color: var(--primary-light);
}

.plan-item .day-marker {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    text-align: center;
    line-height: 40px;
    font-weight: 700;
    font-size: 16px;
    margin-left: 15px;
}

.plan-item.completed .day-marker {
    border-color: var(--primary-color);
}

.plan-item .plan-text-content {
    flex-grow: 1;
}
.plan-item .plan-text-content .date {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}
.plan-item .plan-text-content .task {
    font-size: 16px;
    font-weight: 500;
}

.plan-item .complete-action {
    flex-shrink: 0;
    width: 50px;
    height: 50px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}

.plan-item.completed .complete-action {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: var(--bg-color);
    font-size: 24px;
}

.plan-item:not(.completed) .complete-action:hover {
    border-color: var(--primary-color);
}

/* Styles for actual completion date */
.plan-item .date del {
    color: var(--text-secondary);
    opacity: 0.7;
}

.plan-item .completion-date {
    font-weight: 500;
    margin-right: 5px;
}

.plan-item .completion-date.on-time { color: var(--text-secondary); }
.plan-item .completion-date.late { color: var(--danger-color); font-weight: 700; }

/* ================================== */
/* == Toast & Modal Dialog Systems == */
/* ================================== */

#toast-container {
    position: fixed;
    bottom: 20px;
    left: 0;
    right: 0;
    padding: 0 15px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
    pointer-events: none;
}

.toast {
    background-color: var(--surface-color);
    color: var(--text-color);
    padding: 14px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-right: 5px solid var(--primary-color);
    font-size: 15px;
    font-weight: 500;
    text-align: right;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: auto;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast.error {
    border-right-color: var(--danger-color);
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.2s ease-in-out;
    pointer-events: none;
}

.modal-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background-color: var(--surface-color);
    padding: 25px;
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    text-align: right;
    transform: scale(0.9);
    transition: transform 0.2s ease-in-out;
}

.modal-overlay.show .modal-content {
    transform: scale(1);
}

.modal-content p {
    margin: 0 0 25px 0;
    font-size: 17px;
    line-height: 1.6;
    color: var(--text-color);
}

.modal-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-direction: row-reverse; /* For RTL confirm/cancel order */
}

.modal-btn {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Tajawal', sans-serif;
}

.modal-btn.confirm {
    background-color: var(--danger-color);
    color: #fff;
}
.modal-btn.confirm:hover { filter: brightness(1.1); }

.modal-btn.cancel {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}
.modal-btn.cancel:hover {
    background-color: var(--border-color);
    color: var(--text-color);
}


/* ================================= */
/* == Floating Action Button (FAB) == */
/* ================================= */

.archive-fab-container {
    position: absolute;
    bottom: 25px;
    left: 25px;
    z-index: 100;
}

.fab {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background-color: var(--primary-color);
    color: var(--bg-color);
    border: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s ease, background-color 0.2s ease;
}

.fab:hover {
    transform: scale(1.05);
}

.fab svg {
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.fab.active svg {
    transform: rotate(45deg); 
}

.fab-menu {
    position: absolute;
    bottom: 70px;
    left: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    visibility: hidden;
    opacity: 0;
    transform: translateY(15px);
    transition: all 0.25s ease;
}

.fab-menu.active {
    visibility: visible;
    opacity: 1;
    transform: translateY(0);
}

.fab-menu-item {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    background-color: var(--surface-color);
    color: var(--text-color);
    padding: 10px 15px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    font-size: 15px;
    font-family: 'Tajawal', sans-serif;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.fab-menu-item:hover {
    background-color: var(--primary-light);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* =========================== */
/* == Mobile-Specific Fixes == */
/* =========================== */

@media (max-width: 800px) {
    /* Fix for font vertical alignment on mobile devices */
    .form-group input,
    .form-group select {
        padding-top: 14px;
        padding-bottom: 10px;
    }

    .date-overlay span {
        padding-top: 2px;
    }

    .plan-item .day-marker {
        display: flex;
        align-items: center;
        justify-content: center;
        line-height: 1; /* Reset line-height for flex alignment */
        padding-top: 5px; /* Nudge the text down */
    }
}