/* Memora Specific Styles - style.css?v=3.0 */

/* Inherit global variables and base styles */
@import url('../../css/styleglobal.css');

/* Body specific to the tool page */
body.tool-body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Lato', 'Manrope', sans-serif; /* Prioritize Lato if desired for this tool */
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow-x: hidden; /* Prevent horizontal scroll */
}

.memora-tool-container {
    width: 100%;
    max-width: 1600px; /* Allow wider layout for sidebar + content */
    margin: 0 auto;
    padding: 0; /* Remove padding to allow full-width header/footer */
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

/* Header */
.memora-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px; /* Padding for header content */
    background-color: var(--card-bg); /* Use card background for header */
    border-bottom: 1px solid var(--sidebar-link-hover-bg);
    box-shadow: var(--card-shadow);
    position: sticky; /* Make header sticky */
    top: 0;
    z-index: 999; /* Ensure header is above content */
}

.memora-header h1 {
    font-size: 1.6em;
    font-weight: 700;
    color: var(--text-color);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}
.memora-header .icon {
    color: var(--primary-btn-bg);
}
.memora-header .back-button {
    min-width: auto;
    padding: 8px 12px;
    font-size: 0.9em;
    margin-right: 15px;
}

/* Stopwatch in Header */
.stopwatch-header {
    display: flex;
    align-items: center;
    gap: 10px;
    background-color: var(--bg-color); /* Slightly different background */
    padding: 5px 10px;
    border-radius: 6px;
    border: 1px solid var(--sidebar-link-hover-bg);
    margin-right: 40px; /* Increased margin to push dark mode button further away */
}
#stopwatch-display {
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.1em;
    font-weight: bold;
    color: var(--text-color);
    min-width: 80px; /* Ensure space */
    text-align: center;
}
#stopwatch-controls {
    display: flex;
    gap: 5px;
}
#stopwatch-controls .small-button {
    padding: 5px 8px;
    font-size: 0.9em;
    min-width: auto;
    line-height: 1; /* Ensure icon fits */
}
#stopwatch-controls .small-button i {
    margin-right: 0; /* No extra margin for icon-only buttons */
}

/* Main Layout (Sidebar + Content) */
.memora-main-layout {
    display: flex;
    flex-grow: 1;
    padding: 20px; /* Padding around sidebar/content area */
    gap: 25px;
}

/* Sidebar Navigation */
.memora-sidebar {
    width: 230px; /* Fixed width sidebar */
    flex-shrink: 0;
    background-color: var(--card-bg);
    padding: 15px;
    border-radius: 10px;
    box-shadow: var(--card-shadow);
    height: fit-content; /* Allow sidebar to size to content */
    position: sticky; /* Make sidebar sticky */
    top: 85px; /* Adjust based on header height + padding */
}

.memora-sidebar h2 {
    font-size: 1.1em;
    font-weight: 600;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--sidebar-link-hover-bg);
    color: var(--text-color);
}

.memora-sidebar nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.memora-sidebar nav li {
    margin-bottom: 5px;
}

.memora-sidebar nav a.nav-link {
    display: flex; /* Use flex for icon alignment */
    align-items: center;
    gap: 10px;
    padding: 10px 15px;
    color: var(--text-muted-color);
    text-decoration: none;
    font-size: 0.95em;
    border-radius: 6px;
    transition: background-color 0.2s ease, color 0.2s ease;
    font-weight: 500;
}
.memora-sidebar nav a.nav-link .icon {
    width: 18px; /* Fixed width for icons */
    text-align: center;
    color: var(--text-muted-color);
    transition: color 0.2s ease;
}

.memora-sidebar nav a.nav-link:hover {
    background-color: var(--sidebar-link-hover-bg);
    color: var(--text-color);
}
.memora-sidebar nav a.nav-link:hover .icon {
    color: var(--text-color);
}

.memora-sidebar nav a.nav-link.active {
    background-color: var(--primary-btn-bg);
    color: var(--primary-btn-text);
    font-weight: 600;
}
.memora-sidebar nav a.nav-link.active .icon {
    color: var(--primary-btn-text);
}


/* Content Area */
.memora-content {
    flex-grow: 1;
    min-width: 0; /* Prevent flexbox overflow */
}

.content-section {
    display: none; /* Hidden by default */
    margin-bottom: 25px; /* Space between cards */
    padding: 25px; /* Padding inside cards */
}
.content-section.active {
    display: block; /* Show active section */
}

.content-section h2 {
    font-size: 1.4em;
    font-weight: 600;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--sidebar-link-hover-bg);
    color: var(--text-color);
    display: flex;
    align-items: center;
    gap: 10px;
}
.content-section h2 .icon {
     color: var(--primary-btn-bg);
     font-size: 1em;
}

fieldset {
    border: 1px solid var(--sidebar-link-hover-bg);
    padding: 15px 20px;
    margin-bottom: 20px;
    border-radius: 8px;
}

legend {
    font-weight: 600;
    padding: 0 10px;
    margin-left: 10px; /* Align with padding */
    color: var(--text-color);
    font-size: 1.05em;
}

/* Form Grid adjustments */
.form-grid {
    display: grid;
    gap: 15px 20px; /* Row gap, Column gap */
    margin-bottom: 15px;
}
.form-grid.columns-1 { grid-template-columns: 1fr; }
.form-grid.columns-2 { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.form-grid.columns-3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px; /* Space between label and input */
}
.form-group.span-2 { grid-column: span 2; }
.form-group.span-3 { grid-column: span 3; }

.form-group label {
    font-size: 0.9em;
    font-weight: 500;
    color: var(--text-muted-color);
}

/* Input/Select styling */
input[type="text"],
input[type="number"],
input[type="email"],
input[type="tel"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--sidebar-link-hover-bg);
    border-radius: 6px;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-size: 0.95em;
    transition: border-color 0.3s ease, background-color 0.5s ease, color 0.5s ease;
    box-sizing: border-box; /* Include padding/border in width */
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary-btn-bg);
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1);
    body.dark-mode & {
         box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1);
    }
}
input[readonly] {
    background-color: var(--sidebar-link-hover-bg);
    cursor: not-allowed;
}

textarea {
    resize: vertical;
    min-height: 60px; /* Default min height */
}
textarea.inline-detail-textarea {
    width: 100%;
    margin-top: 5px;
    min-height: 40px;
    font-size: 0.9em;
}

/* Radio Button Groups */
.radio-group-inline {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 15px; /* Row gap, Column gap */
}
.radio-group-inline > label:first-of-type { /* The main label */
    margin-right: 5px;
    white-space: nowrap;
}
.radio-group-inline div { /* Container for radio options */
    display: flex;
    gap: 15px;
}
.radio-group-inline input[type="radio"] {
    width: auto;
    margin-right: 3px;
    cursor: pointer;
}
.radio-group-inline label { /* Labels for individual radios */
    font-weight: 400;
    font-size: 0.95em;
    cursor: pointer;
    margin-bottom: 0;
    display: flex;
    align-items: center;
}

/* Inline detail inputs */
.inline-detail-input {
    flex-grow: 1; /* Allow input to take space */
    margin-left: 10px;
    max-width: 150px; /* Limit width */
}

/* R24H Section */
#intakeSectionsContainer .intake-section {
    border: 1px dashed var(--sidebar-link-hover-bg);
    padding: 15px;
    margin-bottom: 15px;
    border-radius: 8px;
}
#intakeSectionsContainer .intake-section legend {
    font-size: 1em;
    margin-left: 0;
}
#addIntakeBtn {
    margin-bottom: 15px;
}
.intake-header { /* Style for title/delete button container */
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.intake-title-input {
    font-size: 1.1em;
    font-weight: 600;
    border: none;
    border-bottom: 1px solid var(--sidebar-link-hover-bg);
    background: transparent;
    flex-grow: 1;
    margin-right: 10px;
    padding: 5px 0;
}
.intake-title-input:focus {
    outline: none;
    border-bottom-color: var(--primary-btn-bg);
}


/* --- Improved Table Styles --- */

/* General Table Wrapper */
.table-wrapper {
    overflow-x: auto;
    margin-top: 15px;
    border: 1px solid var(--sidebar-link-hover-bg);
    border-radius: 8px;
    background-color: var(--bg-color); /* Ensure background matches theme */
}

/* Common Table Styles (Apply to both .memora-freq-table and .intake-table) */
.memora-freq-table,
.intake-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
    min-width: 600px; /* Minimum width before scroll */
    border-radius: 8px; /* Apply radius to table itself if wrapper isn't used everywhere */
    overflow: hidden; /* Clip content to border-radius */
}

.memora-freq-table th,
.memora-freq-table td,
.intake-table th,
.intake-table td {
    padding: 12px 15px; /* Increased padding */
    text-align: left;
    border-bottom: 1px solid var(--sidebar-link-hover-bg);
    vertical-align: middle; /* Align vertically centered */
}

.memora-freq-table th,
.intake-table th {
    background-color: var(--card-bg); /* Header background */
    color: var(--text-color);
    font-weight: 600;
    font-size: 0.95em;
    position: sticky;
    top: 0;
    z-index: 1;
    border-bottom-width: 2px; /* Make header border slightly thicker */
    border-bottom-color: var(--primary-btn-bg); /* Use theme color for header border */
}

.memora-freq-table tbody tr:last-child td,
.intake-table tbody tr:last-child td {
    border-bottom: none;
}

.memora-freq-table tbody tr:hover,
.intake-table tbody tr:hover {
    background-color: var(--sidebar-link-hover-bg); /* Subtle hover */
}

/* Specific Column Widths/Styles */

/* Frequency Table */
.memora-freq-table td:nth-child(1) { font-weight: 500; min-width: 180px; } /* Food group */
.memora-freq-table td:nth-child(2) { min-width: 300px; } /* Frequency options - wider */
.memora-freq-table td:nth-child(3) { min-width: 150px; } /* Observations */

.memora-freq-table .freq-options {
    display: grid; /* Use grid for better alignment */
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); /* Responsive columns */
    gap: 8px;
}
.memora-freq-table .freq-options label {
    display: flex;
    align-items: center;
    font-size: 0.9em;
    white-space: nowrap;
    cursor: pointer;
    padding: 4px 0; /* Add padding for easier clicking */
    transition: color 0.2s ease;
}
.memora-freq-table .freq-options label:hover {
    color: var(--primary-btn-bg);
}
.memora-freq-table .freq-options input[type="radio"] {
    margin-right: 5px;
    cursor: pointer;
    accent-color: var(--primary-btn-bg); /* Style radio button color */
}
.memora-freq-table textarea { /* Observations textarea */
    width: 100%;
    font-size: 0.9em;
    padding: 8px; /* More padding */
    min-height: 35px;
    border-radius: 4px;
    border: 1px solid var(--sidebar-link-hover-bg);
    background-color: var(--bg-color);
    color: var(--text-color);
    resize: vertical;
    box-sizing: border-box;
}
.memora-freq-table textarea:focus {
     border-color: var(--primary-btn-bg);
     outline: none;
}

/* Intake (R24H) List - DIV based - Refined Styles */
.intake-food-list {
    border: 1px solid var(--sidebar-link-hover-bg);
    border-radius: 8px;
    overflow: hidden; /* Clip content */
    margin-top: 15px; /* More space above */
    background-color: var(--bg-color); /* Ensure background */
}

.intake-list-header,
.intake-list-row {
    display: flex;
    align-items: stretch; /* Make columns same height */
    border-bottom: 1px solid var(--sidebar-link-hover-bg);
    transition: background-color 0.2s ease; /* Add transition for hover */
}
.intake-list-body .intake-list-row:last-child {
    border-bottom: none;
}

.intake-list-header {
    background-color: var(--card-bg); /* Slightly darker header */
    font-weight: 600;
    font-size: 0.85em; /* Slightly smaller header text */
    color: var(--text-muted-color); /* Muted header text */
    padding: 8px 0; /* Adjust padding */
    position: sticky;
    top: 0; /* Adjust if needed based on main header */
    z-index: 1;
    text-transform: uppercase; /* Uppercase headers */
    letter-spacing: 0.5px;
}

.intake-col {
    padding: 10px 12px; /* Consistent padding */
    display: flex;
    align-items: center; /* Vertically center content */
    box-sizing: border-box;
    border-right: 1px solid var(--sidebar-link-hover-bg); /* Add vertical lines */
}
.intake-col:last-child {
    border-right: none; /* Remove last vertical line */
}

/* Column Widths using Flexbox */
.col-hora { flex: 0 0 90px; justify-content: center; } /* Fixed width, centered */
.col-alimento { flex: 1 1 35%; min-width: 180px; } /* Flexible width, more min-width */
.col-cantidad { flex: 0 0 70px; justify-content: center; } /* Fixed width, centered */
.col-unidad { flex: 0 0 90px; } /* Fixed width */
.col-obs { flex: 1 1 25%; min-width: 150px; } /* Flexible width */

/* Input/Textarea Styles within the list */
.intake-col input[type="text"],
.intake-col textarea {
    width: 100%;
    font-size: 0.9em;
    padding: 8px 10px; /* Adjust padding */
    border-radius: 4px;
    border: 1px solid var(--input-border-color, var(--sidebar-link-hover-bg)); /* Use specific var if available */
    background-color: var(--input-bg-color, var(--bg-color)); /* Use specific var if available */
    color: var(--text-color);
    box-sizing: border-box;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.intake-col textarea {
    resize: vertical;
    min-height: 38px; /* Slightly taller to match inputs better */
    line-height: 1.4;
    padding-top: 8px;
    padding-bottom: 8px;
}
.intake-col input:focus,
.intake-col textarea:focus {
    border-color: var(--primary-btn-bg);
    outline: none;
    box-shadow: 0 0 0 2px var(--focus-ring-color, rgba(0, 123, 255, 0.25)); /* Use specific var or default */
}
.col-cantidad input {
    text-align: center;
}

.intake-list-body .intake-list-row {
    background-color: var(--card-bg); /* Row background */
}

.intake-list-body .intake-list-row:nth-child(odd) {
     background-color: var(--bg-color); /* Slightly different for odd rows */
}


.intake-list-body .intake-list-row:hover {
    background-color: var(--sidebar-link-hover-bg); /* Hover effect */
}

/* --- End Intake List Styles --- */

/* Action Buttons Container */
.memora-actions {
    display: flex;
    justify-content: flex-end; /* Align buttons right */
    gap: 15px;
    padding: 20px;
    margin-top: 10px; /* Space above actions */
    border-top: 1px solid var(--sidebar-link-hover-bg);
}
.memora-actions .action-button {
    min-width: 180px; /* Ensure buttons have decent width */
}
.memora-actions .action-button .icon {
    margin-right: 8px;
}

/* Footer */
.tool-footer {
    text-align: center;
    padding: 15px 20px;
    margin-top: auto; /* Push footer down */
    color: var(--text-muted-color);
    border-top: 1px solid var(--sidebar-link-hover-bg);
    font-size: 0.9em;
    background-color: var(--card-bg); /* Match header */
}

/* Orientation Message */
#orientation-message {
    display: none; /* Hidden by default */
    position: fixed;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 10px 15px;
    border-radius: 5px;
    z-index: 1000;
    font-size: 0.9em;
}

/* --- Custom Confirmation Modal Styles --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6); /* Semi-transparent background */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1050; /* Ensure it's above other content */
    opacity: 0; /* Start hidden */
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0s linear 0.3s;
}
.modal-overlay.visible {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.3s ease, visibility 0s linear 0s;
}

.modal-box {
    background-color: var(--card-bg);
    padding: 25px 30px;
    border-radius: 10px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 450px; /* Max width of the modal */
    text-align: center;
    transform: scale(0.9); /* Start slightly smaller */
    transition: transform 0.3s ease;
}
.modal-overlay.visible .modal-box {
    transform: scale(1); /* Scale to full size when visible */
}

.modal-box h3 {
    font-size: 1.3em;
    font-weight: 600;
    color: var(--text-color);
    margin-top: 0;
    margin-bottom: 15px;
}

.modal-box p {
    font-size: 1em;
    color: var(--text-muted-color);
    margin-bottom: 25px;
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    justify-content: center; /* Center buttons */
    gap: 15px;
}

.modal-actions .action-button {
    min-width: 120px; /* Adjust button width */
}
/* Ensure danger button style applies */
.modal-actions .action-button.danger {
    background-color: #dc3545;
    color: white;
    border-color: #dc3545;
}
body.dark-mode .modal-actions .action-button.danger {
     background-color: #a12c34;
     border-color: #a12c34;
}
.modal-actions .action-button.danger:hover {
    background-color: #c82333;
    border-color: #bd2130;
     body.dark-mode & {
         background-color: #8b232b;
         border-color: #8b232b;
     }
}
/* --- End Custom Confirmation Modal Styles --- */


/* Responsive Adjustments */
@media (max-width: 1024px) {
    .memora-main-layout {
        flex-direction: column;
        padding: 15px;
        gap: 15px;
    }
    .memora-sidebar {
        width: 100%;
        position: static; /* Remove sticky on mobile */
        margin-bottom: 15px;
    }
    .memora-sidebar nav ul {
        display: flex;
        flex-wrap: wrap; /* Wrap links */
        justify-content: center;
    }
    .memora-sidebar nav a.nav-link {
        font-size: 0.9em;
        padding: 8px 12px;
    }
    .memora-header {
        padding: 8px 15px;
    }
    .memora-header h1 {
        font-size: 1.4em;
    }
    .stopwatch-header {
        gap: 5px;
        padding: 4px 8px;
    }
    #stopwatch-display {
        font-size: 1em;
        min-width: 70px;
    }
    .content-section {
        padding: 15px;
    }
    .form-grid.columns-2, .form-grid.columns-3 {
        grid-template-columns: 1fr; /* Stack grid items */
    }
    .form-group.span-2, .form-group.span-3 {
        grid-column: span 1;
    }
    .memora-actions {
        flex-direction: column;
        align-items: stretch;
    }
    .memora-actions .action-button {
        min-width: auto;
    }
}

@media (max-width: 768px) and (orientation: portrait) {
    #orientation-message {
        display: block; /* Show message in portrait */
    }
}