/* ========================================================
 * نظام مِقْيَاس — RTL Arabic, mobile-first styling
 * ====================================================== */
:root {
  --bg: #0f1720;
  --surface: #17212b;
  --surface-2: #1e2a36;
  --line: #2a3a49;
  --text: #e8eef4;
  --muted: #94a6b8;
  --brand: #1e9e6a;
  --brand-2: #17b978;
  --accent: #f0a500;
  --danger: #e5484d;
  --warn: #f5a623;
  --ok: #17b978;
  --radius: 14px;
  --shadow: 0 6px 20px rgba(0,0,0,.35);
  --maxw: 640px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  direction: rtl;
  text-align: right;
  font-family: "Segoe UI", "Tahoma", "Cairo", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
}
#app { min-height: 100%; }
.hidden { display: none !important; }

/* ---- App shell ---- */
.appbar {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
  border-bottom: 1px solid var(--line);
  padding: 14px 16px calc(14px + env(safe-area-inset-top, 0));
  display: flex; align-items: center; gap: 12px;
}
.appbar .greeting { font-weight: 700; font-size: 1.15rem; }
.appbar .sub { color: var(--muted); font-size: .8rem; }
.appbar .spacer { flex: 1; }
.appbar .brand-badge {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--brand); display: grid; place-items: center;
  font-weight: 800; color: #fff;
}
.container { max-width: var(--maxw); margin: 0 auto; padding: 16px; }
.container.wide { max-width: 980px; }

/* ---- Buttons ---- */
.btn {
  appearance: none; border: 0; cursor: pointer;
  border-radius: 12px; padding: 13px 18px; font-size: 1rem; font-weight: 700;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line);
  transition: transform .06s ease, background .15s ease;
  font-family: inherit;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #201a00; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.sm { padding: 8px 12px; font-size: .85rem; border-radius: 10px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---- Inputs ---- */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 6px; }
input, select, textarea {
  width: 100%; padding: 12px 14px; font-size: 1rem; font-family: inherit;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand-2); }
.req::after { content: " *"; color: var(--danger); }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

/* ---- Cards ---- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 4px; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }

/* ---- Tabs (status filter) ---- */
.tabs { display: flex; gap: 8px; margin: 14px 0; overflow-x: auto; }
.tab {
  flex: 1; text-align: center; white-space: nowrap;
  padding: 10px 8px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--muted); font-weight: 700; cursor: pointer;
}
.tab.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.tab .count { display: inline-block; font-size: .75rem; opacity: .85; }

/* ---- Search ---- */
.search { position: relative; }
.search input { padding-inline-start: 40px; }
.search .icon { position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }

/* ---- Order list item ---- */
.order-item { display: flex; align-items: center; gap: 12px; }
.order-item .meta { flex: 1; min-width: 0; }
.order-item .meta .name { font-weight: 700; }
.order-item .amount { text-align: left; font-weight: 800; white-space: nowrap; }

/* ---- Status pills ---- */
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .75rem; font-weight: 700; }
.pill.pending { background: rgba(245,166,35,.18); color: var(--warn); }
.pill.approved { background: rgba(23,185,120,.18); color: var(--ok); }
.pill.cancelled { background: rgba(229,72,77,.18); color: var(--danger); }

/* ---- FAB ---- */
.fab {
  position: fixed; inset-block-end: calc(20px + env(safe-area-inset-bottom,0));
  inset-inline-start: 20px; z-index: 30;
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--brand); color: #fff; border: 0; font-size: 2rem; line-height: 1;
  box-shadow: 0 8px 24px rgba(30,158,106,.5); cursor: pointer;
}

/* ---- Sticky add-item bar (pinned under header) ---- */
.add-bar {
  position: sticky; z-index: 15;
  background: var(--bg);
  padding: 10px 0; margin-bottom: 4px;
}

/* ---- Auto-save badge ---- */
.autosave { display: inline-flex; align-items: center; gap: 6px; font-size: .78rem; color: var(--ok); }
.autosave .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.autosave.saving { color: var(--warn); }
.autosave.saving .dot { background: var(--warn); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

/* ---- Collapsible item cards ---- */
.item-card { padding: 12px 14px; }
.item-head { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.item-head .chev { font-size: 1rem; color: var(--muted); width: 14px; }
.item-head .item-title { flex: 1; min-width: 0; font-weight: 700; overflow: hidden; }
.item-head .item-title .small { font-weight: 400; }
.item-head .item-price { font-weight: 800; color: var(--brand-2); white-space: nowrap; }
.item-body { margin-top: 12px; }

/* ---- Item card breakdown ---- */
.breakdown { border-top: 1px dashed var(--line); margin-top: 12px; padding-top: 10px; }
.breakdown .line { display: flex; justify-content: space-between; font-size: .88rem; padding: 3px 0; color: var(--muted); }
.breakdown .line.total { color: var(--text); font-weight: 800; font-size: 1rem; border-top: 1px solid var(--line); margin-top: 6px; padding-top: 8px; }
.breakdown .line b { color: var(--text); }

/* ---- Sticky total bar ---- */
.totalbar {
  position: sticky; bottom: 0; z-index: 10;
  background: var(--surface-2); border-top: 1px solid var(--line);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom,0));
  box-shadow: 0 -6px 20px rgba(0,0,0,.35);
}
.totalbar .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 16px; }
.totalbar .grid .k { color: var(--muted); font-size: .8rem; }
.totalbar .grid .v { font-weight: 800; text-align: left; }
.totalbar .grand { color: var(--brand-2); font-size: 1.2rem; }

/* ---- Offline banner ---- */
#offline-banner {
  background: var(--warn); color: #201a00; text-align: center;
  font-weight: 700; font-size: .85rem; padding: 6px;
}

/* ---- KPI cards ---- */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.kpi .k { color: var(--muted); font-size: .8rem; }
.kpi .v { font-size: 1.4rem; font-weight: 800; margin-top: 4px; }
.kpi.green .v { color: var(--brand-2); }
.kpi.gold .v { color: var(--accent); }
.kpi.red .v { color: var(--danger); }

/* ---- Charts ---- */
.chart-wrap { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.legend { display: flex; flex-direction: column; gap: 6px; }
.legend .li { display: flex; align-items: center; gap: 8px; font-size: .85rem; }
.legend .sw { width: 12px; height: 12px; border-radius: 3px; }
.bar-row { display: grid; grid-template-columns: 90px 1fr auto; gap: 8px; align-items: center; margin: 6px 0; font-size: .85rem; }
.bar-track { background: var(--surface-2); border-radius: 999px; height: 16px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--brand); border-radius: 999px; }

/* ---- misc ---- */
.spinner { text-align: center; padding: 40px; color: var(--muted); }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.divider { height: 1px; background: var(--line); margin: 14px 0; }
.flexbtns { display: flex; gap: 10px; flex-wrap: wrap; }
.toast {
  position: fixed; inset-block-end: 90px; inset-inline: 0; margin: auto; width: max-content;
  max-width: 90%; background: #000; color: #fff; padding: 10px 18px; border-radius: 999px;
  z-index: 60; opacity: 0; transition: opacity .2s ease; pointer-events: none; box-shadow: var(--shadow);
}
.toast.show { opacity: .95; }
.back-btn { background: transparent; border: 0; color: var(--text); font-size: 1.4rem; cursor: pointer; padding: 4px; }
h2.screen-title { margin: 4px 0 12px; }
.tag { display:inline-block; background: var(--surface-2); border:1px solid var(--line); border-radius:999px; padding:2px 10px; font-size:.75rem; color: var(--muted); }
.center { text-align: center; }
table.mini { width: 100%; border-collapse: collapse; font-size: .85rem; }
table.mini th, table.mini td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: right; }
table.mini th { color: var(--muted); font-weight: 600; }
