html[data-mode="bt"] { --primary: #1D4ED8; --primary-dark: #1E40AF; --primary-soft: #E0E7FF; }
:root {
  --primary: #0F766E; --primary-dark: #0B5E57; --primary-soft: #E6F4F2; --accent: #F97316; --accent-dark: #EA580C;
  --bg: #F3F6F8; --card: #FFFFFF; --text: #1F2933; --muted: #6B7A88; --border: #E3E8EF; --danger: #DC2626; --warn: #D97706; --ok: #15803D;
  --field: #EDF4FF; --field-border: #B4C8EC; --radius: 16px; --shadow: 0 1px 3px rgba(16,32,30,.06), 0 8px 24px rgba(16,32,30,.06);
  --nav-h: 64px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: Tajawal, "Segoe UI", Tahoma, system-ui, sans-serif; font-size: 15px; line-height: 1.5; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); text-decoration: none; }
img { max-width: 100%; }
[hidden] { display: none !important; }

/* top bar */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); background: var(--primary); color: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.15); }
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { width: 40px; height: 40px; border-radius: 11px; box-shadow: 0 2px 8px rgba(0,0,0,.2); }
.brand b { display: block; font-size: 19px; line-height: 1.1; }
.brand small { display: block; font-size: 12.5px; opacity: .9; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 999px; background: rgba(255,255,255,.16); font-size: 12.5px; white-space: nowrap; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #cbd5e1; }
.pill.on::before { background: #4ade80; } .pill.off::before { background: #f87171; } .pill.warn::before { background: #fbbf24; }

/* nav: bottom on phones, side on wide screens */
.nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: flex; background: #fff; border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 7px; font-size: 11.5px; color: var(--muted); }
.nav a .ic { font-size: 18px; line-height: 1; width: 34px; height: 24px; display: grid; place-items: center; border-radius: 12px; }
.nav a.on { color: var(--primary); font-weight: 700; }
.nav a.on .ic { background: var(--primary-soft); }
.view { padding: 14px 14px calc(var(--nav-h) + 18px); max-width: 780px; margin: 0 auto; }
.view.wide { max-width: 1040px; }
@media (min-width: 960px) {
  .nav { top: 64px; bottom: 0; right: 0; left: auto; width: 200px; flex-direction: column; border-top: 0; border-left: 1px solid var(--border); padding: 12px 10px; gap: 4px; }
  .nav a { flex: none; flex-direction: row; justify-content: flex-start; gap: 10px; padding: 10px 12px; border-radius: 12px; font-size: 15px; }
  .nav a .ic { width: 28px; height: 28px; border-radius: 8px; background: var(--bg); }
  .nav a.on { background: var(--primary-soft); }
  .view { margin-right: 200px; padding: 22px 28px 40px; max-width: none; }
  .view > .inner { max-width: 780px; margin: 0 auto; }
  .view.wide > .inner { max-width: 1040px; }
}

/* cards and fields */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px; }
.card h3 { margin: 0 0 10px; font-size: 15px; color: var(--primary); }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { min-width: 0; }
.grow { flex: 1; }
.field { display: block; margin-bottom: 10px; }
.field > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.input, select.input, textarea.input { width: 100%; padding: 10px 12px; border: 1px solid var(--field-border); border-radius: 12px; background: var(--field); outline: none; }
.input:focus { border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px rgba(15,118,110,.12); }
textarea.input { min-height: 84px; resize: vertical; text-align: center; font-size: 17px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; border-radius: 12px; border: 1px solid var(--border); background: #fff; cursor: pointer; font-weight: 700; white-space: nowrap; }
.btn:hover { background: #f8fafc; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.print { background: linear-gradient(#fb923c, #ea580c); border-color: #ea580c; color: #fff; font-size: 16px; padding: 13px 18px; width: 100%; box-shadow: 0 6px 16px rgba(234,88,12,.25); }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.icon { width: 42px; height: 42px; padding: 0; font-size: 18px; }
.seg { display: flex; border: 1.5px solid var(--primary); border-radius: 999px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px; color: var(--primary); font-weight: 700; cursor: pointer; }
.seg button.on { background: var(--primary); color: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chips .lbl { font-size: 12.5px; color: var(--muted); margin-left: 4px; }
.chip { border: 1px solid var(--border); background: #fff; border-radius: 10px; padding: 5px 11px; font-size: 13px; cursor: pointer; }
.chip.on { background: var(--primary-soft); border-color: var(--primary-soft); color: var(--primary-dark); font-weight: 700; }
.chip.on::before { content: "✓ "; }
.hint { font-size: 12.5px; color: var(--muted); }
.err { color: var(--danger); font-size: 13px; }
.warn { color: var(--warn); font-size: 13px; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.switch input { appearance: none; width: 42px; height: 24px; border-radius: 12px; background: #cbd5e1; position: relative; transition: .2s; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; right: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked { background: var(--primary); }
.switch input:checked::after { right: 21px; }
.stepper { display: inline-flex; align-items: center; gap: 2px; }
.stepper button { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--border); background: #fff; font-size: 18px; cursor: pointer; }
.stepper b { min-width: 28px; text-align: center; font-size: 17px; }

/* preview */
.preview { display: grid; place-items: center; min-height: 120px; }
.preview img { max-height: 260px; max-width: 100%; box-shadow: 0 6px 18px rgba(0,0,0,.2); border-radius: 4px; background: #fff; }
.preview img.round { border-radius: 50%; }
.preview .empty { color: var(--muted); font-size: 13.5px; padding: 20px; text-align: center; }
.preview-cap { text-align: center; font-size: 12px; color: var(--muted); margin-top: 8px; }

/* search results and queue */
.results { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 10; background: #fff; border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); max-height: 280px; overflow: auto; }
.results div { padding: 9px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.results div:hover { background: var(--bg); }
.results small { color: var(--muted); }
.item { display: flex; align-items: center; gap: 10px; background: #fff; border-radius: 14px; padding: 10px 12px; margin-bottom: 8px; box-shadow: var(--shadow); }
.item .t { flex: 1; min-width: 0; }
.item .t b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .t small { color: var(--muted); }
.empty-state { text-align: center; color: var(--muted); padding: 26px 10px; }
.empty-state .big { font-size: 44px; opacity: .45; }

/* table */
.table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); }
.table th, .table td { padding: 9px 10px; text-align: right; border-bottom: 1px solid var(--border); font-size: 14px; }
.table th { background: var(--primary-soft); color: var(--primary-dark); font-weight: 700; }
.table tr:last-child td { border-bottom: 0; }
.table td.num { font-variant-numeric: tabular-nums; direction: ltr; text-align: right; }
.table .act { white-space: nowrap; }

/* modal and toast */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(15,23,42,.45); display: grid; place-items: center; padding: 16px; }
.modal .box { background: #fff; border-radius: 18px; padding: 18px; width: min(520px, 100%); max-height: 92vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal h3 { margin: 0 0 12px; font-size: 18px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-start; margin-top: 14px; }
.toast { position: fixed; bottom: calc(var(--nav-h) + 14px); left: 50%; transform: translate(-50%, 30px); z-index: 60; background: #10201E; color: #fff; padding: 11px 18px; border-radius: 14px; font-size: 14px; opacity: 0; transition: .25s; pointer-events: none; max-width: 92vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: #991b1b; }
@media (min-width: 960px) { .toast { bottom: 24px; } }
.new-version { position: fixed; top: calc(72px + env(safe-area-inset-top)); left: 12px; right: 12px; z-index: 55; display: flex; align-items: center; gap: 12px; justify-content: space-between; background: #10201E; color: #fff; padding: 10px 14px; border-radius: 14px; max-width: 520px; margin: 0 auto; }
.new-version button { border: 0; background: #FDD04C; color: #10201E; font-weight: 700; padding: 8px 14px; border-radius: 10px; cursor: pointer; }
.qr { display: grid; place-items: center; gap: 6px; padding: 12px; background: var(--bg); border-radius: 14px; text-align: center; }
.qr img { width: 190px; height: 190px; image-rendering: pixelated; border-radius: 8px; background: #fff; padding: 6px; }
.qr code { font-size: 14px; letter-spacing: .5px; direction: ltr; word-break: break-all; max-width: 100%; }
.qr { min-width: 0; }
.key { font-family: Consolas, monospace; font-size: 20px; letter-spacing: 2px; direction: ltr; background: var(--bg); padding: 8px 14px; border-radius: 10px; display: inline-block; }
.pair-screen { max-width: 440px; margin: 30px auto; text-align: center; }
.pair-screen .big { font-size: 56px; }
.camera { position: fixed; inset: 0; z-index: 70; background: #000; display: grid; grid-template-rows: 1fr auto; }
.camera video { width: 100%; height: 100%; object-fit: cover; }
.camera .bar { padding: 14px; display: flex; justify-content: center; gap: 10px; background: #000; }
.help-topic { background: #fff; border-radius: 14px; padding: 12px 14px; margin-bottom: 10px; box-shadow: var(--shadow); }
.help-topic h4 { margin: 0 0 6px; font-size: 16px; color: var(--primary-dark); }
.help-topic p, .help-topic li { margin: 4px 0; font-size: 14px; }
.help-topic ul, .help-topic ol { padding-right: 20px; margin: 6px 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.tile { background: #fff; border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tile b { display: block; }
.tile small { color: var(--muted); display: block; }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.kv:last-child { border-bottom: 0; }
.kv span:last-child { color: var(--muted); direction: ltr; text-align: left; word-break: break-all; }

/* two columns on wide screens */
@media (min-width: 960px) {
  .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
}
/* the designs list */
.tiles.designs .tile.design { cursor: pointer; align-items: center; }
.tile .thumb { width: 86px; height: 64px; display: grid; place-items: center; background: var(--bg); border-radius: 10px; flex: none; }
.tile .thumb img { max-width: 80px; max-height: 58px; box-shadow: 0 2px 6px rgba(0,0,0,.2); background: #fff; }
.tile .thumb img.round { border-radius: 50%; }

/* the editor */
body.editing .nav { display: none; }
body.editing .top { display: none; }
.view.editor { display: flex; flex-direction: column; height: 100vh; height: 100dvh; max-width: none; margin: 0; padding: 0; padding-top: env(safe-area-inset-top); background: var(--bg); }
.ed-top { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--primary); color: #fff; }
.ed-top .btn.icon { background: rgba(255,255,255,.14); border-color: transparent; color: #fff; }
.ed-title { flex: 1; min-width: 0; text-align: center; line-height: 1.2; }
.ed-title b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ed-title small { font-size: 12px; opacity: .9; }
.ed-bar { display: flex; gap: 2px; padding: 4px 6px; background: #fff; border-bottom: 1px solid var(--border); overflow-x: auto; }
.ed-bar .ed-tool { flex: 1; min-width: 56px; }
.ed-tool { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px; border: 0; background: transparent; color: var(--text); font-size: 11.5px; cursor: pointer; border-radius: 10px; }
.ed-tool:hover { background: var(--bg); }
.ed-tool .ic { font-size: 20px; line-height: 1; height: 24px; display: grid; place-items: center; }
.ed-tool.main { background: var(--primary-soft); color: var(--primary-dark); font-weight: 700; }
.ed-canvas-wrap { flex: 1; min-height: 200px; overflow: auto; display: grid; place-items: center; padding: 16px; background: #e6eaef; background-image: radial-gradient(#d4dae1 1px, transparent 1px); background-size: 14px 14px; }
.ed-canvas { position: relative; background: #fff; box-shadow: 0 8px 24px rgba(0,0,0,.22); flex: none; }
.ed-canvas.round { border-radius: 50%; }
.ed-items { position: absolute; inset: 0; }
.ed-item { position: absolute; touch-action: none; user-select: none; -webkit-user-select: none; box-sizing: border-box; cursor: move; }
.ed-item.sel { outline: 2px dashed var(--primary); outline-offset: 1px; }
.ed-item .txt { width: 100%; height: 100%; overflow: hidden; white-space: pre-wrap; word-break: break-word; color: #000; }
.ed-item img { width: 100%; height: 100%; display: block; pointer-events: none; }
.ed-item .ln { position: absolute; left: 0; right: 0; top: 50%; border-top-style: solid; border-top-color: #000; transform: translateY(-50%); }
.ed-item .rc { width: 100%; height: 100%; border-style: solid; border-color: #000; box-sizing: border-box; }
.ed-item .handle { position: absolute; right: -9px; bottom: -9px; width: 18px; height: 18px; border-radius: 50%; background: var(--primary); border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.3); cursor: nwse-resize; touch-action: none; }
.ed-props { padding: 8px 12px; background: #fff; border-top: 1px solid var(--border); max-height: 150px; overflow: auto; display: flex; flex-direction: column; gap: 8px; }
.ed-props .input { padding: 6px 10px; }
.ed-props .field { width: 76px !important; }
.ed-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); background: #fff; border-top: 1px solid var(--border); }
@media (min-width: 960px) {
  .view.editor { height: 100vh; }
  .ed-grid { grid-template-columns: repeat(10, 1fr); }
  .ed-props { max-height: 160px; }
}

/* the shape picker */
.shape-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 8px; margin-top: 10px; }
.shape-tile { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px 6px; border: 1px solid var(--border); border-radius: 12px; background: #fff; cursor: pointer; }
.shape-tile:hover { background: var(--bg); }
.shape-tile.on { border-color: var(--primary); background: var(--primary-soft); }
.shape-tile svg { width: 44px; height: 44px; }
.shape-tile .ln-ico { width: 44px; height: 44px; background: linear-gradient(to top left, transparent calc(50% - 1.5px), #000 calc(50% - 1.5px), #000 calc(50% + 1.5px), transparent calc(50% + 1.5px)); }
.shape-tile small { font-size: 11px; color: var(--muted); line-height: 1.2; text-align: center; }
.ed-item svg { width: 100%; height: 100%; display: block; overflow: visible; pointer-events: none; }

/* the Bluetooth printer */
.bt-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.bt-line .dot { width: 10px; height: 10px; border-radius: 50%; background: #cbd5e1; flex: none; }
.bt-line .dot.on { background: #16a34a; box-shadow: 0 0 0 3px #dcfce7; }
.bt-line .name { font-weight: 700; }
.progress { height: 10px; border-radius: 6px; background: var(--bg); overflow: hidden; margin: 12px 0 6px; }
.progress > div { height: 100%; width: 0; background: var(--primary); transition: width .15s; }
.qr-card h3 { display: flex; align-items: center; gap: 8px; }
.qr-icon { width: 26px; height: 26px; border-radius: 7px; }

/* the maker, and the language */
.brand-card .brand-row { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 44px; height: 44px; border-radius: 12px; flex: none; display: grid; place-items: center; background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff; font-weight: 800; font-size: 22px; font-family: Georgia, serif; }
.free-pill { background: #dcfce7; color: #166534; border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.lang-btn { border: 0; color: #fff; cursor: pointer; font: inherit; }
.lang-btn::before { display: none; }
.lang-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.lang-list .chip { padding: 10px; font-size: 15px; text-align: center; }
html[dir="ltr"] .ed-top > .btn.icon:first-child { transform: scaleX(-1); }
#wifiPrint { display: none; }

.via-seg { margin-bottom: 12px; }
.via-seg button { padding: 11px; font-size: 15px; }
.wifi-steps { background: var(--bg, #F1F5F9); border-radius: 12px; padding: 10px 12px; }
.wifi-steps ol { margin: 0; padding-inline-start: 20px; line-height: 1.8; font-size: 14.5px; }
.wifi-steps .mopria { display: block; background: var(--primary-soft); color: var(--primary-dark); border-color: transparent; font-weight: 700; width: 100%; margin-top: 10px; text-align: center; text-decoration: none; }
.sym-title { margin: 16px 0 0; font-size: 14px; color: var(--muted); }
.shape-tile .sym { height: 44px; display: flex; align-items: center; justify-content: center; font-size: 34px; font-weight: 800; color: #000; line-height: 1; }
.sym-row { flex: none; margin: 0; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
.sym-row .chip { font-size: 17px; font-weight: 700; min-width: 40px; flex: none; }
