:root {
    color-scheme: dark;
    --bg: #1c140f;
    --surface: #271c15;
    --panel: #302218;
    --field: #201711;
    --border: #62482e;
    --gold: #efc775;
    --gold-light: #ffdda0;
    --ink: #f5eadb;
    --muted: #caaf94;
    --green: #b6d69b;
    --red: #ffad9d;
    --radius: 12px;
    font-family: "Segoe UI", system-ui, sans-serif;
    background: var(--bg);
    color: var(--ink);
}

*, *::before, *::after { box-sizing: border-box; }

body {
    min-height: 100vh;
    margin: 0;
    background: radial-gradient(ellipse at 50% 0, #37271a, var(--bg) 36rem);
    line-height: 1.5;
}

a { color: var(--gold); text-underline-offset: 0.2em; }
a:hover { color: var(--gold-light); }
h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-family: Georgia, serif; font-size: clamp(2rem, 5vw, 3.2rem); font-weight: 600; }
h2 { margin: 1.8rem 0 0.65rem; color: var(--gold); font-size: 1.25rem; }
hr { border: 0; border-top: 1px solid var(--border); margin: 0.6rem 0 0.9rem; }

#everything { width: min(960px, calc(100% - 2.5rem)); margin: 0 auto; }
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    column-gap: 0.75rem;
    padding: 2.8rem 0 1.25rem;
}
.app-header a { text-decoration: none; }
.logout-button { white-space: nowrap; }

button, input, select {
    max-width: 100%;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--field);
    color: var(--ink);
    font: inherit;
    padding: 0.48rem 0.65rem;
}
input::placeholder { color: var(--muted); }
select { width: min(100%, 18rem); }
input[type=number] { width: 6rem; }
input[type=radio], input[type=checkbox] { accent-color: var(--gold); }
input[type=radio] + label, input[type=checkbox] + label { margin-right: 0.45rem; }

button, input[type=submit], input[type=button] { cursor: pointer; }
button:hover, input[type=button]:hover { border-color: var(--gold); }
input[type=submit] {
    min-height: 2.7rem;
    color: #23170d;
    background: var(--gold);
    border-color: var(--gold);
    font-weight: 700;
}
input[type=submit]:hover { background: var(--gold-light); }
#logCleanupSubmitBtn { background: #40251e; border-color: #885546; color: var(--red); }
#logCleanupSubmitBtn:hover { background: #563127; }
:focus-visible { outline: 2px solid var(--gold-light); outline-offset: 2px; }
:disabled, input[type=submit]:disabled { opacity: 0.5; cursor: default; }

#tabbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-bottom: 0.75rem;
}
.tab {
    min-height: 2.5rem;
    padding: 0.5rem 0.9rem;
    background: var(--surface);
    color: var(--muted);
    font-weight: 600;
}
.tab.selected { background: var(--gold); border-color: var(--gold); color: #23170d; }
#collapseTab { margin-left: auto; }

#tabcontents, .foodlist, .minibox, dialog, .login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
#tabcontents, .foodlist, .minibox { padding: 1rem; }
.miniboxwrapper {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem;
    margin-top: 0.9rem;
}
.minibox { background: var(--panel); flex: 1 1 15rem; min-width: 0; text-align: center; }
.minibox > div > b, .minibox form > div > b, .savedIngrMealHeader { color: var(--gold-light); }
.foodlist { margin-top: 1rem; }
.wide, #addMealDescription, #editLogDescription { width: 100%; }

.flexbox { display: flex; }
.flexgrow { flex-grow: 1; }
.inlineBlock { display: inline-block; }
.hidden { display: none; }

#logTimeArea { margin-top: 0.65rem; }
#logTimeArea input[type=date], #logTimeArea input[type=time] { margin: 0.25rem 0; }
#mealDescriptionSpan { display: block; overflow: hidden; padding-right: 0.5em; }
#mealDescriptionFloat { float: right; }
#clearLogFieldsBtn { margin-left: 0.4rem; }
#submitSavedMealFromIngrBtn, #addSavedMealClearBtn { margin-top: 0.85rem; }
input[type=submit]:not(#editLogSubmitBtn, #submitSavedMealFromIngrBtn) { width: 100%; margin-top: 0.85rem; }

.filterBoxWrapper { margin: 0.5rem 0; }
.filterBox { width: min(90%, 18rem); padding-right: 1.5rem; }
.clearSearch {
    display: inline-block;
    position: relative;
    width: 0;
    left: -1.5rem;
    color: var(--muted);
    font-weight: 600;
    cursor: pointer;
    user-select: none;
}
.kcalPreviewer { color: var(--muted); font-size: 0.82rem; }
.savedIngrMealHeader { text-align: center; }
.savedIngrMealWrapper { max-height: 16rem; overflow: auto; }

table { width: 100%; border-collapse: collapse; overflow-wrap: anywhere; }
td, th { padding: 0.55rem 0.65rem; border-bottom: 1px solid var(--border); }
th { background: #432f20; color: var(--gold-light); text-align: left; }
tr:nth-child(odd) { background: var(--surface); }
tr:nth-child(even) { background: var(--panel); }
td:nth-child(2), th:nth-child(2) { white-space: nowrap; }
td:first-child, th:first-child, td:nth-child(2), th:nth-child(2) { width: 1%; }
td:last-child, th:last-child, .tableFooter { text-align: right; }
.tableFooter { background: #432f20; font-variant-numeric: tabular-nums; }
.tableFooter b { color: var(--gold-light); }
summary { cursor: pointer; user-select: none; }
.delBtn, .editBtn, .cloneBtn, .closeBtn, .explanationToggler { cursor: pointer; }

dialog { color: var(--ink); width: min(26rem, calc(100% - 2rem)); padding: 1rem; }
dialog::backdrop { background: #170e0ac9; backdrop-filter: blur(3px); }
.closeBtn { float: right; }
#editLogKcal { margin-right: 0.65rem; }
.optionExplanation { color: var(--muted); margin-bottom: 0.9rem; }
.calorieGoalPositive, .calorieGoalNegative, .calorieGoalNeutral { font-weight: 700; }
.calorieGoalPositive { color: var(--green); }
.calorieGoalNegative { color: var(--red); }
.calorieGoalNeutral { color: var(--gold); }

#footer { margin: 1.8rem 1rem; text-align: center; color: var(--muted); font-size: 0.8rem; }
#toastContainer { position: fixed; z-index: 1; inset: auto 0 1.5rem; pointer-events: none; }
#toastNotification {
    visibility: hidden;
    width: fit-content;
    max-width: calc(100% - 2rem);
    margin: auto;
    padding: 0.6rem 0.85rem;
    border: 1px solid var(--gold);
    border-radius: 7px;
    background: var(--surface);
    text-align: center;
}
#toastNotification.show { visibility: visible; }
.login-page { display: grid; place-items: center; padding: 1rem; }
.login-card { width: min(100%, 24rem); padding: clamp(1rem, 6vw, 2rem); }
.login-card h1 { color: var(--gold); margin-bottom: 1.3rem; }
.login-card label, .login-card input[type=password] { display: block; width: 100%; }
.login-card label { margin-bottom: 0.4rem; }
.login-error { color: var(--red); }

@media (max-width: 580px) {
    #everything { width: calc(100% - 1.25rem); }
    .app-header { padding-top: 1.6rem; }
    .tab { padding-inline: 0.55rem; }
    #collapseTab { margin-left: 0; }
    #tabcontents, .foodlist, .minibox { padding: 0.65rem; }
    .minibox { flex-basis: 100%; }
    td, th { padding: 0.4rem 0.3rem; font-size: 0.87rem; }
    td:nth-child(2), th:nth-child(2) { white-space: normal; min-width: 3.2rem; }
}

.food-catalog {
    margin: 0 0 1rem;
    padding: 0.65rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--panel);
}
.food-catalog summary {
    display: block;
    color: var(--gold-light);
    font-weight: 700;
}
.food-catalog summary::before { content: "+ "; }
.food-catalog[open] summary::before { content: "− "; }
.food-catalog-fields {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.45fr) minmax(0, 8.5rem) auto;
    gap: 0.6rem;
    align-items: end;
    margin-top: 0.6rem;
}
.food-catalog-fields label { min-width: 0; }
.food-catalog-fields input, .food-catalog-fields select { display: block; width: 100%; }
.food-catalog-fields button:not(:disabled) {
    background: var(--gold);
    color: #23170d;
    border-color: var(--gold);
    font-weight: 700;
}
.food-catalog output { display: block; color: var(--gold-light); }
.food-catalog output:not(:empty) { margin-top: 0.6rem; }
.food-catalog-source { margin: 0.55rem 0 0; color: var(--muted); font-size: 0.82rem; }

@media (max-width: 730px) {
    .food-catalog-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .food-catalog-fields label:nth-child(-n+2) { grid-column: 1 / -1; }
}

.barcode-lookup-fields, .barcode-portion-fields {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: flex-end;
    margin-top: 0.6rem;
}
.barcode-lookup-fields label {
    flex: 1 1 12rem;
    min-width: 0;
}
.barcode-portion-fields label {
    flex: 1 1 9rem;
    min-width: 0;
}
.barcode-lookup-fields input, .barcode-lookup-fields select, .barcode-portion-fields input, .barcode-portion-fields select {
    display: block;
    width: 100%;
}
.barcode-lookup-fields button:not(:disabled), .barcode-portion-fields button:not(:disabled) {
    background: var(--gold);
    color: #23170d;
    border-color: var(--gold);
    font-weight: 700;
}
.barcode-status { margin: 0.55rem 0 0; color: var(--muted); }
.barcode-status:empty { display: none; }
#offProduct { margin: 0.6rem 0 0; overflow-wrap: anywhere; }
.off-attribution { margin-top: 0.5rem; }

.barcode-product-actions { margin-top: 0.55rem; }
.barcode-product-actions button {
    max-width: 100%;
    white-space: normal;
}

/* A napló elsődleges mezői elöl, a keresők lenyitható segédeszközként jelennek meg. */
.header-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.8rem; }
.language-picker { display: flex; flex-wrap: wrap; gap: 0.2rem; }
.language-picker a {
    min-height: 2.25rem;
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.55rem;
    border: 1px solid transparent;
    border-radius: 0.4rem;
    color: var(--muted);
    font-size: 0.875rem;
    text-decoration: none;
}
.language-picker a[aria-current="true"] {
    border-color: var(--border);
    background: var(--panel);
    color: var(--gold-light);
}
.login-card .language-picker { margin-bottom: 1rem; }
#tabbar { gap: 0.45rem; }
#tabbar .tab { min-height: 2.75rem; }
.section-title { margin: 0 0 0.9rem; }
.meal-fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 9rem); gap: 0.7rem; }
.meal-fields input { display: block; width: 100%; margin-top: 0.25rem; }
.meal-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin: 0.95rem 0 1.2rem; }
.meal-actions #submitMealBtn { width: auto; min-width: 9rem; margin: 0; }
.meal-actions #clearLogFieldsBtn { margin: 0; }
.lookup-tools { display: grid; gap: 0.55rem; }
.lookup-tools .food-catalog { margin: 0; }
.today-view { margin-top: 1.25rem; padding-top: 0.8rem; border-top: 1px solid var(--border); }
.today-view h2, #historyDiv > h2:first-of-type { margin-top: 0; }
.saved-meal-tools { margin-bottom: 0.55rem; }
.cleanup-tools { margin-bottom: 0.75rem; }

@media (max-width: 580px) {
    .app-header { align-items: flex-start; flex-wrap: wrap; row-gap: 0.55rem; }
    .meal-fields { grid-template-columns: minmax(0, 1fr) minmax(0, 7rem); }
    #tabbar .tab { padding-inline: 0.55rem; }
}
.cleanup-tools { margin-top: 1rem; }

/* A termékjavító mezők a kis telefonképernyő szélességét követik. */
.product-editor { margin: 0.9rem 0; }
.product-editor label { display: block; margin: 0.6rem 0; }
.product-editor input { display: block; width: 100%; }

/* A terméklista építésekor a mentés az elsődleges művelet. */
#offSave {
    display: block;
    width: 100%;
    min-height: 3rem;
    padding: 0.7rem 1rem;
    background: var(--gold);
    border-color: var(--gold);
    color: #23170d;
    font-weight: 700;
}
#offSave:hover { background: var(--gold-light); }
