/* Galiway Mobile - a touch-first shell over the existing PHP API. */
:root {
  --blue: #1C3F94; --blue-dark: #16337a; --ink: #1a2233; --ink-soft: #667085;
  --line: #e4e8f0; --line-soft: #eef1f6; --bg: #f4f6fb; --paper: #ffffff;
  --ok: #1c7a48; --ok-bg: #eaf7ef; --warn: #8a6412; --warn-bg: #fbf1e0;
  --err: #c0272d; --pine: #2d4a3e; --radius: 14px; --tap: 46px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  /* Apple's San Francisco on iPhone and Mac; Inter (near-identical to SF) as
     the fallback on Android and elsewhere, so the app reads the same. */
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Inter", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; letter-spacing: -0.01em;
  color: var(--ink); background: var(--bg); font-size: 15px; overscroll-behavior-y: contain;
}
#app { min-height: 100%; display: flex; flex-direction: column; }

/* Top bar */
.top { position: sticky; top: 0; z-index: 20; background: var(--blue); color: #fff;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 14px 12px; display: flex; align-items: center; gap: 10px; }
.top .t-title { font-weight: 700; font-size: 17px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .t-btn { background: rgba(255,255,255,.16); border: 0; color: #fff; width: 38px; height: 38px;
  border-radius: 10px; font-size: 16px; display: grid; place-items: center; cursor: pointer; flex: none; }
.top .t-btn:active { background: rgba(255,255,255,.28); }

/* Views */
.view { flex: 1; padding: 14px; padding-bottom: calc(24px + var(--safe-b)); }
.view.pad0 { padding: 0; }
.muted { color: var(--ink-soft); }
.center { min-height: 60vh; display: grid; place-items: center; text-align: center; color: var(--ink-soft); }

/* Cards + tiles */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 14px; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 10px;
  min-height: 96px; position: relative; }
.tile:active { background: var(--line-soft); }
.tile i { font-size: 22px; color: var(--blue); }
.tile .lab { font-weight: 600; }
.tile .badge { position: absolute; top: 10px; right: 10px; background: var(--err); color: #fff;
  min-width: 20px; height: 20px; border-radius: 999px; font-size: 12px; display: grid; place-items: center; padding: 0 6px; }
[hidden] { display: none !important; }

/* Lists */
.list { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 13px 14px; border-bottom: 1px solid var(--line-soft);
  cursor: pointer; min-height: var(--tap); }
.row:last-child { border-bottom: 0; }
.row:active { background: var(--line-soft); }
.av { width: 40px; height: 40px; border-radius: 50%; color: #fff; flex: none; display: grid; place-items: center; font-weight: 700; font-size: 15px; }
.row .main { flex: 1; min-width: 0; }
.row .main b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .main span { display: block; color: var(--ink-soft); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .end { color: var(--ink-soft); font-size: 12px; text-align: right; flex: none; }
.pill { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--line-soft); color: var(--ink-soft); }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.lead { background: var(--warn-bg); color: var(--warn); }

/* Search */
.search { position: relative; margin-bottom: 12px; }
.search input { width: 100%; padding: 12px 14px 12px 40px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--paper); font: inherit; outline: none; }
.search i { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: var(--ink-soft); }

/* Forms */
.fld { margin-bottom: 12px; }
.fld label { display: block; font-size: 12.5px; color: var(--ink-soft); margin-bottom: 5px; }
.fld input, .fld select, .fld textarea {
  width: 100%; padding: 12px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--paper); font: inherit; color: var(--ink); outline: none; }
.fld input:focus, .fld select:focus, .fld textarea:focus { border-color: var(--blue); }
.fld textarea { min-height: 72px; resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  padding: 13px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper);
  font: inherit; font-weight: 600; color: var(--ink); cursor: pointer; min-height: var(--tap); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:disabled { opacity: .6; }
.btn.ghost { background: transparent; border: 0; color: var(--blue); width: auto; padding: 8px; }
.btn.block { margin-top: 6px; }

/* Login - full blue page */
.login-wrap { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; gap: 8px;
  padding: 24px calc(24px + env(safe-area-inset-left,0px)) calc(24px + var(--safe-b)); background: var(--blue); color: #fff; }
.login-logo { width: 76px; height: 76px; border-radius: 20px; background: #fff; color: var(--blue);
  display: grid; place-items: center; font-weight: 800; font-size: 36px; margin: 0 auto 10px; overflow: hidden; }
.login-logo img { width: 100%; height: 100%; object-fit: contain; }
.login-wrap h1 { text-align: center; margin: 0 0 2px; font-size: 24px; color: #fff; }
.login-wrap p.sub { text-align: center; margin: 0 0 22px; color: rgba(255,255,255,.75); }
.login-wrap .fld label { color: rgba(255,255,255,.85); }
.login-wrap .fld input { background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.28); color: #fff; }
.login-wrap .fld input:focus { border-color: #fff; background: rgba(255,255,255,.22); }
.login-wrap .fld input::placeholder { color: rgba(255,255,255,.55); }
.login-wrap .keep { color: rgba(255,255,255,.85) !important; }
.login-wrap .btn.primary { background: #fff; border-color: #fff; color: var(--blue); }

/* Chat */
.thread { display: flex; flex-direction: column; height: calc(100dvh - 58px - env(safe-area-inset-top,0px)); }
.thread-body { flex: 1; overflow-y: auto; padding: 12px; background: #ece5da; display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: 82%; padding: 8px 11px; border-radius: 12px; font-size: 14.5px; line-height: 1.4;
  background: #fff; border: 1px solid var(--line-soft); align-self: flex-start; word-wrap: break-word; }
.bubble.me { align-self: flex-end; background: #d7ece0; border-color: #c3e0d0; }
.bubble .meta { font-size: 10.5px; color: var(--ink-soft); margin-top: 3px; text-align: right; }
.bubble .filelink { display: inline-flex; gap: 7px; align-items: center; color: var(--blue); text-decoration: none; font-weight: 600; }
.composer { display: flex; gap: 8px; padding: 8px; padding-bottom: calc(8px + var(--safe-b)); background: var(--paper); border-top: 1px solid var(--line); align-items: flex-end; }
.composer textarea { flex: 1; border: 1px solid var(--line); border-radius: 20px; padding: 10px 14px; font: inherit; resize: none; max-height: 120px; outline: none; }
.composer .send { width: 44px; height: 44px; border-radius: 50%; background: var(--blue); color: #fff; border: 0; flex: none; font-size: 17px; }
.win-strip { font-size: 12.5px; padding: 8px 12px; }
.win-strip.closed { background: var(--warn-bg); color: var(--warn); }
.win-strip.open { background: var(--ok-bg); color: var(--ok); }
.win-strip .tmpl { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.win-strip .tmpl button { border: 1px solid #e4c98a; background: #fff; color: var(--warn); border-radius: 999px; padding: 5px 11px; font: inherit; font-size: 12px; }

/* Doc line editor */
.line { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 10px; position: relative; background: var(--paper); }
.line .del { position: absolute; top: 8px; right: 8px; border: 0; background: transparent; color: var(--err); font-size: 15px; }
.total-bar { display: flex; justify-content: space-between; align-items: baseline; padding: 12px 2px; font-weight: 700; }
.total-bar .amt { font-size: 18px; }

/* Toast */
#toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%) translateY(20px);
  background: #222; color: #fff; padding: 11px 16px; border-radius: 10px; font-size: 14px; max-width: 90vw;
  opacity: 0; transition: .2s; z-index: 60; pointer-events: none; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--err); } #toast.ok { background: var(--ok); }

.spin { width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--blue); border-radius: 50%; animation: sp 0.8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
.fab { position: fixed; right: 16px; bottom: calc(20px + var(--safe-b)); width: 56px; height: 56px; border-radius: 50%;
  background: var(--blue); color: #fff; border: 0; font-size: 22px; box-shadow: 0 6px 18px rgba(28,63,148,.4); z-index: 30; }

/* ============================================================
   v2: WhatsApp-style chat, install banner, in-app viewers, KPIs
   ============================================================ */

/* Chat header, WhatsApp style */
.wa-head { background: var(--blue); color: #fff; display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top,0px) + 10px) 12px 10px; }
.wa-head .t-btn { background: transparent; }
.wa-head .av { width: 38px; height: 38px; font-size: 14px; }
.wa-head .who { flex: 1; min-width: 0; }
.wa-head .who b { display: block; font-size: 16px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wa-head .who span { display: block; font-size: 12px; opacity: .85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Wallpaper: WhatsApp-like warm beige with a faint doodle pattern */
.thread-body {
  background-color: #efe7dd;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140' viewBox='0 0 140 140'%3E%3Cg fill='none' stroke='%23d8cdbf' stroke-width='1.4' opacity='0.5'%3E%3Ccircle cx='20' cy='24' r='7'/%3E%3Cpath d='M52 18 l10 10 M62 18 l-10 10'/%3E%3Cpath d='M92 30 q10 -14 20 0'/%3E%3Cpath d='M18 70 h16 M26 62 v16'/%3E%3Ccircle cx='108' cy='74' r='6'/%3E%3Cpath d='M60 96 q12 10 24 0'/%3E%3Cpath d='M112 112 l8 8 M120 112 l-8 8'/%3E%3Cpath d='M22 116 q8 -12 16 0'/%3E%3Ccircle cx='74' cy='58' r='4'/%3E%3C/g%3E%3C/svg%3E");
  background-repeat: repeat;
}
/* Bubbles with tails */
.thread-body .bubble { position: relative; box-shadow: 0 1px 0.5px rgba(0,0,0,.13); border: 0;
  border-radius: 8px; padding: 6px 9px 8px; max-width: 82%; }
.thread-body .bubble:not(.me) { background: #fff; border-top-left-radius: 0; }
.thread-body .bubble.me { background: #d9fdd3; border-top-right-radius: 0; }
.thread-body .bubble:not(.me)::before { content: ''; position: absolute; top: 0; left: -8px;
  border: 8px solid transparent; border-top-color: #fff; border-right: 0; }
.thread-body .bubble.me::before { content: ''; position: absolute; top: 0; right: -8px;
  border: 8px solid transparent; border-top-color: #d9fdd3; border-left: 0; }
.thread-body .bubble .meta { display: flex; gap: 4px; justify-content: flex-end; align-items: center;
  font-size: 11px; color: #667781; margin-top: 2px; }
.thread-body .bubble .tick.read { color: #53bdeb; }
.date-pill { align-self: center; background: #ffffffcc; color: #54656f; font-size: 12px;
  padding: 5px 12px; border-radius: 8px; box-shadow: 0 1px 0.5px rgba(0,0,0,.1); margin: 6px 0; }
.sys-pill { align-self: center; background: #fff5c4; color: #7a6a2f; font-size: 11.5px; text-align: center;
  padding: 6px 12px; border-radius: 8px; margin: 6px 0; max-width: 90%; }

/* Install banner */
.install-bar { position: fixed; left: 10px; right: 10px; bottom: calc(12px + var(--safe-b)); z-index: 55;
  background: var(--blue); color: #fff; border-radius: 14px; padding: 12px 14px; display: flex; gap: 12px;
  align-items: center; box-shadow: 0 8px 24px rgba(16,32,63,.35); }
.install-bar .ic { width: 40px; height: 40px; border-radius: 10px; background: rgba(255,255,255,.18);
  display: grid; place-items: center; font-size: 20px; flex: none; }
.install-bar .txt { flex: 1; min-width: 0; font-size: 13px; line-height: 1.35; }
.install-bar .txt b { display: block; font-size: 14px; }
.install-bar .act { display: flex; gap: 6px; flex: none; }
.install-bar .act button { border: 0; border-radius: 9px; padding: 8px 12px; font: inherit; font-weight: 600; }
.install-bar .act .yes { background: #fff; color: var(--blue); }
.install-bar .act .no { background: transparent; color: #fff; padding: 8px; }
.ios-steps { font-size: 12px; opacity: .9; margin-top: 3px; }

/* In-app viewer overlay (PDF / file / image) */
.viewer { position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.92); display: flex; flex-direction: column; }
.viewer .vbar { display: flex; align-items: center; gap: 12px; padding: calc(env(safe-area-inset-top,0px) + 10px) 12px 10px; color: #fff; }
.viewer .vbar .vt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer .vbar button { background: rgba(255,255,255,.18); border: 0; color: #fff; width: 38px; height: 38px; border-radius: 10px; font-size: 16px; }
.viewer iframe { flex: 1; width: 100%; border: 0; background: #fff; }
.viewer .vimg { flex: 1; display: grid; place-items: center; padding: 10px; }
.viewer .vimg img { max-width: 100%; max-height: 100%; }

/* KPI grid */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.kpi { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.kpi .n { font-size: 20px; font-weight: 700; }
.kpi .l { color: var(--ink-soft); font-size: 12.5px; margin-top: 3px; }
.kpi.wide { grid-column: 1 / -1; }
.stock-pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--line-soft); color: var(--ink-soft); }
.stock-pill.low { background: #fdecea; color: var(--err); }

/* In-app popup (confirmations, prompts) - replaces native alert/confirm/prompt */
.modal-ov { position: fixed; inset: 0; z-index: 90; background: rgba(16,24,40,.5); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; padding: 22px; opacity: 0; transition: opacity .18s; }
.modal-ov.in { opacity: 1; }
.modal { width: 100%; max-width: 380px; background: var(--paper); border-radius: 18px; overflow: hidden;
  box-shadow: 0 20px 50px rgba(16,24,40,.35); transform: translateY(16px) scale(.98); transition: transform .2s; }
.modal-ov.in .modal { transform: none; }
.modal .m-ic { text-align: center; padding: 20px 20px 0; font-size: 30px; color: var(--blue); }
.modal .m-ic.danger { color: var(--err); }
.modal .m-b { padding: 12px 20px 4px; text-align: center; }
.modal .m-b h3 { margin: 0 0 6px; font-size: 17px; }
.modal .m-b p { margin: 0; color: var(--ink-soft); font-size: 14px; line-height: 1.45; }
.modal .m-b .fld { text-align: left; margin-top: 14px; }
.modal .m-f { display: flex; gap: 10px; padding: 16px 20px calc(18px + var(--safe-b)); }
.modal .m-f button { flex: 1; padding: 13px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--paper); font: inherit; font-weight: 600; color: var(--ink); }
.modal .m-f button.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.modal .m-f button.danger { background: var(--err); border-color: var(--err); color: #fff; }
