*{box-sizing:border-box}html,body{margin:0;min-height:100%;font-family:"Segoe UI",Tahoma,Arial,sans-serif}body{background:#f6f7fb;color:#0f172a}.theme-dark{background:#0b1020;color:#e5e7eb}a{color:inherit}.hidden{display:none!important}.app-shell{display:grid;grid-template-columns:310px 1fr;min-height:100vh}.sidebar{background:linear-gradient(180deg,#111827,#0f172a);color:#fff;padding:18px;position:sticky;top:0;height:100vh;overflow:auto;box-shadow:12px 0 40px rgba(15,23,42,.16);z-index:30}.brand-card{display:flex;gap:12px;align-items:center;padding:14px;border:1px solid rgba(255,255,255,.12);background:rgba(255,255,255,.07);border-radius:22px}.brand-logo{width:48px;height:48px;border-radius:16px}.brand-title{font-size:18px;font-weight:800}.brand-sub{font-size:12px;opacity:.72;line-height:1.35}.side-close{display:none;margin-left:auto;background:rgba(255,255,255,.12);color:#fff;border:0;border-radius:12px;width:36px;height:36px}.side-label{margin:22px 4px 10px;font-size:12px;text-transform:uppercase;letter-spacing:.12em;opacity:.55}.app-nav{display:grid;gap:10px}.nav-item{display:flex;gap:10px;align-items:center;padding:13px 14px;text-decoration:none;border-radius:16px;background:rgba(255,255,255,.06);border:1px solid rgba(255,255,255,.08);transition:.18s}.nav-item:hover,.nav-item.active{background:linear-gradient(135deg,var(--primary),var(--accent));transform:translateY(-1px)}.nav-item span{font-size:20px}.admin-link{margin-top:8px}.quota-card{margin-top:18px;padding:16px;border-radius:20px;background:rgba(255,255,255,.08);border:1px solid rgba(255,255,255,.1)}.quota-title{font-weight:800;margin-bottom:8px}.quota-line{font-size:14px;line-height:1.4}.quota-note{font-size:12px;opacity:.72;margin-top:10px;line-height:1.5}.main-panel{min-width:0}.topbar{height:76px;display:flex;align-items:center;justify-content:space-between;padding:0 28px;border-bottom:1px solid rgba(15,23,42,.08);background:rgba(255,255,255,.82);backdrop-filter:blur(18px);position:sticky;top:0;z-index:20}.theme-dark .topbar{background:rgba(15,23,42,.82);border-color:rgba(255,255,255,.08)}.icon-btn{width:42px;height:42px;border:0;border-radius:14px;background:#eef2ff;color:#0f172a;font-size:18px;cursor:pointer}.theme-dark .icon-btn{background:#1f2937;color:#fff}.top-title{display:flex;align-items:center;gap:10px}.top-title img{width:42px;height:42px;border-radius:14px}.top-title strong{display:block}.top-title span{display:block;font-size:12px;opacity:.65}.top-actions{display:flex;gap:10px;align-items:center}.pill-btn,.ghost-btn{border:1px solid rgba(15,23,42,.12);background:#fff;border-radius:999px;padding:10px 14px;font-weight:700;cursor:pointer}.theme-dark .pill-btn,.theme-dark .ghost-btn{background:#111827;color:#e5e7eb;border-color:rgba(255,255,255,.12)}.hero{margin:26px 28px 0;padding:28px;border-radius:28px;background:radial-gradient(circle at top left,rgba(124,58,237,.23),transparent 36%),linear-gradient(135deg,#ffffff,#eef6ff);border:1px solid rgba(15,23,42,.06);display:flex;align-items:flex-end;justify-content:space-between;gap:24px}.theme-dark .hero{background:radial-gradient(circle at top left,rgba(124,58,237,.35),transparent 36%),linear-gradient(135deg,#111827,#0f172a);border-color:rgba(255,255,255,.08)}.eyebrow{font-size:12px;font-weight:800;color:var(--primary);letter-spacing:.12em;text-transform:uppercase}.hero h1{font-size:42px;line-height:1;margin:10px 0}.hero p{margin:0;max-width:700px;line-height:1.6;opacity:.78}.hero-badges{display:flex;gap:10px;flex-wrap:wrap;justify-content:flex-end}.hero-badges span{white-space:nowrap;padding:10px 12px;border-radius:999px;background:rgba(255,255,255,.8);border:1px solid rgba(15,23,42,.08);font-size:13px;font-weight:700}.theme-dark .hero-badges span{background:rgba(255,255,255,.08);border-color:rgba(255,255,255,.08)}.workspace{display:grid;grid-template-columns:minmax(320px,600px) minmax(360px,1fr);gap:22px;padding:22px 28px 36px}.prompt-panel,.result-panel,.floating-card{background:#fff;border:1px solid rgba(15,23,42,.08);border-radius:28px;box-shadow:0 20px 60px rgba(15,23,42,.08)}.theme-dark .prompt-panel,.theme-dark .result-panel,.theme-dark .floating-card{background:#111827;border-color:rgba(255,255,255,.08);box-shadow:0 20px 60px rgba(0,0,0,.28)}.prompt-panel{padding:22px}.form-head{display:flex;align-items:center;justify-content:space-between;gap:14px}.form-head h2,.result-head h2{margin:0;font-size:20px}.form-head span{font-size:12px;font-weight:800;border-radius:999px;background:#eef2ff;color:#3730a3;padding:8px 10px}.theme-dark .form-head span{background:#312e81;color:#fff}textarea,input,select{width:100%;border:1px solid rgba(15,23,42,.12);background:#fff;color:#0f172a;border-radius:16px;padding:13px 14px;font:inherit;outline:none}textarea{margin-top:16px;resize:vertical;min-height:210px;line-height:1.5}.theme-dark textarea,.theme-dark input,.theme-dark select{background:#0b1020;color:#e5e7eb;border-color:rgba(255,255,255,.12)}textarea:focus,input:focus,select:focus{border-color:var(--primary);box-shadow:0 0 0 4px color-mix(in srgb,var(--primary) 16%,transparent)}.quick-prompts{display:flex;gap:10px;overflow:auto;padding:14px 0}.prompt-chip{border:0;background:#f1f5f9;border-radius:999px;padding:10px 13px;white-space:nowrap;cursor:pointer;color:#334155}.theme-dark .prompt-chip{background:#1f2937;color:#e5e7eb}.style-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px;margin:6px 0 16px}.style-card{text-align:left;border:1px solid rgba(15,23,42,.1);background:#fff;border-radius:18px;padding:13px;cursor:pointer;color:#0f172a}.style-card strong{display:block;margin-bottom:5px}.style-card span{display:block;font-size:12px;line-height:1.38;opacity:.65}.style-card.active{border-color:var(--primary);box-shadow:0 0 0 4px color-mix(in srgb,var(--primary) 12%,transparent)}.theme-dark .style-card{background:#0b1020;color:#e5e7eb;border-color:rgba(255,255,255,.1)}.option-grid{display:grid;grid-template-columns:1fr 1fr;gap:12px}.option-grid label,.upload-box label{font-size:13px;font-weight:800;display:grid;gap:8px}.upload-box{margin-top:14px;padding:14px;border:1px dashed rgba(15,23,42,.18);border-radius:20px}.theme-dark .upload-box{border-color:rgba(255,255,255,.16)}.upload-box label span{font-weight:500;opacity:.62}.upload-hint{font-size:12px;opacity:.62;margin-top:8px}.preview-list{display:flex;gap:10px;flex-wrap:wrap;margin-top:10px}.preview-item{width:86px;border-radius:14px;overflow:hidden;background:#f1f5f9;border:1px solid rgba(15,23,42,.08)}.theme-dark .preview-item{background:#0b1020;border-color:rgba(255,255,255,.08)}.preview-item img{width:86px;height:70px;object-fit:cover;display:block}.preview-item span{display:block;font-size:10px;padding:5px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.generate-btn,.download-btn{display:inline-flex;align-items:center;justify-content:center;gap:8px;border:0;border-radius:18px;background:linear-gradient(135deg,var(--primary),var(--accent));color:#fff;font-weight:900;text-decoration:none;padding:14px 18px;cursor:pointer;box-shadow:0 14px 30px color-mix(in srgb,var(--primary) 25%,transparent)}.generate-btn{width:100%;margin-top:18px;font-size:16px}.generate-btn:disabled{opacity:.7;cursor:not-allowed}.generate-btn.small{width:auto;margin:0;padding:12px 16px}.legal-note{font-size:12px;opacity:.7;text-align:center;line-height:1.5;margin-top:12px}.legal-note a{font-weight:800}.result-panel{padding:22px;min-height:640px;display:flex;flex-direction:column}.result-head{display:flex;align-items:flex-start;justify-content:space-between;gap:12px}.result-head p{margin:7px 0 0;opacity:.65;font-size:13px}.status-badge{border-radius:999px;padding:8px 10px;font-size:12px;font-weight:900;background:#f1f5f9;color:#475569}.status-badge.loading{background:#fef3c7;color:#92400e}.status-badge.done{background:#dcfce7;color:#166534}.status-badge.error{background:#fee2e2;color:#991b1b}.theme-dark .status-badge{background:#1f2937;color:#e5e7eb}.status-card{margin-top:16px;display:flex;gap:16px;align-items:center;padding:16px;border-radius:22px;background:linear-gradient(135deg,rgba(124,58,237,.12),rgba(6,182,212,.12));border:1px solid rgba(124,58,237,.18)}.spinner{width:52px;height:52px;border-radius:999px;border:5px solid rgba(124,58,237,.2);border-top-color:var(--primary);animation:spin .9s linear infinite;flex:0 0 auto}@keyframes spin{to{transform:rotate(360deg)}}.status-card h3{margin:0 0 4px}.status-card p{margin:0 0 10px;font-size:13px;opacity:.72}.timer-row{display:flex;gap:8px;align-items:center}.timer-row strong{font-variant-numeric:tabular-nums}.timer-row em{font-style:normal;font-size:12px;opacity:.62}.image-stage{margin-top:16px;min-height:410px;border-radius:24px;background:linear-gradient(135deg,#f8fafc,#eef2ff);border:1px solid rgba(15,23,42,.06);display:grid;place-items:center;position:relative;overflow:hidden}.theme-dark .image-stage{background:linear-gradient(135deg,#0b1020,#111827);border-color:rgba(255,255,255,.08)}.image-stage.is-loading:after{content:"";position:absolute;inset:0;background:repeating-linear-gradient(135deg,rgba(255,255,255,.08) 0 10px,rgba(255,255,255,.16) 10px 20px);animation:slide 1.2s linear infinite}@keyframes slide{to{background-position:40px 0}}.empty-state{text-align:center;display:grid;gap:8px;color:#64748b}.empty-icon{font-size:58px}.image-stage img{max-width:100%;max-height:620px;width:auto;height:auto;display:block;border-radius:18px;box-shadow:0 24px 60px rgba(15,23,42,.18)}.result-actions{display:flex;gap:10px;flex-wrap:wrap;margin-top:16px}.download-btn{width:auto}.error-box{margin-top:14px;padding:14px;border-radius:16px;background:#fee2e2;color:#991b1b;font-weight:700;line-height:1.45}.gallery{margin-top:auto;padding-top:18px}.gallery h3{font-size:15px;margin:0 0 10px}.gallery-grid{display:grid;grid-template-columns:repeat(6,1fr);gap:8px}.gallery-item{border:0;padding:0;border-radius:12px;overflow:hidden;background:#e2e8f0;cursor:pointer;aspect-ratio:1/1}.gallery-item img{width:100%;height:100%;object-fit:cover;display:block}.floating-panel{position:fixed;inset:0;background:rgba(15,23,42,.56);z-index:60;display:grid;place-items:center;padding:20px}.floating-card{width:min(880px,96vw);padding:24px;position:relative}.panel-close{position:absolute;top:16px;right:16px;border:0;background:#f1f5f9;border-radius:12px;width:36px;height:36px;cursor:pointer}.theme-dark .panel-close{background:#1f2937;color:#fff}.key-grid{display:grid;grid-template-columns:1fr 1fr;gap:14px;margin-top:16px}.key-box{padding:16px;border-radius:20px;background:#f8fafc;border:1px solid rgba(15,23,42,.08)}.key-box.pro{background:linear-gradient(135deg,rgba(124,58,237,.1),rgba(6,182,212,.1))}.theme-dark .key-box{background:#0b1020;border-color:rgba(255,255,255,.08)}.key-box h3{margin:0 0 12px}.key-row{display:flex;gap:8px}.key-row button{border:0;border-radius:14px;background:#111827;color:#fff;font-weight:800;padding:0 14px;cursor:pointer}.key-note{font-size:13px;margin-top:10px;opacity:.8}.support-content{line-height:1.6}.watch-modal{position:fixed;inset:0;background:rgba(15,23,42,.62);z-index:80;display:grid;place-items:center;padding:18px}.watch-box{width:min(760px,96vw);background:#fff;color:#0f172a;border-radius:28px;padding:22px;box-shadow:0 30px 90px rgba(0,0,0,.32)}.theme-dark .watch-box{background:#111827;color:#e5e7eb}.watch-box h2{margin:0 0 8px}.watch-box p{margin:0 0 14px;opacity:.72}.watch-video{border-radius:18px;overflow:hidden;background:#0b1020;min-height:260px}.watch-video iframe{width:100%;min-height:315px;display:block}.watch-count{text-align:center;font-weight:900;margin:14px 0;color:var(--primary)}.watch-actions{display:flex;justify-content:flex-end;gap:10px}.video-fallback{padding:40px;text-align:center;color:#fff}.side-backdrop{display:none}
@media (max-width:1100px){.app-shell{grid-template-columns:1fr}.sidebar{position:fixed;left:0;top:0;bottom:0;width:310px;transform:translateX(-110%);transition:.2s}.sidebar.open{transform:translateX(0)}.side-close{display:block}.side-backdrop.show{display:block;position:fixed;inset:0;background:rgba(15,23,42,.5);z-index:25}.workspace{grid-template-columns:1fr}.hero{align-items:flex-start;flex-direction:column}.topbar{padding:0 16px}.top-actions .pill-btn{display:none}}
@media (max-width:720px){.hero{margin:14px 12px 0;padding:20px;border-radius:22px}.hero h1{font-size:32px}.workspace{padding:14px 12px 24px;gap:14px}.prompt-panel,.result-panel{border-radius:22px;padding:16px}.style-grid,.option-grid,.key-grid{grid-template-columns:1fr}.form-head{align-items:flex-start;flex-direction:column}.top-title span{display:none}.gallery-grid{grid-template-columns:repeat(4,1fr)}.key-row{flex-direction:column}.key-row button{padding:12px}.image-stage{min-height:300px}.watch-video iframe{min-height:220px}.watch-actions{flex-direction:column}.watch-actions button{width:100%}}


.option-note{margin:-4px 0 10px;color:var(--muted,#6b7280);font-size:13px}
@media (min-width: 1024px){
  .workspace{margin-top:8px}
}


.section-label{display:block;font-size:17px;font-weight:900;margin:14px 0 10px;color:#0f172a}.theme-dark .section-label{color:#f8fafc}
.style-picker{position:relative;margin:14px 0 18px}
.style-toggle{width:100%;min-height:72px;display:flex;align-items:center;gap:14px;padding:14px 18px;border:2px solid rgba(59,130,246,.75);border-radius:18px;background:#fff;color:#0f172a;cursor:pointer;text-align:left;box-shadow:0 10px 24px rgba(59,130,246,.06);transition:.18s}
.style-toggle:hover,.style-toggle[aria-expanded="true"]{border-color:var(--primary);box-shadow:0 14px 34px rgba(124,58,237,.14)}
.theme-dark .style-toggle{background:#111827;color:#f8fafc;border-color:rgba(124,58,237,.65)}
.style-icon{width:46px;height:46px;display:grid;place-items:center;border-radius:10px;background:#fff7ad;font-size:26px;flex:0 0 auto}
.style-current{display:grid;gap:4px;min-width:0}.style-current strong{font-size:22px;font-weight:900}.style-current em{font-style:normal;color:#64748b;font-size:13px;line-height:1.35;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.theme-dark .style-current em{color:#94a3b8}
.style-arrow{margin-left:auto;font-size:28px;line-height:1;color:#334155;transition:.18s}.style-toggle[aria-expanded="true"] .style-arrow{transform:rotate(180deg)}.theme-dark .style-arrow{color:#cbd5e1}
.style-dropdown{position:absolute;left:0;right:0;top:calc(100% + 10px);z-index:18;background:#fff;border:1px solid rgba(15,23,42,.12);border-radius:20px;box-shadow:0 22px 50px rgba(15,23,42,.18);padding:10px;max-height:340px;overflow:auto}.theme-dark .style-dropdown{background:#0f172a;border-color:rgba(255,255,255,.12)}
.style-option{width:100%;display:flex;align-items:center;gap:12px;text-align:left;border:1px solid transparent;background:transparent;border-radius:16px;padding:12px;cursor:pointer;color:#0f172a}.style-option:hover,.style-option.active{background:#f5f3ff;border-color:rgba(124,58,237,.35)}.theme-dark .style-option{color:#e5e7eb}.theme-dark .style-option:hover,.theme-dark .style-option.active{background:#1e1b4b;border-color:rgba(124,58,237,.55)}
.style-option-icon{width:38px;height:38px;display:grid;place-items:center;border-radius:12px;background:#eef2ff;flex:0 0 auto}.style-option strong{display:block;font-size:15px}.style-option em{display:block;font-style:normal;color:#64748b;font-size:13px;line-height:1.35;margin-top:2px}.theme-dark .style-option em{color:#94a3b8}
@media (max-width:680px){.style-current strong{font-size:19px}.style-current em{white-space:normal}.style-dropdown{position:static;margin-top:10px}.style-toggle{min-height:66px}}


.compact-config{margin:14px 0 18px}.compact-tab-grid{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:10px}.compact-tab{display:flex;align-items:center;gap:10px;border:1px solid rgba(15,23,42,.1);background:#f8fafc;border-radius:18px;padding:12px 14px;cursor:pointer;text-align:left;min-height:76px;transition:.18s;color:#0f172a}.compact-tab:hover,.compact-tab.active{background:#fff;border-color:var(--primary);box-shadow:0 10px 24px rgba(124,58,237,.12)}.theme-dark .compact-tab{background:#0b1020;color:#e5e7eb;border-color:rgba(255,255,255,.1)}.theme-dark .compact-tab:hover,.theme-dark .compact-tab.active{background:#111827;border-color:var(--primary)}.compact-tab-icon{width:40px;height:40px;display:grid;place-items:center;border-radius:14px;background:rgba(124,58,237,.12);font-size:18px;flex:0 0 auto}.compact-tab-meta{display:grid;gap:2px;min-width:0}.compact-tab-meta strong{font-size:13px}.compact-tab-meta em{font-style:normal;font-size:12px;opacity:.68;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:100%}.compact-panel-stack{margin-top:12px}.compact-panel{padding:16px;border:1px solid rgba(15,23,42,.08);border-radius:22px;background:#fff}.theme-dark .compact-panel{background:#111827;border-color:rgba(255,255,255,.08)}.compact-panel-head{display:flex;align-items:flex-start;justify-content:space-between;gap:12px;margin-bottom:12px}.compact-panel-head h3{margin:0;font-size:16px}.compact-panel-head p{margin:0;font-size:12px;opacity:.68;max-width:420px}.single-option{grid-template-columns:1fr}.compact-upload-box{margin-top:0;padding:0;border:0}.compact-upload-box label{font-size:13px}.style-picker{margin:0}.style-picker .section-label{display:none}.style-dropdown{top:calc(100% + 8px)}.upload-box input[type=file]{padding:10px}
@media (max-width:980px){.compact-tab-grid{grid-template-columns:repeat(2,minmax(0,1fr))}}
@media (max-width:560px){.compact-tab-grid{grid-template-columns:1fr 1fr}.compact-tab{min-height:68px;padding:10px 12px}.compact-tab-icon{width:34px;height:34px;font-size:16px}.compact-panel{padding:14px}.compact-panel-head{display:block}.compact-panel-head p{margin-top:4px}.compact-tab-meta strong{font-size:12px}.compact-tab-meta em{font-size:11px}}


/* V7: tab cấu hình chỉ còn chữ, gọn hơn */
.text-only-tabs{grid-template-columns:repeat(4,minmax(0,1fr));gap:8px;margin-top:4px}
.text-only-tabs .compact-tab{min-height:44px;height:44px;display:flex;align-items:center;justify-content:center;padding:0 12px;border-radius:999px;font-size:14px;font-weight:900;line-height:1.1;text-align:center;background:#f8fafc;box-shadow:none;white-space:nowrap}
.text-only-tabs .compact-tab.active{background:linear-gradient(135deg,var(--primary),var(--accent));color:#fff;border-color:transparent;box-shadow:0 10px 22px color-mix(in srgb,var(--primary) 18%,transparent)}
.text-only-tabs .compact-tab:hover{transform:translateY(-1px)}
.text-only-tabs .compact-tab-icon,.text-only-tabs .compact-tab-meta{display:none!important}
.theme-dark .text-only-tabs .compact-tab{background:#0b1020;color:#e5e7eb;border-color:rgba(255,255,255,.12)}
.theme-dark .text-only-tabs .compact-tab.active{background:linear-gradient(135deg,var(--primary),var(--accent));color:#fff;border-color:transparent}
.compact-panel-stack{margin-top:10px}
@media (max-width:560px){.text-only-tabs{grid-template-columns:repeat(2,minmax(0,1fr));gap:7px}.text-only-tabs .compact-tab{height:40px;min-height:40px;font-size:13px;padding:0 8px}}


/* V8 font fix: dùng font hệ thống hỗ trợ tiếng Việt tốt, tránh lỗi dấu khi font quá đậm. */
:root{--safe-font:"Segoe UI",Tahoma,Arial,sans-serif}
body,button,input,textarea,select,a,div,span,strong,em,label,h1,h2,h3,p{font-family:var(--safe-font)!important;text-rendering:geometricPrecision;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}
.text-only-tabs .compact-tab{font-family:var(--safe-font)!important;font-weight:700!important;font-size:15px!important;letter-spacing:0!important;line-height:1.2!important}
.generate-btn,.download-btn{font-family:var(--safe-font)!important;font-weight:700!important;letter-spacing:0!important}
.compact-panel-head h3,.option-grid label,.upload-box label,.style-current strong,.form-head h2,.result-head h2{font-family:var(--safe-font)!important;font-weight:700!important;letter-spacing:0!important}
.nav-item strong,.quota-title,.brand-title{font-family:var(--safe-font)!important;font-weight:700!important}




.version-switch{display:flex;gap:10px;flex-wrap:wrap;margin:14px 0 10px}.version-option{display:inline-flex;align-items:center;cursor:pointer}.version-option input{position:absolute;opacity:0;pointer-events:none}.version-option span{display:inline-flex;align-items:center;justify-content:center;min-height:42px;padding:10px 16px;border-radius:999px;border:1px solid rgba(15,23,42,.14);background:#fff;color:#0f172a;font-weight:700;font-family:"Segoe UI",Tahoma,Arial,sans-serif;transition:.18s}.version-option input:checked+span{border-color:var(--primary);background:linear-gradient(135deg,var(--primary),var(--accent));color:#fff;box-shadow:0 10px 24px color-mix(in srgb,var(--primary) 22%,transparent)}.theme-dark .version-option span{background:#0b1020;color:#e5e7eb;border-color:rgba(255,255,255,.12)}


.quota-line strong{display:inline-block;margin-bottom:4px;color:#fff}.quota-mini{display:inline-block;margin-top:6px;font-size:12px;opacity:.78;line-height:1.45}.watch-video>div,.watch-video iframe{width:100%;min-height:315px;display:block}

.prompt-error-box{margin-top:14px;font-size:14px;border:1px solid #fecaca;background:#fef2f2;color:#b91c1c;box-shadow:0 8px 20px rgba(239,68,68,.08)}
.theme-dark .prompt-error-box{background:#2a1215;color:#fecaca;border-color:#7f1d1d}


.result-error-top{margin:14px 0 0;font-size:15px;border:1px solid #fecaca;background:#fef2f2;color:#b91c1c;box-shadow:0 8px 20px rgba(239,68,68,.08)}
.theme-dark .result-error-top{background:#2a1215;color:#fecaca;border-color:#7f1d1d}

.prompt-panel textarea#promptInput{margin-bottom:10px}


/* V20: Mobile responsive fix - tránh tràn ngang, ảnh co vừa màn hình điện thoại */
html,body{max-width:100%;overflow-x:hidden}
img,video,iframe{max-width:100%}
.main-panel,.workspace,.prompt-panel,.result-panel,.image-stage,.compact-config,.compact-panel,.quick-prompts{min-width:0;max-width:100%}

@media (max-width:720px){
  .app-shell{display:block;width:100%;min-height:100vh;overflow-x:hidden}
  .sidebar{width:min(310px,86vw);max-width:86vw}
  .main-panel{width:100%;overflow-x:hidden}
  .topbar{height:auto;min-height:64px;padding:8px 10px;gap:8px}
  .top-title{min-width:0;gap:8px}
  .top-title img{width:36px;height:36px;border-radius:12px}
  .top-title strong{font-size:15px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:160px}
  .top-actions{gap:6px;flex:0 0 auto}
  .icon-btn{width:38px;height:38px;border-radius:12px}
  .workspace{display:block;width:100%;padding:10px 8px 22px;margin:0;overflow-x:hidden}
  .prompt-panel,.result-panel{width:100%;max-width:100%;border-radius:20px;padding:14px;margin:0 0 12px;overflow:hidden}
  .form-head{gap:8px;margin-bottom:8px}
  .form-head h2,.result-head h2{font-size:18px}
  .form-head span{font-size:11px;padding:7px 9px}
  textarea#promptInput{min-height:150px;max-height:38vh;margin-top:10px;font-size:16px;line-height:1.45;border-radius:16px}
  .quick-prompts{padding:10px 0;gap:8px;overflow-x:auto;-webkit-overflow-scrolling:touch}
  .prompt-chip{font-size:13px;padding:8px 11px}
  .version-switch{gap:7px;margin:10px 0 8px}
  .version-option span{min-height:38px;padding:8px 12px;font-size:13px}
  .text-only-tabs{grid-template-columns:repeat(2,minmax(0,1fr));gap:7px;margin-top:6px}
  .text-only-tabs .compact-tab{height:39px;min-height:39px;font-size:13px!important;padding:0 8px;white-space:nowrap}
  .compact-panel-stack{margin-top:8px}
  .compact-panel{padding:12px;border-radius:18px}
  .compact-panel-head{display:block;margin-bottom:8px}
  .compact-panel-head h3{font-size:15px}
  .compact-panel-head p{font-size:12px;margin-top:3px;line-height:1.35}
  input,select,textarea{font-size:16px;border-radius:14px;padding:11px 12px}
  .style-toggle{min-height:58px;padding:10px 12px;border-radius:16px;gap:10px}
  .style-icon{width:38px;height:38px;font-size:20px}
  .style-current strong{font-size:17px!important}
  .style-current em{font-size:12px;white-space:normal;line-height:1.3}
  .style-arrow{font-size:22px}
  .style-dropdown{position:static;margin-top:8px;max-height:260px;border-radius:16px}
  .style-option{padding:10px;border-radius:14px}
  .upload-box input[type=file]{width:100%;font-size:14px;white-space:normal}
  .upload-hint,.option-note{font-size:12px;line-height:1.4}
  .generate-btn{margin-top:14px;border-radius:16px;min-height:48px;font-size:15px}
  .legal-note{font-size:11px;margin-top:9px}
  .result-head{display:block}
  .result-head p{font-size:12px;line-height:1.4}
  .status-badge{display:inline-flex;margin-top:8px;font-size:11px}
  .result-error-top{font-size:13px;margin-top:10px;padding:11px 12px;border-radius:14px}
  .status-card{padding:12px;border-radius:18px;gap:10px;align-items:flex-start}
  .spinner{width:38px;height:38px;border-width:4px}
  .image-stage{width:100%;min-height:220px;margin-top:12px;border-radius:18px;padding:0;display:flex;align-items:center;justify-content:center;overflow:hidden}
  .image-stage img{width:100%;max-width:100%;height:auto;max-height:none;object-fit:contain;border-radius:14px;box-shadow:none}
  .empty-icon{font-size:42px}
  .empty-state{font-size:13px;padding:24px 10px}
  .result-actions{gap:8px;margin-top:12px;display:grid;grid-template-columns:1fr 1fr}
  .result-actions .download-btn{grid-column:1 / -1}
  .result-actions .ghost-btn,.result-actions .download-btn{width:100%;min-height:42px;padding:10px 12px;font-size:13px;border-radius:999px}
  .gallery{padding-top:12px}
  .gallery-grid{grid-template-columns:repeat(4,1fr);gap:6px}
  .watch-box{border-radius:20px;padding:14px}
  .watch-video{min-height:190px;border-radius:14px}
  .watch-video iframe{min-height:200px}
}

@media (max-width:390px){
  .workspace{padding-left:6px;padding-right:6px}
  .prompt-panel,.result-panel{padding:12px;border-radius:18px}
  .text-only-tabs .compact-tab{font-size:12px!important;padding:0 6px}
  .top-title strong{max-width:125px}
  .form-head h2,.result-head h2{font-size:17px}
  textarea#promptInput{min-height:135px}
  .image-stage{min-height:190px}
}


/* V58 embed mode: khi nhúng vào Chat AGI thì ẩn sidebar Photo và mở rộng full khung */
body.is-embedded{
  background:#f6f7fb!important;
  overflow:auto!important;
}
body.is-embedded .app-shell{
  display:block!important;
  width:100%!important;
  min-height:100vh!important;
  overflow-x:hidden!important;
}
body.is-embedded .sidebar,
body.is-embedded .side-backdrop,
body.is-embedded .sidebar-backdrop{
  display:none!important;
}
body.is-embedded .main-panel{
  width:100%!important;
  max-width:none!important;
  min-width:0!important;
}
body.is-embedded .topbar{
  position:sticky!important;
  top:0!important;
  height:64px!important;
  padding:8px 18px!important;
  border-radius:0!important;
}
body.is-embedded .hero{
  display:none!important;
}
body.is-embedded .workspace{
  width:100%!important;
  max-width:none!important;
  padding:18px!important;
  margin:0!important;
  gap:18px!important;
  grid-template-columns:minmax(360px,520px) minmax(420px,1fr)!important;
}
body.is-embedded .prompt-panel,
body.is-embedded .result-panel{
  max-width:none!important;
  overflow:visible!important;
}
body.is-embedded .image-stage{
  min-height:360px!important;
}
@media(max-width:960px){
  body.is-embedded .workspace{
    display:block!important;
    padding:10px!important;
  }
  body.is-embedded .prompt-panel,
  body.is-embedded .result-panel{
    margin:0 0 12px!important;
  }
  body.is-embedded .topbar{height:auto!important;min-height:58px!important;padding:8px 10px!important;}
  body.is-embedded .image-stage{min-height:240px!important;}
}


/* V59 embed trong Chat AGI: bỏ menu/tab nội bộ, đưa quota lên đầu khung Photo */
body.is-embedded .sidebar,
body.is-embedded .side-backdrop,
body.is-embedded .sidebar-backdrop,
body.is-embedded .topbar,
body.is-embedded .floating-panel,
body.is-embedded .top-actions,
body.is-embedded .icon-btn#openSidebarBtn{
  display:none!important;
}
body.is-embedded .app-shell{padding:0!important;background:transparent!important;display:block!important;}
body.is-embedded .main-panel{padding:0!important;margin:0!important;width:100%!important;max-width:none!important;}
body.is-embedded .workspace{margin:0!important;padding:0!important;display:grid!important;grid-template-columns:minmax(0,1fr) minmax(0,1fr)!important;gap:16px!important;}
body.is-embedded .prompt-panel,
body.is-embedded .result-panel{min-width:0!important;}
body.is-embedded .embed-quota-card{
  margin:0 0 14px 0;
  padding:16px 18px;
  border-radius:20px;
  border:1px solid rgba(139,92,246,.22);
  background:linear-gradient(135deg,rgba(15,23,42,.96),rgba(45,43,75,.96));
  color:#fff;
  box-shadow:0 14px 32px rgba(15,23,42,.16);
}
body.is-embedded .embed-quota-card .quota-title{font-weight:900;font-size:18px;margin-bottom:8px;color:#fff;}
body.is-embedded .embed-quota-card .quota-line{font-size:15px;line-height:1.45;color:#fff;}
body.is-embedded .embed-quota-card .quota-note{font-size:13px;line-height:1.45;color:rgba(255,255,255,.75);margin-top:8px;}
@media(max-width:900px){
  body.is-embedded .workspace{grid-template-columns:1fr!important;gap:12px!important;}
  body.is-embedded .embed-quota-card{border-radius:16px;padding:14px;}
}


/* V60: key-only embed dùng trong tab Key chung của Chat AGI */
body.is-key-only{
  background:transparent!important;
  overflow:auto!important;
}
body.is-key-only .sidebar,
body.is-key-only .side-backdrop,
body.is-key-only .topbar,
body.is-key-only .hero-card,
body.is-key-only .prompt-panel,
body.is-key-only .main-grid,
body.is-key-only .result-panel,
body.is-key-only .embed-quota-card{
  display:none!important;
}
body.is-key-only .app-shell,
body.is-key-only .main-panel{
  display:block!important;
  width:100%!important;
  max-width:none!important;
  min-height:auto!important;
  padding:0!important;
  margin:0!important;
  background:transparent!important;
}
body.is-key-only #keyPanel{
  display:block!important;
  position:static!important;
  inset:auto!important;
  width:100%!important;
  max-width:none!important;
  padding:0!important;
  background:transparent!important;
  box-shadow:none!important;
}
body.is-key-only #keyPanel.hidden{display:block!important}
body.is-key-only #keyPanel .floating-card{
  width:100%!important;
  max-width:none!important;
  margin:0!important;
  border-radius:18px!important;
  box-shadow:none!important;
}
body.is-key-only #keyPanel .panel-close{display:none!important}
body.is-key-only .floating-panel::before{display:none!important}

/* V61: modal xem video co gọn trong iframe Photo, không tràn màn hình */
body.is-embedded .watch-modal,
body.is-key-only .watch-modal{
  position:fixed!important;
  inset:0!important;
  padding:10px!important;
  overflow:auto!important;
  display:grid!important;
  place-items:center!important;
}
body.is-embedded .watch-box,
body.is-key-only .watch-box{
  width:min(720px, calc(100vw - 20px))!important;
  max-width:calc(100vw - 20px)!important;
  max-height:calc(100vh - 20px)!important;
  overflow:auto!important;
  margin:auto!important;
  padding:16px!important;
  border-radius:20px!important;
}
body.is-embedded .watch-video,
body.is-key-only .watch-video{
  width:100%!important;
  aspect-ratio:16/9!important;
  min-height:0!important;
  max-height:min(52vh, 380px)!important;
  border-radius:16px!important;
  overflow:hidden!important;
}
body.is-embedded .watch-video iframe,
body.is-embedded .watch-video video,
body.is-key-only .watch-video iframe,
body.is-key-only .watch-video video{
  width:100%!important;
  height:100%!important;
  min-height:0!important;
  max-height:none!important;
  display:block!important;
  border:0!important;
}
body.is-embedded .watch-count,
body.is-key-only .watch-count{font-size:14px!important;margin:10px 0!important;}
body.is-embedded .watch-actions,
body.is-key-only .watch-actions{gap:8px!important;margin-top:10px!important;}
@media(max-width:720px){
  body.is-embedded .watch-box,
  body.is-key-only .watch-box{padding:12px!important;border-radius:16px!important;}
  body.is-embedded .watch-box h2,
  body.is-key-only .watch-box h2{font-size:18px!important;line-height:1.2!important;}
  body.is-embedded .watch-box p,
  body.is-key-only .watch-box p{font-size:13px!important;line-height:1.35!important;margin-bottom:10px!important;}
  body.is-embedded .watch-video,
  body.is-key-only .watch-video{max-height:38vh!important;}
}


/* V63: sửa popup video không tự hiện khi mở Photo, chỉ hiện khi thật sự cần xem video */
body.is-embedded .watch-modal.hidden,
body.is-key-only .watch-modal.hidden,
.watch-modal.hidden{
  display:none!important;
}
body.is-embedded .watch-modal:not(.hidden),
body.is-key-only .watch-modal:not(.hidden){
  display:grid!important;
  place-items:center!important;
  padding:12px!important;
  overflow:auto!important;
}
body.is-embedded .watch-box,
body.is-key-only .watch-box{
  width:min(680px, calc(100vw - 28px))!important;
  max-height:calc(100vh - 28px)!important;
  overflow:auto!important;
}
body.is-embedded .watch-video,
body.is-key-only .watch-video{
  aspect-ratio:16/9!important;
  height:auto!important;
  min-height:0!important;
  max-height:min(44vh, 330px)!important;
}
body.is-embedded .watch-video iframe,
body.is-key-only .watch-video iframe{
  width:100%!important;
  height:100%!important;
  min-height:0!important;
}

/* V63: đưa lượt miễn phí xuống dưới nút Tạo ảnh ngay, không để trên tiêu đề ngoài */
.create-quota-line{
  margin:10px 0 0;
  padding:10px 12px;
  border-radius:16px;
  background:#eef2ff;
  color:#3730a3;
  font-size:13px;
  font-weight:800;
  line-height:1.45;
  text-align:center;
}
.create-quota-line strong{font-weight:900}
.create-quota-line .quota-mini{display:block;margin-top:4px;font-size:12px;opacity:.8;font-weight:700}
.theme-dark .create-quota-line{background:#312e81;color:#fff}

/* V63: chuyển phần cấu hình ảnh sang cột kết quả để khung mô tả gọn hơn */
.result-side-config{margin:14px 0 0}
.result-side-config .compact-config{margin:0 0 14px!important}
.result-side-config .compact-panel{background:#fff;border-color:rgba(15,23,42,.08)}
body.is-embedded .workspace{grid-template-columns:minmax(360px,.86fr) minmax(440px,1.14fr)!important;align-items:start!important}
body.is-embedded .prompt-panel{display:flex!important;flex-direction:column!important;gap:10px!important}
body.is-embedded textarea#promptInput{min-height:260px!important;margin-top:12px!important}
body.is-embedded .quick-prompts{padding:10px 0 4px!important}
body.is-embedded .generate-btn{margin-top:10px!important}
body.is-embedded .legal-note{margin-top:8px!important}
body.is-embedded .result-panel{min-height:620px!important}
body.is-embedded .image-stage{min-height:320px!important;margin-top:14px!important}
@media(max-width:980px){
  body.is-embedded .workspace{grid-template-columns:1fr!important}
  body.is-embedded textarea#promptInput{min-height:190px!important}
  .result-side-config{margin-top:12px}
}
body.is-embedded .watch-video>div,
body.is-key-only .watch-video>div{height:100%!important;min-height:0!important;width:100%!important}


/* V63: đặt cụm tùy chọn ảnh dưới khung kết quả ảnh */
.result-panel .image-stage + .result-side-config{margin-top:18px!important;}
.result-panel .result-side-config .compact-config{margin-bottom:0!important;}
body.is-embedded .result-panel .image-stage + .result-side-config{margin-top:14px!important;}
@media (max-width:720px){.result-panel .image-stage + .result-side-config{margin-top:12px!important;}}


/* V65: thu gọn cụm tùy chọn ảnh dưới nút Tạo ảnh ngay */
.photo-advanced-row{
  margin-top:12px;
  display:flex;
  align-items:center;
  gap:10px;
  flex-wrap:wrap;
}
.photo-advanced-toggle{
  border:1px solid rgba(15,23,42,.12);
  background:#f8fafc;
  color:#111827;
  border-radius:999px;
  padding:10px 14px;
  font-weight:900;
  cursor:pointer;
  min-height:42px;
}
.photo-advanced-toggle:hover{
  border-color:var(--primary);
  box-shadow:0 10px 24px rgba(124,58,237,.12);
}
.photo-option-summary{
  display:inline-flex;
  align-items:center;
  min-height:42px;
  padding:8px 12px;
  border-radius:999px;
  background:#eef2ff;
  color:#4338ca;
  font-size:13px;
  font-weight:800;
  line-height:1.3;
  max-width:100%;
}
.theme-dark .photo-advanced-toggle{
  background:#0b1020;
  color:#e5e7eb;
  border-color:rgba(255,255,255,.12);
}
.theme-dark .photo-option-summary{
  background:#312e81;
  color:#fff;
}
.prompt-panel .compact-config{
  margin-top:12px!important;
}
@media(max-width:720px){
  .photo-advanced-row{display:grid;grid-template-columns:1fr;gap:8px;}
  .photo-advanced-toggle,.photo-option-summary{width:100%;justify-content:center;text-align:center;border-radius:16px;}
}

/* V66: phiên bản ảnh nhỏ gọn hơn để tối ưu giao diện chính */
.version-switch{
  display:flex!important;
  gap:8px!important;
  flex-wrap:wrap!important;
  margin:8px 0 10px!important;
}
.version-option span{
  min-height:auto!important;
  padding:9px 14px!important;
  border-radius:999px!important;
  font-size:13px!important;
  line-height:1.1!important;
  white-space:nowrap!important;
  box-shadow:none!important;
}
.version-option input:checked + span{
  box-shadow:0 8px 18px rgba(124,58,237,.16)!important;
}
.photo-advanced-row{
  margin-top:10px!important;
}
.watch-actions button:disabled,
#confirmWatchBtn:disabled{
  opacity:.45!important;
  filter:grayscale(.35);
  cursor:not-allowed!important;
  box-shadow:none!important;
}
.watch-box{width:min(760px,calc(100vw - 32px))!important;max-height:92vh!important;overflow:auto!important;}
.watch-video{position:relative!important;width:100%!important;aspect-ratio:16/9!important;min-height:0!important;}
.watch-video iframe,.watch-video video,.watch-video > div{width:100%!important;height:100%!important;min-height:0!important;display:block!important;}
@media(max-width:640px){
  .version-option span{font-size:12px!important;padding:8px 12px!important;}
}
