/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --c1: #6C63FF;
  --c1h: #5a52e0;
  --c2: #43A047;
  --c2h: #388E3C;
  --c3: #E65100;
  --c4: #E53935;
  --c4h: #C62828;
  --bg: #F4F4F6;
  --surface: #FFFFFF;
  --surface2: #F8F8FA;
  --border: rgba(0,0,0,.08);
  --border-s: rgba(0,0,0,.14);
  --text: #1A1A1A;
  --text2: #555;
  --text3: #888;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113;
    --surface: #1E1E22;
    --surface2: #26262C;
    --border: rgba(255,255,255,.08);
    --border-s: rgba(255,255,255,.14);
    --text: #F0F0F2;
    --text2: #AAA;
    --text3: #666;
  }
  .s-wait { background:#3D2700; color:#FFB74D; }
  .s-diag { background:#0D2A45; color:#64B5F6; }
  .s-conf { background:#2A1A45; color:#CE93D8; }
  .s-rep  { background:#3D2000; color:#FFB300; }
  .s-done { background:#0D2D14; color:#81C784; }
  .s-del  { background:#1E2428; color:#90A4AE; }
  .s-rej  { background:#3D0D0D; color:#EF9A9A; }
  .s-low  { background:#3D0D0D; color:#EF9A9A; }
  .s-ok   { background:#0D2D14; color:#81C784; }
  .step.done { background:#0D2D14; color:#81C784; border-color:#388E3C; }
  .pay-opt.on { background:#1E1A40; color:#B39DDB; }
  .price-summary { background:#1E1E22; }
  .tstep.done { background:#0D2D14; }
  .tstep.cur  { background:#1E1A40; }
}

html, body {
  font-family: Vazirmatn, Tahoma, sans-serif;
  direction: rtl;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ===== Layout ===== */
.g2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.g3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.g4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
.row { display: flex; gap: 8px; }
.row .fg { flex: 1; min-width: 0; }

/* ===== Topbar ===== */
.topbar {
  background: var(--surface);
  border-bottom: 0.5px solid var(--border);
  padding: 9px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.logo {
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.logo i { color: var(--c1); font-size: 18px; }
.srch { flex: 1; max-width: 240px; position: relative; }
.srch input {
  width: 100%;
  padding: 6px 30px 6px 10px;
  font-size: 13px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface2);
  color: var(--text);
}
.srch i { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); color: var(--text3); font-size: 15px; pointer-events: none; }
.top-actions { display: flex; gap: 5px; margin-right: auto; }
.tbtn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  font-size: 12px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface2);
  color: var(--text2);
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  transition: background .12s;
}
.tbtn:hover { background: var(--bg); color: var(--text); }

/* ===== Nav ===== */
.nav {
  background: var(--surface);
  border-bottom: 0.5px solid var(--border);
  display: flex;
  overflow-x: auto;
  padding: 0 6px;
  scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }
.nav button {
  padding: 9px 12px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 12px;
  color: var(--text3);
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: color .15s;
  font-family: inherit;
}
.nav button.on { color: var(--c1); border-bottom-color: var(--c1); font-weight: 500; }
.nav button:hover:not(.on) { color: var(--text); background: var(--surface2); }

/* ===== Pages ===== */
.pg { display: none; padding: 14px; }
.pg.on { display: block; }

/* ===== Card ===== */
.card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 12px;
}
.card-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text2);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ===== Stat card ===== */
.stat {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
}
.stat-v { font-size: 20px; font-weight: 500; }
.stat-l { font-size: 11px; color: var(--text3); margin-top: 2px; }

/* ===== Form ===== */
label { font-size: 12px; color: var(--text2); display: block; margin-bottom: 3px; }
input, select, textarea {
  width: 100%;
  padding: 7px 10px;
  border: 0.5px solid var(--border-s);
  border-radius: var(--radius);
  background: var(--surface2);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--c1); }
textarea { resize: vertical; min-height: 60px; }
.fg { margin-bottom: 10px; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 13px;
  border: 0.5px solid var(--border-s);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  transition: background .12s, opacity .12s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface2); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--c1); color: #fff; border-color: var(--c1); }
.btn.primary:hover { background: var(--c1h); }
.btn.success { background: var(--c2); color: #fff; border-color: var(--c2); }
.btn.success:hover { background: var(--c2h); }
.btn.danger  { background: var(--c4); color: #fff; border-color: var(--c4); }
.btn.danger:hover  { background: var(--c4h); }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }

/* ===== Badges ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}
.s-wait { background:#FFF3E0; color:#BF360C; }
.s-diag { background:#E3F2FD; color:#0D47A1; }
.s-conf { background:#EDE7F6; color:#4527A0; }
.s-rep  { background:#FFF8E1; color:#E65100; }
.s-done { background:#E8F5E9; color:#1B5E20; }
.s-del  { background:#ECEFF1; color:#37474F; }
.s-rej  { background:#FFEBEE; color:#B71C1C; }
.s-low  { background:#FFEBEE; color:#B71C1C; }
.s-ok   { background:#E8F5E9; color:#1B5E20; }

/* ===== Order rows ===== */
.orow {
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 7px;
  cursor: pointer;
  background: var(--surface);
  transition: border-color .15s, background .15s;
}
.orow:hover { border-color: var(--c1); background: var(--surface2); }
.oh { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.oid { font-size: 12px; font-weight: 500; color: var(--c1); }
.odev { font-size: 13px; font-weight: 500; }
.ometa { font-size: 11px; color: var(--text3); margin-top: 2px; }
.oprice { font-size: 11px; color: var(--c2); margin-top: 3px; }

/* ===== Steps bar ===== */
.steps-bar { display: flex; gap: 3px; margin-bottom: 14px; }
.step {
  flex: 1;
  text-align: center;
  padding: 5px 2px;
  border-radius: var(--radius);
  font-size: 10px;
  border: 0.5px solid var(--border);
  background: var(--surface2);
  color: var(--text3);
  cursor: default;
  transition: all .15s;
}
.step.done { background:#E8F5E9; color:#2E7D32; border-color:#A5D6A7; }
.step.cur  { background: var(--c1); color: #fff; border-color: var(--c1); font-weight: 500; }
.step.clickable { cursor: pointer; }
.step.clickable:hover { opacity: .8; }

/* ===== Parts table ===== */
.parts-tbl { width: 100%; font-size: 12px; border-collapse: collapse; margin-bottom: 8px; }
.parts-tbl th {
  background: var(--surface2);
  padding: 5px 8px;
  text-align: right;
  font-weight: 500;
  color: var(--text2);
  border-bottom: 0.5px solid var(--border);
}
.parts-tbl td { padding: 5px 8px; border-bottom: 0.5px solid var(--border); }
.parts-tbl tr:last-child td { border-bottom: none; }

/* ===== Payment options ===== */
.pay-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-bottom: 10px; }
.pay-opt {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 6px;
  text-align: center;
  cursor: pointer;
  font-size: 12px;
  color: var(--text2);
  transition: all .15s;
  background: var(--surface2);
  font-family: inherit;
  line-height: 1.4;
}
.pay-opt:hover { border-color: var(--c1); color: var(--c1); }
.pay-opt.on { border-color: var(--c1); background: #EDE7FF; color: #4527A0; font-weight: 500; }
.pay-opt i { display: block; font-size: 18px; margin-bottom: 3px; }

/* ===== Inventory rows ===== */
.irow {
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  margin-bottom: 7px;
  background: var(--surface);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.irow-l { min-width: 0; }
.irow-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.irow-meta { font-size: 11px; color: var(--text3); margin-top: 2px; }

/* ===== Accounting ===== */
.acctxn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
  border-bottom: 0.5px solid var(--border);
}
.acctxn:last-child { border: none; }

/* ===== Price summary ===== */
.price-summary {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 10px;
  font-size: 12px;
}
.price-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  border-bottom: 0.5px solid var(--border);
}
.price-row:last-child { border: none; font-weight: 500; }

/* ===== Tracking ===== */
.track-wrap { max-width: 380px; margin: 20px auto 0; }
.tstep {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--radius);
  background: var(--surface2);
  margin-bottom: 5px;
  font-size: 13px;
}
.tstep.done { background: #E8F5E9; }
.tstep.cur  { background: #EDE7FF; font-weight: 500; }
.tdot { width: 8px; height: 8px; border-radius: 50%; background: var(--border-s); flex-shrink: 0; }
.tstep.done .tdot { background: var(--c2); }
.tstep.cur  .tdot { background: var(--c1); }

/* ===== Modal ===== */
.modal-wrap {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 20px 10px;
  z-index: 100;
  overflow-y: auto;
}
.modal-wrap.on { display: flex; }
.modal {
  background: var(--surface);
  border-radius: 12px;
  border: 0.5px solid var(--border);
  width: 100%;
  max-width: 540px;
  padding: 18px;
  margin: auto;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14px;
  gap: 8px;
}
.modal-head h2 { font-size: 15px; font-weight: 500; line-height: 1.4; }

/* ===== Misc ===== */
.sep { height: 0.5px; background: var(--border); margin: 12px 0; }
.empty { text-align: center; padding: 32px 16px; color: var(--text3); font-size: 13px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  background: var(--surface2);
  border: 0.5px solid var(--border);
  border-radius: 20px;
  font-size: 11px;
  color: var(--text2);
}
.filter-bar { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 10px; }
.fbtn {
  padding: 4px 10px;
  font-size: 11px;
  border: 0.5px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text2);
  cursor: pointer;
  transition: all .12s;
  font-family: inherit;
}
.fbtn.on { background: var(--c1); color: #fff; border-color: var(--c1); }

/* ===== Bar chart ===== */
.bar-chart { display: flex; align-items: flex-end; gap: 5px; height: 90px; padding-bottom: 18px; }
.bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.bar-col { width: 100%; border-radius: 3px 3px 0 0; min-height: 3px; background: var(--c1); opacity: .65; transition: height .3s; }
.bar-lbl { font-size: 9px; color: var(--text3); white-space: nowrap; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  padding: 9px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 9999;
  white-space: nowrap;
  animation: tin .2s ease;
  color: #fff;
}
.toast.ok  { background: #2E7D32; }
.toast.err { background: #C62828; }
.toast.warn { background: #E65100; }
@keyframes tin {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
  .topbar { flex-wrap: wrap; gap: 7px; }
  .srch { max-width: 100%; order: 3; flex: 1 1 100%; }
  .top-actions { margin-right: 0; }
  .g2, .g4 { grid-template-columns: 1fr; }
  .pay-grid { grid-template-columns: 1fr; }
  .steps-bar .step { font-size: 9px; padding: 4px 1px; }
}

/* ===== PWA install prompt ===== */
#install-banner {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--c1);
  color: #fff;
  padding: 12px 16px;
  font-size: 13px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  z-index: 200;
}
#install-banner.show { display: flex; }
</style>
