/* Giao dien app QLTK - mobile first, 1 cot, khong phu thuoc framework.
   Quan trong: [hidden] phai THANG moi class ben duoi (nhieu khoi dung
   display:flex), neu khong man hinh dang nhap se hien chong len app. */
[hidden] { display: none !important; }

:root {
  --bg: #0f172a;
  --bg2: #16213c;
  --card: #1e293b;
  --card2: #273449;
  --line: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary: #2563eb;
  --primary2: #1d4ed8;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

body { padding-bottom: env(safe-area-inset-bottom); }

h1, h2, h3 { margin: 0 0 6px; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.98rem; }
p { margin: 6px 0; }
code { background: var(--bg2); padding: 1px 5px; border-radius: 4px; font-size: 0.85em; }

.muted { color: var(--muted); }
.small { font-size: 0.83rem; }
.center { text-align: center; }
.err { color: #fca5a5; font-size: 0.88rem; }

/* ------------------------------------------------------- man hinh dau */
#login-screen, #boot-error { padding: 24px 18px; }
.boot-box {
  max-width: 420px;
  margin: 8vh auto 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: center;
}
.boot-icon { font-size: 2.6rem; }

/* --------------------------------------------------------- thanh tren */
#topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--bg2);
  border-bottom: 1px solid var(--line);
}
#topbar-title { flex: 1; font-weight: 600; }
#online-badge {
  font-variant-numeric: tabular-nums;
  background: var(--card2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.82rem;
  color: var(--muted);
}

main { padding: 12px; max-width: 720px; margin: 0 auto; }

/* --------------------------------------------------------- nut bam */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card2);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:active { background: var(--primary2); }
.btn.danger { background: #7f1d1d; border-color: #991b1b; color: #fee2e2; }
.btn.block { width: 100%; }
.btn.link { background: none; border: none; color: var(--muted); text-decoration: underline; min-height: 34px; }
.btn:disabled { opacity: 0.55; }

.icon-btn {
  min-width: 38px;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: none;
  color: var(--text);
  font-size: 1.15rem;
  font-family: inherit;
  cursor: pointer;
}
.icon-btn:active { background: var(--card2); }

.row { display: flex; gap: 8px; align-items: center; margin: 10px 0; }
.row > .btn { flex: 1; }
.row > input { flex: 1; min-width: 0; }

/* Dong ghi chu trong man setup (muc tu chay trong nhanqua / chua auto). */
.info-line { margin: 8px 0 2px; padding-left: 4px; line-height: 1.4; }

/* Day button mo tung man Setup (schema.screens): xuong dong, 3 nut/hang. */
.screens-row { flex-wrap: wrap; }
.screens-row > .btn { flex: 1 1 30%; min-width: 96px; }

/* Chip shop trong man setup (mo trang luoi vat pham cua 1 tab). */
.shop-chip { width: 100%; margin: 4px 0; }

input {
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 0.95rem;
  font-family: inherit;
}
input:focus { outline: none; border-color: var(--primary); }

/* select dung chung giao dien input (o chon loai acc, vat pham uu tien) */
select {
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 0.95rem;
  font-family: inherit;
}
select:focus { outline: none; border-color: var(--primary); }
.field select { margin-top: 4px; }
.action select { margin-top: 6px; flex: 1; min-width: 0; }
.action .action-value-row { display: flex; gap: 8px; align-items: center; }

/* Hang setup gop cong tac + o input / 2 nut cung 1 dong (schema "row"):
   vd nut "Auto nhiem vu dan duoc" + o "So NV/ngay"; "Tam gioi bat dau"
   + "Dung"; "Than the bat dau" + "Dung". */
.setup-row { flex-wrap: wrap; }
.setup-row > .toggle { flex: 1.2; margin: 0; }
.setup-row > .action { flex: 1; margin: 0; min-width: 0; }
.setup-row > button { flex: 1; }

/* badge "watcher" tren the acc trong danh sach */
.acc-kind {
  margin-left: 6px;
  padding: 2px 8px;
  font-size: 0.68rem;
  border-radius: 999px;
  cursor: default;
}

/* ------------------------------------------------ man hinh "Chuot" */
.chuot-gio-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 6px;
}
.chuot-gio-row input { flex: 1; min-width: 0; }
.chuot-gio-row .abtn { width: auto; min-height: 40px; flex: none; }
.chuot-gio-label { font-size: 0.85rem; color: var(--muted); white-space: nowrap; }
.chuot-window {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  margin: 4px 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.chuot-window-time { flex: 1; font-size: 0.95rem; }
.muted-strong { color: var(--text); font-weight: 600; margin: 6px 0 0; }

/* log lich su thu cua man hinh "Chuot" */
.chuot-log {
  margin: 4px 0 0;
  max-height: 180px;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 10px;
}
.chuot-log-line {
  font-size: 0.8rem;
  line-height: 1.5;
  word-break: break-word;
  color: var(--muted);
}

/* --------------------------------------------------------- the / card */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin: 10px 0;
}
.card-head { display: flex; align-items: center; gap: 8px; }
.card-head h2, .card-head h3 { flex: 1; margin: 0; }

.view-head { display: flex; align-items: center; gap: 8px; margin: 4px 0 8px; }
.view-head h2 { flex: 1; margin: 0; }

/* ------------------------------------------------- danh sach acc */
#add-form { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin: 10px 0; display: flex; flex-direction: column; gap: 8px; }
#add-form .row { margin: 2px 0 0; }

.acc {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin: 10px 0;
}
.acc-main { cursor: pointer; }
.acc-title { display: flex; align-items: center; gap: 7px; font-weight: 600; }
.acc-sub { color: var(--muted); font-size: 0.83rem; }
.acc-acts { display: flex; gap: 8px; }
.acc-acts .btn { flex: 1; min-height: 38px; font-size: 0.88rem; padding: 6px 8px; }

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}
.dot.online { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot.disconnected { background: var(--amber); }
.dot.offline { background: #64748b; }

/* ------------------------------------------------------------- setup */
.tgroup { margin: 12px 0; }
.tgroup > h3 { margin: 0 0 6px; color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.03em; }

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin: 6px 0;
  cursor: pointer;
}
.toggle input {
  /* An nhung VAN duoc render: neu dung display:none thi trinh duyet coi
     nhu khong render -> bam vao nhan/switch khong con kich hoat checkbox
     (va Playwright cung khong bam duoc). */
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  pointer-events: none;
}
.toggle .switch {
  flex: none;
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: #475569;
  position: relative;
  transition: background 0.15s;
}
.toggle .switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: left 0.15s;
}
.toggle input:checked + .switch { background: var(--primary); }
.toggle input:checked + .switch::after { left: 21px; }
.toggle .tlabel { flex: 1; }
.toggle .tnote { display: block; color: var(--muted); font-size: 0.78rem; }
.toggle .running {
  font-size: 0.72rem;
  color: var(--green);
  border: 1px solid var(--green);
  border-radius: 999px;
  padding: 1px 7px;
}

.action {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 6px 0;
}
.action input { margin-top: 6px; }
.action .abtn { width: 100%; min-height: 40px; }
/* select trong the action (vd "Gửi" vat pham uu tien): duong hang select + nut */
.action .action-value-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 6px;
}
.action .action-value-row select { flex: 1; min-width: 0; margin: 0; }
.action .action-value-row .abtn { width: auto; min-height: 40px; }

/* bang "Chuot (phuc dia) - lv toi thieu" */
.min-table { margin: 6px 0; }
.min-table .action { display: flex; align-items: center; gap: 8px; padding: 8px 10px; }
.min-table .min-name { flex: 1; font-size: 0.9rem; }
.min-table .action input { margin: 0; width: 76px; flex: none; }

/* man hinh "Shop": danh sach hang shop theo DANG LUOI (ten + gia + gioi
   han + o so luong/o tich mua, KHONG co hinh anh) - 2 cot tren dien
   thoai, tu gom lai 1 cot khi man hinh hep. */
.shop-items {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 6px 0;
}
@media (max-width: 340px) {
  .shop-items { grid-template-columns: 1fr; }
}
.shop-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.shop-item-main { min-width: 0; }
.shop-item-name { font-size: 0.92rem; word-break: break-word; }
.shop-item-meta { margin-top: 2px; }
.shop-item input { margin: 0; width: 86px; flex: none; }
.shop-item input.shop-check { width: auto; }
.shop-item .shop-bctrl { display: flex; align-items: center; gap: 6px; }

/* --------------------------------------------------------------- log */
#log-box {
  background: #05080f;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  height: 62vh;
  overflow-y: auto;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.76rem;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
}
#log-box .line { padding: 1px 0; border-bottom: 1px solid rgba(148, 163, 184, 0.08); }

/* ------------------------------------------------- thong tin nhan vat */
.info-row { display: flex; gap: 10px; padding: 5px 0; border-bottom: 1px solid rgba(148, 163, 184, 0.12); }
.info-row .k { color: var(--muted); flex: 0 0 46%; }
.info-row .v { flex: 1; text-align: right; font-weight: 600; }
#info-body pre { margin: 0; white-space: pre-wrap; word-break: break-word; font-size: 0.82rem; }

/* ------------------------------------------------- overlay / popup */
#modal, #report, #sheet, #acc-menu {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(2, 6, 23, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.panel, .sheet-panel {
  width: 100%;
  max-width: 460px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}
.panel-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.panel-head > h3, .panel-head > span { flex: 1; margin: 0; font-weight: 600; }
#report-body { margin: 0; white-space: pre-wrap; word-break: break-word; font-size: 0.82rem; font-family: ui-monospace, Consolas, monospace; }

.field { display: block; margin: 8px 0; font-size: 0.85rem; color: var(--muted); }
.field input { margin-top: 4px; color: var(--text); }

.sheet-panel { display: flex; flex-direction: column; gap: 6px; }
.sheet-item {
  display: block;
  width: 100%;
  text-align: left;
  min-height: 46px;
  padding: 10px 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  cursor: pointer;
}
.sheet-item.danger { color: #fecaca; border-color: #7f1d1d; }

/* ------------------------------------------------------------ toast */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  max-width: 92vw;
  padding: 10px 16px;
  background: rgba(15, 23, 42, 0.97);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.45);
  font-size: 0.9rem;
  text-align: center;
}
