:root {
  --navy: #1b2150;
  --navy-2: #2a3170;
  --blue: #2b7bc0;
  --blue-soft: #e8f1fa;
  --orange: #f7941d;
  --orange-soft: #fff2e0;
  --green: #1e9e5a;
  --green-soft: #e4f6ec;
  --red: #d64545;
  --red-soft: #fde9e9;
  --gray: #6b7280;
  --line: #e5e7eb;
  --bg: #f4f6fa;
  --card: #ffffff;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Cairo', system-ui, sans-serif;
  background: var(--bg); color: #1f2433; font-size: 15px; line-height: 1.6;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  background: var(--navy); color: #fff; padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
}
.top-logo { width: 36px; height: 36px; border-radius: 50%; background: #fff; }
.top-title { flex: 1; font-weight: 700; font-size: 17px; }
.bell { position: relative; background: none; border: 0; color: #fff; padding: 6px; cursor: pointer; }
.badge {
  position: absolute; top: 0; left: 0; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--orange); color: #fff; font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}

/* ---------- layout ---------- */
#app { padding: 14px 14px calc(90px + var(--safe-b)); max-width: 720px; margin: 0 auto; }
.splash { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 70vh; gap: 20px; }
.splash img { width: 140px; }
.spinner { width: 30px; height: 30px; border: 3px solid var(--line); border-top-color: var(--orange); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

h2 { font-size: 18px; margin: 4px 0 12px; color: var(--navy); }
h3 { font-size: 15px; margin: 18px 0 8px; color: var(--navy); }
.muted { color: var(--gray); font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.spacer { height: 12px; }
.center { text-align: center; }

/* ---------- bottom nav ---------- */
#nav {
  position: fixed; bottom: 0; right: 0; left: 0; z-index: 20;
  display: flex; background: #fff; border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
#nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 2px 6px; color: var(--gray); text-decoration: none; font-size: 11.5px; font-weight: 600;
}
#nav a svg { width: 24px; height: 24px; }
#nav a.on { color: var(--navy); }
#nav a.on svg { color: var(--orange); }
#nav a .dot { position: relative; }
#nav a .dot b {
  position: absolute; top: -4px; left: -10px; background: var(--orange); color: #fff;
  font-size: 10px; border-radius: 8px; padding: 0 5px; line-height: 16px;
}

/* ---------- cards ---------- */
.card {
  background: var(--card); border-radius: var(--radius); padding: 12px 14px;
  box-shadow: 0 1px 2px rgba(16,24,40,.06); margin-bottom: 10px; border: 1px solid var(--line);
}
a.card, .card.tap { display: block; color: inherit; text-decoration: none; cursor: pointer; }
.order-top { display: flex; align-items: center; gap: 8px; }
.order-no { font-weight: 700; color: var(--navy); }
.order-name { font-weight: 700; font-size: 16px; margin-top: 2px; }
.order-meta { color: var(--gray); font-size: 13px; }
.order-fault { font-size: 14px; margin-top: 4px; }
.order-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; font-size: 13px; }
.tech-tag { color: var(--blue); font-weight: 600; }

.chip { display: inline-block; padding: 1px 10px; border-radius: 20px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.st-new { background: var(--blue-soft); color: var(--blue); }
.st-assigned { background: #eef0fb; color: var(--navy-2); }
.st-next { background: #f1e8fb; color: #7a3fb8; }
.st-on_way { background: var(--orange-soft); color: #b8650a; }
.st-working { background: #fff7d6; color: #8a6a00; }
.st-done { background: var(--green-soft); color: var(--green); }
.st-postponed_customer, .st-postponed_parts { background: var(--red-soft); color: var(--red); }
.st-pending_approval { background: #fff2e0; color: #b8650a; border: 1px dashed var(--orange); }
.st-rejected { background: #eee; color: #666; }
.st-cancelled { background: var(--red); color: #fff; }
.card.card-cancelled { background: var(--red-soft); border: 1.5px solid var(--red); }
.card.card-cancelled .order-name, .card.card-cancelled .order-no { color: var(--red); }

/* ---------- filters ---------- */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.filters .full { grid-column: 1 / -1; }
.pills { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; scrollbar-width: none; }
.pills::-webkit-scrollbar { display: none; }
.pill { border: 1px solid var(--line); background: #fff; border-radius: 20px; padding: 4px 12px; font-size: 13px; white-space: nowrap; cursor: pointer; }
.pill.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.count-line { font-size: 13px; color: var(--gray); margin-bottom: 8px; }

/* ---------- forms ---------- */
label { display: block; font-size: 13px; font-weight: 600; color: var(--navy); margin: 10px 0 4px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid #cfd5e1; border-radius: 10px; background: #fff;
  font-size: 15px; color: inherit; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(43,123,192,.15); }
textarea { min-height: 70px; resize: vertical; }
input[type=checkbox], input[type=radio] { width: auto; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; color: inherit; margin: 6px 0; }
.radio-group { display: flex; gap: 8px; }
.radio-group label { flex: 1; margin: 0; border: 1px solid #cfd5e1; border-radius: 10px; padding: 10px; text-align: center; font-weight: 600; cursor: pointer; }
.radio-group input { display: none; }
.radio-group input:checked + span { color: var(--navy); }
.radio-group label:has(input:checked) { border-color: var(--navy); background: #eef0fb; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 700; cursor: pointer;
  background: var(--navy); color: #fff; text-decoration: none; font-size: 15px;
}
.btn:disabled { opacity: .55; }
.btn.block { width: 100%; }
.btn.orange { background: var(--orange); }
.btn.blue { background: var(--blue); }
.btn.green { background: var(--green); }
.btn.red { background: var(--red); }
.btn.ghost { background: #fff; color: var(--navy); border: 1px solid #cfd5e1; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.btn-grid .full { grid-column: 1 / -1; }

.fab {
  position: fixed; left: 18px; bottom: calc(78px + var(--safe-b)); z-index: 15;
  width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--orange); color: #fff;
  font-size: 32px; line-height: 1; box-shadow: 0 6px 16px rgba(247,148,29,.45); cursor: pointer;
}

/* ---------- details ---------- */
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 10px; font-size: 14px; }
.kv dt { color: var(--gray); }
.kv dd { margin: 0; font-weight: 600; }
.alert { border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-bottom: 10px; }
.alert.warn { background: var(--orange-soft); color: #8a4b05; border: 1px solid #f5c98d; }
.alert.info { background: var(--blue-soft); color: #1d5a8f; }
.alert.err { background: var(--red-soft); color: #9b2c2c; }
.alert.ok { background: var(--green-soft); color: #166b3f; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { border-right: 2px solid var(--line); padding: 0 12px 10px 0; position: relative; font-size: 13px; }
.timeline li::before { content: ''; position: absolute; right: -6px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--blue); }
.timeline .when { color: var(--gray); font-size: 12px; }

table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list td, table.list th { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: right; }
table.list th { color: var(--gray); font-weight: 600; font-size: 12px; }

.list-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--blue-soft); color: var(--blue); display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; }
.notif.unread { border-right: 4px solid var(--orange); }

/* ---------- attendance ---------- */
.checkin-btn {
  width: 180px; height: 180px; border-radius: 50%; border: 0; margin: 20px auto; display: flex;
  flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  background: var(--navy); color: #fff; font-size: 20px; font-weight: 700; cursor: pointer;
  box-shadow: 0 0 0 10px #e3e6f5;
}
.checkin-btn.done { background: var(--green); box-shadow: 0 0 0 10px var(--green-soft); }

/* ---------- login ---------- */
.login { max-width: 380px; margin: 30px auto; }
.login .logo { display: block; width: 150px; margin: 0 auto 10px; }
.login h1 { text-align: center; color: var(--navy); font-size: 20px; margin: 0 0 20px; }
.tabs { display: flex; background: #e6e9f2; border-radius: 10px; padding: 4px; margin-bottom: 10px; }
.tabs button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 8px; font-weight: 700; color: var(--gray); cursor: pointer; }
.tabs button.on { background: #fff; color: var(--navy); }

/* ---------- toast & modal ---------- */
#toast {
  position: fixed; bottom: calc(90px + var(--safe-b)); right: 16px; left: 16px; z-index: 60;
  background: #1f2433; color: #fff; padding: 12px 14px; border-radius: 12px; font-size: 14px; text-align: center;
  box-shadow: 0 8px 20px rgba(0,0,0,.25);
}
#toast.err { background: var(--red); }
#toast.ok { background: var(--green); }
#modal { position: fixed; inset: 0; z-index: 50; background: rgba(15,20,40,.5); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: #fff; width: 100%; max-width: 720px; max-height: 92vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 16px 16px calc(20px + var(--safe-b));
  animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.sheet-head h2 { margin: 0; }
.x { background: none; border: 0; font-size: 26px; color: var(--gray); cursor: pointer; line-height: 1; }
.pay-row { display: grid; grid-template-columns: 1fr 1fr 36px; gap: 6px; margin-bottom: 6px; }
.empty { text-align: center; color: var(--gray); padding: 30px 10px; }
