:root{
  --bg1:#060B14;
  --bg2:#0B1020;
  --border: rgba(255,255,255,.12);
  --text: rgba(255,255,255,.92);
  --muted: rgba(255,255,255,.62);

  --shadow: 0 18px 45px rgba(0,0,0,.35);
  --shadow2: 0 10px 24px rgba(0,0,0,.25);

  --grad1: #7c3aed;
  --grad2: #06b6d4;
  --grad3: #22c55e;

  --btn: rgba(255,255,255,.08);
  --btn-border: rgba(255,255,255,.14);

  --hl-low: rgba(250, 204, 21, .16);
  --hl-med: rgba(248, 113, 113, .18);
  --hl-high: rgba(248, 113, 113, .26);

  --radius: 18px;
}

*{box-sizing:border-box}
html,body{height:100%}

body{
  margin:0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, "Noto Sans", "Liberation Sans", sans-serif;
  background: radial-gradient(1200px 900px at 15% 10%, rgba(124,58,237,.22), transparent 60%),
              radial-gradient(900px 700px at 85% 30%, rgba(6,182,212,.18), transparent 55%),
              radial-gradient(1100px 800px at 50% 95%, rgba(34,197,94,.14), transparent 55%),
              linear-gradient(180deg, var(--bg1), var(--bg2));
  color: var(--text);
  color-scheme: dark;
}

.bg-blur{
  position: fixed;
  width: 520px;
  height: 520px;
  filter: blur(50px);
  opacity: .35;
  z-index: -1;
}
.bg-blur.b1{ left:-140px; top:-120px; background: radial-gradient(circle, rgba(124,58,237,.8), transparent 60%); }
.bg-blur.b2{ right:-140px; top:120px; background: radial-gradient(circle, rgba(6,182,212,.8), transparent 60%); }

.shell{
  max-width: 1220px;
  margin: 26px auto;
  padding: 0 16px 18px;
}

/* hero */
.hero{
  display:flex;
  gap: 16px;
  align-items: flex-end;
  justify-content: space-between;
  padding: 18px 18px 14px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,.07), rgba(255,255,255,.04));
  border-radius: var(--radius);
  box-shadow: var(--shadow2);
  backdrop-filter: blur(10px);
}
.badge{
  display:inline-flex;
  align-items:center;
  gap:10px;
  padding: 7px 12px;
  border: 1px solid rgba(255,255,255,.16);
  background: rgba(255,255,255,.06);
  border-radius: 999px;
  font-weight: 800;
  font-size: 12px;
  color: rgba(255,255,255,.78);
}
.badge .dot{
  width:8px;height:8px;border-radius:999px;
  background: linear-gradient(90deg, var(--grad1), var(--grad2));
  box-shadow: 0 0 0 4px rgba(124,58,237,.15);
}
.hero-title{
  margin: 10px 0 8px;
  font-size: 34px;
  line-height: 1.05;
  letter-spacing: -0.5px;
  font-weight: 900;
}
.grad{
  background: linear-gradient(90deg, var(--grad1), var(--grad2), var(--grad3));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero-sub{
  margin: 0;
  color: var(--muted);
  max-width: 760px;
  font-size: 13.5px;
  line-height: 1.55;
}
.hero-right{
  display:flex;
  gap: 10px;
  align-items: stretch;
}
.stat{
  min-width: 150px;
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.05);
  border-radius: 14px;
}
.stat-label{
  font-size: 11px;
  color: var(--muted);
  font-weight: 800;
}
.stat-value{
  margin-top: 6px;
  font-size: 16px;
  font-weight: 900;
}

/* layout */
.grid{
  margin-top: 14px;
  display:grid;
  grid-template-columns: 1.7fr 1fr;
  gap: 14px;
}

/* Fixed-height panels */
.panel{
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,.065), rgba(255,255,255,.04));
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  overflow:hidden;
  display:flex;
  flex-direction:column;

  height: 72vh;
  min-height: 620px;
  max-height: 860px;
}

.panel-head{
  display:flex;
  justify-content: space-between;
  align-items:flex-start;
  gap: 12px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid rgba(255,255,255,.10);
}
.panel-title{
  font-size: 13px;
  letter-spacing: .6px;
  font-weight: 900;
  text-transform: uppercase;
}
.panel-desc{
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}

/* controls row (classic style) */
.controls{
  display:flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  max-width: 760px;
}
.ph-left{ min-width: 220px; }

.chip{
  display:inline-flex;
  align-items:center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.05);
  font-size: 12px;
  font-weight: 900;
  color: rgba(255,255,255,.85);
  white-space: nowrap;
}
.chipBtn{ cursor:pointer; user-select:none; }

.chip select{
  appearance:none;
  -webkit-appearance:none;
  -moz-appearance:none;

  border: 1px solid rgba(255,255,255,.14);
  background: rgba(0,0,0,.22);
  color: rgba(255,255,255,.92);
  font-weight: 900;
  border-radius: 999px;
  padding: 6px 28px 6px 10px;
  cursor: pointer;
  outline: none;
  min-width: 160px;

  background-image:
    linear-gradient(45deg, transparent 50%, rgba(255,255,255,.75) 50%),
    linear-gradient(135deg, rgba(255,255,255,.75) 50%, transparent 50%);
  background-position:
    calc(100% - 14px) 55%,
    calc(100% - 9px) 55%;
  background-size:
    5px 5px,
    5px 5px;
  background-repeat: no-repeat;
}
.chip select:focus{
  border-color: rgba(6,182,212,.35);
  box-shadow: 0 0 0 4px rgba(6,182,212,.12);
}
option{ background:#0b1220; color: rgba(255,255,255,.92); }


/* upload */
.fileInput{ display:none; }
.fileChip{ cursor:pointer; user-select:none; }
.fileName{
  display:inline-block;
  max-width: 140px;
  overflow:hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: .8;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(0,0,0,.20);
  padding: 4px 8px;
  border-radius: 999px;
}

/* Sticky action bar */
.editor-actions{
  position: sticky;
  top: 10px;
  z-index: 30;

  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;

  margin: 10px 10px 0;
  padding: 10px 12px;

  border-radius: 16px;
  border: 1px solid rgba(255,255,255,.14);
  background: linear-gradient(180deg, rgba(0,0,0,.28), rgba(0,0,0,.12));
  backdrop-filter: blur(10px);
  box-shadow: 0 18px 35px rgba(0,0,0,.25);
}
.editor-actions .left,
.editor-actions .right{
  display:flex;
  align-items:center;
  gap: 10px;
}

/* editor */
.editor-wrap{
  position:relative;
  flex: 1;
  min-height: 0;
}
.editorBox{
  height: 100%;
  padding: 14px 16px 16px;
  overflow:auto;

  font-size: 14px;
  line-height: 26px;
  font-weight: 500;

  outline: none;
  border: 0;
  color: rgba(255,255,255,.92);

  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;

  scrollbar-gutter: stable both-edges;
  font-variant-ligatures: none;
  font-feature-settings: "liga" 0, "clig" 0;
  scroll-behavior: smooth;
}
.editorBox:empty::before{
  content: attr(data-placeholder);
  color: rgba(255,255,255,.35);
}
.editorBox:focus{
  box-shadow: inset 0 0 0 2px rgba(6,182,212,.25);
  border-radius: 12px;
}
.editorBox.dragover{
  box-shadow: inset 0 0 0 2px rgba(34,197,94,.35);
  border-radius: 12px;
  background: rgba(34,197,94,.06);
}

/* highlight */
.m{ border-radius: 4px; box-shadow: inset 0 -2px 0 rgba(248,113,113,.65); }
.low{ background: var(--hl-low); box-shadow: inset 0 -2px 0 rgba(250,204,21,.65); }
.med{ background: var(--hl-med); box-shadow: inset 0 -2px 0 rgba(248,113,113,.65); }
.high{ background: var(--hl-high); box-shadow: inset 0 -2px 0 rgba(248,113,113,.85); }

/* goto pulse */
.jumpPulse{
  animation: jumpPulse .9s ease;
  outline: 2px solid rgba(6,182,212,.85);
  outline-offset: 3px;
  border-radius: 6px;
}
@keyframes jumpPulse{
  0%   { filter: brightness(1); transform: translateY(0); }
  40%  { filter: brightness(1.25); transform: translateY(-1px); }
  100% { filter: brightness(1); transform: translateY(0); }
}

/* buttons */
.btn{
  border-radius: 14px;
  border: 1px solid var(--btn-border);
  background: var(--btn);
  color: rgba(255,255,255,.9);
  padding: 10px 14px;
  font-weight: 900;
  cursor:pointer;
  transition: transform .12s ease, border-color .12s ease, opacity .12s ease;
  display:inline-flex;
  align-items:center;
  gap: 8px;
}
.btn:hover{ transform: translateY(-1px); border-color: rgba(255,255,255,.22); }
.btn:active{ transform: translateY(0px) scale(.99); }
.btn:disabled{ opacity: .55; cursor:not-allowed; transform:none; }
.btn.primary{
  border-color: rgba(255,255,255,.22);
  background: linear-gradient(90deg, rgba(124,58,237,.9), rgba(6,182,212,.9));
  box-shadow: 0 18px 30px rgba(124,58,237,.18);
}
.btn.ghost{ background: rgba(255,255,255,.05); }
.btn-icon{ filter: drop-shadow(0 8px 12px rgba(0,0,0,.35)); }

/* result */
.out{
  padding: 14px;
  overflow:auto;
  flex: 1;
  min-height: 0;
}
.empty{
  height:100%;
  display:flex;
  flex-direction:column;
  justify-content:center;
  align-items:center;
  color: var(--muted);
  gap: 10px;
  text-align:center;
  padding: 24px 8px;
}
.spark{
  font-size: 30px;
  width: 56px;
  height: 56px;
  display:grid;
  place-items:center;
  border-radius: 16px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.10);
}
.empty-title{ color: rgba(255,255,255,.92); font-weight: 900; }
.empty-sub{ font-size: 12px; max-width: 320px; line-height: 1.5; }

.card{
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.045);
  border-radius: 16px;
  padding: 12px;
  margin-bottom: 10px;
}
.row{ display:flex; align-items:center; justify-content: space-between; gap: 10px; }
.badge2{
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.05);
  color: rgba(255,255,255,.72);
  font-weight: 900;
  white-space: nowrap;
}
.kv{ margin-top: 8px; font-size: 13px; color: rgba(255,255,255,.86); line-height: 1.45; }
.kv b{ color: rgba(255,255,255,.65); font-weight: 900; margin-right: 6px; }
.kv pre{
  margin: 8px 0 0;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(0,0,0,.20);
  color: rgba(255,255,255,.86);
  overflow:auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.actions{ display:flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.small{
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.05);
  color: rgba(255,255,255,.9);
  border-radius: 12px;
  padding: 8px 10px;
  cursor:pointer;
  font-weight: 900;
  transition: transform .12s ease, border-color .12s ease;
}
.small:hover{ transform: translateY(-1px); border-color: rgba(255,255,255,.22); }
.small.primary{
  background: rgba(6,182,212,.14);
  border-color: rgba(6,182,212,.28);
}

/* footer */
.footer{
  margin-top: 14px;
  display:flex;
  justify-content: space-between;
  gap: 10px;
  align-items:center;
  padding: 12px 4px;
  color: var(--muted);
  font-size: 12px;
}
.footer-note{ display:flex; align-items:center; gap: 8px; }
.warn{
  width: 22px;height: 22px;
  display:grid;place-items:center;
  border-radius: 8px;
  background: rgba(250,204,21,.12);
  border: 1px solid rgba(250,204,21,.2);
}
.footer-coffee{
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.05);
}

/* Coffee button */
.coffeeBtn{
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
}
.coffeeBtn .coffeeHint{
  font-size: 11px;
  font-weight: 900;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(0,0,0,.18);
  color: rgba(255,255,255,.82);
}

/* Modal */
.modal{ position: fixed; inset: 0; display: none; z-index: 9999; }
.modal.show{ display: block; }
.modal-backdrop{
  position: absolute; inset: 0;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(8px);
}
.modal-card{
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, calc(100vw - 24px));
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,.14);
  background: linear-gradient(180deg, rgba(255,255,255,.075), rgba(255,255,255,.04));
  box-shadow: 0 30px 80px rgba(0,0,0,.55);
  overflow: hidden;
}
.modal-head{ padding: 16px 16px 12px; border-bottom: 1px solid rgba(255,255,255,.10); }
.modal-title{ font-weight: 900; font-size: 18px; letter-spacing: -.2px; }
.modal-sub{ margin-top: 6px; color: rgba(255,255,255,.68); font-size: 12.5px; line-height: 1.5; }
.modal-close{
  position: absolute; top: 10px; right: 10px;
  width: 38px; height: 38px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(0,0,0,.20);
  color: rgba(255,255,255,.88);
  cursor: pointer;
  font-weight: 900;
}
.modal-close:hover{ border-color: rgba(255,255,255,.24); }
.modal-body{ padding: 14px 16px 16px; display: grid; gap: 12px; }
.seg{ display:flex; gap: 10px; flex-wrap: wrap; }
.segItem{
  display:flex; align-items:center; gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(0,0,0,.14);
  cursor: pointer;
  user-select: none;
  font-weight: 900;
}
.segItem input{ accent-color: rgba(6,182,212,.9); }
.field{ display:grid; gap: 6px; }
.fieldLabel{ font-size: 12px; font-weight: 900; color: rgba(255,255,255,.78); }
.fieldInput{
  width: 100%;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(0,0,0,.22);
  color: rgba(255,255,255,.92);
  outline: none;
}
.fieldInput:focus{
  border-color: rgba(6,182,212,.35);
  box-shadow: 0 0 0 4px rgba(6,182,212,.12);
}
.fieldHelp{ font-size: 12px; color: rgba(255,255,255,.6); line-height: 1.45; }
.modalActions{ display:flex; gap: 10px; justify-content: flex-end; margin-top: 2px; }

/* QR */
.qrWrap{ display: grid; gap: 12px; padding: 16px; }
.qrFrame{
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,.14);
  background: radial-gradient(600px 220px at 20% 0%, rgba(124,58,237,.18), transparent 60%),
              radial-gradient(520px 240px at 90% 20%, rgba(6,182,212,.14), transparent 55%),
              rgba(0,0,0,.18);
  padding: 14px;
  display: grid;
  place-items: center;
}
.qrImg{
  width: min(360px, 100%);
  aspect-ratio: 1 / 1;
  object-fit: contain;
  border-radius: 16px;
  background: #fff;
  padding: 12px;
  box-shadow: 0 18px 35px rgba(0,0,0,.35);
}
.qrMeta{ display: grid; gap: 6px; text-align: center; }
.qrBrand{ font-weight: 900; color: rgba(255,255,255,.92); }
.qrTip{ font-size: 12px; color: rgba(255,255,255,.65); line-height: 1.45; }

@media (max-width: 980px){
  .hero{ flex-direction:column; align-items:stretch; }
  .hero-right{ justify-content:flex-start; }
  .grid{ grid-template-columns: 1fr; }
  .panel{
    height: 70vh;
    min-height: 560px;
    max-height: none;
  }
  .editor-actions{ top: 8px; margin: 10px 8px 0; }
  .controls{ justify-content:flex-start; max-width: 100%; }
  .chip select{ min-width: 150px; }
  }

/* --- v15 controls layout (2 rows) --- */
.controls{
  display:flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
  justify-content: flex-end;
  max-width: 820px;
}
.ctrlRow{
  display:flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
}
.ctrlRow-top{
  flex-wrap: wrap;
}
.ctrlRow-adv{
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 6px;
  max-width: 820px;
  scrollbar-width: thin;
}
.ctrlRow-adv::-webkit-scrollbar{ height: 8px; }
.ctrlRow-adv::-webkit-scrollbar-track{ background: rgba(0,0,0,.10); border-radius: 999px; }
.ctrlRow-adv::-webkit-scrollbar-thumb{ background: rgba(255,255,255,.14); border-radius: 999px; }
.ctrlRow-adv:hover::-webkit-scrollbar-thumb{ background: rgba(255,255,255,.20); }

/* select gọn hơn để đủ 1 hàng */
.chip select{ min-width: 140px; }

@media (max-width: 980px){
  .controls{ align-items: flex-start; max-width: 100%; }
  .ctrlRow{ justify-content: flex-start; }
  .ctrlRow-adv{ max-width: 100%; }
}

/* nếu màn hình hẹp thì File/Preset xuống hàng nhẹ */
  max-width: 520px;
}

.panel.editor .panel-head.editorHead .headToolbar{
  display:flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 6px;
  scrollbar-width: thin;
}

.panel.editor .panel-head.editorHead .headToolbar::-webkit-scrollbar{ height: 8px; }
.panel.editor .panel-head.editorHead .headToolbar::-webkit-scrollbar-track{ background: rgba(0,0,0,.10); border-radius: 999px; }
.panel.editor .panel-head.editorHead .headToolbar::-webkit-scrollbar-thumb{ background: rgba(255,255,255,.14); border-radius: 999px; }
.panel.editor .panel-head.editorHead .headToolbar:hover::-webkit-scrollbar-thumb{ background: rgba(255,255,255,.20); }

/* Make select slightly narrower so it fits nicer */
.panel.editor .panel-head.editorHead .chip select{ min-width: 140px; }
.panel.editor .panel-head.editorHead #model{ min-width: 190px; }

@media (max-width: 980px){
  .panel.editor .panel-head.editorHead .headTop{ flex-direction: column; }
  .panel.editor .panel-head.editorHead .headTopRight{ max-width: 100%; }
  .panel.editor .panel-head.editorHead .headToolbar{ justify-content: flex-start; }
}

/* --- v18 controls: API cùng hàng với File --- */
.controls{
  display:flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-end;
  justify-content: flex-end;
  max-width: 900px;
}

.ctrlRow{
  display:flex;
  gap: 12px;
  align-items:center;
  justify-content: flex-end;
}

/* Row 1: File + API + Preset (ưu tiên ở 1 hàng, hẹp thì wrap) */
.topRow{
  flex-wrap: wrap;
}

/* Keep File + API close */
.topRow .fileChip{ margin-right: 0; }

/* Row 2: luôn 1 hàng, thiếu chỗ thì cuộn ngang */
.advRow{
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 6px;
  max-width: 900px;
  scrollbar-width: thin;
}

.advRow::-webkit-scrollbar{ height: 8px; }
.advRow::-webkit-scrollbar-track{ background: rgba(0,0,0,.10); border-radius: 999px; }
.advRow::-webkit-scrollbar-thumb{ background: rgba(255,255,255,.14); border-radius: 999px; }
.advRow:hover::-webkit-scrollbar-thumb{ background: rgba(255,255,255,.20); }

/* Đảm bảo không bị "cắt mất chữ" ở đầu hàng */
.advRow{ padding-left: 2px; }

/* Responsive */
@media (max-width: 980px){
  .controls{ align-items: flex-start; max-width: 100%; }
  .ctrlRow{ justify-content: flex-start; }
  .advRow{ max-width: 100%; }
}
