@import url("ds/tokens.css");

/* Portal dùng token chung của ds/tokens.css (màu, bo góc, bóng, giao diện tối).
   Các tên cũ bên dưới là bí danh để phần CSS còn lại không phải đổi. */
:root {
  --bg-bar: var(--bg-surface);
  --bg-hover: var(--bg-subtle);
  --accent: var(--brand);
  --accent-hover: var(--brand-hover);
  --accent-soft: var(--brand-soft);
  --bad: var(--danger);
  --idle: var(--text-faint);
  --shadow: var(--sh-lg);
  --radius: var(--r-md);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg-app); color: var(--text); }
button { font: inherit; cursor: pointer; color: inherit; }
.muted { color: var(--text-muted); }

/* ---------- nút chuyển Sáng / Tối ---------- */
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--bg-hover); border: 1px solid var(--border); border-radius: 999px; }
.seg-btn { border: 0; background: transparent; color: var(--text-muted); padding: 5px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.seg-btn:hover { color: var(--text); }
.seg-btn[aria-pressed="true"] { background: var(--accent); color: #fff; }

/* ---------- đăng nhập ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 400px; background: var(--bg-surface); border: 1px solid var(--border); border-radius: 12px; padding: 28px 32px 32px; display: grid; gap: 14px; box-shadow: var(--shadow); }
.login-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand-lg { font-size: 26px; font-weight: 800; letter-spacing: .5px; }
.brand-lg span, .brand span { color: var(--accent); margin-left: 4px; font-weight: 500; }
.login-card p { margin: 0; }
label { display: grid; gap: 6px; font-weight: 600; font-size: 13px; }
input { font: inherit; color: var(--text); padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-app); }
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.error { color: var(--bad); font-size: 13px; }
.btn-primary { background: var(--accent); color: #fff; border: 0; border-radius: var(--radius); padding: 11px 14px; font-weight: 600; }
:root[data-theme="dark"] .btn-primary { color: #0b1220; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .6; cursor: progress; }

/* ---------- khung chính: thanh công cụ ở trên, nội dung bên dưới ---------- */
/* minmax(0, 1fr): không để thanh công cụ (nhiều tab) nới cột lưới rộng hơn màn hình; trước đây trên iPad cả trang bị tràn ngang */
.shell { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; height: 100%; }
.bar { min-width: 0; }
html, body { overflow-x: hidden; }
.bar { display: flex; align-items: center; gap: 20px; padding: 0 16px; min-height: 56px; background: var(--bg-bar); border-bottom: 1px solid var(--border); }
.brand { font-size: 18px; font-weight: 800; letter-spacing: .5px; white-space: nowrap; }

.tools { display: flex; gap: 6px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.tools::-webkit-scrollbar { display: none; }
.tool { display: inline-flex; align-items: center; gap: 9px; white-space: nowrap; background: transparent; border: 1px solid transparent; border-radius: var(--radius); padding: 8px 14px; font-weight: 600; color: var(--text-muted); }
.tool:hover { background: var(--bg-hover); color: var(--text); }
.tool.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.tool:focus-visible, .seg-btn:focus-visible, .btn-ghost:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Số hội thoại có tin chưa đọc trên tab Messenger và Zalo */
.tool-n { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: #e5484d; color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; flex: none; }
.tool-n[hidden] { display: none; }
.tool-n--warn { background: #e07a1f; margin-left: 3px; }
#bot-alert { position: fixed; right: 18px; bottom: 18px; z-index: 50; max-width: 360px; text-align: left; border: 0; border-radius: 12px; padding: 12px 16px; background: #e07a1f; color: #fff; font: 600 13.5px/1.4 inherit; box-shadow: 0 10px 30px rgba(0,0,0,.2); cursor: pointer; }
#bot-alert[hidden] { display: none; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--idle); flex: none; }
.dot.up { background: var(--ok); box-shadow: 0 0 0 0 rgba(34, 197, 94, .55); animation: pulse 2.4s infinite; }
.dot.down { background: var(--bad); }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px rgba(34, 197, 94, 0); } 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); } }
@media (prefers-reduced-motion: reduce) { .dot.up { animation: none; } }

.bar-right { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.who { color: var(--text-muted); font-size: 13px; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-ghost { background: transparent; border: 1px solid var(--border); border-radius: var(--radius); padding: 7px 12px; color: var(--text); }
.btn-ghost:hover { background: var(--bg-hover); }

.stage { position: relative; min-width: 0; min-height: 0; background: var(--bg-surface); }
.stage iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: var(--bg-surface); }
/* Tab Bot: thanh chuyển giữa Bộ não và Trợ lý của chủ */
.botbar { position: absolute; inset: 0 0 auto 0; height: 42px; display: flex; align-items: center; gap: 6px; padding: 0 12px; background: var(--bg-surface); border-bottom: 1px solid var(--border); z-index: 2; }
.botbar[hidden] { display: none; }
.botbar button { display: inline-flex; align-items: center; gap: 6px; background: transparent; border: 1px solid transparent; border-radius: var(--radius); padding: 5px 12px; font-weight: 600; color: var(--text-muted); cursor: pointer; }
.botbar button:hover { background: var(--bg-hover); color: var(--text); }
.botbar button.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.stage.has-subbar iframe { top: 42px; height: calc(100% - 42px); }

/* ---------- di động / PWA: thanh tiêu đề gọn + thanh điều hướng dưới + bảng "Thêm" ---------- */
.tabbar, .bar-title, .menu-fab { display: none; }
.shell { height: 100vh; height: 100dvh; }
@media (max-width: 760px) {
  body { font-size: 15px; overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
  input, select, textarea { font-size: 16px; } /* iOS không tự phóng to khi bấm vào ô nhập */
  .login-card { padding: 22px 20px 26px; }

  .shell { grid-template-rows: auto 1fr; }
  .menu-fab { display: grid; place-items: center; position: fixed; left: 0; top: 42%; z-index: 35; width: 26px; height: 54px; padding: 0; border: 0; border-radius: 0 14px 14px 0; background: var(--accent); color: #fff; opacity: .6; box-shadow: var(--shadow); }
  :root[data-theme="dark"] .menu-fab { color: #0b1220; }
  .menu-fab:active { opacity: 1; }
  .menu-fab svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
  .menu-fab.has-n::after { content: ""; position: absolute; top: 6px; right: 4px; width: 8px; height: 8px; border-radius: 50%; background: #e5484d; }
  .bar { min-height: 0; padding: env(safe-area-inset-top) calc(14px + env(safe-area-inset-right)) 0 calc(14px + env(safe-area-inset-left)); gap: 10px; }
  .brand, .bar-title, .tools, .bar-right { display: none; }

  .tabbar { display: flex; background: var(--bg-bar); border-top: 1px solid var(--border); padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
  .mtab { position: relative; flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 56px; padding: 6px 2px; background: transparent; border: 0; color: var(--text-muted); font-size: 11px; font-weight: 600; }
  .mtab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .mtab span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mtab.active { color: var(--accent); }
  .mtab.active::before { content: ""; position: absolute; top: 0; left: 28%; right: 28%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }
  .mtab .tool-n { position: absolute; top: 4px; left: calc(50% + 6px); min-width: 16px; height: 16px; line-height: 16px; font-size: 10px; padding: 0 4px; }
  .mtab:focus-visible { outline: 2px solid var(--accent); outline-offset: -4px; }

  .sheet-back { position: fixed; inset: 0; z-index: 40; background: rgba(2, 6, 23, .5); }
  .sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 85dvh; overflow: auto; display: grid; gap: 14px; padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); background: var(--bg-surface); border-radius: 16px 16px 0 0; border-top: 1px solid var(--border); box-shadow: var(--shadow); animation: sheet-up .18s ease-out; }
  .sheet { max-width: 560px; margin: 0 auto; }   /* máy tính bảng: bảng không kéo hết chiều ngang */
  .sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 0 auto; }
  .sheet-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .sheet-grid .mtab { border: 1px solid var(--border); border-radius: 12px; background: var(--bg-app); min-height: 74px; }
  .sheet-grid .mtab.active { border-color: var(--accent); background: var(--accent-soft); }
  .sheet-grid .mtab.active::before { display: none; }
  .sheet-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
  .sheet-row .who { display: block; max-width: 55%; }
  .sheet-wide { width: 100%; padding: 11px 12px; }
  .sheet-hint { margin: 0; font-size: 12.5px; }
  .btn-ghost, .seg-btn { min-height: 40px; }
  .stage iframe { overscroll-behavior: contain; }

  /* trang Kết nối */
  .conn { padding: 16px 14px 24px; }
  .conn-form { max-height: 88dvh; padding: 18px 16px; }
  .conn-toast { left: 12px; right: 12px; bottom: calc(16px + env(safe-area-inset-bottom)); max-width: none; }
}
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }

/* ---------- trang Kết nối ---------- */
.conn { position: absolute; inset: 0; overflow: auto; padding: 24px clamp(16px, 4vw, 48px) 48px; background: var(--bg-app); }
.conn h1 { margin: 0 0 4px; font-size: 22px; }
.conn h2 { margin: 0 0 10px; font-size: 14px; letter-spacing: .3px; display: flex; align-items: center; gap: 8px; }
.conn p { margin: 0; }
.conn-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px 24px; margin-bottom: 20px; }
.conn-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.conn-group { margin-bottom: 24px; }
.count { font-size: 12px; font-weight: 600; color: var(--text-muted); background: var(--bg-hover); border-radius: 999px; padding: 1px 8px; }
.conn-row { display: grid; grid-template-columns: minmax(180px, 1fr) auto auto auto; align-items: center; gap: 10px 16px; background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; }
.conn-name { font-weight: 600; overflow-wrap: anywhere; }
.conn-sub { font-size: 12.5px; overflow-wrap: anywhere; }
.conn-tools { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; font-size: 12.5px; padding: 4px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--bg-app); cursor: pointer; }
.chip input { width: auto; padding: 0; margin: 0; accent-color: var(--accent); }
.chip:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.conn-actions { display: flex; gap: 6px; }
.btn-ghost.sm { padding: 5px 10px; font-size: 13px; }
.btn-ghost.danger { color: var(--bad); }
.btn-ghost:disabled, .conn .btn-primary:disabled { opacity: .55; cursor: progress; }
.conn .btn-primary { padding: 9px 14px; }
.pill { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border); white-space: nowrap; }
.pill.ok { color: var(--ok); border-color: var(--ok); }
.pill.bad { color: var(--bad); border-color: var(--bad); }
.pill.idle { color: var(--text-muted); }
.conn-empty { text-align: center; padding: 56px 16px; border: 1px dashed var(--border); border-radius: var(--radius); }
.conn-audit { margin-top: 28px; font-size: 13px; }
.conn-audit summary { cursor: pointer; color: var(--text-muted); font-weight: 600; }
.conn-audit ul { margin: 10px 0 0; padding-left: 18px; color: var(--text-muted); }
.conn-overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: rgba(2, 6, 23, .55); }
.conn-form { width: 100%; max-width: 460px; max-height: 92vh; overflow: auto; display: grid; gap: 14px; background: var(--bg-surface); border: 1px solid var(--border); border-radius: 12px; padding: 22px 24px; box-shadow: var(--shadow); }
.conn-form h2 { font-size: 18px; margin: 0; }
.conn-form select { font: inherit; color: var(--text); padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-app); }
.conn-fields { display: grid; gap: 14px; }
.lbl { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.conn-form-actions { display: flex; justify-content: flex-end; gap: 8px; }
.conn-toast { position: fixed; right: 20px; bottom: 20px; z-index: 30; max-width: 360px; padding: 10px 14px; border-radius: var(--radius); background: var(--text); color: var(--bg-surface); box-shadow: var(--shadow); font-size: 13px; }
.conn-toast.bad { background: var(--bad); color: #fff; }
/* Bong bóng Trợ lý */
.ast-fab { position: fixed; right: 20px; bottom: 20px; z-index: 40; width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; cursor: pointer; box-shadow: 0 6px 20px rgba(0, 0, 0, .28); }
.ast-fab:hover { filter: brightness(1.08); }
.ast-fab[hidden], .ast-panel[hidden] { display: none; }
.ast-n { position: absolute; top: -4px; right: -4px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: var(--bad); color: #fff; font-size: 12px; line-height: 20px; text-align: center; }
.ast-panel { position: fixed; right: 20px; bottom: 88px; z-index: 40; width: 400px; height: min(620px, calc(100vh - 110px)); display: grid; grid-template-rows: auto 1fr; background: var(--bg-surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.ast-head { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.ast-sp { flex: 1; }
.ast-frames { position: relative; min-height: 0; }
.ast-frames iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: var(--bg-surface); }
@media (max-width: 520px) { .ast-panel { right: 0; bottom: 0; width: 100%; height: 100%; border-radius: 0; } .ast-fab { right: 14px; bottom: 14px; } }
@media (max-width: 860px) {
  .conn-row { grid-template-columns: 1fr auto; }
  .conn-tools, .conn-actions { grid-column: 1 / -1; }
}

/* Di động: bong bóng Trợ lý nằm trên thanh tab dưới, không đè lên */
@media (max-width: 760px) {
  .ast-fab { bottom: calc(70px + env(safe-area-inset-bottom)); }
  .ast-panel { bottom: calc(136px + env(safe-area-inset-bottom)); }
}
@media (max-width: 520px) { .ast-fab { right: 14px; bottom: calc(70px + env(safe-area-inset-bottom)); } .ast-panel { bottom: 0; height: 100%; } }

@media (max-width: 760px) { .ast-fab { display: none; } .ast-panel { right: 0; left: 0; bottom: 0; width: 100%; height: 100dvh; border-radius: 0; } }

/* Khung "Có gì mới" (whatsnew.js) */
#whatsnew { position: fixed; inset: 0; z-index: 100; background: rgba(15, 25, 35, .45); display: flex; align-items: center; justify-content: center; padding: 16px; }
#whatsnew .wn { background: var(--bg-surface, #fff); color: var(--text, #1d2733); width: min(560px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.3); overflow: hidden; }
#whatsnew .wn-h { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; background: #3F7CA5; color: #fff; font-size: 16px; }
#whatsnew .wn-x { border: 0; background: none; color: #fff; font-size: 22px; cursor: pointer; line-height: 1; }
#whatsnew .wn-b { overflow-y: auto; padding: 6px 18px 4px; }
#whatsnew section { padding: 10px 0; border-bottom: 1px solid rgba(127, 166, 201, .3); }
#whatsnew section:last-child { border-bottom: 0; }
#whatsnew .wn-d { font-size: 11.5px; color: var(--text-muted, #7a8794); }
#whatsnew h3 { margin: 2px 0 6px; font-size: 14.5px; }
#whatsnew ul { margin: 0; padding-left: 18px; font-size: 13.5px; line-height: 1.5; }
#whatsnew .wn-f { padding: 12px 18px; display: flex; justify-content: flex-end; }
#whatsnew .wn-ok { border: 0; border-radius: 8px; padding: 9px 18px; background: #3F7CA5; color: #fff; font: inherit; font-weight: 600; cursor: pointer; }

/* Nhắc cài app (điện thoại) */
.install-toast { position: fixed; left: 12px; right: 12px; bottom: calc(14px + env(safe-area-inset-bottom)); z-index: 60; display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--bg-surface); color: var(--text); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); animation: sheet-up .2s ease-out; }
.install-toast img { border-radius: 10px; flex: none; }
.install-toast div { flex: 1; min-width: 0; display: grid; gap: 1px; line-height: 1.3; }
.install-toast div span { color: var(--text-muted); font-size: 12.5px; }
.install-toast .btn-primary { padding: 8px 12px; flex: none; }
.install-toast .btn-ghost { flex: none; }
@media (min-width: 761px) { .install-toast { left: auto; right: 16px; bottom: 16px; width: 420px; } }
@media (hover: hover) and (pointer: fine) { .install-toast { display: none; } }

/* ---------- Máy tính bảng (iPad...): thanh trên gọn lại, nút to đủ chạm, chừa tai thỏ / thanh home ---------- */
.bar { padding-top: env(safe-area-inset-top); padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
.stage { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); padding-bottom: env(safe-area-inset-bottom); }
@media (min-width: 761px) and (max-width: 1180px) {
  .bar { gap: 10px; }
  .brand { font-size: 16px; }
  .tool { padding: 8px 10px; gap: 6px; }
  .who { display: none; }
  .bar-right { gap: 8px; }
}
@media (pointer: coarse) {
  body { -webkit-tap-highlight-color: transparent; }
  .tool, .btn-ghost, .seg-btn { min-height: 42px; }
  .conn-row .btn-ghost.sm { min-height: 38px; }
  input, select, textarea { font-size: 16px; }   /* iOS không tự phóng to khi bấm vào ô nhập */
}

/* ---------- menu trái: rail nhóm + panel công cụ (máy tính) ---------- */
/* Mặc định thu gọn: chỉ còn dải icon 48px. Rê chuột (hoặc Tab) vào thì rail mở rộng và panel công cụ hiện đè lên nội dung;
   chọn xong một công cụ thì thu lại ngay, tới khi chuột rời khỏi menu rồi vào lại. */
.shell { grid-template-columns: 48px minmax(0, 1fr); }
.shell .bar { grid-column: 1 / -1; }
.side { grid-column: 1; grid-row: 2; min-height: 0; position: relative; z-index: 30; }
.shell .stage { grid-column: 2; grid-row: 2; }
.rail { position: absolute; top: 0; bottom: 0; left: 0; z-index: 2; width: 48px; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 0; background: var(--bg-surface); border-right: 1px solid var(--border); overflow: hidden; transition: width .15s ease; }
.rail-b { position: relative; width: 40px; height: 40px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding: 0; border: 0; border-radius: var(--radius); background: transparent; color: var(--text-muted); font-size: 10px; font-weight: 600; line-height: 1.15; text-align: center; }
.rail-b span { display: none; }
.side:not([data-closed]):hover .rail, .side:not([data-closed]):focus-within .rail , .side.is-open:not([data-closed]) .rail { width: 68px; overflow-y: auto; scrollbar-width: none; }
.side:not([data-closed]):hover .rail::-webkit-scrollbar, .side:not([data-closed]):focus-within .rail::-webkit-scrollbar , .side.is-open:not([data-closed]) .rail::-webkit-scrollbar { display: none; }
.side:not([data-closed]):hover .rail-b, .side:not([data-closed]):focus-within .rail-b , .side.is-open:not([data-closed]) .rail-b { width: 56px; height: auto; padding: 8px 0 6px; justify-content: flex-start; }
.side:not([data-closed]):hover .rail-b span, .side:not([data-closed]):focus-within .rail-b span , .side.is-open:not([data-closed]) .rail-b span { display: block; }
.rail-b svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.rail-b:hover { background: var(--bg-hover); color: var(--text); }
.rail-b[aria-current="true"] { background: var(--brand-soft); color: var(--brand); }
.rail-b:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.rail-b[hidden] { display: none; }
.rail-b .tool-n--grp { position: absolute; top: 0; right: 0; min-width: 16px; height: 16px; line-height: 16px; font-size: 10px; padding: 0 4px; }
.side:not([data-closed]):hover .rail-b .tool-n--grp, .side:not([data-closed]):focus-within .rail-b .tool-n--grp , .side.is-open:not([data-closed]) .rail-b .tool-n--grp { top: 2px; right: 4px; }
.side .tools { position: absolute; top: 0; bottom: 0; left: 68px; z-index: 1; width: 208px; flex-direction: column; gap: 2px; padding: 14px 8px 12px; background: var(--bg-bar); border-right: 1px solid var(--border); box-shadow: var(--shadow); overflow-x: hidden; overflow-y: auto; scrollbar-width: thin; opacity: 0; visibility: hidden; transform: translateX(-8px); transition: opacity .15s ease, transform .15s ease, visibility 0s .15s; }
.side:not([data-closed]):hover .tools, .side:not([data-closed]):focus-within .tools , .side.is-open:not([data-closed]) .tools { opacity: 1; visibility: visible; transform: none; transition-delay: 0s; }
@media (prefers-reduced-motion: reduce) { .rail, .side .tools { transition: none; } }
.panel-h { margin: 0 10px 8px; font-size: 15px; font-weight: 700; color: var(--text); }
.grp { display: none; }
.grp.is-on { display: block; }
.grp[hidden] { display: none; }
.grp-b { display: flex; flex-direction: column; gap: 2px; }
.side .tool { width: 100%; justify-content: flex-start; padding: 8px 10px; font-weight: 500; border-color: transparent; }
.side .tool.active { font-weight: 600; }
.side .tool .tool-n { margin-left: auto; }
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; }
  .shell .stage { grid-column: 1; }
}

/* Công cụ trong panel: ô icon mang màu đại diện của công cụ đó (tokens: [data-page]) */
.side .tool { gap: 10px; }
.tile { width: 26px; height: 26px; border-radius: 8px; flex: none; display: grid; place-items: center; background: var(--page-fill); }
.tile svg { width: 15px; height: 15px; fill: none; stroke: #fff; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.side .tool:hover { background: var(--bg-hover); }
.side .tool.active { background: var(--page-soft); color: var(--page-strong); }

/* Bảng chọn công cụ trên điện thoại: chia theo nhóm như menu máy tính */
.sheet-gh { grid-column: 1 / -1; margin: 10px 2px 0; font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--text-muted); }
.sheet-gh:first-child { margin-top: 0; }

/* Menu trái mở rộng (mặc định): luôn hiện mọi nhóm và công cụ, không cần rê chuột */
.side-tog { margin-top: auto; flex: none; }
.side-collapse { display: none; }
html[data-side="open"] .shell { grid-template-columns: 236px minmax(0, 1fr); }
html[data-side="open"] .rail { display: none; }
html[data-side="open"] .side .tools { left: 0; width: 236px; opacity: 1; visibility: visible; transform: none; box-shadow: none; transition: none; padding: 10px 8px 12px; }
html[data-side="open"] .panel-h { display: none; }
html[data-side="open"] .grp { display: block; margin-bottom: 8px; }
html[data-side="open"] .grp[hidden] { display: none; }
html[data-side="open"] .grp::before { content: attr(data-name); display: block; margin: 8px 10px 4px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); }
html[data-side="open"] .side .tool { padding: 6px 10px; }
html[data-side="open"] .side-collapse { display: block; width: calc(100% - 4px); margin: 8px 2px 0; padding: 8px 10px; border: 1px dashed var(--border); border-radius: var(--radius); background: transparent; color: var(--text-muted); font-size: 12.5px; text-align: left; cursor: pointer; }
html[data-side="open"] .side-collapse:hover { color: var(--text); background: var(--bg-hover); }
@media (max-width: 760px) { html[data-side="open"] .shell { grid-template-columns: minmax(0, 1fr); } }
