/* DataEnt Design System: nền tối phẳng, góc vuông, một màu nhấn #CF6679 */
:root {
  --page-bg: #121212;
  --card-bg: #171717;
  --table-head: #111111;
  --input-bg: #1F1F1F;
  --input-bg-hover: #232323;
  --input-bg-focus: #252525;
  --text: #E6EEF8;
  --text-input: #EAEAEA;
  --muted: #93A0AD;
  --dim: #777777;
  --accent: #CF6679;
  --ring: rgba(207, 102, 121, 0.25);
  --danger: #BE1E2D;
  --neutral: #9CA3AF;
  --hover-bg: rgba(255, 255, 255, 0.15);
  --border-subtle: rgba(255, 255, 255, 0.04);
  --table-border: rgba(255, 255, 255, 0.08);
  --input-border-hover: rgba(255, 255, 255, 0.12);
  --row-alt: rgba(255, 255, 255, 0.02);
  --row-divider: rgba(255, 255, 255, 0.05);

  --bar-h: 44px;

  /* Phần hiển thị code: JS ghi đè theo Cài đặt */
  --code-font: ui-monospace, 'Roboto Mono', Menlo, Consolas, monospace;
  --code-size: 15px;
  --code-lh: 1.7;
  --code-pad: 12px;
  --c-bg: #121212;
  --c-text: #E6EEF8;
  --c-punct: #777777;
  --c-tag: #CF6679;
  --c-attr: #93A0AD;
  --c-val: #8FB996;
  --c-comment: #5F6B76;
  --c-entity: #D9A86C;
  --c-cursor: #CF6679;
  --c-line: #777777;
}

* { box-sizing: border-box; border-radius: 0 !important; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; margin: 0; }
body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--page-bg);
  color: var(--text);
  font-family: 'Comfortaa', sans-serif;
  color-scheme: dark;
  overscroll-behavior: none;
  padding-top: env(safe-area-inset-top);
}
button, input, select { font-family: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: square; stroke-linejoin: miter; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ---------- Thanh trên ---------- */
#bar {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  height: var(--bar-h);
  background: var(--card-bg);
  user-select: none;
}
.ghost {
  flex: none;
  width: var(--bar-h);
  height: var(--bar-h);
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.2s;
}
.ghost:hover, .ghost:active { background: var(--hover-bg); color: var(--text); }
#title {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
}
#fname { overflow: hidden; text-overflow: ellipsis; }
#dot { flex: none; width: 7px; height: 7px; background: var(--accent); }
#dot[hidden] { display: none; }

/* Vạch tiến độ: nằm ở mép dưới thanh, cao 2px */
#progress { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: var(--table-border); }
#progress i { display: block; height: 100%; background: var(--accent); transform-origin: 0 50%; transform: scaleX(0); will-change: transform; }

/* ---------- Vùng code ---------- */
#main { position: relative; flex: 1; min-height: 0; background: var(--c-bg); }
#editor { height: 100%; }
#empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  pointer-events: none;
}
#empty[hidden] { display: none; }

.tk-punct { color: var(--c-punct); }
.tk-tag { color: var(--c-tag); }
.tk-attr { color: var(--c-attr); }
.tk-val { color: var(--c-val); }
.tk-comment { color: var(--c-comment); }
.tk-entity { color: var(--c-entity); }
.tk-text { color: var(--c-text); }
.tk-invalid { color: var(--danger); }

/* ---------- Nút ---------- */
.btn {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 8px 12px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn:hover, .btn:active { background: var(--accent); color: #fff; }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-danger:hover, .btn-danger:active { background: var(--danger); color: #fff; }
.btn-muted { border-color: var(--neutral); color: var(--neutral); }
.btn-muted:hover, .btn-muted:active { background: var(--neutral); color: #fff; }
.btn:disabled { opacity: 0.4; pointer-events: none; }
.btn-icon { width: 50px; height: 50px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }

/* ---------- Hai nút chuyển file ---------- */
#endnav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 10;
  display: flex;
  justify-content: space-between;
  padding: 0 12px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}
#endnav.show { opacity: 1; }
#endnav .nav-btn { background: var(--card-bg); pointer-events: none; }
#endnav.show .nav-btn { pointer-events: auto; }
#endnav .nav-btn:disabled { background: var(--card-bg); }

/* ---------- Ngăn file ---------- */
#overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
#overlay.on { opacity: 1; pointer-events: auto; }
#drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  width: min(86vw, 360px);
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  background: var(--card-bg);
  border-right: 1px solid var(--border-subtle);
  transform: translateX(-100%);
  visibility: hidden;
  transition: transform 0.2s, visibility 0s 0.2s;
}
#drawer.on {
  transform: none;
  visibility: visible;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
  transition: transform 0.2s;
}
.dhead { flex: none; display: flex; align-items: center; justify-content: space-between; padding-left: 15px; }
.dtitle { color: var(--accent); font-size: 17.6px; font-weight: 700; letter-spacing: 0.5px; }
.dsearch { flex: none; padding: 0 9px 9px; border-bottom: 1px solid var(--border-subtle); }

.txt {
  width: 100%;
  background: var(--input-bg);
  color: var(--text-input);
  border: 1px solid var(--table-border);
  padding: 10px 12px;
  font-size: 14px;
  transition: all 0.2s;
}
.txt:hover { background: var(--input-bg-hover); border-color: var(--input-border-hover); }
.txt:focus { background: var(--input-bg-focus); border-color: var(--accent); box-shadow: 0 0 2px 2px var(--ring); outline: none; }
.dsearch .txt { height: 44px; text-align: center; }
.txt[readonly] { color: var(--muted); }

#list { flex: 1; min-height: 0; margin: 0; padding: 0; list-style: none; overflow-y: auto; }
#list li {
  display: flex;
  align-items: center;
  gap: 13px;
  min-height: 44px;
  padding: 8px 15px;
  border-bottom: 1px solid var(--row-divider);
  font-size: 12.8px;
  cursor: pointer;
  transition: background 0.2s;
}
#list li:nth-child(even) { background: var(--row-alt); }
#list li:hover, #list li:active { background: var(--hover-bg); font-weight: 600; }
#list li.active { color: var(--accent); font-weight: 700; box-shadow: inset 2px 0 0 var(--accent); }
#list .info { flex: 1; min-width: 0; }
#list .nm, #list .fd { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#list .fd { margin-top: 2px; color: var(--dim); font-size: 0.8em; font-weight: 400; }
#list .sz { flex: none; color: var(--dim); font-size: 0.8em; font-weight: 400; }
#list .dd { flex: none; width: 7px; height: 7px; background: var(--accent); }
#list .none { justify-content: center; color: var(--muted); cursor: default; }
#list .none:hover { background: transparent; font-weight: 400; }

.dfoot {
  flex: none;
  padding: 9px;
  padding-bottom: calc(9px + env(safe-area-inset-bottom));
  background: var(--table-head);
  border-top: 2px solid #444444;
  text-align: center;
  font-size: 14.4px;
  font-weight: 700;
  color: #EEEEEE;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.05); }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.08); }

/* ---------- Cài đặt (modal) ---------- */
#modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(4px);
}
#modal[hidden] { display: none; }
.dialog {
  width: min(560px, 100%);
  max-height: 94dvh;
  overflow-y: auto;
  padding: 24px;
  background: var(--card-bg);
  border: 1px solid var(--border-subtle);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
}
.title { margin: 0 0 24px; text-align: center; color: var(--accent); font-size: 30px; font-weight: 700; }
.dialog h3 {
  margin: 24px 0 15px;
  padding-top: 15px;
  border-top: 1px solid var(--row-divider);
  color: var(--accent);
  font-size: 13.6px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.dialog h3:first-of-type { margin-top: 0; padding-top: 0; border-top: 0; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.full { grid-column: 1 / -1; }
.dialog label { display: block; margin-bottom: 5px; color: var(--accent); font-size: 13.6px; font-weight: 600; }
.dialog .txt { background: var(--input-bg-focus); }
.dialog select.txt { appearance: none; -webkit-appearance: none; }
.status { font-size: 13.6px; font-weight: 600; color: var(--dim); }
.status.ok { color: var(--accent); }
.actions, .foot { display: flex; justify-content: center; gap: 12px; }
.actions .btn, .foot .btn { min-width: 150px; }
.foot { margin-top: 32px; }
.checks { display: flex; flex-direction: column; justify-content: center; gap: 9px; }
.dialog label.check { display: flex; align-items: center; gap: 9px; margin: 0; color: var(--text); font-weight: 400; cursor: pointer; }
input[type=checkbox] {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 22px;
  height: 22px;
  margin: 0;
  background: var(--input-bg-focus);
  border: 1px solid var(--table-border);
  cursor: pointer;
  position: relative;
  transition: all 0.2s;
}
input[type=checkbox]:checked { background: var(--accent); border-color: var(--accent); }
input[type=checkbox]:checked::after {
  content: '';
  position: absolute;
  left: 6px;
  top: 2px;
  width: 6px;
  height: 12px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 30px; margin: 0; padding: 0; background: transparent; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 2px; background: var(--table-border); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 22px; margin-top: -10px; background: var(--accent); border: 0; }
input[type=range]::-moz-range-track { height: 2px; background: var(--table-border); }
input[type=range]::-moz-range-thumb { width: 14px; height: 22px; background: var(--accent); border: 0; }
input[type=color] { width: 100%; height: 40px; padding: 3px; background: var(--input-bg-focus); border: 1px solid var(--table-border); cursor: pointer; }

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 50;
  max-width: 60vw;
  padding: 9px 15px;
  background: var(--card-bg);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: 13.6px;
  font-weight: 700;
  text-align: center;
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
#toast.on { opacity: 1; }

/* ---------- Mobile ---------- */
@media (max-width: 768px) {
  .dialog { padding: 16px; }
  .title { font-size: 24px; margin-bottom: 15px; }
  .grid { grid-template-columns: 1fr; }
  .actions .btn, .foot .btn { min-width: 110px; font-size: 13px; }
  #toast { max-width: 52vw; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

@media (max-width: 768px) {
  #colors { grid-template-columns: 1fr 1fr; }
}
