/* Plain CSS, no build step needed on shared hosting. Uses logical properties so RTL and LTR both work. */
:root {
    --bg: #faf7f2; --card: #fff; --ink: #2b2118; --muted: #7a6a5a; --line: #e8dfd3;
    --brand: #8a4b2a; --brand-ink: #fff; --ok: #2e7d32; --warn: #b26a00; --bad: #c62828; --soft: #f3ece2;
    --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif; }
a { color: var(--brand); }
h1 { font-size: 1.4rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .6rem; }
.container { max-width: 1100px; margin: 0 auto; padding: 1rem 16px 3rem; }
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; padding: .6rem 16px; background: var(--card); border-block-end: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; text-decoration: none; color: var(--ink); }
.brand img { height: 32px; width: auto; }
.mainnav { display: flex; gap: .25rem; flex-wrap: wrap; }
.mainnav a { padding: .4rem .7rem; border-radius: 8px; text-decoration: none; color: var(--ink); }
.mainnav a.active, .mainnav a:hover { background: var(--soft); }
.userbox { margin-inline-start: auto; display: flex; align-items: center; gap: .75rem; font-size: .9rem; flex-wrap: wrap; }
.menu-toggle { display: none; margin-inline-start: auto; background: none; border: 1px solid var(--line); border-radius: 8px; font-size: 1.2rem; padding: .2rem .6rem; }
@media (max-width: 760px) {
    .menu-toggle { display: block; }
    .mainnav, .userbox { display: none; width: 100%; }
    body.nav-open .mainnav, body.nav-open .userbox { display: flex; flex-direction: column; align-items: stretch; }
    .userbox { margin: 0; }
}
.sync { display: inline-flex; align-items: center; gap: .35rem; }
.sync .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.sync .lbl { display: none; }
.sync[data-state=ok] .ok, .sync[data-state=saving] .saving, .sync[data-state=lost] .lost { display: inline; }
.sync[data-state=saving] .dot { background: var(--warn); }
.sync[data-state=lost] .dot { background: var(--bad); }
.sync[data-state=lost] { color: var(--bad); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-block-end: 1rem; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.stat .label { color: var(--muted); font-size: .85rem; }
.stat .value { font-size: 1.4rem; font-weight: 700; }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; justify-content: space-between; margin-block-end: 1rem; }
.toolbar h1 { margin: 0; }
.btn { display: inline-block; padding: .55rem 1rem; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer; font: inherit; text-decoration: none; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.big { padding: .8rem 1.4rem; font-size: 1.05rem; }
.btn:disabled { opacity: .6; cursor: wait; }
button.link { background: none; border: 0; color: var(--brand); cursor: pointer; padding: 0; font: inherit; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--card); }
th, td { padding: .5rem .6rem; border-block-end: 1px solid var(--line); text-align: start; vertical-align: top; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; background: var(--soft); }
td.num, th.num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
tfoot td { font-weight: 700; }
label { display: block; margin-block-end: .75rem; font-size: .9rem; }
label.check { display: flex; gap: .4rem; align-items: center; }
input, select, textarea { display: block; width: 100%; margin-block-start: .25rem; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: #fff; }
input[type=checkbox], input[type=radio] { display: inline; width: auto; margin: 0; }
.form-grid { display: grid; gap: 0 1rem; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.error { color: var(--bad); font-size: .85rem; margin: .2rem 0 .5rem; }
.flash { padding: .6rem 1rem; border-radius: 8px; margin-block-end: 1rem; }
.flash.ok { background: #e8f5e9; color: var(--ok); }
.flash.bad { background: #ffebee; color: var(--bad); }
.badge { display: inline-block; padding: .05rem .5rem; border-radius: 99px; font-size: .75rem; background: var(--soft); color: var(--muted); }
.badge.warn { background: #fff3e0; color: var(--warn); }
.badge.bad { background: #ffebee; color: var(--bad); }
.badge.ok { background: #e8f5e9; color: var(--ok); }
details.advanced { margin-block: .5rem 1rem; }
details.advanced summary { cursor: pointer; color: var(--muted); }
.radio-row { display: flex; flex-wrap: wrap; gap: 1rem; margin-block-end: .75rem; }
.radio-row label { display: flex; gap: .35rem; align-items: center; margin: 0; }
.alerts li { margin-block-end: .3rem; }
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 360px; }
.row-actions { white-space: nowrap; }
.line-item { display: grid; gap: .5rem; grid-template-columns: 2fr 1fr 1fr 1fr auto; align-items: end; border-block-end: 1px dashed var(--line); padding-block: .5rem; }
.line-item label { margin: 0; }
@media (max-width: 760px) { .line-item { grid-template-columns: 1fr 1fr; } }

/* Product photos next to recipes */
.recipe-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 1rem; align-items: start; }
.recipe-main { min-width: 0; }
.product-photo { display: flex; flex-direction: column; align-items: center; gap: .5rem; text-align: center; }
.product-photo img, .photo-empty { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; background: var(--soft); }
.photo-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .4rem; }
.photo-empty svg { width: 45%; }
.photo-btn { width: 100%; text-align: center; }
.dim { opacity: .4; }
.product-cell { display: inline-flex; align-items: center; gap: .6rem; }
.thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; flex: none; background: var(--soft); }
.thumb-empty { display: inline-flex; align-items: center; justify-content: center; font-size: 1.3rem; }
@media (max-width: 760px) {
    .recipe-layout { grid-template-columns: 1fr; }
    .product-photo { flex-direction: row; flex-wrap: wrap; justify-content: center; }
    .product-photo img, .photo-empty { width: 160px; }
    .photo-btn { width: auto; }
}

/* Pricing calculator */
.pricing-layout { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
.pricing-result { position: sticky; top: 4.5rem; }
.big-price { font-size: 2rem; font-weight: 700; color: var(--brand); line-height: 1.2; }
.calc-rows { width: 100%; }
.calc-rows td { padding: .35rem .2rem; }
.calc-rows tr.total td { font-weight: 700; border-block-start: 2px solid var(--ink); }
.calc-rows tr.sub td { color: var(--muted); font-size: .9rem; }
.pos { color: var(--ok); } .neg { color: var(--bad); }
fieldset.group { border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem .8rem .2rem; margin: 0 0 1rem; }
fieldset.group legend { font-weight: 600; padding: 0 .3rem; }
.hint { display: block; font-size: .8rem; color: var(--muted); font-weight: normal; }
@media (max-width: 900px) { .pricing-layout { grid-template-columns: 1fr; } .pricing-result { position: static; } }
.price-bar { display: none; }
@media (max-width: 900px) {
    .price-bar { display: block; position: sticky; bottom: 0; margin: 0 -16px; padding: .7rem 16px; background: var(--brand); color: var(--brand-ink); text-decoration: none; font-size: .9rem; z-index: 5; }
}
