:root {
  --bg: #f5f5f4; --surface: #ffffff; --surface-2: #f0efed; --text: #1c1917; --muted: #6b6560;
  --border: #e4e2df; --accent: #0f766e; --accent-bg: #ccfbf1; --on-accent: #ffffff;
  --mine: #d9f5e9; --danger: #b42318; --danger-bg: #fde8e7; --warn: #92570a; --warn-bg: #fdf0d9;
  --info: #175cd3; --info-bg: #e3edfc; --ok: #067647; --ok-bg: #dcf5e7; --violet: #5b3fb8; --violet-bg: #ece7fb;
  --radius: 10px; --nav-h: 60px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121110; --surface: #1c1b1a; --surface-2: #262523; --text: #f2f1ef; --muted: #a29d97;
    --border: #34322f; --accent: #2dd4bf; --accent-bg: #123b37; --on-accent: #062a26;
    --mine: #163a2e; --danger: #f97066; --danger-bg: #3d1714; --warn: #fdb022; --warn-bg: #3b2a0c;
    --info: #84adff; --info-bg: #142545; --ok: #47cd89; --ok-bg: #0f3322; --violet: #b9a7f5; --violet-bg: #2a2045;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", system-ui, sans-serif; font-size: 15px; line-height: 1.55;
  -webkit-tap-highlight-color: transparent;
}
#app { max-width: 760px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius); padding: 8px 14px; }
button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
button.ghost { border-color: transparent; background: transparent; }
button.small { padding: 4px 10px; font-size: 13px; }
input, select, textarea {
  width: 100%; border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius); padding: 9px 11px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
.num { direction: ltr; unicode-bidi: isolate; }

.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; background: var(--surface); border-bottom: 1px solid var(--border); min-height: 56px;
}
.topbar h1 { font-size: 17px; font-weight: 600; margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .sub { font-size: 12px; color: var(--muted); font-weight: 400; }
.content { flex: 1; padding: 14px; padding-bottom: calc(var(--nav-h) + 20px); }

.nav {
  position: sticky; bottom: 0; display: flex; background: var(--surface); border-top: 1px solid var(--border);
  height: var(--nav-h); padding-bottom: env(safe-area-inset-bottom);
}
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: 12px; position: relative; }
.nav a.on { color: var(--accent); font-weight: 600; }
.nav svg { width: 22px; height: 22px; }
.badge { background: var(--accent); color: var(--on-accent); border-radius: 999px; font-size: 11px; padding: 0 6px; min-width: 18px; text-align: center; }
.nav .badge { position: absolute; top: 6px; inset-inline-start: calc(50% + 6px); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 6px; text-align: center; }
.stat b { display: block; font-size: 22px; }
.stat span { font-size: 12px; color: var(--muted); }
.stat.danger b { color: var(--danger); }

.list { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.row { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); text-decoration: none; color: inherit; }
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--surface-2); }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; display: flex; justify-content: space-between; gap: 8px; }
.row .meta { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar { width: 42px; height: 42px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-weight: 600; background: var(--accent-bg); color: var(--accent); flex-shrink: 0; }

.chip { font-size: 12px; padding: 2px 9px; border-radius: 999px; white-space: nowrap; font-weight: 500; }
.s-new, .s-quoted { background: var(--violet-bg); color: var(--violet); }
.s-approved, .s-production, .s-ready { background: var(--warn-bg); color: var(--warn); }
.s-shipped { background: var(--info-bg); color: var(--info); }
.s-delivered { background: var(--ok-bg); color: var(--ok); }
.s-cancelled { background: var(--surface-2); color: var(--muted); }
.s-late { background: var(--danger-bg); color: var(--danger); }

.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tabs button { border-radius: 999px; padding: 5px 14px; font-size: 13px; }
.tabs button.on { background: var(--accent-bg); color: var(--accent); border-color: var(--accent); }

table.items { width: 100%; border-collapse: collapse; font-size: 14px; }
table.items th, table.items td { padding: 8px 4px; border-bottom: 1px solid var(--border); text-align: start; }
table.items th { color: var(--muted); font-weight: 500; font-size: 12px; }
.totals { display: flex; justify-content: space-between; padding: 10px 12px; background: var(--surface-2); border-radius: var(--radius); margin-top: 10px; }

.steps { list-style: none; padding: 0; margin: 0; }
.steps li { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; font-size: 14px; }
.steps .dot { width: 12px; height: 12px; border-radius: 50%; margin-top: 5px; flex-shrink: 0; border: 2px solid var(--border); }
.steps .done .dot { background: var(--ok); border-color: var(--ok); }
.steps .cur .dot { background: var(--warn); border-color: var(--warn); }
.steps .todo { color: var(--muted); }
.steps small { color: var(--muted); display: block; font-size: 12px; }

.item-row { display: grid; grid-template-columns: 2fr 1fr 1.4fr; gap: 8px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; background: var(--surface); }
.item-row .dims { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 8px; align-items: end; }
.item-row label { margin-top: 0; }
.item-row .m2 { font-size: 13px; color: var(--muted); padding-bottom: 10px; white-space: nowrap; }

.chat { display: flex; flex-direction: column; height: 100dvh; }
.messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 4px; }
.bubble { max-width: 80%; padding: 7px 11px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); align-self: flex-end; word-wrap: break-word; }
.bubble .text, .bubble .orig { white-space: pre-wrap; }
.bubble.mine { background: var(--mine); border-color: transparent; align-self: flex-start; }
.bubble .who { font-size: 12px; font-weight: 600; color: var(--accent); }
.bubble .foot { font-size: 11px; color: var(--muted); margin-top: 3px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.bubble .foot a { color: var(--accent); cursor: pointer; text-decoration: none; }
.bubble .pending { color: var(--muted); }
.bubble .orig { border-top: 1px dashed var(--border); margin-top: 6px; padding-top: 4px; font-size: 13px; color: var(--muted); }
.ticks.read { color: var(--info); }
.composer { display: flex; gap: 8px; padding: 10px; background: var(--surface); border-top: 1px solid var(--border); padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
.composer textarea { resize: none; max-height: 140px; min-height: 42px; }
.composer button[data-mic] { padding: 8px 10px; display: flex; align-items: center; }
.recbar { flex: 1; display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.recdot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .25; } }
.voice { display: flex; align-items: center; gap: 10px; min-width: 210px; padding: 2px 0; }
.voice .play { width: 36px; height: 36px; border-radius: 50%; padding: 0; display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--on-accent); border: 0; flex-shrink: 0; }
.vbar { flex: 1; height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.vprog { height: 100%; width: 0; background: var(--accent); }
.vtime { font-size: 12px; color: var(--muted); min-width: 32px; }
.voice + .text { margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--border); }

.center { max-width: 380px; margin: 40px auto; padding: 0 16px; width: 100%; }
.center h1 { font-size: 22px; text-align: center; }
.logo { width: 72px; height: 72px; display: block; margin: 0 auto 10px; }
.error { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 18px; }
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.checks label { display: flex; gap: 10px; align-items: center; color: var(--text); font-size: 15px; margin: 0; padding: 10px 0; border-bottom: 1px solid var(--border); }
.checks input { width: auto; }
.actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fab { position: fixed; bottom: calc(var(--nav-h) + 16px); inset-inline-end: max(16px, calc(50% - 364px)); border-radius: 999px; padding: 12px 18px; box-shadow: 0 4px 14px rgba(0,0,0,.18); z-index: 6; }
.toast { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 999px; font-size: 14px; z-index: 20; }
@media (max-width: 480px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .item-row { grid-template-columns: 1fr 1fr; }
  .item-row .type { grid-column: 1 / -1; }
  .item-row .dims { grid-template-columns: 1fr 1fr 1fr; }
  .item-row .dims .m2 { grid-column: 1 / -1; padding: 0; }
}
