:root {
  --green: #15803d;
  --green-dark: #116530;
  --green-soft: #e7f5ec;
  --orange: #f59e0b;
  --red: #dc2626;
  --red-soft: #fdecec;
  --blue: #2563eb;
  --blue-soft: #e8effd;
  --purple: #7c3aed;
  --purple-soft: #f1ebfd;
  --bg: #f3f6f4;
  --card: #ffffff;
  --text: #17211b;
  --muted: #66746b;
  --line: #e2e8e4;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(16, 40, 24, .06), 0 4px 14px rgba(16, 40, 24, .06);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: 'Cairo', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 6px;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 12px 8px;
  background: var(--green); color: #fff;
  min-height: 56px;
}
.topbar h1 { font-size: 18px; font-weight: 700; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 0;
  display: grid; place-items: center; background: transparent; color: inherit; cursor: pointer; flex: none;
}
.icon-btn:active { background: rgba(255,255,255,.18); }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

main { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(96px + var(--safe-b)); }

/* ---------- splash / login ---------- */
.splash { min-height: 70dvh; display: grid; place-items: center; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 4px solid var(--green-soft); border-top-color: var(--green); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.login-wrap { min-height: calc(100dvh - 32px); display: flex; flex-direction: column; justify-content: center; gap: 24px; }
.brand { text-align: center; }
.brand img { width: 88px; height: 88px; border-radius: 24px; box-shadow: var(--shadow); }
.brand h2 { margin: 12px 0 0; font-size: 26px; font-weight: 800; letter-spacing: .3px; }
.brand p { margin: 2px 0 0; color: var(--muted); }

/* ---------- cards & lists ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 12px; }
.stack > * + * { margin-top: 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }

.hello { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.hello .avatar { width: 48px; height: 48px; border-radius: 14px; background: var(--green); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 20px; flex: none; }
.hello h2 { margin: 0; font-size: 19px; }
.hello p { margin: 0; color: var(--muted); font-size: 14px; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 14px; min-height: 116px;
  display: flex; flex-direction: column; justify-content: space-between; gap: 10px;
  cursor: pointer; transition: transform .08s; position: relative; border: 0; text-align: right; width: 100%;
}
.tile:active { transform: scale(.97); }
.tile .ti { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--green-soft); color: var(--green); }
.tile .ti svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tile b { font-size: 16px; font-weight: 700; line-height: 1.3; }
.tile small { display: block; color: var(--muted); font-size: 12.5px; font-weight: 400; margin-top: 2px; }
.tile.wide { grid-column: span 2; min-height: 0; flex-direction: row; align-items: center; justify-content: flex-start; gap: 14px; }
.tile.c-blue .ti { background: var(--blue-soft); color: var(--blue); }
.tile.c-orange .ti { background: #fef3dc; color: #b45309; }
.tile.c-purple .ti { background: var(--purple-soft); color: var(--purple); }
.tile.c-red .ti { background: var(--red-soft); color: var(--red); }
.tile.primary { background: var(--green); color: #fff; }
.tile.primary .ti { background: rgba(255,255,255,.18); color: #fff; }
.tile.primary small { color: rgba(255,255,255,.85); }

.section-title { font-size: 14px; font-weight: 700; color: var(--muted); margin: 22px 4px 8px; }

.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 13px 16px;
  border-bottom: 1px solid var(--line); cursor: pointer; width: 100%; background: none; border-inline: 0; border-top: 0; text-align: right;
}
.row:last-child { border-bottom: 0; }
.row:active { background: #f6f9f7; }
.row .grow { flex: 1; min-width: 0; }
.row .t { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .s { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .end { text-align: left; flex: none; }
.row .price { font-weight: 800; color: var(--green-dark); direction: ltr; white-space: nowrap; }
.chev { width: 18px; height: 18px; flex: none; fill: none; stroke: #a7b3ab; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--green-soft); color: var(--green-dark); white-space: nowrap; }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.orange { background: #fef3dc; color: #b45309; }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.gray { background: #eef1ef; color: var(--muted); }

.empty { text-align: center; color: var(--muted); padding: 32px 16px; }
.empty svg { width: 48px; height: 48px; fill: none; stroke: #b9c4bd; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- forms ---------- */
.field { display: block; }
.field + .field { margin-top: 14px; }
.field > span { display: block; font-size: 14px; font-weight: 700; margin-bottom: 6px; }
.field > small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.input, select.input, textarea.input {
  width: 100%; height: 50px; padding: 0 14px; border-radius: 12px;
  border: 1.5px solid var(--line); background: #fff; outline: none; font-size: 16px;
  transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; min-height: 80px; padding: 12px 14px; }
.input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(21,128,61,.14); }
.input.ltr { direction: ltr; text-align: right; }
.input-group { display: flex; gap: 8px; }
.input-group .input { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grid2 .field + .field, .grid3 .field + .field { margin-top: 0; }

.btn {
  height: 50px; padding: 0 18px; border-radius: 12px; border: 0; cursor: pointer;
  background: var(--green); color: #fff; font-weight: 700; font-size: 16px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:active { background: var(--green-dark); }
.btn:disabled { opacity: .6; }
.btn.block { width: 100%; }
.btn.light { background: var(--green-soft); color: var(--green-dark); }
.btn.ghost { background: #eef1ef; color: var(--text); }
.btn.danger { background: var(--red-soft); color: var(--red); }
.btn.square { width: 50px; padding: 0; flex: none; }
.btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.btn-row { display: flex; gap: 10px; margin-top: 18px; }
.btn-row .btn { flex: 1; }

.check { display: flex; align-items: center; gap: 12px; padding: 10px 0; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--green); flex: none; }
.check + .check { border-top: 1px solid var(--line); }

.err { color: var(--red); font-size: 14px; margin-top: 10px; min-height: 1em; }
.warn { background: #fff7e6; color: #92400e; border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-top: 12px; }

/* ---------- search ---------- */
.searchbar { position: sticky; top: 56px; z-index: 10; background: var(--bg); padding: 4px 0 10px; margin-top: -4px; display: flex; gap: 8px; }
.searchbar .input { height: 52px; padding-inline-start: 44px; background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2366746b' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M20 20l-4-4'/%3E%3C/svg%3E") no-repeat right 14px center / 20px; }
.searchbar .btn { height: 52px; width: 52px; padding: 0; flex: none; }
.result-info { font-size: 13px; color: var(--muted); margin: 0 4px 8px; }

/* ---------- product detail ---------- */
.price-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.price-box { background: var(--green-soft); border-radius: 14px; padding: 12px; text-align: center; }
.price-box span { display: block; font-size: 13px; color: var(--muted); }
.price-box b { font-size: 24px; font-weight: 800; color: var(--green-dark); direction: ltr; display: inline-block; }
.price-box.cost { background: #fef3dc; }
.price-box.cost b { color: #92400e; }
.barcode-chip { direction: ltr; font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: 1px; background: #eef1ef; padding: 4px 10px; border-radius: 8px; display: inline-block; }

/* ---------- FAB ---------- */
.fab {
  position: fixed; bottom: calc(20px + var(--safe-b)); left: 20px; z-index: 30;
  width: 60px; height: 60px; border-radius: 20px; background: var(--green); color: #fff;
  display: grid; place-items: center; box-shadow: 0 8px 20px rgba(21,128,61,.35); border: 0; cursor: pointer;
}
.fab svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; }
.fab:active { transform: scale(.95); }

/* ---------- tabs / segmented ---------- */
.tabs { display: flex; background: #e6ece8; border-radius: 12px; padding: 4px; gap: 4px; margin-bottom: 14px; }
.tabs a, .tabs button { flex: 1; text-align: center; padding: 8px 4px; border-radius: 9px; font-weight: 700; font-size: 14px; white-space: nowrap; color: var(--muted); border: 0; background: none; cursor: pointer; }
.tabs .on { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

.week-nav { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.week-nav .lbl { flex: 1; text-align: center; font-weight: 700; }
.week-nav .btn { height: 44px; width: 44px; padding: 0; }

.day { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 10px; overflow: hidden; }
.day-h { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: #f8faf9; border-bottom: 1px solid var(--line); }
.day-h b { flex: 1; }
.day.today .day-h { background: var(--green-soft); }
.day.today .day-h b::after { content: ' • اليوم'; color: var(--green); font-size: 13px; }
.day-h .add { width: 34px; height: 34px; border-radius: 10px; border: 0; background: var(--green); color: #fff; display: grid; place-items: center; cursor: pointer; }
.day-h .add svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; }
.day .none { padding: 10px 14px; color: var(--muted); font-size: 14px; }
.shift-time { direction: rtl; font-weight: 800; color: var(--green-dark); white-space: nowrap; font-size: 15px; }

.big-shift { display: flex; align-items: center; gap: 14px; }
.big-shift .date { width: 58px; flex: none; text-align: center; background: var(--green-soft); border-radius: 12px; padding: 6px 0; }
.big-shift .date b { display: block; font-size: 22px; line-height: 1.1; color: var(--green-dark); }
.big-shift .date span { font-size: 12px; color: var(--muted); }
.big-shift.is-today .date { background: var(--green); }
.big-shift.is-today .date b, .big-shift.is-today .date span { color: #fff; }

/* ---------- modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 20, 14, .45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.modal { background: var(--card); width: 100%; max-width: 640px; border-radius: 22px 22px 0 0; padding: 8px 16px calc(20px + var(--safe-b)); max-height: 92dvh; overflow-y: auto; animation: up .2s ease-out; }
.modal .grab { width: 44px; height: 5px; border-radius: 3px; background: #d5ddd8; margin: 4px auto 10px; }
.modal h3 { margin: 0 0 14px; font-size: 18px; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }

/* ---------- scanner ---------- */
.scan-bg { position: fixed; inset: 0; z-index: 60; background: #000; display: flex; flex-direction: column; }
.scan-bg #scanRegion { flex: 1; width: 100%; overflow: hidden; display: flex; align-items: center; }
.scan-bg #scanRegion video { width: 100% !important; height: auto; object-fit: cover; }
.scan-bar { padding: 16px 16px calc(20px + var(--safe-b)); display: flex; flex-direction: column; gap: 12px; color: #fff; text-align: center; background: #000; }
.scan-bar .btn { background: #fff; color: #000; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translate(-50%, 20px);
  background: #1c2a21; color: #fff; padding: 11px 18px; border-radius: 12px; font-size: 15px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 100; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--red); }

.spinner.sm { width: 20px; height: 20px; border-width: 3px; border-color: rgba(255,255,255,.35); border-top-color: currentColor; }
.avatar.sm { width: 40px; height: 40px; border-radius: 12px; background: var(--green); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 17px; flex: none; }
.avatar.sm.off { background: #b9c4bd; }
.row-ic { width: 40px; height: 40px; border-radius: 12px; background: var(--green-soft); color: var(--green); display: grid; place-items: center; flex: none; }
.row-ic svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- shift assignment calendar ---------- */
.badge.indigo { background: #e6e8fd; color: #4338ca; }
.btn.sm { height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.sm svg { width: 18px; height: 18px; }
.tpl-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.tpl-head b { flex: 1; font-size: 15px; }
.tpl-row { display: flex; align-items: center; justify-content: space-between; padding: 5px 0; }

.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.modes button {
  height: 54px; border-radius: 14px; border: 2px solid var(--line); background: #fff; cursor: pointer;
  font-weight: 700; font-size: 15px; display: flex; align-items: center; justify-content: center; gap: 6px;
}
.modes button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.modes .morning.on { background: #f59e0b; border-color: #f59e0b; color: #fff; }
.modes .evening.on { background: #4f46e5; border-color: #4f46e5; color: #fff; }
.modes .clear.on { background: var(--red); border-color: var(--red); color: #fff; }

.cal { padding: 12px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal-h { text-align: center; font-size: 12px; font-weight: 700; color: var(--muted); padding-bottom: 2px; }
.cal-d {
  aspect-ratio: 1 / 1.15; border: 0; border-radius: 11px; background: #f1f4f2; cursor: pointer; padding: 2px 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; min-width: 0;
  transition: transform .08s;
}
.cal-d:active { transform: scale(.92); }
.cal-d b { font-size: 16px; line-height: 1.1; }
.cal-d span { font-size: 9.5px; font-weight: 700; line-height: 1.2; white-space: nowrap; overflow: hidden; max-width: 100%; }
.cal-d.today { box-shadow: inset 0 0 0 2px var(--green); }
.cal-d.past { opacity: .5; }
.cal-d.morning { background: #f59e0b; color: #fff; }
.cal-d.evening { background: #4f46e5; color: #fff; }
.cal-d.custom { background: var(--green-soft); color: var(--green-dark); }
.cal-d.leave { background: repeating-linear-gradient(45deg, #eceff0, #eceff0 5px, #dfe4e1 5px, #dfe4e1 10px); color: var(--muted); }
.cal-sum { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 12px; }

.danger-zone { border: 1.5px solid #f5c2c2; }
.wipe-code { font-size: 34px; font-weight: 800; letter-spacing: 8px; text-align: center; background: var(--red-soft); color: var(--red); border-radius: 14px; padding: 10px; margin-bottom: 12px; user-select: none; -webkit-user-select: none; }

.install-hint { display: flex; align-items: center; gap: 12px; margin-top: 16px; }
.install-hint .grow { flex: 1; font-size: 14px; }
.code { direction: ltr; text-align: left; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; background: #eef1ef; padding: 10px; border-radius: 10px; word-break: break-all; user-select: all; }
