/* ورشة | Warsha — RTL, offline, mobile-first */
:root {
  --accent: #1d4ed8;
  --accent-strong: #1e40af;
  --accent-soft: #dbeafe;
  --hero-from: #1d4ed8;
  --hero-to: #1e40af;
  --accent-btn: #1d4ed8;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --text: #1f2937;
  --text-dim: #6b7280;
  --border: #e2e8f0;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 14px rgba(15, 23, 42, .05);
  --radius: 14px;
}
[data-theme="dark"] {
  --accent: #60a5fa;
  --accent-strong: #93c5fd;
  --accent-soft: #172554;
  --hero-from: #1e40af;
  --hero-to: #1e3a8a;
  --accent-btn: #1d4ed8;
  --bg: #0f1420;
  --surface: #1a2130;
  --text: #e9eef7;
  --text-dim: #93a1b8;
  --border: #2c3850;
  --shadow: 0 1px 3px rgba(0, 0, 0, .35), 0 4px 14px rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0); clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, "Segoe UI", Tahoma, "Noto Kufi Arabic", Arial, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.6; min-height: 100vh;
}
body.theme-ready { transition: background .25s, color .25s; }

.app-header {
  background: linear-gradient(135deg, var(--hero-from), var(--hero-to));
  color: #fff; padding: 18px 16px; position: sticky; top: 0; z-index: 20; box-shadow: var(--shadow);
}
.header-inner { max-width: 1000px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-name { margin: 0; font-size: 24px; font-weight: 800; }
.brand-en { font-size: 14px; font-weight: 600; opacity: .8; letter-spacing: .4px; }
.brand-sub { margin: 0; font-size: 12.5px; opacity: .92; }
.header-actions { display: flex; gap: 6px; }
.icon-btn {
  background: rgba(255, 255, 255, .16); border: none; color: #fff;
  width: 40px; height: 40px; border-radius: 10px; cursor: pointer; transition: background .2s;
  display: grid; place-content: center;
}
.icon-btn:hover { background: rgba(255, 255, 255, .3); }
.icon-btn:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

.container { max-width: 1000px; margin: 0 auto; padding: 18px 14px 60px; }
section { margin-bottom: 18px; }
h2 { font-size: 17px; margin: 0 0 10px; }

.stats-bar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.stat {
  background: var(--surface); border-radius: var(--radius); padding: 14px 8px;
  text-align: center; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 2px;
}
.stat-num { font-size: 20px; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.stat-num.warn { color: var(--warn); }
.stat-label { font-size: 12px; color: var(--text-dim); }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.toolbar input[type="search"] { flex: 1; min-width: 180px; }
.toolbar select { width: auto; min-width: 140px; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.w-card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; display: flex; flex-direction: column; gap: 8px;
  border-inline-start: 4px solid var(--accent);
}
.w-card.overdue { border-inline-start-color: var(--danger); }
.w-card.delivered { opacity: .75; }
.w-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.w-num {
  background: var(--accent-soft); color: var(--accent); font-weight: 800; font-size: 12.5px;
  padding: 3px 10px; border-radius: 999px; font-variant-numeric: tabular-nums;
}
.w-status {
  font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; color: #fff;
}
.st-received { background: #0284c7; }
.st-diagnosing { background: #7c3aed; }
.st-waiting_parts { background: #d97706; }
.st-repairing { background: #2563eb; }
.st-ready { background: var(--ok); }
.st-delivered { background: #6b7280; }
.w-overdue-badge {
  background: var(--danger); color: #fff; font-size: 11.5px; font-weight: 800;
  padding: 2px 9px; border-radius: 999px;
}
.w-customer { font-size: 16px; font-weight: 800; margin: 0; overflow-wrap: anywhere; }
.w-device { font-size: 13px; color: var(--text-dim); }
.w-issue { font-size: 14px; margin: 0; overflow-wrap: anywhere; }
.w-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12.5px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.w-money { display: flex; gap: 12px; font-size: 13.5px; flex-wrap: wrap; }
.w-money b { font-variant-numeric: tabular-nums; }
.w-money .rem { color: var(--danger); }
.w-photos { display: flex; gap: 6px; }
.w-photos img {
  width: 54px; height: 54px; object-fit: cover; border-radius: 8px; cursor: zoom-in;
  border: 1px solid var(--border);
}
.w-photos img:focus-visible { outline: 3px solid var(--accent); }
.w-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.w-actions .btn { padding: 8px 14px; font-size: 13px; }
.btn-wa { background: #16a34a; color: #fff; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn-wa:hover { background: #15803d; }
.btn-next { background: transparent; color: var(--accent); border-color: var(--accent); }
.btn-next:hover { background: var(--accent-soft); }
.btn-edit { background: transparent; color: var(--text-dim); border-color: var(--border); }
.btn-edit:hover { color: var(--accent); border-color: var(--accent); }

input[type="text"], input[type="tel"], input[type="number"], input[type="date"], input[type="search"], select, textarea {
  font-family: inherit; font-size: 14.5px; padding: 10px 12px;
  border: 1.5px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); transition: border-color .15s;
  width: 100%;
}
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
label { display: flex; flex-direction: column; gap: 5px; font-size: 13.5px; font-weight: 600; margin-bottom: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.form-row { margin-bottom: 12px; }
.form-label { display: block; font-size: 13.5px; font-weight: 600; margin-bottom: 6px; }
input[type="file"] { font-size: 13px; color: var(--text-dim); }
.photo-preview { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.photo-preview .pv { position: relative; width: 64px; height: 64px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.photo-preview .pv img { width: 100%; height: 100%; object-fit: cover; }
.photo-preview .pv button {
  position: absolute; top: 2px; inset-inline-end: 2px; width: 20px; height: 20px;
  border: none; border-radius: 50%; background: rgba(0, 0, 0, .65); color: #fff; font-size: 11px; cursor: pointer;
}

.btn {
  font-family: inherit; font-size: 14px; font-weight: 700; padding: 10px 18px;
  border-radius: 10px; border: 1.5px solid transparent; cursor: pointer; transition: all .18s;
}
.btn-primary { background: var(--accent-btn); color: #fff; }
.btn-primary:hover { background: var(--hero-from); }
.btn-ghost { background: transparent; color: var(--accent); border-color: var(--accent); }
.btn-ghost:hover { background: var(--accent-soft); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn:focus-visible, .btn-wa:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.modal {
  border: none; border-radius: var(--radius); padding: 0;
  width: min(560px, 94vw); max-height: 90vh; overflow-y: auto;
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.modal::backdrop { background: rgba(15, 23, 42, .55); }
.modal-body { padding: 22px; }
.modal-actions { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.modal-actions .spacer { flex: 1; }

.photo-modal { border: none; padding: 0; background: transparent; max-width: 92vw; }
.photo-modal::backdrop { background: rgba(0, 0, 0, .8); }
.photo-modal img { max-width: 92vw; max-height: 86vh; border-radius: 10px; display: block; }
.photo-close {
  position: absolute; top: -14px; inset-inline-start: -14px;
  width: 36px; height: 36px; border-radius: 50%; border: none;
  background: #fff; color: #111; font-size: 16px; cursor: pointer;
}

.toast {
  position: fixed; bottom: 22px; inset-inline-start: 50%;
  transform: translateX(50%) translateY(80px);
  background: var(--text); color: var(--bg);
  padding: 10px 22px; border-radius: 999px; font-size: 14px; font-weight: 600;
  opacity: 0; transition: all .3s; pointer-events: none; z-index: 50; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(50%) translateY(0); pointer-events: auto; }
.toast-undo {
  font-family: inherit; border: none; background: none; color: #60a5fa;
  font-weight: 800; font-size: 14px; cursor: pointer; margin-inline-start: 12px; padding: 2px 8px; border-radius: 6px;
}
.toast-undo:hover { text-decoration: underline; }

.empty-note { text-align: center; color: var(--text-dim); padding: 30px 10px; font-size: 15px; }

@media (max-width: 560px) {
  .brand-sub { display: none; }
  .grid-2 { grid-template-columns: 1fr; }
  .stats-bar { grid-template-columns: repeat(2, 1fr); gap: 6px; }
}

/* Customer receipt print: prints the open card's receipt when .printing is set on body */
@media print {
  .app-header, .toolbar, .stats-bar, .toast, .w-actions, .w-photos { display: none !important; }
  body { background: #fff; color: #000; }
  .w-card { box-shadow: none; border: 1px solid #333; break-inside: avoid; opacity: 1; }
}
