/* JoTrack Field — tablet-first, Arabic right-to-left.
   No external fonts or assets: the app must render fully with no signal. */

:root {
  --brand: #1d71b8;
  --brand-dark: #155a93;
  --ink: #0f1a2c;
  --muted: #5b6b80;
  --line: #d6dee8;
  --bg: #f3f6fa;
  --card: #ffffff;
  --ok: #1f8a4c;
  --warn: #b7791f;
  --bad: #c0392b;
  --radius: 14px;
  --tap: 52px;               /* comfortable for a gloved or hurried finger */
  font-size: 17px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", "Noto Sans", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font: inherit; color: inherit; }

.hidden { display: none !important; }

/* ── Top bar ─────────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px;
  background: var(--ink); color: #fff;
}
.topbar .brand { font-weight: 800; letter-spacing: .2px; }
.topbar .brand small { display: block; font-weight: 500; opacity: .7; font-size: .72rem; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: .85rem; opacity: .9; }
.topbar button { background: transparent; border: 1px solid rgba(255,255,255,.35); color: #fff;
  border-radius: 10px; padding: 6px 12px; cursor: pointer; }

/* Connection + pending-upload strip. Always visible so a technician is never
   unsure whether a signed form has actually left the tablet. */
.status {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 18px; font-size: .88rem; border-bottom: 1px solid var(--line);
  background: #eaf2fb;
}
.status.offline { background: #fff4e0; }
.status.pending { background: #fff4e0; }
.status .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); flex: none; }
.status.offline .dot { background: var(--warn); }
.status button { margin-inline-start: auto; }

main { max-width: 980px; margin: 0 auto; padding: 18px; }

/* ── Cards & sections ────────────────────────────────────────────────── */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px;
}
.section-title {
  display: flex; align-items: baseline; gap: 10px;
  margin: 0 0 14px; font-size: 1.1rem; font-weight: 800;
}
.section-title small { font-weight: 500; color: var(--muted); font-size: .78rem; }

.muted { color: var(--muted); }
.lead { font-size: 1.05rem; }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  min-height: var(--tap); padding: 0 22px; border-radius: 12px; border: 1px solid transparent;
  font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:active { background: var(--brand-dark); }
.btn-primary:disabled { background: #9fb6cc; cursor: not-allowed; }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn-sm { min-height: 38px; padding: 0 14px; font-size: .88rem; border-radius: 10px; }
.btn-block { width: 100%; }

/* ── Sign-in ─────────────────────────────────────────────────────────── */
.signin { text-align: center; padding: 48px 20px; }
.signin h1 { margin: 0 0 8px; font-size: 1.6rem; }
.signin p { margin: 0 0 26px; }

/* ── Ticket list ─────────────────────────────────────────────────────── */
.list-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.list-head h2 { margin: 0; font-size: 1.2rem; }
.list-head .spacer { flex: 1; }

.ticket {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: start;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 10px; cursor: pointer;
}
.ticket:active { border-color: var(--brand); }
.ticket .main { flex: 1; min-width: 0; }
.ticket .title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ticket .meta { color: var(--muted); font-size: .88rem; }
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .75rem; font-weight: 700;
  background: #e8eef5; color: var(--muted); white-space: nowrap;
}
.badge.mine { background: #e3f0fb; color: var(--brand-dark); }
.badge.draft { background: #fff1d6; color: #8a5a12; }
.badge.queued { background: #fff1d6; color: #8a5a12; }

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

/* ── Form fields ─────────────────────────────────────────────────────── */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-weight: 700; font-size: .92rem; }
.field label small { font-weight: 500; color: var(--muted); }
.req::after { content: " *"; color: var(--bad); }

input[type=text], input[type=tel], textarea {
  min-height: var(--tap); width: 100%; padding: 10px 14px; border: 1px solid var(--line);
  border-radius: 12px; background: #fff;
}
textarea { min-height: 88px; resize: vertical; }
input:focus, textarea:focus { outline: 3px solid rgba(29,113,184,.25); border-color: var(--brand); }
input.ltr { direction: ltr; text-align: right; }

/* Choice chips: one tap each, far easier on a tablet than tiny radios. */
.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  min-height: var(--tap); padding: 0 18px; border-radius: 12px; border: 2px solid var(--line);
  background: #fff; cursor: pointer; font-weight: 600; display: inline-flex; align-items: center; gap: 8px;
}
.chip[aria-pressed=true] { border-color: var(--brand); background: #e3f0fb; color: var(--brand-dark); }
.chip .tick {
  width: 18px; height: 18px; border-radius: 5px; border: 2px solid #98a6b8; flex: none;
}
.chip[aria-pressed=true] .tick { background: var(--brand); border-color: var(--brand); }

/* Fault grid */
.fault-table { width: 100%; border-collapse: collapse; }
.fault-table th, .fault-table td { border-bottom: 1px solid var(--line); padding: 8px 4px; text-align: center; }
.fault-table th:first-child, .fault-table td:first-child { text-align: start; font-weight: 700; }
.fault-table th { font-size: .82rem; color: var(--muted); font-weight: 700; }
.cell-toggle {
  width: 44px; height: 44px; border-radius: 10px; border: 2px solid var(--line); background: #fff; cursor: pointer;
}
.cell-toggle[aria-pressed=true] { background: var(--brand); border-color: var(--brand); }
.fault-scroll { overflow-x: auto; }

/* ── Signatures ──────────────────────────────────────────────────────── */
.declaration {
  background: #eef3f8; border-radius: 12px; padding: 14px 16px; font-weight: 700; margin-bottom: 14px;
}
.declaration small { display: block; font-weight: 500; color: var(--muted); margin-top: 6px; }

.sig-wrap { position: relative; }
.sig {
  width: 100%; height: 200px; display: block; background: #fff;
  border: 2px dashed #98a6b8; border-radius: 12px;
  touch-action: none;          /* signing must not scroll the page */
}
.sig.signed { border-style: solid; border-color: var(--brand); }
.sig-hint {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: #9aa8ba; pointer-events: none; font-size: 1.05rem;
}
.sig-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }

/* ── Errors & banners ────────────────────────────────────────────────── */
.errors {
  border: 1px solid #f1b8b0; background: #fdecea; color: #7f1d12; border-radius: 12px;
  padding: 12px 16px; margin-bottom: 16px;
}
.errors ul { margin: 6px 0 0; padding-inline-start: 20px; }
.notice {
  border-radius: 12px; padding: 12px 16px; margin-bottom: 16px; background: #eaf2fb; color: #123d63;
}
.notice.warn { background: #fff4e0; color: #6b4410; }

.field-error input, .field-error textarea { border-color: var(--bad); }

/* Sticky submit bar: always reachable at the bottom of a long form. */
.submitbar {
  position: sticky; bottom: 0; z-index: 10;
  display: flex; gap: 12px; padding: 12px 0; margin-top: 8px;
  background: linear-gradient(to top, var(--bg) 70%, rgba(243,246,250,0));
}
.submitbar .btn-primary { flex: 1; }

/* ── Done ────────────────────────────────────────────────────────────── */
.done { text-align: center; padding: 40px 20px; }
.done .big { font-size: 2.2rem; font-weight: 800; margin: 6px 0; direction: ltr; }
.done .icon {
  width: 72px; height: 72px; border-radius: 50%; background: #e3f5ea; color: var(--ok);
  display: inline-flex; align-items: center; justify-content: center; font-size: 2.2rem; font-weight: 800;
}
.done.queued .icon { background: #fff1d6; color: var(--warn); }

@media (max-width: 680px) {
  :root { font-size: 16px; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  main { padding: 12px; }
}
