:root {
  --green: #0a3a2a;
  --green-2: #124d39;
  --gold: #c5a059;
  --bg: #f4f3ef;
  --card: #ffffff;
  --text: #1c1c1a;
  --muted: #6f6e69;
  --line: #e6e3dc;
  --danger: #c62828;
  --ok: #1b7f4b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.05);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans Arabic", Tahoma, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}

button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }

/* ---------- buttons & fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border-radius: 12px; border: 1px solid transparent;
  font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: transform .1s ease, background .2s ease, opacity .2s ease;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: wait; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.block { width: 100%; }
.btn.primary { background: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-2); }
.btn.secondary { background: #fff; border-color: var(--green); color: var(--green); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.topbar .btn.ghost { color: #fff; border-color: rgba(255,255,255,.35); }
.btn.danger { background: #fff; color: var(--danger); border-color: #f1c4c4; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0;
}
.icon-btn:hover { border-color: var(--green); }
.icon-btn.danger { color: var(--danger); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
input:not([type=checkbox]):not([type=file]), select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; outline: none; transition: border-color .2s, box-shadow .2s;
}
textarea { resize: vertical; min-height: 96px; }
input:focus, select:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(10, 58, 42, .12); }
input.invalid, textarea.invalid { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(198, 40, 40, .12); }

.hint { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
.hint.muted { text-align: center; margin-top: 18px; }
.form-error { color: var(--danger); font-size: 14px; min-height: 20px; margin: 10px 0 0; text-align: center; }

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

.login {
  min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 500px at 50% -10%, #1a5a43 0%, var(--green) 55%, #06261c 100%);
}
.login-card {
  width: 100%; max-width: 380px; background: #fff; border-radius: 20px; padding: 28px 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
.password-wrap { display: flex; gap: 8px; }
.password-wrap input { flex: 1; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand img { width: 36px; height: 36px; }
.brand strong { display: block; letter-spacing: .18em; font-size: 15px; line-height: 1.1; }
.brand span { font-size: 12px; opacity: .75; }
.brand-lg { justify-content: center; margin-bottom: 24px; color: var(--green); }
.brand-lg img { width: 48px; height: 48px; }
.brand-lg strong { font-size: 20px; }

/* ---------- app shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--green); color: #fff;
}
.topbar-actions { display: flex; gap: 8px; }
.tabs {
  position: sticky; top: 60px; z-index: 19; display: flex; gap: 4px; padding: 8px 12px;
  background: var(--bg); border-bottom: 1px solid var(--line); overflow-x: auto;
}
.tabs button {
  flex: 1; min-height: 40px; border: 0; border-radius: 10px; background: transparent;
  font-weight: 700; color: var(--muted); cursor: pointer;
}
.tabs button.active { background: #fff; color: var(--green); box-shadow: var(--shadow); }

.panel { max-width: 1100px; margin: 0 auto; padding: 14px 14px 110px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat { background: #fff; border-radius: 12px; padding: 10px; text-align: center; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 20px; color: var(--green); }
.stat span { font-size: 12px; color: var(--muted); }

.toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.toolbar input[type=search] { flex: 1.4; }
.toolbar select { flex: 1; }

/* ---------- product list ---------- */
.product-list { display: grid; gap: 10px; }
@media (min-width: 760px) { .product-list { grid-template-columns: 1fr 1fr; } }

.product-row {
  display: grid; grid-template-columns: 76px 1fr; gap: 12px; padding: 10px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid transparent;
}
.product-row.is-hidden { opacity: .62; border-style: dashed; border-color: var(--line); }
.product-thumb {
  width: 76px; height: 76px; border-radius: 10px; object-fit: cover; background: #eee; cursor: pointer;
}
.product-main { min-width: 0; }
.product-title { font-weight: 700; margin: 0 0 2px; font-size: 15px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.product-price { font-weight: 800; color: var(--green); text-align: right; }
.product-price s { color: var(--muted); font-weight: 400; margin-inline-start: 6px; font-size: 13px; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 8px; }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: #eef3f0; color: var(--green); font-weight: 700; }
.tag.gold { background: #f7efdf; color: #8a6a2a; }
.tag.grey { background: #eceae5; color: var(--muted); }
.tag.new { background: #e3f4ea; color: #12663f; }
.tag.offer { background: #fdeaea; color: #b42318; }
.date-field { margin-top: 14px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.row-actions .icon-btn { width: 36px; height: 36px; font-size: 14px; }

.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

.fab {
  position: fixed; bottom: calc(16px + env(safe-area-inset-bottom)); inset-inline-start: 50%; transform: translateX(50%);
  z-index: 30; min-height: 52px; padding: 0 24px; border-radius: 999px; border: 0;
  background: var(--gold); color: #1c1c1a; font-weight: 800; font-size: 16px; cursor: pointer;
  box-shadow: 0 8px 24px rgba(197, 160, 89, .45);
}

/* ---------- orders ---------- */
.order-list { display: grid; gap: 10px; }
@media (min-width: 760px) { .order-list { grid-template-columns: 1fr 1fr; } }
.order-card { background: #fff; border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.order-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 8px; }
.order-number { font-weight: 800; font-size: 14px; direction: ltr; }
.order-date { font-size: 12px; color: var(--muted); }
.order-head select { width: auto; min-height: 36px; padding: 4px 8px; font-size: 13px; font-weight: 700; }
.order-customer { font-weight: 700; }
.order-contact { display: flex; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.order-items { margin: 8px 0 0; padding: 8px 0 0; border-top: 1px solid var(--line); list-style: none; font-size: 14px; }
.order-items li { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; }
.order-total { display: flex; justify-content: space-between; font-weight: 800; color: var(--green); margin-top: 6px; }
.status-pending { color: #a16207; } .status-confirmed { color: #1d4ed8; } .status-processing { color: #7c3aed; }
.status-shipped { color: #0e7490; } .status-delivered { color: var(--ok); } .status-cancelled { color: var(--danger); }

/* ---------- history ---------- */
.history-list { display: grid; gap: 8px; }
.history-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: #fff; border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); }
.history-item small { color: var(--muted); display: block; }

/* ---------- editor ---------- */
.editor { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .45); display: flex; justify-content: center; }
.editor-sheet {
  width: 100%; max-width: 760px; height: 100%; background: var(--bg); display: flex; flex-direction: column;
  animation: rise .2s ease;
}
@keyframes rise { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (min-width: 800px) { .editor { padding: 24px; } .editor-sheet { border-radius: 18px; overflow: hidden; height: auto; max-height: 100%; } }
.editor-header {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top));
  background: #fff; border-bottom: 1px solid var(--line);
}
.editor-header h2 { flex: 1; margin: 0; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor-body { flex: 1; overflow-y: auto; padding: 14px 14px 40px; overscroll-behavior: contain; }

.card { background: #fff; border: 0; border-radius: var(--radius); padding: 14px; margin: 0 0 12px; box-shadow: var(--shadow); min-width: 0; }
.card legend { float: right; width: 100%; font-weight: 800; color: var(--green); margin-bottom: 12px; padding: 0; }
.card legend + * { clear: both; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.image-row { display: grid; grid-template-columns: 120px 1fr; gap: 12px; align-items: start; }
.image-preview {
  width: 120px; height: 120px; border-radius: 12px; background: #f0eee9; display: grid; place-items: center;
  overflow: hidden; color: var(--muted); font-size: 12px; text-align: center; border: 1px dashed var(--line);
}
.image-preview img { width: 100%; height: 100%; object-fit: cover; }
.image-actions .btn { width: 100%; margin-bottom: 10px; }

.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .slider { width: 46px; height: 26px; border-radius: 999px; background: #d6d3cc; position: relative; transition: background .2s; flex-shrink: 0; }
.switch .slider::after { content: ""; position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked + .slider { background: var(--ok); }
.switch input:checked + .slider::after { transform: translateX(-20px); }
.switch input:focus-visible + .slider { box-shadow: 0 0 0 3px rgba(10, 58, 42, .2); }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 36px; padding: 0 12px; border-radius: 999px; border: 1px dashed var(--green); background: #f3f8f5; color: var(--green); font-weight: 700; cursor: pointer; font-size: 13px; }

.group-box { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 10px; background: #fcfbf9; }
.group-head { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.group-head input { font-weight: 700; }
.option-row { display: grid; grid-template-columns: 1fr 92px 40px; gap: 6px; align-items: center; padding: 8px 0; border-top: 1px dashed var(--line); }
.option-row .option-extra { grid-column: 1 / -1; display: flex; gap: 6px; align-items: center; }
.option-row .option-extra input { flex: 1; min-height: 38px; font-size: 13px; }
.option-row .option-extra img { width: 38px; height: 38px; border-radius: 8px; object-fit: cover; background: #eee; }
.mini-check { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; white-space: nowrap; color: var(--muted); }
.add-option { margin-top: 6px; }

.badge-row { display: grid; grid-template-columns: 1fr 1fr 40px; gap: 6px; align-items: center; margin-bottom: 8px; }
.badge-row .swatches { grid-column: 1 / -1; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.swatch.active { box-shadow: 0 0 0 2px var(--green); }
.badge-preview { padding: 4px 10px; border-radius: 6px; font-size: 11px; font-weight: 800; letter-spacing: .05em; direction: ltr; }

.danger-zone { margin-top: 18px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: calc(84px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  z-index: 100; max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 12px;
  background: #1c1c1a; color: #fff; font-weight: 600; box-shadow: 0 10px 30px rgba(0,0,0,.25); text-align: center;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--ok); }
