:root {
  --bg: #f4f6f7;
  --card: #ffffff;
  --field: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #0d9488;
  --brand-ink: #ffffff;
  --tint: #e6f5f3;
  --tint-ink: #0f766e;
  --red: #dc2626;
  --red-tint: #fef2f2;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1416;
    --card: #162023;
    --field: #0f181b;
    --ink: #e6edf0;
    --muted: #8fa0a6;
    --line: #25343a;
    --brand: #14b8a6;
    --brand-ink: #04201d;
    --tint: #11302d;
    --tint-ink: #5eead4;
    --red: #f87171;
    --red-tint: #2b1618;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: calc(86px + env(safe-area-inset-bottom, 0px));
  -webkit-text-size-adjust: 100%;
}

.top {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px 16px 8px;
  font-size: 19px;
  font-weight: 800;
}

main { max-width: 760px; margin: 0 auto; padding: 0 12px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
}

h2 { font-size: 16px; margin: 0 0 12px; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid.gap-top { margin-top: 12px; }
.full { grid-column: 1 / -1; }

label { display: block; font-size: 12.5px; color: var(--muted); margin: 0 0 5px; }

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

input, select {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--field);
  color: var(--ink);
}
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }

button {
  border: 0;
  border-radius: 12px;
  padding: 12px 14px;
  font-weight: 700;
  cursor: pointer;
}
button:disabled { opacity: .55; cursor: not-allowed; }
button:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.primary { background: var(--brand); color: var(--brand-ink); width: 100%; margin-top: 12px; }
.secondary { background: var(--tint); color: var(--tint-ink); }
.danger { background: var(--red-tint); color: var(--red); }
.small { padding: 7px 11px; font-size: 12.5px; }
.block { width: 100%; margin-top: 8px; }

.hint { font-size: 12px; color: var(--muted); margin: 8px 0 0; line-height: 1.7; }
.rowhead { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.rowhead h2 { margin: 0; }

details > summary {
  list-style: none;
  cursor: pointer;
  font-weight: 800;
  font-size: 16px;
  color: var(--tint-ink);
}
details > summary::-webkit-details-marker { display: none; }

/* الملخص */
.hero-box {
  background: var(--brand);
  color: var(--brand-ink);
  border-radius: 14px;
  padding: 16px;
  margin: 14px 0 10px;
  text-align: center;
}
.hero-label { font-size: 13px; opacity: .9; }
.hero-value { font-size: 34px; font-weight: 800; margin: 4px 0; overflow-wrap: anywhere; }
.hero-value.bad { color: #fecaca; }
.hero-sub { font-size: 12.5px; opacity: .9; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.stat { background: var(--bg); border-radius: 12px; padding: 10px 12px; }
.stat span { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 4px; }
.stat strong { font-size: 16px; overflow-wrap: anywhere; }
.stat strong.bad { color: var(--red); }

/* الأوردرات */
.orders { display: grid; gap: 8px; }
.order { border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.order-top { display: flex; justify-content: space-between; gap: 8px; align-items: start; }
.order h3 { font-size: 14px; margin: 0 0 3px; }
.order p { font-size: 12px; color: var(--muted); margin: 4px 0; line-height: 1.6; }
.order .money { font-weight: 800; color: var(--tint-ink); white-space: nowrap; font-size: 14px; }
.order-actions { display: flex; gap: 6px; margin-top: 8px; }
.order-actions button { padding: 6px 12px; font-size: 12px; }

.empty { text-align: center; color: var(--muted); padding: 22px 8px; font-size: 13px; }

/* السجل */
.result-bar { font-size: 14px; font-weight: 700; line-height: 1.7; }
.result-bar small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
.btn-row { display: flex; gap: 8px; margin-top: 10px; }
.btn-row button { flex: 1; }

.shift-item {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px; margin-bottom: 8px;
}
.shift-item.active { border-color: var(--brand); }
.shift-item strong { font-size: 14px; }
.shift-item .day { color: var(--muted); font-size: 12px; margin-inline-start: 6px; }
.shift-item p { margin: 4px 0 0; font-size: 12px; color: var(--muted); line-height: 1.6; }
.shift-buttons { display: flex; gap: 6px; flex-shrink: 0; }
.shift-buttons button { padding: 8px 12px; font-size: 12.5px; }

/* عم أحمد */
.chat-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.chat-head strong { display: block; font-size: 16px; }
.chat-head span { font-size: 12px; color: var(--muted); }
.avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--tint); display: grid; place-items: center; font-size: 24px;
}
.chat-log {
  display: flex; flex-direction: column; gap: 8px;
  max-height: 46vh; min-height: 160px; overflow-y: auto;
  padding: 4px 2px 8px;
}
.msg {
  max-width: 88%; padding: 10px 13px; border-radius: 16px;
  white-space: pre-wrap; line-height: 1.8; font-size: 14px; overflow-wrap: anywhere;
}
.msg.me { align-self: flex-start; background: var(--brand); color: var(--brand-ink); border-end-start-radius: 4px; }
.msg.ahmed { align-self: flex-end; background: var(--tint); color: var(--ink); border-end-end-radius: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chips button { padding: 7px 11px; font-size: 12.5px; font-weight: 600; background: var(--bg); color: var(--tint-ink); border: 1px solid var(--line); }
.chat-input { display: flex; gap: 8px; }
.chat-input .primary { width: auto; margin: 0; padding: 0 18px; }

.footer { font-size: 12px; color: var(--muted); line-height: 1.7; text-align: center; padding: 6px 18px; }

/* شريط التبويبات */
.tabbar {
  position: fixed; inset: auto 0 0 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 10;
}
.tabbar button {
  flex: 1; background: none; color: var(--muted);
  border-radius: 0; padding: 9px 4px 10px; font-size: 12px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tabbar button i { font-style: normal; font-size: 21px; line-height: 1.2; }
.tabbar button.on { color: var(--brand); }

.tab[hidden] { display: none; }

@media (min-width: 600px) {
  .stats { grid-template-columns: repeat(4, 1fr); }
}

/* ====== التقرير المطبوع / PDF ====== */
#printArea { display: none; }

@media print {
  @page { size: A4; margin: 12mm; }
  html, body { background: #fff !important; color: #000 !important; padding: 0 !important; }
  body > *:not(#printArea) { display: none !important; }
  #printArea { display: block !important; color: #000; background: #fff; font-size: 12px; line-height: 1.6; }

  .r-title { font-size: 20px; margin: 0 0 4px; color: #0f766e; }
  .r-meta { color: #475569; margin: 0 0 12px; font-size: 11px; }
  .r-summary { border: 1px solid #99d9d2; background: #f0fbf9; border-radius: 6px; padding: 8px 10px; margin-bottom: 14px; }
  .r-summary b { color: #0f766e; }
  .r-shift { margin-bottom: 16px; break-inside: avoid-page; }
  .r-shift h2 { font-size: 14px; margin: 0 0 4px; padding-bottom: 3px; border-bottom: 2px solid #0f766e; }
  .r-line { margin: 4px 0 6px; font-size: 11px; color: #334155; }
  .r-table { width: 100%; border-collapse: collapse; font-size: 11px; }
  .r-table thead { display: table-header-group; }
  .r-table tr { break-inside: avoid; }
  .r-table th, .r-table td { border: 1px solid #cbd5e1; padding: 3px 5px; text-align: right; }
  .r-table th { background: #e6f5f3; }
  .r-empty { color: #64748b; font-size: 11px; }
}

/* ====== الدخول والمزامنة ====== */
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.who { display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 600; }
.who strong { max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--tint-ink); }
#syncStatus { font-weight: 600; color: var(--muted); }
#syncStatus.bad { color: var(--red); }

.auth { display: none; min-height: 100vh; min-height: 100dvh; padding: 20px 14px; align-items: center; justify-content: center; }
body.locked .auth { display: flex; }
body.locked > header, body.locked > main, body.locked > nav, body.locked > #printArea { display: none; }
.auth-card {
  width: 100%; max-width: 420px; background: var(--card);
  border: 1px solid var(--line); border-radius: 20px; padding: 22px 18px;
}
.auth-logo { font-size: 44px; text-align: center; }
.auth-card h1 { font-size: 22px; text-align: center; margin: 6px 0 4px; }
.hint.center { text-align: center; margin-bottom: 14px; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--bg); padding: 4px; border-radius: 14px; margin-bottom: 14px; }
.auth-tabs button { background: none; color: var(--muted); padding: 10px; }
.auth-tabs button.on { background: var(--card); color: var(--brand); box-shadow: 0 0 0 1px var(--line); }
.gap-label { margin-top: 10px; }
.auth-err { min-height: 18px; margin: 10px 0 0; font-size: 13px; color: var(--red); line-height: 1.6; }
#authId { letter-spacing: 3px; text-align: center; font-size: 18px; }
