/* ============================================================================
   File:     app.css
   Version:  1.0.0
   Part of:  Mikyal (المكيال) - Mikyal Web (iPhone / iPad), 1.0.96-web
   The phone app's look (Mobile/Ui.cs 1.5.0): the same colours, light and
   dark, Tajawal, gold for what matters. Fits the iPhone's notch and home
   bar (safe-area insets); on an iPad the page stays phone-wide, centred.
   ============================================================================ */

@font-face { font-family: 'Tajawal'; src: url('../fonts/Tajawal-Regular.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Tajawal'; src: url('../fonts/Tajawal-Bold.woff2') format('woff2'); font-weight: 700; font-display: swap; }

:root, :root[data-theme="light"] {
  --header: #1E2A2B; --ink: #1E2A2B; --muted: #5F6B69; --gold: #A8741F; --gold-soft: #FAF4E6; --gold-line: #E5CE9E;
  --paper: #F4F1EA; --card: #FFFFFF; --line: #E3DCCD; --row-line: #EFEAE0;
  --danger: #C2410C; --warning: #B45309; --success: #15803D;
  --pill: rgba(255,255,255,.10); --pill-line: rgba(255,255,255,.18); --head-ink: #F4F1EA; --head-sub: #BFD0CE;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --header: #141D1E; --ink: #F3F0E6; --muted: #9CA8A6; --gold: #D49B35; --gold-soft: #2A2317; --gold-line: #6B5322;
  --paper: #12191A; --card: #1C2729; --line: #2E3E40; --row-line: #253335;
  --danger: #F97316; --warning: #F59E0B; --success: #22C55E;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: 'Tajawal', -apple-system, 'Segoe UI', sans-serif;
  font-size: 15px; line-height: 1.45; color: var(--ink); background: var(--paper);
  -webkit-text-size-adjust: 100%; min-height: 100vh; min-height: 100dvh;
}
#app { max-width: 640px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; background: var(--paper); }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.splash { display: grid; place-items: center; min-height: 100vh; background: var(--header); }
.splash img { border-radius: 22px; }

/* ---- header ---- */
.top {
  position: sticky; top: 0; z-index: 5; background: var(--header); color: var(--head-ink);
  padding: calc(env(safe-area-inset-top) + 10px) calc(env(safe-area-inset-right) + 14px) 10px calc(env(safe-area-inset-left) + 14px);
}
.top-row { display: flex; align-items: center; gap: 10px; }
.top-title { flex: 1; min-width: 0; }
.title { font-weight: 700; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.subtitle { font-size: 12px; color: var(--head-sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tools { display: flex; gap: 6px; flex-shrink: 0; }
.pill {
  border: 1px solid var(--pill-line); background: var(--pill); color: var(--head-ink);
  border-radius: 999px; padding: 5px 12px; font-size: 13px; font-weight: 700; min-height: 32px; cursor: pointer;
}
.pill.icon { width: 36px; padding: 0; }
.pill.gold { background: var(--gold); border-color: var(--gold); color: #fff; }
.pill:disabled { opacity: .55; }
.sync-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.sync-label { flex: 1; min-width: 0; font-size: 12px; color: var(--head-sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sync-actions { display: flex; gap: 6px; }

/* ---- tabs ---- */
.sticky { position: sticky; top: 0; z-index: 5; }
.sticky > .top { position: static; }
.tabs {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--card); border-bottom: 1px solid var(--line);
  padding: 0 calc(env(safe-area-inset-right) + 6px) 0 calc(env(safe-area-inset-left) + 6px);
}
.tab {
  border: 0; background: none; color: var(--muted); padding: 12px 2px 9px; font-size: 14px; white-space: nowrap;
  border-bottom: 3px solid transparent; cursor: pointer;
}
.tab.active { color: var(--gold); font-weight: 700; border-bottom-color: var(--gold); }

/* ---- body ---- */
.body { padding: 16px calc(env(safe-area-inset-right) + 14px) calc(env(safe-area-inset-bottom) + 24px) calc(env(safe-area-inset-left) + 14px); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.pad { padding: 14px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.danger { color: var(--danger); }
.warning { color: var(--warning); }
.success { color: var(--success); }

.hero {
  background: #F4F1EA; border: 1px solid #E5CE9E; border-radius: 16px; padding: 14px 18px; margin-bottom: 14px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.hero-logo { height: 70px; width: auto; }
.hero-motto { height: 60px; width: auto; }
.hero-version { font-size: 12px; color: #5F6B69; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.body > .card { margin-bottom: 14px; }
.card-title { margin: 0 0 10px; font-size: 16px; color: var(--gold); }
.card > * + * { margin-top: 10px; }
.card > :first-child { margin-top: 0; }
.card p { margin-bottom: 0; }
/* money is its own run inside a sentence; its numbers are isolated in app.js (nums) */
.money { unicode-bidi: isolate; }

.input {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--paper); color: var(--ink); font-size: 16px; /* 16px: iOS does not zoom into the field */
}
.input:focus { outline: 2px solid var(--gold-line); border-color: var(--gold); }
.ltr { direction: ltr; text-align: left; }
.field-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: -4px; }
.store-name { font-weight: 700; font-size: 16px; color: var(--gold); }

.btn {
  display: block; width: 100%; min-height: 46px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font-weight: 700; font-size: 15px; cursor: pointer; padding: 8px 12px;
}
.btn.primary { background: var(--gold); border-color: var(--gold); color: #fff; }
.btn.small { min-height: 36px; width: auto; display: inline-block; padding: 4px 16px; font-size: 14px; }
.btn:disabled { opacity: .55; }
.body > .btn { margin-top: 4px; }

.spinner { width: 28px; height: 28px; margin: 4px auto; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--gold); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

.hint { background: var(--gold-soft); border: 1px solid var(--gold-line); border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; }
.hint p { margin: 6px 0 10px; font-size: 14px; }

/* ---- the day ---- */
.segments { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.seg { border: 0; border-radius: 9px; min-height: 36px; background: transparent; color: var(--muted); font-size: 13px; cursor: pointer; padding: 0 2px; }
.seg.active { background: var(--gold); color: #fff; font-weight: 700; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 2px; border-bottom: 1px solid var(--row-line); }
.card > .row { margin-top: 0; }
.row:last-child { border-bottom: 0; }
.row-label { color: var(--muted); font-size: 14px; }
.row-value { font-weight: 700; font-size: 15px; text-align: end; }
.row.highlight { background: var(--gold-soft); border: 1px solid var(--gold-line); border-radius: 8px; padding: 6px 10px; margin: 6px 0; }
.row.highlight .row-label { color: var(--ink); font-weight: 700; }
.row.highlight .row-value { color: var(--gold); font-size: 16px; }
.row.warning .row-label, .row.warning .row-value { color: var(--danger); font-weight: 700; }

/* ---- lists ---- */
.searchbar > * + * { margin-top: 8px; }
.filter-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.check input { width: 20px; height: 20px; accent-color: var(--gold); }
.badge { background: var(--gold-soft); color: var(--gold); border: 1px solid var(--gold-line); border-radius: 999px; padding: 2px 10px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.banner { background: var(--gold-soft); border: 1px solid var(--gold-line); color: var(--ink); border-radius: 12px; padding: 10px 14px; font-weight: 700; }

.item, .party { display: flex; justify-content: space-between; gap: 10px; padding: 12px 14px; }
.item > * + *, .party > * + * { margin-top: 0; }
.item-main, .party-main { min-width: 0; flex: 1; }
.item-name, .party-name { font-weight: 700; overflow-wrap: anywhere; }
.item-code { font-size: 13px; }
.item-side { text-align: end; flex-shrink: 0; max-width: 55%; }
.item-qty { font-weight: 700; }
.item-price, .item-cost { font-size: 13px; }
.party-phone { display: inline-block; font-size: 13px; text-decoration: none; }
.party-balance { font-weight: 700; text-align: end; flex-shrink: 0; max-width: 60%; align-self: center; }

.offline { background: var(--warning); color: #fff; text-align: center; font-size: 13px; padding: 6px 12px; }

/* ---- dialogs, camera, update bar ---- */
.modal-back { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.5); display: grid; place-items: center; padding: 20px; }
.modal { background: var(--card); color: var(--ink); border-radius: 16px; padding: 18px; width: min(420px, 100%); box-shadow: 0 10px 40px rgba(0,0,0,.35); }
.modal-text { margin: 0 0 16px; white-space: pre-line; }
.modal-buttons { display: flex; gap: 8px; }
.modal-buttons .btn { flex: 1; }

.scan { position: fixed; inset: 0; z-index: 60; background: #000; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
        padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 16px); }
.scan-video { width: 100%; max-width: 480px; max-height: 65vh; object-fit: cover; border-radius: 14px; background: #111; }
.scan-frame { position: absolute; width: min(62vw, 300px); aspect-ratio: 1; border: 3px solid #E0AE57; border-radius: 18px; pointer-events: none; top: 32%; transform: translateY(-50%); }
.scan-text { color: #F4F1EA; text-align: center; margin: 0; }
.scan .btn { max-width: 320px; }

.update { position: fixed; z-index: 40; inset-inline: 12px; bottom: calc(env(safe-area-inset-bottom) + 12px);
          background: var(--header); color: var(--head-ink); border-radius: 14px; padding: 10px 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px;
          box-shadow: 0 6px 24px rgba(0,0,0,.3); max-width: 616px; margin: 0 auto; }
