:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --line: #dfe3e8;
  --text: #1c1e21;
  --muted: #65676b;
  --accent: #1877f2;
  --accent-dark: #1461c9;
  --ok: #1a7f37;
  --warn: #b45309;
  --err: #c0392b;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #18191a;
    --card: #242526;
    --line: #3a3b3c;
    --text: #e4e6eb;
    --muted: #b0b3b8;
    --accent: #2d88ff;
    --accent-dark: #1877f2;
    --ok: #4ade80;
    --warn: #fbbf24;
    --err: #f87171;
  }
}

* { box-sizing: border-box; }

/* Cac quy tac display ben duoi (label, .grid2, .modal, .chips...) manh hon
   [hidden] cua trinh duyet, nen phai ep lai o day — neu khong, moi thu dat
   thuoc tinh hidden van hien ra. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

header h1 { margin: 0; font-size: 18px; font-weight: 650; }
.head-right { display: flex; align-items: center; gap: 10px; }

main {
  max-width: 940px;
  margin: 0 auto;
  padding: 20px 16px 80px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.card h2 {
  margin: 0 0 14px;
  font-size: 16px;
  font-weight: 650;
  display: flex;
  align-items: center;
  gap: 10px;
}

.card h3 {
  margin: 20px 0 10px;
  font-size: 14px;
  font-weight: 650;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.step {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

label {
  display: block;
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

input[type=text], input[type=password], input[type=number],
input[type=search], input[type=datetime-local], select, textarea {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 9px 11px;
  font: inherit;
  font-weight: 400;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 7px;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

textarea { resize: vertical; }

.grid2, .grid3 { display: grid; gap: 0 14px; }
.grid2 { grid-template-columns: 1fr 1fr; }
.grid3 { grid-template-columns: 1fr 1fr 1fr; }

@media (max-width: 700px) {
  .grid2, .grid3 { grid-template-columns: 1fr; }
}

.pair { display: flex; align-items: center; gap: 8px; margin-top: 5px; }
.pair input { margin-top: 0; }
.pair span { color: var(--muted); }

button {
  padding: 9px 16px;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
}

button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: not-allowed; }

button.primary, #btn-save-settings, #btn-load {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
button.primary:hover:not(:disabled),
#btn-save-settings:hover:not(:disabled),
#btn-load:hover:not(:disabled) { background: var(--accent-dark); }

button.ghost { background: transparent; }
button.small { padding: 5px 10px; font-size: 13px; }

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.row input[type=search] { flex: 1; min-width: 180px; margin-top: 0; }

.chk {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 0 0 8px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
}
.chk input { width: auto; margin: 0; }
.chk.big { padding: 10px 12px; background: var(--bg); border-radius: 7px; }

.chips { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 12px; }

.hint { margin: 0 0 14px; font-size: 13px; color: var(--muted); }
.hint-inline { font-weight: 400; color: var(--muted); }

code {
  padding: 1px 5px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: .9em;
}

.msg { font-size: 13px; color: var(--muted); }
.msg.ok { color: var(--ok); }
.msg.err { color: var(--err); }

.pill {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.pill.ok { background: rgba(26,127,55,.14); color: var(--ok); }
.pill.warn { background: rgba(180,83,9,.14); color: var(--warn); }

/* --- danh sach tai khoan --- */
.picker {
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
}
.picker:empty { display: none; }

.acc {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.acc:last-child { border-bottom: 0; }
.acc:hover { background: var(--bg); }
.acc input { width: auto; margin: 0; }
.acc .name { flex: 1; font-size: 14px; }
.acc .meta { font-size: 12px; color: var(--muted); }
.acc .st { font-size: 11px; padding: 2px 7px; border-radius: 4px; background: var(--bg); }
.acc .st.bad { color: var(--err); }

/* --- tag / goi y --- */
.tagbox { position: relative; margin-top: 5px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.tags:empty { display: none; }
.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  font-size: 13px;
  font-weight: 500;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.tag button {
  padding: 0;
  width: 16px;
  height: 16px;
  line-height: 1;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 15px;
}
.tagbox input { margin-top: 0; }

.suggest {
  position: absolute;
  z-index: 10;
  left: 0;
  right: 0;
  max-height: 220px;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 7px;
  box-shadow: 0 6px 20px rgba(0,0,0,.15);
}
.suggest div { padding: 8px 11px; font-size: 14px; font-weight: 400; cursor: pointer; }
.suggest div:hover { background: var(--bg); }
.suggest .sub { font-size: 12px; color: var(--muted); }

/* --- upload --- */
.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tab { border-radius: 999px; }
.tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.drop {
  padding: 26px;
  margin-bottom: 14px;
  text-align: center;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  cursor: pointer;
}
.drop.small { padding: 16px; }
.drop:hover, .drop.over { border-color: var(--accent); color: var(--accent); }
.drop p { margin: 0; font-size: 14px; }
.drop img, .drop video { max-width: 260px; max-height: 200px; margin-top: 12px; border-radius: 7px; }

.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 12px; }
.bar.big { height: 10px; margin-bottom: 10px; }
.bar > div { height: 100%; width: 0; background: var(--accent); transition: width .25s; }

/* --- ket qua --- */
pre {
  max-height: 380px;
  overflow: auto;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.res {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  margin-bottom: 6px;
  font-size: 14px;
  background: var(--bg);
  border-left: 3px solid var(--ok);
  border-radius: 5px;
}
.res.bad { border-left-color: var(--err); }
.res .grow { flex: 1; }
.res a { color: var(--accent); }
.res .why { font-size: 13px; color: var(--err); }

details summary { cursor: pointer; font-size: 13px; color: var(--muted); margin-top: 10px; }

/* --- hang nguoi dung / nhom token trong trang quan tri --- */
.urow {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 13px;
  margin-bottom: 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 7px;
}
.urow.off { opacity: .55; }
.urow .grow { flex: 1; min-width: 0; }
.urow .meta { margin-top: 3px; font-size: 12px; color: var(--muted); }
.urow .acts { display: flex; flex-wrap: wrap; gap: 6px; }

nav.tabs { margin-bottom: 4px; }

/* --- bang nhat ky --- */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td {
  padding: 7px 9px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.tbl th { font-weight: 650; color: var(--muted); white-space: nowrap; }
.tbl td:nth-child(4) { word-break: break-word; }

/* --- hop thoai phan quyen --- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, .5);
}
.modal-box {
  width: min(760px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  margin: 0;
}
.modal-box .picker { max-height: 46vh; }

.hint.err { color: var(--err); }

/* --- dashboard --- */
main.wide { max-width: 1500px; }

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.tile {
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.tile .lbl { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.tile strong { font-size: 19px; font-weight: 650; }

/* Cuon trong khung bang -> hang tieu de dinh o day, khong bi thanh header
   cua trang (cung sticky) che mat. */
.tbl-wrap {
  max-height: 68vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.tbl-wrap .tbl { min-width: 1100px; }
.tbl thead th {
  position: sticky;
  top: 0;
  background: var(--card);
  z-index: 2;
  white-space: nowrap;
}
.tbl td { vertical-align: middle; }
.tbl td.r, .tbl th.r { text-align: right; }
.tbl tbody tr:hover { background: var(--bg); }
.tbl .w-name {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tbl .meta { font-size: 11px; color: var(--muted); }

/* cong tac bat/tat */
.sw {
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .03em;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--muted);
}
.sw.on { background: rgba(26,127,55,.16); border-color: transparent; color: var(--ok); }
.sw:hover:not(:disabled) { border-color: var(--accent); }

.linkish {
  padding: 2px 6px;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  text-decoration: underline dotted;
}

/* --- danh sach nhieu file creative --- */
.assets { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.assets:empty { display: none; }
.asset {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.asset .thumb {
  width: 52px; height: 52px;
  object-fit: cover;
  border-radius: 5px;
  background: var(--line);
  flex: none;
}
.asset .grow { flex: 1; min-width: 0; }
.asset .fname {
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.asset .meta { font-size: 12px; color: var(--muted); }
.asset .no { font-size: 12px; font-weight: 700; color: var(--muted); }
