:root {
  --bg: #f3f6f5;
  --card: #ffffff;
  --ink: #13201c;
  --muted: #5a6964;
  --line: #dfe6e3;
  --brand: #0f7b5f;
  --brand-ink: #ffffff;
  --brand-soft: #e3f3ee;
  --warn: #9a5200;
  --warn-soft: #fff3e0;
  --shadow: 0 1px 2px rgba(19, 32, 28, .06), 0 6px 24px rgba(19, 32, 28, .07);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1513; --card: #16201d; --ink: #e6efec; --muted: #97a8a2; --line: #283632;
    --brand: #3cc79c; --brand-ink: #06120e; --brand-soft: #173a30;
    --warn: #f0a648; --warn-soft: #33260f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1513; --card: #16201d; --ink: #e6efec; --muted: #97a8a2; --line: #283632;
  --brand: #3cc79c; --brand-ink: #06120e; --brand-soft: #173a30; --warn: #f0a648; --warn-soft: #33260f;
  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.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
[hidden] { display: none !important; }
.wrap { max-width: 980px; margin: 0 auto; padding: 0 16px; }
a { color: var(--brand); }
code, kbd { font: .88em ui-monospace, Consolas, monospace; background: var(--brand-soft); padding: .1em .4em; border-radius: 5px; }
kbd { border: 1px solid var(--line); background: var(--card); }

/* ------------------------------------------------------------ đầu trang */
.top { background: var(--card); border-bottom: 1px solid var(--line); }
.top-in { display: flex; align-items: center; justify-content: space-between; height: 60px; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 700; font-size: 19px; }
.brand img { border-radius: 8px; }
.tag { color: var(--muted); font-weight: 500; font-size: 15px; }
.home-link { display: inline-flex; align-items: center; gap: 6px; flex: none; text-decoration: none; color: var(--ink);
  font-weight: 600; font-size: 14px; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); white-space: nowrap; }
.home-link:hover { background: rgba(127, 127, 127, .08); }

/* ------------------------------------------------------------ thẻ chọn */
.tabs { display: flex; gap: 6px; margin: 22px 0 14px; border-bottom: 1px solid var(--line); }
.tab { appearance: none; border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted);
  padding: 10px 14px; border-bottom: 3px solid transparent; margin-bottom: -1px; cursor: pointer; }
.tab.on { color: var(--brand); border-bottom-color: var(--brand); }

.pane { background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 22px; }
.grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; grid-template-rows: auto 1fr;
  grid-template-areas: "link out" "opts out"; column-gap: 28px; row-gap: 0; align-items: start; }
.col-form { grid-area: link; }
.col-opts { grid-area: opts; }
.col-out { grid-area: out; }
.col-opts > .lbl:first-child { margin-top: 18px; }
@media (max-width: 760px) {
  .col-opts > .lbl:first-child { margin-top: 2px; }
  /* điện thoại: mã QR hiện ngay dưới ô link, không phải cuộn */
  .grid { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; grid-template-areas: "link" "out" "opts"; row-gap: 16px; }
  .pane { padding: 16px; border-radius: 14px; }
  .tabs { margin-top: 14px; }
}

/* ------------------------------------------------------------ ô nhập */
.lbl { display: block; font-weight: 600; font-size: 15px; margin: 16px 0 6px; }
.lbl:first-child { margin-top: 0; }
.opt { color: var(--muted); font-weight: 400; }
input[type="text"], input[type="url"], textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--card);
  border: 1.5px solid var(--line); border-radius: 10px; padding: 11px 12px; outline: none;
}
input:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea { resize: vertical; font: 14px/1.6 ui-monospace, Consolas, monospace; }

.linkbox { display: flex; gap: 8px; align-items: stretch; position: relative; }
.linkbox input { font-size: 17px; padding: 14px 44px 14px 14px; flex: 1; min-width: 0; }
.icon-btn { position: absolute; right: 84px; top: 50%; transform: translateY(-50%); appearance: none; border: 0;
  background: none; color: var(--muted); padding: 6px; border-radius: 8px; cursor: pointer; display: flex; }
.icon-btn:hover { color: var(--ink); background: rgba(127, 127, 127, .1); }

.linkinfo { margin-top: 8px; font-size: 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; }
.chip { background: var(--brand-soft); color: var(--brand); font-weight: 600; font-size: 13px; padding: 2px 10px; border-radius: 999px; }
.final { flex-basis: 100%; color: var(--muted); font: 12.5px/1.45 ui-monospace, Consolas, monospace; word-break: break-all; }
.note { flex-basis: 100%; color: var(--muted); }
.hint { color: var(--muted); font-size: 14px; margin: 8px 0 0; }
.hint.small { font-size: 13px; }
.warn { color: var(--warn); background: var(--warn-soft); font-size: 14px; padding: 8px 12px; border-radius: 10px; margin: 10px 0 0; }

/* ------------------------------------------------------------ nút */
.btn { appearance: none; font: inherit; font-weight: 600; font-size: 15px; border-radius: 10px; padding: 10px 16px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 1.5px solid transparent; white-space: nowrap; }
.btn-main { background: var(--brand); color: var(--brand-ink); }
.btn-main:hover { filter: brightness(1.07); }
.btn-soft { background: var(--brand-soft); color: var(--brand); padding: 0 18px; }
.btn-soft:hover { filter: brightness(.97); }
.btn-line { background: var(--card); color: var(--ink); border-color: var(--line); }
.btn-line:hover { border-color: var(--muted); }
.btn-sm { font-size: 14px; padding: 6px 12px; }
.link-btn { appearance: none; border: 0; background: none; color: var(--muted); font: inherit; font-size: 14px; cursor: pointer; text-decoration: underline; }
.link-btn:hover { color: var(--ink); }

/* ------------------------------------------------------------ tùy chỉnh */
.more { margin-top: 18px; border: 1px solid var(--line); border-radius: 12px; }
.more summary { cursor: pointer; padding: 11px 14px; font-weight: 600; font-size: 15px; color: var(--muted); list-style-position: inside; }
.more[open] summary { color: var(--ink); border-bottom: 1px solid var(--line); }
.more-in { padding: 6px 14px 12px; }
.row { display: flex; align-items: center; gap: 12px; padding: 8px 0; flex-wrap: wrap; }
.lbl-in { width: 88px; flex: none; font-size: 14px; color: var(--muted); }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.swatches button, .sw-custom { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--card); background: var(--c);
  box-shadow: 0 0 0 1.5px var(--line); cursor: pointer; padding: 0; }
.swatches button.on, .sw-custom.on { box-shadow: 0 0 0 2.5px var(--brand); }
.sw-custom { position: relative; overflow: hidden; background: conic-gradient(#e33, #ec3, #3c5, #39e, #a3e, #e33); }
.sw-custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; border: 0; padding: 0; }
.seg { display: inline-flex; border: 1.5px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { appearance: none; border: 0; background: none; font: inherit; font-size: 14px; padding: 6px 14px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.logo-pick { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.logo-pick img { width: 34px; height: 34px; object-fit: contain; border-radius: 6px; border: 1px solid var(--line); background: #fff; }

/* ------------------------------------------------------------ xem trước */
.col-out { position: sticky; top: 16px; }
.preview { background: #ffffff; border: 1px solid var(--line); border-radius: 14px; min-height: 340px;
  display: flex; align-items: center; justify-content: center; overflow: hidden; }
.preview canvas { display: block; width: 100%; height: auto; cursor: zoom-in; }
.empty { text-align: center; color: #8a9893; padding: 30px 20px; }
.empty p { margin: 10px 0 0; font-size: 15px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.actions .btn-main { flex: 1 1 100%; padding: 13px 16px; font-size: 16px; }
.actions .btn-line { flex: 1 1 0; padding: 9px 10px; font-size: 14px; }
.actions-more { margin-top: 10px; font-size: 13.5px; color: var(--muted); text-align: center; }
@media (max-width: 760px) { .col-out { position: static; } .preview { min-height: 0; } .empty { padding: 26px 16px; } }

/* ------------------------------------------------------------ gần đây */
.history { margin-top: 24px; border-top: 1px solid var(--line); padding-top: 16px; }
.history-head { display: flex; align-items: baseline; justify-content: space-between; }
.history h2 { font-size: 16px; margin: 0 0 8px; }
.history ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.history li { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); cursor: pointer; }
.history li:hover { border-color: var(--brand); }
.history li canvas { width: 40px; height: 40px; flex: none; border-radius: 4px; background: #fff; }
.history .h-txt { min-width: 0; flex: 1; }
.history .h-title { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history .h-link { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: ui-monospace, Consolas, monospace; }
.history .h-time { color: var(--muted); font-size: 12.5px; flex: none; }
.history .h-del { flex: none; }

/* ------------------------------------------------------------ nhiều link */
#tab-nhieu .actions { align-items: center; }
#tab-nhieu .actions .btn-main { flex: 0 0 auto; padding: 11px 18px; font-size: 15px; }
#tab-nhieu .actions .btn-line { flex: 0 0 auto; padding: 10px 16px; }
.count { color: var(--muted); font-size: 14px; }
.batch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; margin-top: 16px; }
.batch-grid figure { margin: 0; background: #fff; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.batch-grid canvas { display: block; width: 100%; height: auto; }
.batch-grid figcaption { font-size: 12.5px; color: #5a6964; padding: 6px 10px; border-top: 1px solid #e8eeeb;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.foot { color: var(--muted); font-size: 13px; text-align: center; padding: 22px 16px 32px; }

/* ------------------------------------------------------------ phóng to */
.big { position: fixed; inset: 0; z-index: 50; background: #fff; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 16px; cursor: zoom-out; }
.big img { max-width: 100%; max-height: calc(100% - 40px); object-fit: contain; }
.big p { color: #8a9893; font-size: 13px; margin: 10px 0 0; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; background: #13201c; color: #fff;
  padding: 10px 18px; border-radius: 999px; font-size: 14.5px; box-shadow: 0 6px 24px rgba(0, 0, 0, .25); max-width: calc(100% - 32px); }

/* ------------------------------------------------------------ in */
.print-area { display: none; }
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; }
  body > *:not(.print-area) { display: none !important; }
  .print-area { display: block !important; }
  .print-one { display: flex; justify-content: center; padding-top: 10mm; }
  .print-one img { width: 110mm; height: auto; }
  .print-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8mm 10mm; }
  .print-grid img { width: 100%; height: auto; break-inside: avoid; border: .3mm dashed #bbb; }
}
