
:root {
    --primary-color: #007bff;
    --primary-hover: #0056b3;
    --secondary-color: #f8f9fa;
    --text-color: #333;
    --background-color: #fff;
    --surface-color: #fff;
    --border-color: #e9ecef;
    --border-soft: #eee;
    --danger-color: #dc3545;
    --container-padding: 20px;
    --border-radius: 8px;
    --box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
    --primary-color: #4dabf7;
    --primary-hover: #74c0fc;
    --secondary-color: #1e1e1e;
    --text-color: #e0e0e0;
    --background-color: #121212;
    --surface-color: #2a2a2a;
    --border-color: #3a3a3a;
    --border-soft: #3a3a3a;
    --danger-color: #e03131;
    --box-shadow: 0 4px 6px rgba(0, 0, 0, 0.4);
}

body {
    font-family: "Malgun Gothic", "Apple SD Gothic Neo", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    margin: 0;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
    transition: background-color 0.3s, color 0.3s;
}

header {
    position: relative;
    background-color: var(--primary-color);
    color: white;
    text-align: center;
    padding: 1.5rem 0;
    box-shadow: var(--box-shadow);
}

#theme-toggle {
    position: absolute;
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
    transition: background-color 0.3s;
}

#theme-toggle:hover {
    background-color: rgba(255, 255, 255, 0.35);
}

main {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    padding: var(--container-padding);
    max-width: 1200px;
    margin: 0 auto;
}

@media (min-width: 992px) {
    main {
        grid-template-columns: repeat(2, 1fr);
    }
    #user-profile, #food-entry, .meal-sections, #total-log, #ai-feedback {
        grid-column: 1 / -1;
    }
}

section {
    background-color: var(--secondary-color);
    padding: var(--container-padding);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
}

.meal-sections {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
}

.log-section {
    background-color: var(--surface-color); /* Give meal logs a slightly different background */
    border: 1px solid var(--border-color);
}

#total-log {
    text-align: right;
    font-size: 1.2rem;
    background: none;
    box-shadow: none;
    padding: 0;
}

h2 {
    margin-top: 0;
    color: var(--primary-color);
    font-size: 1.5rem;
}

form {
    display: grid;
    grid-template-columns: 1fr;
    gap: 15px;
}

@media (min-width: 768px) {
    #food-form {
        grid-template-columns: 1fr 1fr 1fr auto;
        align-items: end;
    }
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

#profile-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}


input, select, textarea {
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
    width: 100%;
    box-sizing: border-box;
    background-color: var(--surface-color);
    color: var(--text-color);
}

textarea {
    resize: vertical;
    font-family: inherit;
}

button {
    padding: 12px;
    border-radius: 4px;
    font-size: 1rem;
    width: 100%;
    box-sizing: border-box;
}

button, #get-feedback-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    cursor: pointer;
    transition: background-color 0.3s;
    white-space: nowrap;
}

button:hover, #get-feedback-btn:hover {
    background-color: var(--primary-hover);
}

#breakfast-list, #lunch-list, #dinner-list, #snack-list {
    list-style: none;
    padding: 0;
    min-height: 60px; /* Ensure empty lists have some height */
}

.log-section ul li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid var(--border-soft);
    font-size: 0.95rem;
}

.food-details {
    display: flex;
    align-items: center;
    gap: 8px;
}

.food-calories {
    font-weight: 600;
}

.delete-btn {
    background-color: var(--danger-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.3s;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
}

.delete-btn:hover {
    background-color: #c82333;
}

#total-calories {
    font-weight: bold;
    color: var(--primary-color);
}

#ai-feedback #feedback-result {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    padding: 15px;
    border-radius: var(--border-radius);
    margin-top: 15px;
    white-space: pre-wrap; 
    font-family: monospace;
    min-height: 100px;
}

#diary-nav .date-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.date-controls button {
    width: auto;
    padding: 10px 14px;
}

.date-controls #diary-date {
    width: auto;
    flex: 1;
    min-width: 140px;
}

#diary-history h3 {
    margin: 0 0 10px;
    font-size: 1.05rem;
    color: var(--text-color);
    opacity: 0.85;
}

#history-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 220px;
    overflow-y: auto;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    margin-bottom: 6px;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
}

.history-item:hover {
    border-color: var(--primary-color);
}

.history-item.active {
    border-color: var(--primary-color);
    background-color: rgba(0, 123, 255, 0.08);
    font-weight: 600;
}

.history-cal {
    color: var(--primary-color);
    font-weight: 600;
    white-space: nowrap;
}

.empty-history {
    list-style: none;
    opacity: 0.6;
    padding: 8px 0;
}

.contact-desc {
    margin-top: 0;
    font-size: 0.95rem;
    opacity: 0.85;
}

#contact-status {
    margin-bottom: 0;
    font-weight: 600;
    min-height: 1.2em;
}

#contact-status.success {
    color: #2f9e44;
}

#contact-status.error {
    color: var(--danger-color);
}

footer {
    text-align: center;
    padding: 1rem 0;
    margin-top: 2rem;
    background-color: var(--secondary-color);
}
