/* Gramora Specific Styles - style.css?v=1.8 */
/* Mimicking Evalus Style */

/* Inherit global variables and base styles (already linked in HTML) */

/* Body specific to the tool page */
body.tool-body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Manrope', sans-serif; /* Ensure font consistency */
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow-x: hidden; /* Prevent horizontal scroll */
}

.gramora-tool-container {
    width: 100%;
    max-width: 1200px; /* Adjust max width as needed */
    margin: 0 auto;
    padding: 20px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

/* Header */
.gramora-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 15px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--sidebar-link-hover-bg); /* Subtle separator */
}

.gramora-header h1 {
    font-size: 1.8em;
    font-weight: 600;
    color: var(--text-color);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.gramora-header .back-button {
    min-width: auto;
    padding: 8px 15px;
    font-size: 0.9em;
}

.gramora-header h1 .fa-solid { /* Style icon in title */
    color: var(--primary-btn-bg); /* Use theme color */
    font-size: 0.9em;
}

/* Dark mode button positioning is handled globally */

/* Main Content Layout */
.gramora-main-content {
    display: flex;
    gap: 25px; /* Space between columns */
    flex-grow: 1;
}

.input-column {
    flex: 1 1 40%; /* Allow shrinking, base width 40% */
    display: flex;
    flex-direction: column;
    min-width: 300px; /* Minimum width for inputs */
}
.results-column {
    flex: 1 1 60%; /* Allow shrinking, base width 60% - takes more space */
    display: flex;
    flex-direction: column;
    gap: 20px; /* Space between cards in a column */
    min-width: 0; /* Prevent flexbox overflow issues */
}

/* Card Styling */
.card {
    background-color: var(--card-bg);
    border-radius: 10px;
    padding: 20px;
    box-shadow: var(--card-shadow);
    transition: background-color 0.5s ease, box-shadow 0.5s ease;
    width: 100%;
    border: 1px solid var(--border-color); /* Use theme border */
}

.card h2 {
    font-size: 1.2em;
    font-weight: 600;
    margin-top: 0; /* Remove default margin */
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--sidebar-link-hover-bg);
    color: var(--text-color);
    display: flex;
    align-items: center;
    gap: 8px;
}
.card h2 .icon {
     color: var(--primary-btn-bg); /* Theme color for icons */
     font-size: 1.1em;
}

/* Form Grid */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); /* Adjust minmax */
    gap: 15px;
}

.form-group {
    display: flex;
    flex-direction: column;
    position: relative; /* Explicitly set relative positioning for absolute children */
}

.form-group label,
.form-label { /* Target both general labels and specific ones */
    font-size: 0.85em;
    margin-bottom: 5px;
    color: var(--text-muted-color);
    font-weight: 500;
}
.form-label-sm { /* Specific style for smaller labels */
     font-size: 0.8em;
     font-weight: normal;
     color: var(--text-muted-color);
}


/* Input/Select styling */
input[type="text"],
input[type="number"],
select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color); /* Use theme border */
    border-radius: 6px;
    background-color: var(--bg-color); /* Match background */
    color: var(--text-color);
    font-size: 0.9em;
    transition: border-color 0.3s ease, background-color 0.5s ease, color 0.5s ease;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--primary-btn-bg); /* Highlight focus */
    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);
    }
}

/* Readonly/Disabled Inputs */
input:disabled, input[readonly],
.form-control:disabled, .form-control[readonly] {
    background-color: var(--secondary-btn-hover-bg) !important; /* Use theme color, override Bootstrap */
    color: var(--text-muted-color) !important;
    opacity: 0.7;
    border-color: var(--border-color) !important;
    cursor: not-allowed;
}

.form-text {
    font-size: 0.85em;
    color: var(--text-muted-color);
    margin-top: 5px;
}
.form-text .fa-solid { /* Icon in form text */
    margin-right: 4px;
}

/* Search Results Dropdown */
/* Ensure the parent .form-group has position: relative (added in HTML) */
.search-results-dropdown {
    position: absolute;
    top: 100%; /* Position directly below the parent .form-group */
    left: 0;
    right: 0; /* Ensure it spans the full width */
    width: auto; /* Let left/right define width */
    z-index: 100; /* Increase z-index */
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 6px 6px;
    box-shadow: var(--card-shadow);
    max-height: 250px; /* Slightly increase max height */
    overflow-y: auto;
    display: none; /* Hide by default */
}
/* Remove the :focus/:hover CSS rules, JS controls visibility */
/* #search-input:focus + .search-results-dropdown, */
/* .search-results-dropdown:hover { */
/*     display: block; */
/* } */

.search-results-dropdown .list-group-item {
    display: block; /* Ensure one item per line */
    width: 100%; /* Take full width */
    background-color: transparent;
    color: var(--text-color);
    border: none;
    border-bottom: 1px solid var(--border-color);
    padding: 0.6rem 1rem; /* Slightly adjust padding */
    font-size: 0.9em;
    cursor: pointer;
    transition: background-color 0.2s ease;
    text-align: left; /* Ensure text is left-aligned */
    white-space: nowrap; /* Prevent text wrapping */
    overflow: hidden; /* Hide overflow */
    text-overflow: ellipsis; /* Add ellipsis for long names */
    text-decoration: none; /* Remove underline from link */
}
.search-results-dropdown .list-group-item:last-child {
    border-bottom: none;
}
.search-results-dropdown .list-group-item:hover {
    background-color: var(--sidebar-link-hover-bg);
}

/* Calculated Nutrients Section */
.calculated-nutrients-title {
    font-size: 1.1em;
    font-weight: 600;
    margin-top: 15px;
    margin-bottom: 10px;
    color: var(--text-color);
    display: flex;
    align-items: center;
    gap: 8px;
}
.calculated-nutrients-title .icon {
    color: var(--primary-btn-bg);
    font-size: 1em;
}
.calculated-outputs { /* Grid for the output fields */
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); /* Smaller minmax */
    gap: 10px;
}
.calculated-outputs .form-group input {
    font-weight: 500; /* Make output values slightly bolder */
}


/* Buttons */
.full-width-button {
    width: 100%;
}
.action-buttons-grouped {
    display: flex;
    /* flex-wrap: wrap; */ /* Removed wrap to keep buttons inline */
    gap: 10px;
    justify-content: flex-end; /* Align buttons to the right in footer */
}
.action-buttons-grouped .action-button {
    flex: 0 1 auto; /* Don't grow, allow shrinking */
    min-width: 120px; /* Minimum button width */
    padding: 10px 15px; /* Adjust padding */
}
.action-buttons-grouped .action-button .fa-solid { /* Icon in button */
    margin-right: 6px;
}

/* Danger button specific style */
.action-button.danger {
    background-color: #dc3545;
    color: white;
    border-color: #dc3545;
}
body.dark-mode .action-button.danger {
     background-color: #a12c34;
     border-color: #a12c34;
}
.action-button.danger:hover {
    background-color: #c82333;
    border-color: #bd2130;
     body.dark-mode & {
         background-color: #8b232b;
         border-color: #8b232b;
     }
}

/* Table Styling */
.table-responsive {
    /* max-height: 450px; */ /* Vertical height is determined by card */
    /* border: 1px solid var(--border-color); */ /* Border is on the card */
    border-radius: 6px; /* Optional: Keep radius for the scroll container */
    overflow-x: auto;   /* Allow horizontal scroll if table wider than container */
    /* overflow-y: hidden; /* Explicitly hide vertical scrollbar if needed, but card should grow */
    margin-top: 10px;
}
.table {
    color: var(--text-color);
    border-color: var(--border-color);
    margin-bottom: 0;
    width: 100%;
    border-collapse: collapse; /* Ensure borders connect */
}

.table th,
.table td {
    border-color: var(--border-color);
    vertical-align: middle;
    padding: 0.6rem 0.75rem; /* Adjust padding */
    font-size: 0.85em; /* Smaller font for table */
    border-bottom: 1px solid var(--border-color);
    border-left: 1px solid var(--border-color);
}
.table th:first-child,
.table td:first-child {
    border-left: none;
}
.table td:first-child { /* Align food name left */
    text-align: left;
}
.table th {
    text-align: center;
}


.table thead th {
    background-color: var(--table-header-bg);
    color: var(--text-color);
    border-bottom-width: 2px;
    font-weight: 600;
    position: sticky; /* Make header sticky */
    top: 0;
    z-index: 2;
}

.table tbody tr:nth-of-type(odd) {
  background-color: var(--table-stripe-bg);
}
.table tbody tr:hover {
  background-color: var(--table-hover-bg);
}

.table tfoot td {
    background-color: var(--table-footer-bg);
    font-weight: bold;
    position: sticky; /* Make footer sticky */
    bottom: 0;
    z-index: 2;
    border-top: 2px solid var(--border-color);
}

.table caption {
    caption-side: top;
    padding: 0.5rem 0;
    font-size: 0.9em;
    color: var(--text-muted-color);
    text-align: left;
}

/* Footer */
.tool-footer {
    text-align: center;
    padding: 15px 0;
    margin-top: 30px;
    font-size: 0.85em;
    color: var(--text-muted-color);
    border-top: 1px solid var(--sidebar-link-hover-bg);
}

/* Responsive Adjustments */
@media (max-width: 992px) {
    .gramora-main-content {
        flex-direction: column;
    }
    .input-column,
    .results-column {
        flex: 1 1 100%; /* Take full width when stacked */
    }
}

@media (max-width: 768px) {
    .gramora-header h1 {
        font-size: 1.5em;
    }
    .gramora-header .back-button {
        font-size: 0.8em;
        padding: 6px 10px;
    }
    .card {
        padding: 15px;
    }
    .form-grid {
        grid-template-columns: 1fr; /* Stack form elements */
    }
    .action-buttons-grouped {
        flex-direction: column;
    }
    .action-buttons-grouped .action-button {
        width: 100%;
    }
    .table th, .table td {
        font-size: 0.8em;
        padding: 0.4rem 0.5rem;
    }
}
/* Visibility control for search dropdown */
.search-results-dropdown.is-visible {
    display: block;
}