:root {
  --dark: #1f3326;
  --green: #3d7a3a;
  --amber: #b98708;
  --red: #b3261e;
  --bg: #eef1ea;
  --card: #ffffff;
  --text: #1d261f;
  --muted: #5d6b60;
  --line: #d9dfd3;
  --input-bg: #f7f9f4;
  --ok-bg: #e3f1e0;
  --err-bg: #fbe4e2;
  --warn-bg: #fbf0d4;
  --shadow: 0 1px 3px rgba(31, 51, 38, .12);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131a15;
    --card: #1c261f;
    --text: #e6ece6;
    --muted: #9db0a0;
    --line: #2f3d33;
    --input-bg: #141c16;
    --ok-bg: #1f3a1e;
    --err-bg: #43201d;
    --warn-bg: #3d3212;
    --green: #56a052;
    --red: #e0655d;
    --amber: #d9a521;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
h1 { font-size: 1.35rem; margin: 0 0 .75rem; }
h2 { font-size: 1.1rem; margin: 1.25rem 0 .5rem; }
h3 { font-size: 1rem; margin: 0; }
a { color: var(--green); }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--dark); color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
}
.topbar-title { font-weight: 700; font-size: 1.05rem; }
.topbar-user { display: flex; align-items: center; gap: 12px; font-size: .85rem; opacity: .95; }
.topbar-user form { margin: 0; }
.link-btn { background: none; border: 0; color: #fff; font: inherit; text-decoration: underline; padding: 4px; cursor: pointer; }
.container { max-width: 760px; margin: 0 auto; padding: 14px 16px; }
.loading { text-align: center; color: var(--muted); padding: 40px 0; }

.tabbar {
  position: fixed; bottom: 0; inset-inline: 0; z-index: 30;
  display: flex; background: var(--dark);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 2px 6px; color: rgba(255, 255, 255, .65); text-decoration: none; font-size: .72rem;
}
.tabbar a.active { color: #fff; box-shadow: inset 0 3px 0 var(--amber); background: rgba(255, 255, 255, .07); }

/* ---------- cards & forms ---------- */
.card { background: var(--card); border-radius: 14px; padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card.inactive { opacity: .7; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 560px) { .grid.g3 { grid-template-columns: repeat(3, 1fr); } }
.field { display: block; margin-bottom: 10px; }
.field > span, .field-label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: 3px; }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; font: inherit; color: var(--text);
  background: var(--input-bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; min-height: 44px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--green); outline-offset: 0; }
input.num { direction: ltr; text-align: right; }
input.invalid { border-color: var(--red); }
textarea { min-height: 60px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; margin: 6px 0 10px; }
.check input { width: 20px; height: 20px; accent-color: var(--green); }

.btn {
  font: inherit; font-weight: 600; cursor: pointer; border: 0; border-radius: 10px;
  padding: 10px 16px; min-height: 44px; background: var(--input-bg); color: var(--text); border: 1px solid var(--line);
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
}
.btn-primary { background: var(--green); color: #fff; border-color: var(--green); }
.btn-amber { background: var(--amber); color: #fff; border-color: var(--amber); }
.btn-danger { color: var(--red); border-color: var(--red); background: transparent; }
.btn-block { display: flex; width: 100%; }
.btn:disabled { opacity: .55; cursor: wait; }
.row-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 4px; }
.row-actions .btn-primary { flex: 1; }

.msg { border-radius: 10px; padding: 10px 12px; margin: 8px 0; font-size: .92rem; }
.msg-ok { background: var(--ok-bg); color: var(--green); }
.msg-err { background: var(--err-bg); color: var(--red); }
.msg-warn { background: var(--warn-bg); color: var(--amber); }
.inline-msg { font-size: .88rem; min-height: 1.4em; }
.inline-msg.ok { color: var(--green); }
.inline-msg.err { color: var(--red); }
.big-warning { font-size: 1.15rem; border: 2px solid var(--red); padding: 16px; text-align: center; }

.badge { display: inline-block; font-size: .75rem; padding: 1px 8px; border-radius: 99px; background: var(--input-bg); border: 1px solid var(--line); color: var(--muted); }
.badge.ok { background: var(--ok-bg); color: var(--green); border-color: transparent; }
.badge.bad { background: var(--err-bg); color: var(--red); border-color: transparent; }
.muted { color: var(--muted); font-size: .88rem; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: right; padding: 8px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: .8rem; }
td.n, th.n { direction: ltr; text-align: left; font-variant-numeric: tabular-nums; }
tr.total td { font-weight: 700; border-bottom: 0; }

/* ---------- blend result ---------- */
.bar { display: flex; height: 44px; border-radius: 10px; overflow: hidden; margin: 8px 0 10px; background: var(--input-bg); direction: rtl; }
.bar > div { display: flex; align-items: center; justify-content: center; color: #fff; font-size: .78rem; font-weight: 600; overflow: hidden; white-space: nowrap; min-width: 0; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .82rem; margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 5px; }
.pass { color: var(--green); font-weight: 600; }
.fail { color: var(--red); font-weight: 600; }
.cost-box { display: flex; gap: 10px; margin-top: 10px; }
.cost-box > div { flex: 1; background: var(--warn-bg); border-radius: 10px; padding: 8px 12px; }
.cost-box b { display: block; font-size: 1.15rem; direction: ltr; text-align: right; }
.cost-box span { font-size: .78rem; color: var(--muted); }
.result-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.notes { margin: 6px 0 0; padding-inline-start: 20px; color: var(--muted); font-size: .88rem; }
.hist-item { display: flex; justify-content: space-between; gap: 8px; width: 100%; text-align: right; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 10px 0; font: inherit; color: inherit; cursor: pointer; }
.hist-item:last-child { border-bottom: 0; }

/* ---------- misc ---------- */
.limits { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; align-items: end; margin-bottom: 8px; }
.limits .lbl { font-weight: 600; padding-bottom: 10px; }
.limits-head { color: var(--muted); font-size: .78rem; }
.audit-row { border-bottom: 1px solid var(--line); padding: 8px 0; font-size: .9rem; }
.audit-row:last-child { border-bottom: 0; }
.audit-row .diff { direction: ltr; text-align: right; color: var(--muted); font-size: .82rem; word-break: break-word; }
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.toolbar .btn { flex: 1; }

/* ---------- login / install ---------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 380px; padding: 22px; }
.login-card h1 { text-align: center; }
.login-logo { display: block; margin: 0 auto 8px; border-radius: 16px; }
.checks { list-style: none; padding: 0; }
.checks .ok { color: var(--green); }
.checks .bad { color: var(--red); }
