:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --line: #e3e8ef;
  --text: #17202e;
  --muted: #5d6b7e;
  --brand: #0f766e;
  --brand-2: #115e59;
  --brand-soft: #e6f4f2;
  --warn: #b45309;
  --warn-soft: #fef3e2;
  --err: #b91c1c;
  --err-soft: #fdecec;
  --ok-soft: #e7f6ee;
  --ok: #15803d;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 14px rgba(16, 24, 40, .05);
  --checker: #e9edf2;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b;
    --panel: #161d27;
    --panel-2: #1b2430;
    --line: #2a3544;
    --text: #e6ebf2;
    --muted: #93a1b3;
    --brand: #2dd4bf;
    --brand-2: #5eead4;
    --brand-soft: #123532;
    --warn: #fbbf24;
    --warn-soft: #3a2c10;
    --err: #f87171;
    --err-soft: #3b1717;
    --ok-soft: #12301f;
    --ok: #4ade80;
    --shadow: none;
    --checker: #222c39;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", "Noto Sans Lao", "Noto Sans Thai", "Lao UI", "Leelawadee UI", "Phetsarath OT", Tahoma, Roboto, sans-serif;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .6em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ---- Top bar ---------------------------------------------------------- */
.top {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.top .in {
  max-width: 1240px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; gap: 20px; height: 58px;
}
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); }
.logo:hover { text-decoration: none; }
.logo .mark {
  width: 30px; height: 30px; border-radius: 8px; background: var(--brand);
  display: grid; place-items: center;
}
.logo .mark svg { width: 18px; height: 18px; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  padding: 7px 12px; border-radius: 8px; color: var(--muted); font-weight: 500;
}
.nav a:hover { background: var(--panel-2); text-decoration: none; color: var(--text); }
.nav a.on { background: var(--brand-soft); color: var(--brand); }
.who { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .9rem; }
.who form { margin: 0; }

.wrap { max-width: 1240px; margin: 0 auto; padding: 24px 16px 60px; }

/* ---- Panels / cards ----------------------------------------------------- */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px;
}
.card + .card { margin-top: 16px; }
.grid-gen { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 20px; align-items: start; }
.sticky { position: sticky; top: 78px; }
@media (max-width: 960px) {
  .grid-gen { grid-template-columns: 1fr; }
  .sticky { position: static; }
  #previewCard { order: -1; } /* phones: see the code first */
}

/* ---- Forms -------------------------------------------------------------- */
label { display: block; font-weight: 500; font-size: .88rem; margin-bottom: 5px; }
.field { margin-bottom: 14px; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
input[type=text], input[type=url], input[type=password], input[type=email], input[type=tel],
input[type=number], input[type=search], input[type=datetime-local], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--text); font: inherit;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
input[type=color] {
  width: 100%; height: 40px; padding: 3px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); cursor: pointer;
}
input[type=range] { width: 100%; accent-color: var(--brand); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--brand); margin: 0; }
.hint { color: var(--muted); font-size: .82rem; margin-top: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--panel-2); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #062b28; } }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--err); }
.btn.sm { padding: 5px 10px; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.btns .btn { flex: 1; }

/* ---- Tabs / chips -------------------------------------------------------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: -4px 0 18px; }
.tabs button {
  border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted);
  padding: 10px 14px; border-bottom: 2px solid transparent; cursor: pointer; margin-bottom: -1px;
}
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.chips button {
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: 999px; padding: 6px 13px; font: inherit; font-size: .88rem; cursor: pointer;
}
.chips button.on { background: var(--brand); border-color: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .chips button.on { color: #062b28; } }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; width: 100%; }
.seg button {
  flex: 1; border: 0; background: var(--panel); color: var(--muted); font: inherit; font-size: .85rem;
  padding: 8px 6px; cursor: pointer; border-right: 1px solid var(--line);
}
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }

details.more { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 12px; }
details.more summary { cursor: pointer; font-weight: 600; margin-bottom: 12px; }

/* ---- Smart link box ------------------------------------------------------ */
.smart {
  border: 1px solid var(--line); border-radius: 10px; padding: 14px; background: var(--panel-2);
  margin-bottom: 14px;
}
.smart.on { border-color: var(--brand); background: var(--brand-soft); }
.smart .fields { margin-top: 12px; }
.shortbox {
  display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 6px 6px 12px; margin-top: 10px;
}
.shortbox a { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prefix { display: flex; }
.prefix span {
  padding: 9px 10px; border: 1px solid var(--line); border-right: 0; border-radius: 8px 0 0 8px;
  background: var(--panel-2); color: var(--muted); font-size: .85rem; white-space: nowrap;
}
.prefix input { border-radius: 0 8px 8px 0; }

/* ---- Preview --------------------------------------------------------------- */
.stage {
  border-radius: 10px; padding: 22px; display: grid; place-items: center; min-height: 300px;
  background-color: var(--panel-2);
  background-image: linear-gradient(45deg, var(--checker) 25%, transparent 25%),
    linear-gradient(-45deg, var(--checker) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--checker) 75%),
    linear-gradient(-45deg, transparent 75%, var(--checker) 75%);
  background-size: 18px 18px; background-position: 0 0, 0 9px, 9px -9px, -9px 0;
  margin-bottom: 14px;
}
.stage canvas, .stage svg, .stage img { max-width: 100%; height: auto; display: block; }
.stage .empty { color: var(--muted); text-align: center; font-size: .92rem; }
.encoded {
  font-size: .8rem; color: var(--muted); word-break: break-all; background: var(--panel-2);
  border-radius: 8px; padding: 8px 10px; margin-bottom: 14px; max-height: 76px; overflow: auto;
}
.status { font-size: .85rem; padding: 8px 11px; border-radius: 8px; margin-bottom: 14px; }
.status.ok { background: var(--ok-soft); color: var(--ok); }
.status.warn { background: var(--warn-soft); color: var(--warn); }
.status.err { background: var(--err-soft); color: var(--err); }
.status:empty { display: none; }

/* ---- Flash / alerts ------------------------------------------------------- */
.flash { padding: 11px 14px; border-radius: 10px; margin-bottom: 18px; font-weight: 500; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.warn { background: var(--warn-soft); color: var(--warn); }
.flash.err { background: var(--err-soft); color: var(--err); }

/* ---- Tables ----------------------------------------------------------------- */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { padding: 10px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.tbl th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .thumb { width: 56px; }
.tbl .thumb canvas { width: 48px; height: 48px; display: block; border-radius: 4px; }
.tbl .dest { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tbl-wrap { overflow-x: auto; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.badge.on { background: var(--ok-soft); color: var(--ok); }
.badge.off { background: var(--warn-soft); color: var(--warn); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi b { display: block; font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.kpi span { color: var(--muted); font-size: .85rem; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar form { display: flex; gap: 8px; flex: 1; min-width: 240px; }
.pager { display: flex; gap: 6px; justify-content: center; margin-top: 16px; }

/* ---- Stats ------------------------------------------------------------------ */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 140px; padding-top: 10px; }
.bars div { flex: 1; background: var(--brand); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; position: relative; }
.bars div:hover { opacity: 1; }
.bars-x { display: flex; justify-content: space-between; color: var(--muted); font-size: .75rem; margin-top: 6px; }
.split { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.meter { margin-bottom: 9px; }
.meter .t { display: flex; justify-content: space-between; font-size: .88rem; margin-bottom: 3px; }
.meter .b { height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.meter .b i { display: block; height: 100%; background: var(--brand); }
.grid-link { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
@media (max-width: 900px) { .grid-link { grid-template-columns: 1fr; } }

/* ---- Batch ------------------------------------------------------------------- */
.sheet { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-top: 16px; }
.sheet .item {
  background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px; text-align: center;
  color: #111; font-size: .75rem; word-break: break-all;
}
.sheet .item svg, .sheet .item canvas { max-width: 100%; height: auto; display: block; margin: 0 auto 6px; }

/* ---- Auth / bare pages -------------------------------------------------------- */
.bare { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.bare .card { width: 100%; max-width: 400px; }
.bare .logo { justify-content: center; margin-bottom: 18px; font-size: 1.15rem; }
.err-msg { background: var(--err-soft); color: var(--err); padding: 9px 12px; border-radius: 8px; margin-bottom: 14px; font-size: .9rem; }

@media (max-width: 640px) {
  .top .in { gap: 10px; }
  .logo span.name { display: none; }
  .who .u { display: none; }
  .nav a { padding: 7px 9px; }
}

@media print {
  body { background: #fff; }
  .top, .no-print, .flash { display: none !important; }
  .wrap { padding: 0; max-width: none; }
  .card { border: 0; box-shadow: none; padding: 0; }
  .sheet { grid-template-columns: repeat(4, 1fr); gap: 8px; }
  .sheet .item { break-inside: avoid; border: 1px dashed #bbb; }
}

/* ---- Plans ---------------------------------------------------------------- */
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.plan {
  position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; display: flex; flex-direction: column; gap: 8px; box-shadow: var(--shadow);
}
.plan.best { border-color: var(--brand); }
.plan.cur { background: var(--brand-soft); border-color: var(--brand); }
.plan h2 { margin: 0; }
.plan .price { font-size: 1.25rem; font-weight: 700; }
.plan .life { color: var(--brand); font-weight: 600; }
.plan ul { margin: 4px 0 10px; padding-left: 18px; color: var(--muted); font-size: .9rem; flex: 1; }
.plan .btn { width: 100%; }
.plan .ribbon {
  position: absolute; top: -10px; right: 14px; background: var(--brand); color: #fff;
  font-size: .72rem; font-weight: 700; padding: 3px 9px; border-radius: 999px;
}
.who a.u { color: var(--muted); }

/* ---- Scan to remake ------------------------------------------------------- */
.remake {
  display: flex; align-items: center; gap: 12px; justify-content: space-between; flex-wrap: wrap;
  background: var(--panel-2); border: 1px dashed var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 16px;
}
.scan-dlg {
  width: min(520px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); color: var(--text); padding: 18px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
.scan-dlg::backdrop { background: rgba(10, 15, 22, .55); }
.scan-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.scan-drop { border: 2px dashed var(--line); border-radius: 10px; padding: 12px; margin-bottom: 12px; }
.scan-drop.over { border-color: var(--brand); background: var(--brand-soft); }
.scan-view { position: relative; margin-bottom: 10px; }
.scan-view video { width: 100%; border-radius: 8px; background: #000; display: block; max-height: 55vh; object-fit: cover; }
.scan-frame {
  position: absolute; inset: 18% 22%; border: 3px solid rgba(255, 255, 255, .9); border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .25); pointer-events: none;
}

/* ---- Language switcher -------------------------------------------------------- */
.langs { display: flex; gap: 2px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.langs a { padding: 3px 8px; border-radius: 6px; font-size: .82rem; color: var(--muted); white-space: nowrap; }
.langs a:hover { text-decoration: none; color: var(--text); }
.langs a.on { background: var(--panel); color: var(--brand); font-weight: 600; box-shadow: var(--shadow); }
.bare .langs { margin-top: 14px; justify-content: center; background: none; border: 0; }
@media (max-width: 760px) {
  .top .in { flex-wrap: wrap; height: auto; padding-top: 8px; padding-bottom: 8px; row-gap: 6px; }
  .nav { order: 3; flex-basis: 100%; overflow-x: auto; }
  .langs { margin-left: auto; }
}

.plan .price.ask { font-size: 1rem; color: var(--muted); }
