:root{
  --bg:#0a0c12; --panel:#11141d; --panel2:#161a26; --surface:#151a26; --surface2:#1c2231;
  --border:#242a3a; --text:#eef1f8; --text2:#9aa3b8; --text3:#6b7488;
  --tint:#D9941C; --tint2:#E5A93C; --tint-text:#17130a; --danger:#EF4444; --success:#22C55E;
  color-scheme: dark;
}
*{box-sizing:border-box;}
html,body{margin:0; padding:0; height:100%;}
body{
  background:var(--bg); color:var(--text); font-family:'Be Vietnam Pro',system-ui,sans-serif;
  font-size:13px; -webkit-tap-highlight-color:transparent;
}
.msym{
  font-family:'Material Symbols Outlined';
  font-variation-settings:'FILL' 0,'wght' 400,'GRAD' 0,'opsz' 24;
  font-size:20px; line-height:1; display:inline-block; vertical-align:middle;
}
button{font-family:inherit; cursor:pointer;}
input,textarea,select{font-family:inherit; font-size:12.5px;}
::-webkit-scrollbar{width:8px; height:8px;}
::-webkit-scrollbar-thumb{background:#2a3145; border-radius:8px;}
a{color:inherit;}

#app{display:flex; flex-direction:column; min-height:100vh;}

.btn{display:inline-flex; align-items:center; gap:6px; padding:8px 13px; border-radius:10px; border:1px solid var(--border); background:var(--surface2); color:var(--text); font-size:12.5px; font-weight:600; white-space:nowrap;}
.btn:hover{border-color:#3a4258;}
.btn.primary{background:var(--tint); border-color:var(--tint); color:var(--tint-text);}
.btn.primary:hover{background:var(--tint2); border-color:var(--tint2);}
.btn.ghost{background:transparent;}
.btn.danger{color:#ff8a8a; border-color:#4a2027;}
.btn.icon-only{padding:8px;}
.btn[disabled]{opacity:.5; cursor:default;}

/* ---------- màn hình Đăng nhập ---------- */
.login-screen{flex:1; display:flex; align-items:center; justify-content:center; padding:24px;}
.login-card{width:100%; max-width:360px; background:var(--panel); border:1px solid var(--border); border-radius:18px; padding:28px; display:flex; flex-direction:column; gap:16px;}
.login-brand{display:flex; align-items:center; gap:10px;}
.login-brand .ico{width:40px; height:40px; border-radius:12px; background:linear-gradient(135deg,var(--tint),var(--tint2)); display:flex; align-items:center; justify-content:center; color:var(--tint-text);}
.login-brand .t{font-size:16px; font-weight:800;}
.login-brand .s{font-size:11px; color:var(--text3);}
.field{display:flex; flex-direction:column; gap:6px;}
.field label{font-size:11px; color:var(--text2); font-weight:700;}
.field input[type=text], .field input[type=password], .field input[type=number], .field input[type=color], .field textarea, .field select{
  background:var(--surface2); border:1px solid var(--border); border-radius:9px; padding:9px 10px; color:var(--text); outline:none; width:100%;
}
.field input:focus, .field textarea:focus, .field select:focus{border-color:var(--tint);}
.field textarea{resize:vertical; min-height:70px; font-family:'SFMono-Regular',Consolas,monospace; font-size:11px;}
.login-error{color:#ff8a8a; font-size:12px; min-height:16px;}
.login-hint{font-size:10.5px; color:var(--text3); line-height:1.4;}
.login-divider{display:flex; align-items:center; gap:10px; color:var(--text3); font-size:10.5px; font-weight:700; text-transform:uppercase;}
.login-divider:before,.login-divider:after{content:""; height:1px; background:var(--border); flex:1;}
.google-login{background:#fff; color:#202124; border-color:#d7dce3;}
.google-login:hover{border-color:#fff;}
.google-login[disabled]{background:var(--surface2); color:var(--text3); border-color:var(--border);}
.google-mark{width:19px; height:19px; border-radius:50%; background:#fff; color:#4285F4; display:inline-flex; align-items:center; justify-content:center; font-weight:800; font-family:Arial,sans-serif; font-size:14px;}
.google-login[disabled] .google-mark{opacity:.55;}

/* ---------- màn hình Danh sách layout ---------- */
.list-screen{flex:1; display:flex; flex-direction:column;}
.list-topbar{display:flex; align-items:center; justify-content:space-between; gap:16px; padding:16px 24px; border-bottom:1px solid var(--border); background:var(--panel);}
.list-body{flex:1; padding:24px; max-width:920px; width:100%; margin:0 auto;}
.list-head{display:flex; align-items:center; justify-content:space-between; margin-bottom:16px; gap:12px; flex-wrap:wrap;}
.list-head h1{font-size:19px; margin:0;}
.layout-grid{display:grid; grid-template-columns:repeat(auto-fill,minmax(230px,1fr)); gap:14px;}
.layout-card{border:1px solid var(--border); border-radius:14px; background:var(--panel); padding:16px; display:flex; flex-direction:column; gap:10px; cursor:pointer; transition:border-color .15s ease;}
.layout-card:hover{border-color:var(--tint);}
.layout-card .thumb{height:64px; border-radius:10px; background:linear-gradient(135deg,#1c2231,#0f1219); display:flex; align-items:center; justify-content:center; color:var(--text3);}
.layout-card .name{font-weight:700; font-size:13.5px;}
.layout-card .meta{font-size:10.5px; color:var(--text3);}
.layout-card .row-actions{display:flex; gap:6px; margin-top:2px;}
.layout-card .row-actions button{flex:1; padding:6px; border-radius:8px; border:1px solid var(--border); background:var(--surface2); color:var(--text2); font-size:11px; display:flex; align-items:center; justify-content:center; gap:4px;}
.layout-card .row-actions button:hover{border-color:var(--tint); color:var(--text);}
.layout-card .row-actions button.danger:hover{border-color:#4a2027; color:#ff8a8a;}
.empty-state{border:1.5px dashed var(--border); border-radius:16px; padding:40px 20px; text-align:center; color:var(--text3);}
.empty-state .msym{font-size:32px; margin-bottom:8px; color:var(--text3);}

/* ---------- shell trình soạn thảo (editor) ---------- */
.editor-shell{display:flex; flex-direction:column; flex:1; min-height:100vh;}
.topbar{display:flex; align-items:center; justify-content:space-between; gap:16px; padding:12px 20px; border-bottom:1px solid var(--border); background:var(--panel); flex-wrap:wrap;}
.brand{display:flex; align-items:center; gap:10px; min-width:0;}
.brand-icon{width:34px; height:34px; border-radius:10px; background:linear-gradient(135deg,var(--tint),var(--tint2)); display:flex; align-items:center; justify-content:center; color:var(--tint-text); flex:0 0 auto;}
.layout-name-input{background:transparent; border:1px solid transparent; border-radius:8px; padding:5px 8px; font-size:14px; font-weight:800; color:var(--text); min-width:0;}
.layout-name-input:hover, .layout-name-input:focus{border-color:var(--border); background:var(--surface2);}
.brand-sub{font-size:10.5px; color:var(--text3);}
.topbar-actions{display:flex; align-items:center; gap:8px; flex-wrap:wrap;}
.account-chip{display:flex; align-items:center; gap:7px; padding:5px 10px 5px 5px; border-radius:999px; border:1px solid var(--border); background:var(--surface2); cursor:pointer; position:relative;}
.account-avatar{width:26px; height:26px; border-radius:50%; background:linear-gradient(135deg,var(--tint),var(--tint2)); color:var(--tint-text); display:flex; align-items:center; justify-content:center; font-weight:800; font-size:11px;}

.subbar{display:flex; align-items:center; justify-content:space-between; gap:12px; padding:9px 20px; border-bottom:1px solid var(--border); background:var(--panel2); flex-wrap:wrap;}
.seg{display:flex; background:var(--surface2); border:1px solid var(--border); border-radius:10px; padding:3px; gap:2px;}
.seg button{background:transparent; border:none; color:var(--text2); font-weight:700; font-size:12px; padding:6px 12px; border-radius:7px; display:flex; align-items:center; gap:6px;}
.seg button.active{background:var(--tint); color:var(--tint-text);}
.subbar-right{display:flex; align-items:center; gap:8px; position:relative;}

.pagebar{display:flex; align-items:center; justify-content:space-between; gap:12px; padding:10px 20px; border-bottom:1px solid var(--border); flex-wrap:wrap;}
.pagebar-left{display:flex; align-items:center; gap:8px;}
.page-picker{font-size:14px; font-weight:800; background:#171a22; color:var(--text); border:1px solid var(--border); border-radius:9px; padding:7px 10px; font-family:inherit; max-width:220px;}
.pagebar-right{display:flex; align-items:center; gap:8px; flex-wrap:wrap;}

.ai-status-banner{margin:0 20px 0; padding:8px 13px; border:1px dashed #4a3a17; background:#1c1a0f; color:#e8c281; border-radius:10px; font-size:11px; display:flex; align-items:center; gap:8px; margin-top:10px;}
.ai-status-banner.ok{border-color:#173a24; background:#0f1c15; color:#93dcb1;}
.ai-status-banner .msym{font-size:15px;}

.main{display:flex; flex:1; min-height:0; gap:0;}
.col{overflow-y:auto;}
.col-lib{width:270px; flex:0 0 auto; border-right:1px solid var(--border); background:var(--panel); padding:14px; display:flex; flex-direction:column; gap:12px;}
.col-canvas{flex:1; min-width:0; background:radial-gradient(circle at 50% 0%, #141826, #0a0c12 60%); display:flex; flex-direction:column; align-items:center; padding:24px 16px 60px;}
.col-props{width:340px; flex:0 0 auto; border-left:1px solid var(--border); background:var(--panel); display:flex; flex-direction:column; min-height:0;}
.col-props.hidden{display:none;}
.main.fullscreen .col-lib, .main.fullscreen .col-props{display:none;}

.lib-group-title{font-size:10px; font-weight:800; letter-spacing:.06em; color:var(--text3); text-transform:uppercase; margin:10px 0 6px;}
.lib-group-title:first-child{margin-top:0;}
.lib-list{display:flex; flex-direction:column; gap:6px;}
.lib-item{display:flex; align-items:center; gap:9px; padding:8px; border:1px solid var(--border); border-radius:11px; background:var(--surface2);}
.lib-item:hover{border-color:var(--tint); cursor:grab;}
.lib-ico{width:28px; height:28px; border-radius:8px; background:#242b3e; color:var(--tint2); display:flex; align-items:center; justify-content:center; flex:0 0 auto;}
.lib-ico .msym{font-size:16px;}
.lib-txt{flex:1; min-width:0;}
.lib-txt .t{font-weight:700; font-size:11.5px;}
.lib-txt .d{font-size:9.5px; color:var(--text3); margin-top:1px;}
.lib-add{width:22px; height:22px; border-radius:6px; border:1px solid var(--border); background:transparent; color:var(--text2); display:flex; align-items:center; justify-content:center; flex:0 0 auto;}
.lib-add:hover{border-color:var(--tint); color:var(--tint);}

/* ---------- Phone canvas ---------- */
.phone{width:340px; height:718px; max-width:100%; border-radius:38px; background:#111318; padding:12px; box-shadow:0 30px 70px rgba(0,0,0,.55), 0 0 0 1px #1c2131; box-sizing:border-box;}
.phone.tablet{width:520px;}
.phone-screen{
  --a-bg:#F5F6FA; --a-surface:#FFFFFF; --a-surface2:#ECEEF2; --a-text:#111827; --a-text2:#6B7280; --a-text3:#9CA3AF;
  --a-border:#E2E4E9; --a-tint:#D9941C; --a-tint-text:#0A0B0D;
  background:var(--a-bg); color:var(--a-text); border-radius:28px; overflow:hidden; display:flex; flex-direction:column; width:100%; height:100%;
}
.status-bar{display:flex; align-items:center; justify-content:space-between; padding:10px 18px 2px; font-size:11px; font-weight:700; color:var(--a-text); flex:0 0 auto;}
.status-bar .msym{font-size:14px;}
.page-header{padding:10px 16px 6px; flex:0 0 auto;}
.page-header .title{font-weight:800; font-size:15px;}
.page-header .subtitle{font-size:11px; color:var(--a-text2); margin-top:1px;}

#canvasRoot{flex:1; min-height:0; overflow-y:auto; -webkit-overflow-scrolling:touch; padding:12px 14px 24px; display:flex; flex-direction:column; gap:10px; background:var(--a-bg); scrollbar-width:none; -ms-overflow-style:none;}
#canvasRoot::-webkit-scrollbar{display:none;}

.bottom-nav{display:flex; justify-content:space-around; align-items:center; padding:9px 8px 12px; background:var(--a-surface); border-top:1px solid var(--a-border); flex:0 0 auto;}
.nav-item{display:flex; flex-direction:column; align-items:center; gap:2px; background:none; border:none; font:inherit; color:var(--a-text3); cursor:pointer; padding:2px 6px;}
.nav-item .msym{font-size:20px;}
.nav-item span{font-size:9px; font-weight:700;}
.nav-item.active{color:var(--a-tint);}

.drop-slot{position:relative;}
.drop-slot.drop-hover{outline:2px dashed var(--a-tint); outline-offset:3px; border-radius:12px; background:rgba(212,175,52,.12);}
.drop-placeholder{border:1.5px dashed var(--a-border); border-radius:12px; padding:14px; text-align:center; font-size:11px; color:var(--a-text3);}

.ls-node{position:relative; border-radius:14px;}
.ls-node.selected{outline:2px solid #D9941C; outline-offset:2px;}
.ls-del{position:absolute; top:-8px; right:-8px; width:20px; height:20px; border-radius:50%; background:#241014; border:1px solid #4a2027; color:#ff8a8a; font-size:13px; line-height:1; display:none; align-items:center; justify-content:center; z-index:5;}
.ls-node:hover > .ls-del{display:flex;}

.ln-row{display:flex; gap:10px;}
.ln-column{display:flex; flex-direction:column; gap:8px;}
.ln-grid{display:grid; gap:10px;}
.ln-carousel{display:flex; gap:10px; overflow-x:auto; padding-bottom:2px;}
.ln-carousel::-webkit-scrollbar{display:none;}
.ln-card{border:1px solid var(--a-border); background:var(--a-surface); border-radius:18px; padding:14px;}
.ln-card-empty{color:var(--a-text3); font-size:10.5px;}

.ln-tabs{border:1px solid var(--a-border); border-radius:14px; background:var(--a-surface); overflow:hidden;}
.ln-tabs-head{display:flex; gap:6px; padding:8px; overflow-x:auto;}
.ln-tabs-head button{flex:0 0 auto; padding:6px 12px; border-radius:999px; border:1px solid var(--a-border); background:var(--a-bg); color:var(--a-text2); font-size:11px; font-weight:700; display:flex; align-items:center; gap:5px;}
.ln-tabs-head button.active{background:var(--a-tint); color:var(--a-tint-text); border-color:var(--a-tint);}
.ln-tabs-body{padding:10px; display:flex; flex-direction:column; gap:8px;}

.dev-card{width:98px; border:1.5px solid var(--a-border); border-radius:16px; background:var(--a-surface); padding:9px; display:flex; flex-direction:column; gap:6px; flex:0 0 auto;}
.dev-card .msym{font-size:18px; color:var(--a-text2);}
.dev-card .nm{font-size:10.5px; font-weight:700; color:var(--a-text); line-height:1.2;}
.dev-card .sub{font-size:9px; color:var(--a-text3);}

.ln-text{line-height:1.35;}
.ln-btn{display:inline-flex; align-items:center; gap:7px; padding:9px 14px; border-radius:11px; background:var(--a-tint); color:var(--a-tint-text); font-size:12px; font-weight:700; cursor:pointer;}
.ln-toggle{display:flex; align-items:center; justify-content:space-between; gap:8px; padding:10px 12px; border:1px solid var(--a-border); border-radius:12px; background:var(--a-surface); font-size:11.5px; font-weight:600;}
.ln-toggle .switch{width:34px; height:19px; border-radius:999px; background:var(--a-border); position:relative; flex:0 0 auto;}
.ln-toggle .switch i{position:absolute; top:2px; left:2px; width:15px; height:15px; border-radius:50%; background:#fff;}
.ln-slider{padding:9px 12px; border:1px solid var(--a-border); border-radius:12px; background:var(--a-surface);}
.ln-slider .lbl{font-size:10.5px; color:var(--a-text2); margin-bottom:6px; font-weight:700;}
.ln-slider .track{height:6px; border-radius:4px; background:var(--a-surface2);}
.ln-gauge{display:flex; flex-direction:column; align-items:center; gap:6px; padding:12px; border:1px solid var(--a-border); border-radius:14px; background:var(--a-surface);}
.ln-gauge .ring{width:52px; height:52px; border-radius:50%; border:6px solid var(--a-tint); display:flex; align-items:center; justify-content:center; font-size:10px; font-weight:800;}
.ln-stepper{display:flex; align-items:center; justify-content:space-between; padding:9px 12px; border:1px solid var(--a-border); border-radius:12px; background:var(--a-surface); font-weight:700; font-size:12px;}
.ln-stepper button{width:24px; height:24px; border-radius:50%; border:1px solid var(--a-border); background:transparent; color:var(--a-text2);}
.ln-card-element{display:flex; align-items:center; gap:10px; padding:11px; border:1px solid var(--a-border); border-radius:14px; background:var(--a-surface);}
.ln-card-element .msym{font-size:19px; color:var(--a-text2);}
.ln-singleton{border:1.5px dashed var(--a-border); border-radius:14px; padding:14px; text-align:center; color:var(--a-text2); font-size:11px; display:flex; flex-direction:column; align-items:center; gap:4px;}
.ln-singleton .msym{font-size:20px; color:var(--a-tint);}

/* ---------- cột thuộc tính ---------- */
.right-tabs{display:flex; border-bottom:1px solid var(--border);}
.right-tabs button{flex:1; padding:11px; background:transparent; border:none; color:var(--text3); font-weight:700; font-size:12px; display:flex; align-items:center; justify-content:center; gap:6px; border-bottom:2px solid transparent;}
.right-tabs button.active{color:var(--text); border-bottom-color:var(--tint);}
.right-tab-pane{flex:1; min-height:0; overflow-y:auto; padding:14px; display:flex; flex-direction:column; gap:12px;}
.props-empty{font-size:12px; color:var(--text3); line-height:1.5; padding:6px 2px;}
.props-kicker{font-size:10px; font-weight:800; letter-spacing:.06em; text-transform:uppercase; color:var(--tint2); background:#2a2211; display:inline-block; padding:4px 9px; border-radius:6px; width:fit-content;}
.props-id{font-size:10px; color:var(--text3); font-family:'SFMono-Regular',Consolas,monospace;}
.props-section-title{font-size:11px; font-weight:800; color:var(--text2); margin:6px 0 -2px; display:flex; align-items:center; justify-content:space-between;}
.props-actions{display:flex; gap:8px; margin-top:4px;}
.props-actions button{flex:1; display:flex; align-items:center; justify-content:center; gap:5px; padding:8px; border-radius:9px; border:1px solid var(--border); background:var(--surface2); color:var(--text); font-size:11px; font-weight:700;}
.props-actions button.danger{color:#ff8a8a; border-color:#4a2027;}
.props-close{background:transparent; border:none; color:var(--text3); font-size:16px;}
.checkbox-row{display:flex; align-items:center; gap:8px; font-size:12px; color:var(--text2);}

.ai-banner{font-size:11px; color:var(--text3); background:var(--surface2); border:1px solid var(--border); border-radius:10px; padding:9px 11px; line-height:1.4;}
.ai-log{flex:1; min-height:160px; display:flex; flex-direction:column; gap:8px; overflow-y:auto;}
.ai-msg{font-size:12px; line-height:1.45; padding:9px 11px; border-radius:11px; max-width:92%; white-space:pre-wrap;}
.ai-msg.ai-user{align-self:flex-end; background:var(--tint); color:var(--tint-text); border-bottom-right-radius:3px;}
.ai-msg.ai-assistant{align-self:flex-start; background:var(--surface2); border:1px solid var(--border); border-bottom-left-radius:3px;}
.ai-msg.ai-thinking{color:var(--text3); font-style:italic;}
.ai-inputrow{display:flex; gap:8px; align-items:flex-end;}
.ai-inputrow textarea{flex:1; background:var(--surface2); border:1px solid var(--border); border-radius:10px; padding:9px 10px; color:var(--text); resize:none; min-height:40px; max-height:110px; outline:none;}
.ai-inputrow textarea:focus{border-color:var(--tint);}
.ai-inputrow button{padding:10px 14px; border-radius:10px; border:none; background:var(--tint); color:var(--tint-text); font-weight:800; display:flex; align-items:center; gap:6px;}
.ai-inputrow button[disabled]{opacity:.5;}

/* ---------- dropdown / modal / toast ---------- */
.dropdown{position:absolute; top:calc(100% + 6px); right:0; background:var(--panel2); border:1px solid var(--border); border-radius:12px; box-shadow:0 18px 38px rgba(0,0,0,.5); min-width:190px; padding:6px; z-index:40; display:none;}
.dropdown.open{display:block;}
.dropdown button{display:flex; align-items:center; gap:9px; width:100%; text-align:left; padding:9px 10px; background:transparent; border:none; color:var(--text); border-radius:8px; font-size:12.5px;}
.dropdown button:hover{background:var(--surface2);}
.dropdown .msym{font-size:17px; color:var(--text2);}

.modal-overlay{position:fixed; inset:0; background:rgba(4,5,9,.7); display:none; align-items:center; justify-content:center; z-index:100; padding:20px;}
.modal-overlay.open{display:flex;}
.modal-box{background:var(--panel2); border:1px solid var(--border); border-radius:16px; max-width:560px; width:100%; max-height:85vh; display:flex; flex-direction:column; overflow:hidden;}
.modal-head{display:flex; align-items:center; justify-content:space-between; padding:14px 16px; border-bottom:1px solid var(--border);}
.modal-head h3{margin:0; font-size:14.5px;}
.modal-body{padding:16px; overflow-y:auto; font-size:12.5px; line-height:1.6; color:var(--text2); display:flex; flex-direction:column; gap:14px;}
.modal-body textarea{width:100%; min-height:220px; background:#05070c; border:1px solid var(--border); border-radius:10px; color:#c9e6b0; font-family:'SFMono-Regular',Consolas,monospace; font-size:11px; padding:10px; outline:none;}
.modal-foot{display:flex; justify-content:flex-end; gap:8px; padding:12px 16px; border-top:1px solid var(--border);}
.tab-strip{display:flex; gap:6px; margin-bottom:4px;}
.tab-strip button{padding:6px 12px; border-radius:8px; border:1px solid var(--border); background:var(--surface2); color:var(--text2); font-size:11.5px; font-weight:700;}
.tab-strip button.active{background:var(--tint); color:var(--tint-text); border-color:var(--tint);}

.toast{position:fixed; left:50%; bottom:26px; transform:translateX(-50%) translateY(12px); background:#171b26; border:1px solid var(--border); color:var(--text); padding:10px 16px; border-radius:11px; font-size:12.5px; opacity:0; pointer-events:none; transition:opacity .2s ease, transform .2s ease; z-index:200; max-width:88vw; text-align:center;}
.toast.show{opacity:1; transform:translateX(-50%) translateY(0);}

@media (max-width: 900px){
  .col-lib, .col-props{position:fixed; top:0; bottom:0; z-index:30; width:82vw; max-width:320px;}
  .col-lib{left:0; transform:translateX(-100%); transition:transform .2s ease;}
  .col-props{right:0; transform:translateX(100%); transition:transform .2s ease;}
  .col-lib.open{transform:translateX(0);}
  .col-props.open{transform:translateX(0);}
}
