/* Order Approval — styles
   Palette: cool dispatch-desk grey, cobalt for actions, status colours carry meaning.
   One bold element: the rubber-stamp status on each order. */

:root {
  --bg: #e9edf1;
  --surface: #ffffff;
  --surface-2: #f3f6f8;
  --ink: #16202b;
  --muted: #5b6875;
  --line: #d3dae1;
  --accent: #1e5bd8;
  --accent-ink: #ffffff;
  --green: #13804b;
  --red: #c2362b;
  --amber: #a86d0f;
  --grey: #66717c;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(22, 32, 43, .06), 0 6px 18px rgba(22, 32, 43, .05);
  --font: "Figtree", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-ur: "Noto Nastaliq Urdu", "Jameel Noori Nastaleeq", "Noto Naskh Arabic", "Segoe UI", serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a;
    --surface: #18202a;
    --surface-2: #1f2934;
    --ink: #e7ecf1;
    --muted: #96a3b0;
    --line: #2c3743;
    --accent: #6f9bff;
    --accent-ink: #0b1220;
    --green: #3fbf80;
    --red: #ff7b6f;
    --amber: #e5ad4c;
    --grey: #9aa5b0;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
img { max-width: 100%; display: block; }
a { color: var(--accent); }
h1 { font-size: 1.6rem; line-height: 1.15; font-weight: 800; letter-spacing: -.01em; margin: 0 0 .25rem; }
h2 { font-size: 1.05rem; font-weight: 700; margin: 0 0 .6rem; }
p { margin: 0 0 .6rem; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.wrap { width: 100%; max-width: 920px; margin: 0 auto; padding: 0 16px; }
.wrap.narrow { max-width: 620px; }
main.wrap { padding-top: 18px; padding-bottom: 48px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }

.ur {
  display: block;
  font-family: var(--font-ur);
  font-size: .95em;
  line-height: 1.9;
  font-weight: 500;
}

/* ------------------------------------------------------------ top bars */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
}
.topbar-in { display: flex; align-items: center; justify-content: space-between; min-height: 56px; gap: 12px; }
.topbar-brand { font-weight: 800; font-size: 1.1rem; color: var(--ink); text-decoration: none; }
.topbar-back { font-weight: 600; text-decoration: none; }
.topbar-who { color: var(--muted); font-size: .9rem; display: flex; gap: 12px; align-items: center; }

.cust-top {
  background: var(--ink);
  color: var(--bg);
  font-weight: 800;
  font-size: 1.05rem;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 0 14px;
}

/* ------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px;
  border: 1.5px solid transparent; border-radius: var(--radius-sm);
  font: 600 1rem/1.2 var(--font);
  text-decoration: none; cursor: pointer; text-align: center;
  transition: transform .08s ease, background-color .15s ease;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-green { background: var(--green); color: #fff; }
.btn-red { background: var(--red); color: #fff; }
.btn-soft { background: var(--surface-2); color: var(--ink); border-color: var(--line); }
.btn-outline-red { background: var(--surface); color: var(--red); border-color: var(--red); }
.btn-big { min-height: 64px; font-size: 1.1rem; flex-direction: column; gap: 0; }
.btn-big .ur { font-size: .9rem; line-height: 1.6; opacity: .92; }
.btn .ur { display: inline; }
.btn-big .ur { display: block; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 10px 0; }
.btn-row .btn { flex: 1 1 160px; }
@media (prefers-color-scheme: dark) {
  .btn-green, .btn-red { color: #0b1220; }
}

/* ------------------------------------------------------------ cards & forms */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin: 0 0 16px;
  box-shadow: var(--shadow);
}
.card-title { margin-bottom: .7rem; }
.card-title .ur { font-size: .9rem; color: var(--muted); }

.form label { display: block; font-weight: 600; margin-bottom: 14px; }
.form label .muted { font-weight: 400; }
input, textarea {
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  font: 400 1rem/1.4 var(--font);
  color: var(--ink);
  background: var(--surface-2);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
}
input:focus, textarea:focus { border-color: var(--accent); outline: none; background: var(--surface); }
textarea { resize: vertical; }
fieldset { border: 0; padding: 0; margin: 4px 0 18px; }
legend { font-weight: 600; padding: 0; margin-bottom: 8px; }

.alert { padding: 10px 14px; border-radius: var(--radius-sm); font-weight: 500; }
.alert.tone-red { background: color-mix(in srgb, var(--red) 12%, transparent); color: var(--red); }

/* ------------------------------------------------------------ login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; }
.login-card h1 { margin-bottom: .2rem; }
.login-card label { display: block; font-weight: 600; margin-bottom: 14px; }

/* ------------------------------------------------------------ dashboard */
.dash-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.dash-head h1 { margin: 0; }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.tab {
  flex: 0 0 auto;
  padding: 8px 14px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  color: var(--ink); text-decoration: none; font-weight: 600; font-size: .92rem;
}
.tab-n { color: var(--muted); font-weight: 500; margin-left: 2px; }
.tab.is-active { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.tab.is-active .tab-n { color: inherit; opacity: .7; }

.search { display: flex; gap: 8px; margin-bottom: 16px; }
.search input { margin: 0; flex: 1; }
.search .btn { flex: 0 0 auto; }

.order-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.order-list li + li { border-top: 1px solid var(--line); }
.order-row { display: flex; align-items: center; gap: 14px; padding: 12px 14px; color: var(--ink); text-decoration: none; }
.order-row:hover { background: var(--surface-2); }
.order-row.has-unread { box-shadow: inset 4px 0 0 var(--accent); }
.order-thumb { flex: 0 0 52px; height: 52px; border-radius: 8px; background: var(--surface-2); overflow: hidden; }
.order-thumb img { width: 100%; height: 100%; object-fit: cover; }
.order-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.order-no { font-weight: 800; font-size: 1.05rem; }
.order-sub { color: var(--muted); font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.order-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: 0 0 auto; }
.order-time { color: var(--muted); font-size: .8rem; }
.unread { font-size: .8rem; font-weight: 700; color: var(--accent); }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .8rem; font-weight: 700; white-space: nowrap; }
.badge.tone-amber { background: color-mix(in srgb, var(--amber) 15%, transparent); color: var(--amber); }
.badge.tone-red   { background: color-mix(in srgb, var(--red) 14%, transparent);   color: var(--red); }
.badge.tone-green { background: color-mix(in srgb, var(--green) 14%, transparent); color: var(--green); }
.badge.tone-grey  { background: color-mix(in srgb, var(--grey) 15%, transparent);  color: var(--grey); }

.empty { text-align: center; padding: 48px 20px; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty p { color: var(--muted); max-width: 36ch; margin: 0 auto 16px; }

/* ------------------------------------------------------------ order page + the stamp */
.order-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 18px; }
.order-meta { color: var(--muted); margin: 0 0 4px; }

.stamp {
  --c: var(--grey);
  flex: 0 0 auto;
  margin: 4px 6px 0 0;
  padding: 6px 14px;
  color: var(--c);
  border: 3px solid var(--c);
  outline: 1.5px solid var(--c);
  outline-offset: 3px;
  border-radius: 6px;
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: .02em;
  transform: rotate(-6deg);
  opacity: .9;
  white-space: nowrap;
  animation: stamp-in .35s cubic-bezier(.2, 1.4, .4, 1) both;
}
.stamp.tone-amber { --c: var(--amber); }
.stamp.tone-red   { --c: var(--red); }
.stamp.tone-green { --c: var(--green); }
@keyframes stamp-in { from { transform: rotate(-14deg) scale(1.5); opacity: 0; } }

.status-msg { border-left: 4px solid var(--grey); background: var(--surface); padding: 14px 16px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; margin-bottom: 16px; }
.status-msg p { margin: 0; font-weight: 600; }
.status-msg .ur { margin-top: 4px; color: var(--muted); }
.status-msg.tone-amber { border-color: var(--amber); }
.status-msg.tone-red   { border-color: var(--red); }
.status-msg.tone-green { border-color: var(--green); }

.note { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 16px; }

.photos { display: grid; gap: 8px; margin-bottom: 8px; }
.photos-2 { grid-template-columns: 1fr 1fr; }
.photos-3 { grid-template-columns: 1fr 1fr; }
.photos-3 a:first-child { grid-column: 1 / -1; }
.photos a { display: block; border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-2); }
.photos img { width: 100%; height: 100%; max-height: 520px; object-fit: cover; aspect-ratio: 4 / 3; }
.photos-1 img { aspect-ratio: auto; object-fit: contain; }
.order-page > .photos + * { margin-top: 16px; }

.send-card.is-highlight { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.sms-preview { font-size: .92rem; background: var(--surface-2); margin: 0; }
.card-issue { border-color: var(--red); }
.card-issue .card-title { color: var(--red); }
.card-ok { border-color: var(--green); }
.card-ok .card-title { color: var(--green); }
.quote { font-size: 1.05rem; font-weight: 500; border-left: 3px solid var(--red); padding-left: 12px; }
.issue-photo { display: block; max-width: 220px; border-radius: var(--radius-sm); overflow: hidden; margin-bottom: 10px; }

.replace summary { font-weight: 700; cursor: pointer; }
.replace[open] summary { margin-bottom: 12px; }

/* customer decision */
.decide { display: grid; gap: 10px; margin: 18px 0 20px; }
.decide form { margin: 0; }
.issue-form { margin-top: 6px; }

/* ------------------------------------------------------------ photo picker */
.picker-thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.picker-thumbs:not(:empty) { margin-bottom: 10px; }
.thumb { position: relative; width: 92px; height: 92px; border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-2); border: 1px solid var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb.is-loading { background: linear-gradient(100deg, var(--surface-2) 30%, var(--line) 50%, var(--surface-2) 70%) 0 0 / 200% 100%; animation: shimmer 1s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.thumb-x {
  position: absolute; top: 4px; right: 4px;
  width: 28px; height: 28px; border-radius: 50%;
  border: 0; background: rgba(0, 0, 0, .65); color: #fff;
  font-size: .8rem; cursor: pointer;
}
.picker-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.picker-btns .btn { font-size: .95rem; padding: 10px; }
.picker .hint { margin: 8px 0 0; color: var(--muted); font-size: .875rem; }

/* ------------------------------------------------------------ chat */
.chat-list {
  max-height: 360px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 8px;
  padding: 4px 2px 10px;
}
.chat-empty { color: var(--muted); font-size: .92rem; margin: 6px 0; }
.chat-closed { color: var(--muted); font-size: .92rem; margin: 6px 0 0; }
.msg { max-width: 84%; padding: 8px 12px; border-radius: 14px 14px 14px 4px; background: var(--surface-2); border: 1px solid var(--line); align-self: flex-start; }
.msg.is-mine { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-color: transparent; border-radius: 14px 14px 4px 14px; }
.msg-who { font-size: .75rem; font-weight: 700; opacity: .75; }
.msg-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-time { font-size: .72rem; opacity: .65; margin-top: 2px; }
.msg-system { align-self: center; max-width: 92%; background: transparent; border: 0; padding: 2px 8px; text-align: center; color: var(--muted); font-size: .82rem; }
.msg-system .msg-who { display: none; }
.msg-system .msg-body { font-style: italic; }
.chat-form { display: flex; gap: 8px; align-items: flex-end; border-top: 1px solid var(--line); padding-top: 12px; }
.chat-form textarea { margin: 0; min-height: 48px; max-height: 140px; resize: none; }
.chat-form .btn { flex: 0 0 auto; }

/* ------------------------------------------------------------ lightbox + toast */
.lightbox {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(5, 8, 12, .92);
  display: grid; place-items: center; padding: 16px;
  cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }
.lightbox-x {
  position: absolute; top: calc(12px + env(safe-area-inset-top, 0px)); right: 12px;
  width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: rgba(255, 255, 255, .15); color: #fff; font-size: 1.1rem; cursor: pointer;
}

#toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); z-index: 60;
  transform: translate(-50%, 20px);
  max-width: min(92vw, 440px);
  background: var(--ink); color: var(--bg);
  padding: 12px 16px; border-radius: var(--radius-sm);
  font-weight: 500; box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 700px) {
  h1 { font-size: 2rem; }
  .stamp { font-size: 1.15rem; padding: 8px 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
